Skip to content

Instantly share code, notes, and snippets.

@sumerman
Last active September 21, 2024 19:19
Show Gist options
  • Save sumerman/72db78dcf6129fd31ccd to your computer and use it in GitHub Desktop.
Save sumerman/72db78dcf6129fd31ccd to your computer and use it in GitHub Desktop.
This snippet checks whether current riak node is a primary for the given key. (Works only for the N=1 case; use itr_pop for N > 1)
is_primary_for_doc(BKey) ->
{ok, CHBin} = riak_core_ring_manager:get_chash_bin(),
DocIdx = riak_core_util:chash_key(BKey),
Itr = chashbin:iterator(DocIdx, CHBin),
MyNode = node(),
case chashbin:itr_value(Itr) of
{Idx, Node} when Node == MyNode -> true;
{_Idx, _Node} -> false
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment