diff options
author | Magnus Ahltorp <map@kth.se> | 2015-09-24 16:38:03 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2015-11-11 13:32:36 +0100 |
commit | 90760d10d14c11ee4c99826163c206bbf20a77f6 (patch) | |
tree | 5965c6bb108538507464d98595cc631dd9441aa7 /src/db.erl | |
parent | 346a3f973b828abc21cffb8a0a976daddcabe492 (diff) |
Change perm interface to be add/commit based
Diffstat (limited to 'src/db.erl')
-rw-r--r-- | src/db.erl | 37 |
1 files changed, 11 insertions, 26 deletions
@@ -14,7 +14,7 @@ -export([get_by_index/1, get_by_indices/3, get_by_leaf_hash/1]). -export([get_by_entry_hash/1, entry_for_leafhash/1, leafhash_for_index/1]). -export([leafhash_for_indices/2, indexsize/0]). --export([indexforhash_sync/2, indexforhash_nosync/2, index_sync/0]). +-export([indexforhash_nosync/2, indexforhash_dosync/0, index_sync/0]). %% gen_server callbacks. -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). @@ -78,13 +78,14 @@ stop() -> -spec add(binary(), binary()) -> ok. add(LeafHash, Data) -> lager:debug("add leafhash ~s", [mochihex:to_hex(LeafHash)]), - ok = perm:ensurefile(entry_root_path(), LeafHash, Data), + ok = perm:addvalue(entry_db, LeafHash, Data), + perm:commit(entry_db), lager:debug("leafhash ~s added", [mochihex:to_hex(LeafHash)]), ok. -spec add_entryhash(binary(), binary()) -> ok | differ. add_entryhash(LeafHash, EntryHash) -> - perm:ensurefile_nosync(entryhash_root_path(), EntryHash, LeafHash). + perm:addvalue(entryhash_db, EntryHash, LeafHash). -spec add_index_nosync_noreverse(binary(), non_neg_integer()) -> ok. add_index_nosync_noreverse(LeafHash, Index) -> @@ -168,26 +169,11 @@ terminate(_Reason, _State) -> %%%%%%%%%%%%%%%%%%%% %% The meat. -% Table for Leaf hash -> Entry -entry_root_path() -> - {ok, Value} = application:get_env(plop, entry_root_path), - Value. - -% Table for Leaf hash -> Entry -indexforhash_root_path() -> - {ok, Value} = application:get_env(plop, indexforhash_root_path), - Value. - % Table for Index -> Leaf hash index_path() -> {ok, Value} = application:get_env(plop, index_path), Value. -% Table for Entry hash -> Leaf hash -entryhash_root_path() -> - {ok, Value} = application:get_env(plop, entryhash_root_path), - Value. - % File that stores the number of verified entries verifiedsize_path() -> {ok, Value} = application:get_env(plop, verifiedsize_path), @@ -199,10 +185,10 @@ sendsth_verified_path() -> Value. entry_for_leafhash(LeafHash) -> - perm:readfile(entry_root_path(), LeafHash). + perm:getvalue(entry_db, LeafHash). index_for_leafhash(LeafHash) -> - case perm:readfile(indexforhash_root_path(), LeafHash) of + case perm:getvalue(indexforhash_db, LeafHash) of noentry -> noentry; Index -> @@ -216,7 +202,7 @@ leafhash_for_indices(Start, End) -> index:getrange(index_path(), Start, End). leafhash_for_entryhash(EntryHash) -> - perm:readfile(entryhash_root_path(), EntryHash). + perm:getvalue(entryhash_db, EntryHash). get_by_indices_helper(Start, _End) when Start < 0 -> []; @@ -240,13 +226,12 @@ handle_call({add_index_nosync_noreverse, {LeafHash, Index}}, _From, State) -> {reply, ok, State}. indexforhash_nosync(LeafHash, Index) -> - ok = perm:ensurefile_nosync(indexforhash_root_path(), - LeafHash, integer_to_binary(Index)), + ok = perm:addvalue(indexforhash_db, + LeafHash, integer_to_binary(Index)), ok. -indexforhash_sync(LeafHash, Index) -> - ok = perm:ensurefile(indexforhash_root_path(), - LeafHash, integer_to_binary(Index)), +indexforhash_dosync() -> + perm:commit(indexforhash_db, 300000), ok. index_sync() -> |