You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2011/01/28 00:36:27 UTC

svn commit: r1064360 - /cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java

Author: brandonwilliams
Date: Thu Jan 27 23:36:26 2011
New Revision: 1064360

URL: http://svn.apache.org/viewvc?rev=1064360&view=rev
Log:
Fix RP.describeOwnership()
Patch by Jon Hermes, reviewed by brandonwilliams for CASSANDRA-2071

Modified:
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java?rev=1064360&r1=1064359&r2=1064360&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java Thu Jan 27 23:36:26 2011
@@ -148,15 +148,14 @@ public class RandomPartitioner implement
             Token start = (Token)i.next(); BigInteger ti = ((BigIntegerToken)start).token;  // The first token and its value
             Token t; BigInteger tim1 = ti;                                                  // The last token and its value (after loop)
             while (i.hasNext()) {
-                t = (Token)i.next(); ti = ((BigIntegerToken)t).token;                       // The next token and its value
-                float x = new BigDecimal(ti.subtract(tim1)).divide(r).floatValue();         // %age = T(i) - T(i-1) / R
-                ownerships.put(t, x);                                                       // save (T(i) -> %age)
-                tim1 = ti;                                                                  // -> advance loop
+                t = (Token)i.next(); ti = ((BigIntegerToken)t).token;                               // The next token and its value
+                float x = new BigDecimal(ti.subtract(tim1).add(ri).mod(ri)).divide(r).floatValue(); // %age = ((T(i) - T(i-1) + R) % R) / R
+                ownerships.put(t, x);                                                               // save (T(i) -> %age)
+                tim1 = ti;                                                                          // -> advance loop
             }
-            // The start token's range extends backward to the last token, which is why both were saved
-            //  above. The simple calculation for this is: T(start) - T(end) + r % r / r.
-            //  (In the 1-case, this produces 0% instead of 100%.)
-            ownerships.put(start, new BigDecimal(((BigIntegerToken)start).token.subtract(ti).add(ri).mod(ri)).divide(r).floatValue());
+            // The start token's range extends backward to the last token, which is why both were saved above.
+            float x = new BigDecimal(((BigIntegerToken)start).token.subtract(ti).add(ri).mod(ri)).divide(r).floatValue();
+            ownerships.put(start, x);
         }
         return ownerships;
     }