diff options
author | Magnus Ahltorp <map@kth.se> | 2014-10-20 12:22:50 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-10-29 14:59:30 +0100 |
commit | 92a84310aaabdb44c523ba90aa38aecce2314a63 (patch) | |
tree | dc696eebc5512359060ef39da99da7458bbd6fb7 /src/db.erl | |
parent | 3e80686736e9b1f717cf2a3d32eccb30d397f2c7 (diff) |
Added HTTP API:s for external merge
Diffstat (limited to 'src/db.erl')
-rw-r--r-- | src/db.erl | 38 |
1 files changed, 36 insertions, 2 deletions
@@ -6,8 +6,8 @@ %% API. -export([start_link/0, stop/0]). --export([add/4, size/0]). --export([get_by_index/1, get_by_indices/3, get_by_leaf_hash/1, get_by_entry_hash/1]). +-export([add/4, add/2, add_entryhash/2, add_index/2, set_treesize/1, size/0]). +-export([get_by_index/1, get_by_indices/3, get_by_leaf_hash/1, get_by_entry_hash/1, entry_for_leafhash/1, leafhash_for_index/1]). %% gen_server callbacks. -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). @@ -34,6 +34,22 @@ stop() -> add(LeafHash, EntryHash, Data, Index) -> gen_server:call(?MODULE, {add, {LeafHash, EntryHash, Data, Index}}). +-spec add(binary(), binary()) -> ok. +add(LeafHash, Data) -> + gen_server:call(?MODULE, {add, {LeafHash, Data}}). + +-spec add_entryhash(binary(), binary()) -> ok. +add_entryhash(LeafHash, EntryHash) -> + gen_server:call(?MODULE, {add_entryhash, {LeafHash, EntryHash}}). + +-spec add_index(binary(), non_neg_integer()) -> ok. +add_index(LeafHash, Index) -> + gen_server:call(?MODULE, {add_index, {LeafHash, Index}}). + +-spec set_treesize(non_neg_integer()) -> ok. +set_treesize(Size) -> + gen_server:call(?MODULE, {set_treesize, Size}). + -spec get_by_indices(integer(), integer(), {sorted, true|false}) -> [{non_neg_integer(), binary(), binary()}]. get_by_indices(Start, End, {sorted, Sorted}) -> @@ -145,6 +161,24 @@ handle_call({add, {LeafHash, EntryHash, Data, Index}}, _From, State) -> ok = atomic:replacefile(treesize_path(), integer_to_list(Index+1)), {reply, ok, State}; +handle_call({add, {LeafHash, Data}}, _From, State) -> + ok = perm:ensurefile(entry_root_path(), LeafHash, Data), + {reply, ok, State}; + +handle_call({add_entryhash, {LeafHash, EntryHash}}, _From, State) -> + ok = perm:ensurefile(entryhash_root_path(), EntryHash, LeafHash), + {reply, ok, State}; + +handle_call({add_index, {LeafHash, Index}}, _From, State) -> + ok = perm:ensurefile(indexforhash_root_path(), + LeafHash, integer_to_binary(Index)), + ok = index:add(index_path(), Index, LeafHash), + {reply, ok, State}; + +handle_call({set_treesize, Size}, _From, State) -> + ok = atomic:replacefile(treesize_path(), integer_to_list(Size)), + {reply, ok, State}; + handle_call({get_by_indices, {Start, End, _Sorted}}, _From, State) -> {reply, get_by_indices_helper(Start, End), State}; |