Created
June 9, 2011 15:11
-
-
Save kellymclaughlin/1016929 to your computer and use it in GitHub Desktop.
next_index function
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
diff --git a/src/chash.erl b/src/chash.erl | |
index ecf0fb2..8aafb20 100644 | |
--- a/src/chash.erl | |
+++ b/src/chash.erl | |
@@ -37,7 +37,7 @@ | |
successors/2,successors/3, | |
predecessors/2,predecessors/3, | |
contains_name/2,key_of/1, | |
- merge_rings/2]). | |
+ merge_rings/2, next_index/2]). | |
-define(RINGTOP, trunc(math:pow(2,160)-1)). % SHA-1 space | |
-include_lib("eunit/include/eunit.hrl"). | |
@@ -133,6 +133,14 @@ ordered_from(Index, {NumPartitions, Nodes}) -> | |
{A, B} = lists:split((IndexAsInt div Inc)+1, Nodes), | |
B ++ A. | |
+% @doc Given an object key, return the next Index. | |
+% @spec next_index(Index :: index(), CHash :: chash()) -> [NodeEntry] | |
+next_index({Bucket, Key}, NumPartitions) -> | |
+ ChashKey = riak_core_util:chash_key({Bucket, Key}), | |
+ <<Index:160/integer>> = ChashKey, | |
+ Inc = ?RINGTOP div NumPartitions, | |
+ ((Index div Inc) + 1) * Inc. | |
+ | |
% @doc Given any term used to name an object, produce that object's key | |
% into the ring. Two names with the same SHA-1 hash value are | |
% considered the same name. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment