summaryrefslogtreecommitdiff
path: root/src/index.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-02-02 14:37:22 +0100
committerMagnus Ahltorp <map@kth.se>2015-02-19 12:33:51 +0100
commite5d870308d6e71dd12f46ec4745640e6e75d43d9 (patch)
tree50f01c07b984da3ca0b1d27455fededd4bde9c2b /src/index.erl
parenta287b6c12c4d81b9fd09dd4ae9a85d8f6eef1cb9 (diff)
Only serialize the actual write on storagedb, not the fsync
Diffstat (limited to 'src/index.erl')
-rw-r--r--src/index.erl14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/index.erl b/src/index.erl
index c0e344a..9d0df96 100644
--- a/src/index.erl
+++ b/src/index.erl
@@ -12,7 +12,7 @@
%% TODO: Checksums
-module(index).
--export([get/2, getrange/3, add/3, add_nosync/3, addlast/2, indexsize/1]).
+-export([get/2, getrange/3, add/3, add_nosync/3, addlast_nosync/2, indexsize/1, sync/1]).
-define(ENTRYSIZE, 32).
-define(ENTRYSIZEINFILE, (?ENTRYSIZE*2+1)).
@@ -64,7 +64,7 @@ add(Basepath, Index, Entry, Syncflag) when is_binary(Entry), size(Entry) == ?ENT
ok = file:close(File),
case Syncflag of
sync ->
- util:fsync([Basepath, filename:dirname(Basepath)]);
+ sync(Basepath);
nosync ->
ok
end;
@@ -74,9 +74,13 @@ add(Basepath, Index, Entry, Syncflag) when is_binary(Entry), size(Entry) == ?ENT
end.
--spec addlast(string(), integer()) -> ok.
-addlast(Basepath, Entry) ->
- add(Basepath, last, Entry).
+-spec sync(string()) -> ok.
+sync(Basepath) ->
+ util:fsync([Basepath, filename:dirname(Basepath)]).
+
+-spec addlast_nosync(string(), integer()) -> ok.
+addlast_nosync(Basepath, Entry) ->
+ add_nosync(Basepath, last, Entry).
decodedata(Binary) ->
lists:reverse(decodedata(Binary, [])).