diff options
author | Magnus Ahltorp <map@kth.se> | 2014-09-26 10:28:47 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2014-09-26 10:28:47 +0200 |
commit | 9c0d01c3059a7f82ac9acd5574755feed2f351a8 (patch) | |
tree | 72465f4872d7400123c86bc4067201af8cd91ccb /src | |
parent | 7fe4225f5969d0c5135363dcfa99d7511100a0b8 (diff) |
index: Added fsyncfsync3
Diffstat (limited to 'src')
-rw-r--r-- | src/index.erl | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/index.erl b/src/index.erl index 5382485..5fd468b 100644 --- a/src/index.erl +++ b/src/index.erl @@ -7,6 +7,10 @@ %% that stores an ordered list of fixed-size entries. Entries can be %% added at the end and are retrieved by index. The list can also be %% truncated. +%% +%% Writes(add, truncate, addlast) need to be serialized. + +%% TODO: Checksums -module(index). -export([get/2, add/3, addlast/2, truncate/2]). @@ -28,7 +32,8 @@ add(Basepath, Index, Entry) when is_binary(Entry), size(Entry) == ?ENTRYSIZE -> end, EntryText = hex:bin_to_hexstr(Entry) ++ "\n", ok = file:write(File, EntryText), - file:close(File); + ok = file:close(File), + util:fsync([Basepath, filename:dirname(Basepath)]); {error, Error} -> util:exit_with_error(Error, writefile, "Error opening file for writing") @@ -39,7 +44,8 @@ truncate(Basepath, Index) -> {ok, File} -> {ok, _Position} = file:position(File, Index * ?ENTRYSIZEINFILE), ok = file:truncate(File), - file:close(File); + ok = file:close(File), + util:fsync([Basepath, filename:dirname(Basepath)]); {error, Error} -> util:exit_with_error(Error, writefile, "Error opening file for writing") |