Anonymous avatar Anonymous committed 049a806

add get_merkle and get_vclocks vnode calls to support TCP replication

Comments (0)

Files changed (2)

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
+get_vclock(BKey,Mod,ModState) ->
+    case Mod:get(ModState, BKey) of
+        {error, notfound} -> vclock:fresh();
+        {ok, Val} -> riak_object:vclock(binary_to_term(Val))
+    end.
+
+%% @private
 code_change(_OldVsn, StateName, State, _Extra) -> {ok, StateName, State}.
 
 %% @private
-handle_event(_Event, _StateName, StateData) ->
-    {stop,badmsg,StateData}.
+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}.
 
 %% @private
 handle_sync_event(_Event, _From, _StateName, StateData) ->

src/riak_vnode_master.erl

              {BKey,ReqID}}, From, State) ->
     Pid = get_vnode(Partition, State),
     gen_fsm:send_event(Pid, {delete, From, BKey, ReqID}),
+    {noreply, State};
+handle_call({get_merkle, Partition}, From, State) ->
+    Pid = get_vnode(Partition, State),
+    spawn(fun() -> gen_fsm:send_all_state_event(Pid, {get_merkle, From}) end),
+    {noreply, State};
+handle_call({get_vclocks,Partition,KeyList},From,State) ->
+    Pid = get_vnode(Partition, State),
+    spawn(fun() -> gen_fsm:send_all_state_event(
+                     Pid,{get_vclocks,From,KeyList}) end),
     {noreply, State}.
 
 %% @private
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.