Commits

Anonymous committed e1357f0

fix get_merkle in vnode

Comments (0)

Files changed (1)

apps/riak/src/riak_vnode.erl

     end.
 
 %% @private
+get_merkle(_State=#state{mod=Mod,modstate=ModState}) ->
+    KeyList = Mod:list(ModState),
+    Merk0 = merkerl:build_tree([]),
+    get_merk(Mod,ModState,KeyList,Merk0).
+%% @private
+get_merk(_Mod,_ModState,[],Merk) -> Merk;
+get_merk(Mod,ModState,[BKey|KeyList],Merk) ->
+    V = Mod:get(ModState,BKey), % normally, V = {ok,BinObj}
+    get_merk(Mod,ModState,KeyList,merkerl:insert({BKey,erlang:phash2(V)},Merk)).
+
+%% @private
 get_vclocks(KeyList,_State=#state{mod=Mod,modstate=ModState}) ->
     [{BKey, get_vclock(BKey,Mod,ModState)} || BKey <- KeyList].
 %% @private
 code_change(_OldVsn, StateName, State, _Extra) -> {ok, StateName, State}.
 
 %% @private
+handle_event({get_merkle, From}, StateName, State) ->
+    gen_server2:reply(From, get_merkle(State)),
+    {next_state, StateName, State, ?TIMEOUT};
 handle_event({get_vclocks, From, KeyList}, StateName, State) ->
     gen_server2:reply(From, get_vclocks(KeyList, State)),
     {next_state, StateName, State, ?TIMEOUT};