Skip to content

Instantly share code, notes, and snippets.

@cdahlqvist
Created June 28, 2013 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdahlqvist/5885692 to your computer and use it in GitHub Desktop.
Save cdahlqvist/5885692 to your computer and use it in GitHub Desktop.

This is an erlang snippet to be run from a riak attach session

After pasting the following into the attach session, to repair all riak_kv partitions, run

RepairProc = RepairAllKv(60).

or, to repair all riak_search partitions, run

RepairProc = RepairAllSearch(60).

60 represents the tick time in seconds, change to suit your needs The partition list will be extracted from the ring, and filtered to locally owned partitions. One partition at a time will be repaired. Once per tick seconds, RepairWait will check to see if the current repair is still in progress. If not, the next repair will be started. If you need to interrupt the process before completion, either restart riak or from a riak attach session run

exit(RepairProc,kill).

In addition to the normal handoff messages, this will cause 2 log entries in the console.log:

Begginning repair of <n> [riak_kv_vnode|riak_search_vnode] partitions and Repair of <n> [riak_kv_vnode|riak_search_vnode] partitions completed.

f().
RepairWait = fun(Mod,Partition,Tick,LoopFun) ->
receive after Tick ->
case Mod:repair_status(Partition) of
in_progress -> LoopFun(Mod,Partition, Tick, LoopFun);
_ -> ok
end
end
end.
DoRepair=fun(Mod,Partition,Tick) ->
lager:log(info,self(),"Beginning repair of partition ~p",[Partition]),
Mod:repair(Partition),
RepairWait(Mod,Partition,Tick,RepairWait),
lager:log(info,self(),"Repair of partition ~p complete",[Partition])
end.
RepairAll = fun(Mod,Tick) ->
{ok,Ring} = riak_core_ring_manager:get_my_ring(),
Vnodes = [ Partition || {Partition, Node} <- riak_core_ring:all_owners(Ring), Node =:= node()],
spawn(fun() ->
lager:log(info,self(),"Begin repair of ~p w partitions",[length(Vnodes),Mod]),
[ DoRepair(Mod,P,Tick*1000) || P <- Vnodes ],
lager:log(info,self(),"Repair of ~p ~w partitions completed.",[length(Vnodes),Mod])
end)
end.
RepairAllKv = fun(Tick) ->
RepairAll(riak_kv_vnode,Tick)
end.
RepairAllSearch = fun(Tick) ->
RepairAll(riak_search_vnode,Tick)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment