summaryrefslogtreecommitdiff
path: root/src/db.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.erl')
-rw-r--r--src/db.erl37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/db.erl b/src/db.erl
index 8c096a1..0b9e9a2 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -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() ->