From 83d4a5410a8ed97ebe2d193c0703a2c2fa968ec1 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Thu, 18 Jun 2015 09:21:10 +0100 Subject: Preliminary merge secondary implementation. --- src/db.erl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/db.erl') diff --git a/src/db.erl b/src/db.erl index f53cd19..feb864b 100644 --- a/src/db.erl +++ b/src/db.erl @@ -8,6 +8,8 @@ -export([start_link/0, stop/0]). -export([create_size_table/0]). -export([add/2, add_entryhash/2, add_index_nosync/2, set_treesize/1, size/0]). +-export([add_index_nosync_noreverse/2]). +-export([verifiedsize/0, set_verifiedsize/1]). -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]). @@ -26,6 +28,9 @@ size() -> [{_, Size}] = ets:lookup(?DB_SIZE_TABLE, db_size), Size. +verifiedsize() -> + binary_to_integer(atomic:readfile(verifiedsize_path())). + indexsize() -> index:indexsize(index_path()). @@ -65,11 +70,19 @@ add_entryhash(LeafHash, EntryHash) -> add_index_nosync(LeafHash, Index) -> call(?MODULE, {add_index_nosync, {LeafHash, Index}}). +-spec add_index_nosync_noreverse(binary(), non_neg_integer()) -> ok. +add_index_nosync_noreverse(LeafHash, Index) -> + call(?MODULE, {add_index_nosync_noreverse, {LeafHash, Index}}). + -spec set_treesize(non_neg_integer()) -> ok. set_treesize(Size) -> true = ets:insert(?DB_SIZE_TABLE, {db_size, Size}), ok. +-spec set_verifiedsize(non_neg_integer()) -> ok. +set_verifiedsize(Size) -> + ok = atomic:replacefile(verifiedsize_path(), integer_to_binary(Size)). + -spec get_by_indices(integer(), integer(), {sorted, true|false}) -> [{non_neg_integer(), binary(), notfetched}]. get_by_indices(Start, End, {sorted, _Sorted}) -> @@ -151,6 +164,11 @@ 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), + Value. + entry_for_leafhash(LeafHash) -> perm:readfile(entry_root_path(), LeafHash). @@ -192,6 +210,10 @@ handle_call({add_index_nosync, {LeafHash, Index}}, _From, State) -> ok = perm:ensurefile_nosync(indexforhash_root_path(), LeafHash, integer_to_binary(Index)), ok = index:add_nosync(index_path(), Index, LeafHash), + {reply, ok, State}; + +handle_call({add_index_nosync_noreverse, {LeafHash, Index}}, _From, State) -> + ok = index:add_nosync(index_path(), Index, LeafHash), {reply, ok, State}. indexforhash_sync(LeafHash, Index) -> -- cgit v1.1