Last active
September 21, 2024 19:19
-
-
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)
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
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