From 9c0d01c3059a7f82ac9acd5574755feed2f351a8 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Fri, 26 Sep 2014 10:28:47 +0200 Subject: index: Added fsync --- src/index.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/index.erl') 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") -- cgit v1.1