summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-11-14 23:16:42 +0100
committerMagnus Ahltorp <map@kth.se>2014-11-19 05:03:19 +0100
commitf8902f7899b4d76cabbf65763866d1a28fbcf743 (patch)
tree34dc786c30f603041ce02113cbfe2f86e8c2b136 /src
parented641d942ce265bd12913713794cd2221b312733 (diff)
Remove support for internal merge
Diffstat (limited to 'src')
-rw-r--r--src/db.erl102
-rw-r--r--src/plop.erl6
2 files changed, 35 insertions, 73 deletions
diff --git a/src/db.erl b/src/db.erl
index 943c70e..1c5c21f 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -6,7 +6,7 @@
%% API.
-export([start_link/0, stop/0]).
--export([add/4, add/2, add_entryhash/2, add_index/2, set_treesize/1, size/0]).
+-export([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]).
-export([get_by_entry_hash/1, entry_for_leafhash/1, leafhash_for_index/1]).
-export([leafhash_for_indices/2, indexsize/0]).
@@ -36,17 +36,17 @@ stop() ->
%%%%%%%%%%%%%%%%%%%%
%% Public API.
--spec add(binary(), binary(), binary(), non_neg_integer()) -> ok.
-add(LeafHash, EntryHash, Data, Index) ->
- call(?MODULE, {add, {LeafHash, EntryHash, Data, Index}}).
-
-spec add(binary(), binary()) -> ok.
add(LeafHash, Data) ->
- call(?MODULE, {add, {LeafHash, Data}}).
+ lager:debug("add leafhash ~p", [LeafHash]),
+ ok = perm:ensurefile(entry_root_path(), LeafHash, Data),
+ lager:debug("leafhash ~p added", [LeafHash]),
+ ok.
-spec add_entryhash(binary(), binary()) -> ok.
add_entryhash(LeafHash, EntryHash) ->
- call(?MODULE, {add_entryhash, {LeafHash, EntryHash}}).
+ ok = perm:ensurefile(entryhash_root_path(), EntryHash, LeafHash),
+ ok.
-spec add_index(binary(), non_neg_integer()) -> ok.
add_index(LeafHash, Index) ->
@@ -54,27 +54,46 @@ add_index(LeafHash, Index) ->
-spec set_treesize(non_neg_integer()) -> ok.
set_treesize(Size) ->
- call(?MODULE, {set_treesize, Size}).
+ ok = atomic:replacefile(treesize_path(), integer_to_binary(Size)).
-spec get_by_indices(integer(), integer(), {sorted, true|false}) ->
[{non_neg_integer(), binary(), binary()}].
get_by_indices(Start, End, {sorted, Sorted}) ->
- call(?MODULE, {get_by_indices, {Start, End, Sorted}}).
+ get_by_indices_helper(Start, End).
-spec get_by_index(binary()) -> notfound |
{non_neg_integer(), binary(), binary()}.
get_by_index(Index) ->
- call(?MODULE, {get_by_index, Index}).
+ LeafHash = leafhash_for_index(Index),
+ Entry = entry_for_leafhash(LeafHash),
+ {Index, LeafHash, Entry}.
-spec get_by_leaf_hash(binary()) -> notfound |
{non_neg_integer(), binary(), binary()}.
get_by_leaf_hash(LeafHash) ->
- call(?MODULE, {get_by_leaf_hash, LeafHash}).
+ case entry_for_leafhash(LeafHash) of
+ noentry ->
+ notfound;
+ Entry ->
+ case index_for_leafhash(LeafHash) of
+ noentry ->
+ notfound;
+ Index ->
+ {Index, LeafHash, Entry}
+ end
+ end.
-spec get_by_entry_hash(binary()) -> notfound |
{non_neg_integer(), binary(), binary()}.
get_by_entry_hash(EntryHash) ->
- call(?MODULE, {get_by_entry_hash, EntryHash}).
+ case leafhash_for_entryhash(EntryHash) of
+ noentry ->
+ notfound;
+ LeafHash ->
+ Entry = entry_for_leafhash(LeafHash),
+ %% Don't fetch index, isn't used and might not exist
+ {notfetched, LeafHash, Entry}
+ end.
%%%%%%%%%%%%%%%%%%%%
%% gen_server callbacks.
@@ -158,65 +177,8 @@ get_by_indices_helper(Start, End) ->
handle_call(stop, _From, State) ->
{stop, normal, stopped, State};
-handle_call({add, {LeafHash, EntryHash, Data, Index}}, _From, State) ->
- ok = perm:ensurefile(entry_root_path(), LeafHash, Data),
- ok = perm:ensurefile(entryhash_root_path(), EntryHash, LeafHash),
- ok = perm:ensurefile(indexforhash_root_path(),
- LeafHash, integer_to_binary(Index)),
- ok = index:add(index_path(), Index, LeafHash),
- ok = atomic:replacefile(treesize_path(), integer_to_binary(Index+1)),
- {reply, ok, State};
-
-handle_call({add, {LeafHash, Data}}, _From, State) ->
- lager:debug("add leafhash ~p", [LeafHash]),
- ok = perm:ensurefile(entry_root_path(), LeafHash, Data),
- lager:debug("leafhash ~p added", [LeafHash]),
- {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_binary(Size)),
- {reply, ok, State};
-
-handle_call({get_by_indices, {Start, End, _Sorted}}, _From, State) ->
- {reply, get_by_indices_helper(Start, End), State};
-
-handle_call({get_by_index, Index}, _From, State) ->
- LeafHash = leafhash_for_index(Index),
- Entry = entry_for_leafhash(LeafHash),
- R = {Index, LeafHash, Entry},
- {reply, R, State};
-
-handle_call({get_by_leaf_hash, LeafHash}, _From, State) ->
- R = case entry_for_leafhash(LeafHash) of
- noentry ->
- notfound;
- Entry ->
- case index_for_leafhash(LeafHash) of
- noentry ->
- notfound;
- Index ->
- {Index, LeafHash, Entry}
- end
- end,
- {reply, R, State};
-
-handle_call({get_by_entry_hash, EntryHash}, _From, State) ->
- R = case leafhash_for_entryhash(EntryHash) of
- noentry ->
- notfound;
- LeafHash ->
- Entry = entry_for_leafhash(LeafHash),
- %% Don't fetch index, isn't used and might not exist
- {notfetched, LeafHash, Entry}
- end,
- {reply, R, State}.
+ {reply, ok, State}.
diff --git a/src/plop.erl b/src/plop.erl
index d363582..b1ad658 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -121,11 +121,13 @@ handle_http_reply(State, {storage_sendentry_http, {OwnRequestId}},
case RepliesUntilQuorum - 1 of
0 ->
%% reached quorum
+ lager:debug("reached quorum"),
gen_server:reply(From, ok),
StateWithCompletion = Completion(State),
{noreply, remove_own_request(StateWithCompletion,
OwnRequestId)};
NewRepliesUntilQuorum ->
+ lager:debug("replies until quorum: ~p", [NewRepliesUntilQuorum]),
{noreply, add_own_request(State, OwnRequestId,
{storage_sendentry,
{From, Completion,
@@ -272,9 +274,7 @@ handle_call({add, {LogEntry, TreeLeafHash, EntryHash}}, From, Plop) ->
lager:debug("add leafhash ~p", [TreeLeafHash]),
case storage_nodes() of
[] ->
- ok = db:add(TreeLeafHash, EntryHash, LogEntry, ht:size()),
- ok = ht:add(TreeLeafHash),
- {reply, ok, Plop};
+ exit(internal_merge_not_supported);
Nodes ->
{noreply,
store_at_all_nodes(Nodes, {LogEntry, TreeLeafHash, EntryHash},