Created
October 12, 2016 13:25
-
-
Save imetallica/83ac425410dfe5cf3c57b96e898896a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_empty(state) do | |
result = :queue.is_empty(state.queue) | |
Logger.debug "#{inspect __MODULE__}: Empty? #{inspect result}." | |
{result, state} | |
end | |
def delete(state) do | |
Logger.debug "#{inspect __MODULE__}: Deleting #{inspect state}." | |
{:ok, state} | |
end | |
def handoff_starting(target_node, state) do | |
Logger.debug "#{inspect __MODULE__}: Handoff to #{inspect target_node} starting." | |
{true, state} | |
end | |
def handoff_cancelled(state) do | |
Logger.debug "#{inspect __MODULE__}: Cancelling handoff #{inspect state}." | |
{:ok, state} | |
end | |
def handle_handoff_data(bin, state) do | |
Logger.debug "#{inspect __MODULE__}: Handling handoff item #{inspect bin} - #{inspect state}" | |
{"queue", queue} = :erlang.binary_to_term(bin) | |
{:reply, :ok, %{state | queue: queue}} | |
end | |
@doc """ | |
The `visit_fun` is `riak_core_handoff_sender:visit_item/3`. It is going to do all of the hard work of taking your | |
serialized data and pushing it over the wire to the remote node. | |
`acc0` here is the internal state of the handoff. `riak_core_handoff_sender:visit_item/3` returns an updated handoff | |
state, so you should use that in your own fold over vnode data elements. | |
""" | |
def handle_handoff_command(riak_core_fold_req_v2(foldfun: visit_fun, acc0: acc0), sender, state) do | |
Logger.debug "#{inspect __MODULE__}: Handling handoff command #{inspect acc0} - #{inspect sender} - #{inspect state}" | |
work = visit_fun.(:any, {"queue", state.queue}, acc0) | |
{:reply, work, state} | |
end | |
def encode_handoff_item(k, {"queue", queue} = data) do | |
Logger.debug "#{inspect __MODULE__}: Encoding handoff item #{inspect k} #{inspect queue}." | |
:erlang.term_to_binary(data) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment