From b5e8dd9ab57c8a971ea169b5212aceaa8326c7b7 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Mon, 2 Feb 2015 14:37:22 +0100 Subject: Only serialize the actual write on storagedb, not the fsync --- src/index.erl | 14 +++++++++----- src/storagedb.erl | 8 +++++--- 2 files changed, 14 insertions(+), 8 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, [])). diff --git a/src/storagedb.erl b/src/storagedb.erl index 444abc1..9cdf4c1 100644 --- a/src/storagedb.erl +++ b/src/storagedb.erl @@ -36,7 +36,9 @@ fetchnewhashes(Index) -> -spec add(binary()) -> ok. add(LeafHash) -> - call(?MODULE, {add, LeafHash}). + ok = call(?MODULE, {add_nosync, LeafHash}), + ok = index:sync(newentries_path()), + ok. %%%%%%%%%%%%%%%%%%%% %% gen_server callbacks. @@ -63,6 +65,6 @@ newentries_path() -> handle_call(stop, _From, State) -> {stop, normal, stopped, State}; -handle_call({add, LeafHash}, _From, State) -> - ok = index:addlast(newentries_path(), LeafHash), +handle_call({add_nosync, LeafHash}, _From, State) -> + ok = index:addlast_nosync(newentries_path(), LeafHash), {reply, ok, State}. -- cgit v1.1