cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1054723 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/dht/
Date Mon, 03 Jan 2011 19:50:24 GMT
Author: jbellis
Date: Mon Jan  3 19:50:23 2011
New Revision: 1054723

URL: http://svn.apache.org/viewvc?rev=1054723&view=rev
Log:
implement describeOwnership for BOP,COPP
patch by mck; reviewed by jbellis for CASSANDRA-1928

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1054723&r1=1054722&r2=1054723&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Mon Jan  3 19:50:23 2011
@@ -7,6 +7,7 @@ dev
  * add RMI authentication options to nodetool (CASSANDRA-1921)
  * Make snitches configurable at runtime (CASSANDRA-1374)
  * retry hadoop split requests on connection failure (CASSANDRA-1927)
+ * implement describeOwnership for BOP, COPP (CASSANDRA-1928)
 
 
 0.7.0-rc4

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java?rev=1054723&r1=1054722&r2=1054723&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
Mon Jan  3 19:50:23 2011
@@ -20,26 +20,33 @@ package org.apache.cassandra.dht;
 
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Random;
 
 import org.apache.commons.lang.ArrayUtils;
 
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
 
 public abstract class AbstractByteOrderedPartitioner implements IPartitioner<BytesToken>
 {
     public static final BytesToken MINIMUM = new BytesToken(ArrayUtils.EMPTY_BYTE_ARRAY);
-    
+
     public static final BigInteger BYTE_MASK = new BigInteger("255");
 
     public DecoratedKey<BytesToken> decorateKey(ByteBuffer key)
     {
         return new DecoratedKey<BytesToken>(getToken(key), key);
     }
-    
+
     public DecoratedKey<BytesToken> convertFromDiskFormat(ByteBuffer key)
     {
         return new DecoratedKey<BytesToken>(getToken(key), key);
@@ -49,7 +56,7 @@ public abstract class AbstractByteOrdere
     {
         int ll,rl;
         ByteBuffer lb,rb;
-        
+
         if(ltoken.token instanceof byte[])
         {
             ll = ((byte[])ltoken.token).length;
@@ -60,7 +67,7 @@ public abstract class AbstractByteOrdere
             ll = ((ByteBuffer)ltoken.token).remaining();
             lb = (ByteBuffer)ltoken.token;
         }
-        
+
         if(rtoken.token instanceof byte[])
         {
             rl = ((byte[])rtoken.token).length;
@@ -160,4 +167,41 @@ public abstract class AbstractByteOrdere
     }
 
     public abstract BytesToken getToken(ByteBuffer key);
+
+    public Map<Token, Float> describeOwnership(List<Token> sortedTokens)
+    {
+        // allTokens will contain the count and be returned, sorted_ranges is shorthand for
token<->token math.
+        Map<Token, Float> allTokens = new HashMap<Token, Float>();
+        List<Range> sortedRanges = new ArrayList<Range>();
+
+        // this initializes the counts to 0 and calcs the ranges in order.
+        Token lastToken = sortedTokens.get(sortedTokens.size() - 1);
+        for (Token node : sortedTokens)
+        {
+            allTokens.put(node, new Float(0.0));
+            sortedRanges.add(new Range(lastToken, node));
+            lastToken = node;
+        }
+
+        for (String ks : DatabaseDescriptor.getTables())
+        {
+            for (CFMetaData cfmd : DatabaseDescriptor.getKSMetaData(ks).cfMetaData().values())
+            {
+                for (Range r : sortedRanges)
+                {
+                    // Looping over every KS:CF:Range, get the splits size and add it to
the count
+                    allTokens.put(r.right, allTokens.get(r.right) + StorageService.instance.getSplits(ks,
cfmd.cfName, r, 1).size());
+                }
+            }
+        }
+
+        // Sum every count up and divide count/total for the fractional ownership.
+        Float total = new Float(0.0);
+        for (Float f : allTokens.values())
+            total += f;
+        for (Map.Entry<Token, Float> row : allTokens.entrySet())
+            allTokens.put(row.getKey(), row.getValue() / total);
+
+        return allTokens;
+    }
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java?rev=1054723&r1=1054722&r2=1054723&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java
Mon Jan  3 19:50:23 2011
@@ -19,8 +19,6 @@
 package org.apache.cassandra.dht;
 
 import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.Map;
 
 public class ByteOrderedPartitioner extends AbstractByteOrderedPartitioner
 {
@@ -30,6 +28,4 @@ public class ByteOrderedPartitioner exte
             return MINIMUM;
         return new BytesToken(key);
     }
-
-    public Map<Token, Float> describeOwnership(List<Token> sortedTokens){ throw
new UnsupportedOperationException(); }
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java?rev=1054723&r1=1054722&r2=1054723&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
Mon Jan  3 19:50:23 2011
@@ -163,38 +163,38 @@ public class OrderPreservingPartitioner 
 
     public Map<Token, Float> describeOwnership(List<Token> sortedTokens)
     {
-        // alltokens will contain the count and be returned, sorted_ranges is shorthand for
token<->token math.
-        Map<Token, Float> alltokens = new HashMap<Token, Float>();
-        List<Range> sorted_ranges = new ArrayList<Range>();
+        // allTokens will contain the count and be returned, sorted_ranges is shorthand for
token<->token math.
+        Map<Token, Float> allTokens = new HashMap<Token, Float>();
+        List<Range> sortedRanges = new ArrayList<Range>();
 
         // this initializes the counts to 0 and calcs the ranges in order.
-        Token last_t = sortedTokens.get(sortedTokens.size()-1);
+        Token lastToken = sortedTokens.get(sortedTokens.size() - 1);
         for (Token node : sortedTokens)
         {
-            alltokens.put(node, new Float(0.0));
-            sorted_ranges.add(new Range(last_t, node));
-            last_t = node;
+            allTokens.put(node, new Float(0.0));
+            sortedRanges.add(new Range(lastToken, node));
+            lastToken = node;
         }
 
-        for(String ks : DatabaseDescriptor.getTables())
+        for (String ks : DatabaseDescriptor.getTables())
         {
             for (CFMetaData cfmd : DatabaseDescriptor.getKSMetaData(ks).cfMetaData().values())
             {
-                for (Range r : sorted_ranges)
+                for (Range r : sortedRanges)
                 {
                     // Looping over every KS:CF:Range, get the splits size and add it to
the count
-                    alltokens.put(r.right, alltokens.get(r.right) + StorageService.instance.getSplits(ks,
cfmd.cfName, r, 1).size());
+                    allTokens.put(r.right, allTokens.get(r.right) + StorageService.instance.getSplits(ks,
cfmd.cfName, r, 1).size());
                 }
             }
         }
 
         // Sum every count up and divide count/total for the fractional ownership.
         Float total = new Float(0.0);
-        for (Float f : alltokens.values()) { total += f; }
-        for (Map.Entry<Token, Float> row : alltokens.entrySet()) {
-            alltokens.put(row.getKey(), row.getValue() / total);
-        }
-        
-        return alltokens;
+        for (Float f : allTokens.values())
+            total += f;
+        for (Map.Entry<Token, Float> row : allTokens.entrySet())
+            allTokens.put(row.getKey(), row.getValue() / total);
+
+        return allTokens;
     }
 }



Mime
View raw message