cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r769016 [2/2] - in /incubator/cassandra/trunk: src/org/apache/cassandra/db/ src/org/apache/cassandra/dht/ src/org/apache/cassandra/io/ src/org/apache/cassandra/locator/ src/org/apache/cassandra/service/ src/org/apache/cassandra/tools/ src/o...
Date Mon, 27 Apr 2009 15:01:30 GMT
Modified: incubator/cassandra/trunk/src/org/apache/cassandra/tools/TokenUpdater.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/tools/TokenUpdater.java?rev=769016&r1=769015&r2=769016&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/tools/TokenUpdater.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/tools/TokenUpdater.java Mon Apr 27
15:01:29 2009
@@ -20,16 +20,12 @@
 
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.InputStreamReader;
-import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.cassandra.io.ICompactSerializer;
+import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.net.EndPoint;
 import org.apache.cassandra.net.Message;
 import org.apache.cassandra.net.MessagingService;
@@ -50,16 +46,17 @@
         }
         
         String ipPort = args[0];
-        String token = args[1];
+        IPartitioner p = StorageService.getPartitioner();
+        Token token = p.getTokenFactory().fromString(args[1]);
         String file = args[2];
         
         String[] ipPortPair = ipPort.split(":");
         EndPoint target = new EndPoint(ipPortPair[0], Integer.valueOf(ipPortPair[1]));
-        TokenInfoMessage tiMessage = new TokenInfoMessage( target, new BigInteger(token)
);
-        
+
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         DataOutputStream dos = new DataOutputStream(bos);
-        TokenInfoMessage.serializer().serialize(tiMessage, dos);
+        Token.serializer().serialize(token, dos);
+
         /* Construct the token update message to be sent */
         Message tokenUpdateMessage = new Message( new EndPoint(FBUtilities.getHostAddress(),
port_), "", StorageService.tokenVerbHandler_, new Object[]{bos.toByteArray()} );
         
@@ -70,8 +67,8 @@
         {
             String[] nodeTokenPair = line.split(" ");
             /* Add the node and the token pair into the header of this message. */
-            BigInteger nodeToken = new BigInteger(nodeTokenPair[1]);
-            tokenUpdateMessage.addHeader(nodeTokenPair[0], nodeToken.toByteArray());
+            Token nodeToken = p.getTokenFactory().fromString(nodeTokenPair[1]);
+            tokenUpdateMessage.addHeader(nodeTokenPair[0], p.getTokenFactory().toByteArray(nodeToken));
         }
         
         System.out.println("Sending a token update message to " + target);
@@ -79,64 +76,5 @@
         Thread.sleep(TokenUpdater.waitTime_);
         System.out.println("Done sending the update message");
     }
-    
-    public static class TokenInfoMessage implements Serializable
-    {
-        private static ICompactSerializer<TokenInfoMessage> serializer_;
-        private static AtomicInteger idGen_ = new AtomicInteger(0);
-        
-        static
-        {
-            serializer_ = new TokenInfoMessageSerializer();            
-        }
-        
-        static ICompactSerializer<TokenInfoMessage> serializer()
-        {
-            return serializer_;
-        }
 
-        private EndPoint target_;
-        private BigInteger token_;
-        
-        TokenInfoMessage(EndPoint target, BigInteger token)
-        {
-            target_ = target;
-            token_ = token;
-        }
-        
-        EndPoint getTarget()
-        {
-            return target_;
-        }
-        
-        BigInteger getToken()
-        {
-            return token_;
-        }
-    }
-    
-    public static class TokenInfoMessageSerializer implements ICompactSerializer<TokenInfoMessage>
-    {
-        public void serialize(TokenInfoMessage tiMessage, DataOutputStream dos) throws IOException
-        {
-            byte[] node = EndPoint.toBytes( tiMessage.getTarget() );
-            dos.writeInt(node.length);
-            dos.write(node);
-            
-            byte[] token = tiMessage.getToken().toByteArray();
-            dos.writeInt( token.length );
-            dos.write(token);
-        }
-        
-        public TokenInfoMessage deserialize(DataInputStream dis) throws IOException
-        {
-            byte[] target = new byte[dis.readInt()];
-            dis.readFully(target);
-            
-            byte[] token = new byte[dis.readInt()];
-            dis.readFully(token);
-            
-            return new TokenInfoMessage(EndPoint.fromBytes(target), new BigInteger(token));
-        }
-    }
 }

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/utils/FastObjectHash.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/utils/FastObjectHash.java?rev=769016&r1=769015&r2=769016&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/utils/FastObjectHash.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/utils/FastObjectHash.java Mon Apr 27
15:01:29 2009
@@ -187,7 +187,7 @@
         }
         else
         { // already FULL or REMOVED, must probe
-            // compute the double hash
+            // compute the double token
             final int probe = 1 + (hash % (length - 2));
 
             // if the slot we landed on is FULL (but not removed), probe

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java?rev=769016&r1=769015&r2=769016&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/SystemTableTest.java Mon Apr
27 15:01:29 2009
@@ -9,6 +9,6 @@
 public class SystemTableTest extends ServerTest {
     @Test
     public void testMain() throws IOException {
-        SystemTable.openSystemTable(SystemTable.cfName_).updateToken( StorageService.hash("503545744:0")
);
+        SystemTable.openSystemTable(SystemTable.cfName_).updateToken( StorageService.token("503545744:0")
);
     }
 }

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java?rev=769016&r1=769015&r2=769016&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/dht/RangeTest.java Mon Apr 27
15:01:29 2009
@@ -2,19 +2,17 @@
 
 import org.testng.annotations.Test;
 
-import java.math.BigInteger;
-
 public class RangeTest {
     @Test
     public void testRange() {
-        Range left = new Range(new BigInteger("0"), new BigInteger("100"));
-        assert left.contains(new BigInteger("10"));
-        assert !left.contains(new BigInteger("-1"));
-        assert !left.contains(new BigInteger("101"));
+        Range left = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
+        assert left.contains(new BigIntegerToken("10"));
+        assert !left.contains(new BigIntegerToken("-1"));
+        assert !left.contains(new BigIntegerToken("101"));
 
-        Range right = new Range(new BigInteger("100"), new BigInteger("0"));
-        assert right.contains(new BigInteger("200"));
-        assert right.contains(new BigInteger("-10"));
-        assert !right.contains(new BigInteger("1"));
+        Range right = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
+        assert right.contains(new BigIntegerToken("200"));
+        assert right.contains(new BigIntegerToken("-10"));
+        assert !right.contains(new BigIntegerToken("1"));
     }
 }



Mime
View raw message