Commits

Anonymous committed 19e2625

new vnode calls to support per-vnode replication

Comments (0)

Files changed (2)

src/riak_vnode.erl

                 sidekick=Sidekick,mapcache=Cache,mod=Mod,modstate=ModState}}.
 
 %% @private
+handle_cast({get_merkle,From},State) ->
+    gen_server2:reply(From, get_merkle(State)),
+    {noreply, State};
+handle_cast({get_vclocks, From, KeyList},State) ->
+    gen_server2:reply(From, get_vclocks(KeyList,State)),
+    {noreply, State};
 handle_cast({mapcache,BKey,{M,F,Arg,KeyData},MF_Res},
             State=#state{mapcache=Cache}) ->
     KeyCache0 = case dict:find(BKey, Cache) of
     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
 handle_info(_Msg, State) -> {noreply, State}.
 
 %% @private

src/riak_vnode_master.erl

 
 
 %% @private
-handle_call(all_possible_vnodes, _From, State) ->
-    {reply, make_all_active(State), State};
+handle_call({get_merkle,Partition},From,State) ->
+    Pid = get_vnode(Partition, State),
+    spawn(fun() -> gen_server2:cast(Pid,{get_merkle,From}) end),
+    {noreply, State};
+handle_call({get_vclocks,Partition,KeyList},From,State) ->
+    Pid = get_vnode(Partition, State),
+    spawn(fun() -> gen_server2:cast(Pid,{get_vclocks,From,KeyList}) end),
+    {noreply, State};
 handle_call(all_vnodes, _From, State) ->
     {reply, all_vnodes(State), State};
 handle_call({vnode_del, {Partition,_Node},
 all_vnodes(_State=#state{idxtab=T}) ->
     lists:flatten(ets:match(T, {idxrec, '_', '$1', '_'})).
 
-make_all_active(State) ->
-    {ok, Ring} = riak_ring_manager:get_my_ring(),
-    [{I,get_vnode(I,State)} || I <- riak_ring:my_indices(Ring)].
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.