Skip to content
This repository
Browse code

fix edge case where 0 resolved to a negative partition

  • Loading branch information...
commit b56a65dd3d85a5c816eaf6dfd503635a76ec0917 1 parent 32a9a8a
authored May 08, 2009
2  elibs/membership.erl
@@ -505,6 +505,8 @@ int_partition_for_key(Key, _State, Config) ->
505 505
   Q = Config#config.q,
506 506
   find_partition(KeyHash, Q).
507 507
 
  508
+find_partition(0, _) ->
  509
+  1;
508 510
 find_partition(Hash, Q) ->
509 511
   Size = partitions:partition_range(Q),
510 512
   Factor = (Hash div Size),
10  etest/membership_test.erl
@@ -16,7 +16,8 @@ all_test_() ->
16 16
     {"test_partitions_for_node_all", ?_test(test_partitions_for_node_all())},
17 17
     {"test_initial_partition_setup", ?_test(test_initial_partition_setup())},
18 18
     {"test_recover_from_old_membership_read", ?_test(test_recover_from_old_membership_read())},
19  
-    {"test_membership_server_throughput", test_membership_server_throughput_()}
  19
+    {"test_membership_server_throughput", test_membership_server_throughput_()},
  20
+    {"test_find_partition", ?_test(test_find_partition())}
20 21
   ]}.
21 22
 
22 23
 test_write_membership_to_disk() ->
@@ -29,6 +30,13 @@ test_write_membership_to_disk() ->
29 30
   membership:stop(),
30 31
   verify().
31 32
 
  33
+test_find_partition() ->
  34
+  ?assertEqual(1, find_partition(0, 6)),
  35
+  ?assertEqual(1, find_partition(1, 6)),
  36
+  ?assertEqual((2 bsl 31) - 67108863, find_partition(2 bsl 31, 6)),
  37
+  ?assertEqual((2 bsl 30) - 67108863, find_partition((2 bsl 30)-1, 6)).
  38
+  
  39
+
32 40
 test_load_membership_from_disk() ->
33 41
   State = create_initial_state(node(), [node()], configuration:get_config(), ets:new(partitions, [set, public])),
34 42
   NS = State#membership{version=[a,b,c]},

0 notes on commit b56a65d

Please sign in to comment.
Something went wrong with that request. Please try again.