cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [2/3] git commit: Handle states for non-vnode clusters correctly. Patch by brandonwilliams reviewed by slebresne for CASSANDRA-5127
Date Tue, 08 Jan 2013 19:26:11 GMT
Handle states for non-vnode clusters correctly.
Patch by brandonwilliams reviewed by slebresne for CASSANDRA-5127


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/94585307
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/94585307
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/94585307

Branch: refs/heads/trunk
Commit: 945853076c44d071ba5b554ecb69a080e5719d32
Parents: 8349fce
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Tue Jan 8 13:25:13 2013 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Tue Jan 8 13:25:13 2013 -0600

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 src/java/org/apache/cassandra/gms/Gossiper.java    |    5 ++
 .../apache/cassandra/service/StorageService.java   |   39 ++++++---------
 3 files changed, 22 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/94585307/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 733c3a3..16473ec 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -24,6 +24,7 @@
  * Ensure CL guarantees on digest mismatch (CASSANDRA-5113)
  * Validate correctly selects on composite partition key (CASSANDRA-5122)
  * Fix exception when adding collection (CASSANDRA-5117)
+ * Handle states for non-vnode clusters correctly (CASSANDRA-5127)
 Merged from 1.1:
  * Pig: correctly decode row keys in widerow mode (CASSANDRA-5098)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94585307/src/java/org/apache/cassandra/gms/Gossiper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java
index 1179815..b861b56 100644
--- a/src/java/org/apache/cassandra/gms/Gossiper.java
+++ b/src/java/org/apache/cassandra/gms/Gossiper.java
@@ -625,6 +625,11 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean
         return false;
     }
 
+    public boolean usesVnodes(InetAddress endpoint)
+    {
+        return usesHostId(endpoint) && getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.TOKENS)
!= null;
+    }
+
     public UUID getHostId(InetAddress endpoint)
     {
         if (!usesHostId(endpoint))

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94585307/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 9cddc1a..b9e4c21 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -1193,16 +1193,21 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         return vvalue.getBytes(ISO_8859_1);
     }
 
-    private Collection<Token> getTokensFor(InetAddress endpoint)
+    private Collection<Token> getTokensFor(InetAddress endpoint, String piece)
     {
-        try
-        {
-            return TokenSerializer.deserialize(getPartitioner(), new DataInputStream(new
ByteArrayInputStream(getApplicationStateValue(endpoint, ApplicationState.TOKENS))));
-        }
-        catch (IOException e)
+        if (Gossiper.instance.usesVnodes(endpoint))
         {
-            throw new RuntimeException(e);
+            try
+            {
+                return TokenSerializer.deserialize(getPartitioner(), new DataInputStream(new
ByteArrayInputStream(getApplicationStateValue(endpoint, ApplicationState.TOKENS))));
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException(e);
+            }
         }
+        else
+            return Arrays.asList(getPartitioner().getTokenFactory().fromString(piece));
     }
 
     /**
@@ -1220,10 +1225,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         //   versions >= 1.2 .....: use TOKENS app state
         Collection<Token> tokens;
         // explicitly check for TOKENS, because a bootstrapping node might be bootstrapping
in legacy mode; that is, not using vnodes and no token specified
-        if (Gossiper.instance.usesHostId(endpoint) && Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.TOKENS)
!= null)
-            tokens = getTokensFor(endpoint);
-        else
-            tokens = Arrays.asList(getPartitioner().getTokenFactory().fromString(pieces[1]));
+        tokens = getTokensFor(endpoint, pieces[1]);
 
         if (logger.isDebugEnabled())
             logger.debug("Node " + endpoint + " state bootstrapping, token " + tokens);
@@ -1267,10 +1269,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
 
         Collection<Token> tokens;
 
-        if (Gossiper.instance.usesHostId(endpoint))
-            tokens = getTokensFor(endpoint);
-        else
-            tokens = Arrays.asList(getPartitioner().getTokenFactory().fromString(pieces[1]));
+        tokens = getTokensFor(endpoint, pieces[1]);
 
         if (logger.isDebugEnabled())
             logger.debug("Node " + endpoint + " state normal, token " + tokens);
@@ -1407,10 +1406,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
     {
         assert pieces.length >= 2;
         Collection<Token> tokens;
-        if (Gossiper.instance.usesHostId(endpoint))
-            tokens = getTokensFor(endpoint);
-        else
-            tokens =  Arrays.asList(getPartitioner().getTokenFactory().fromString(pieces[1]));
+        tokens = getTokensFor(endpoint, pieces[1]);
 
         if (logger.isDebugEnabled())
             logger.debug("Node " + endpoint + " state leaving, tokens " + tokens);
@@ -1446,10 +1442,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         assert pieces.length >= 2;
         Collection<Token> tokens;
         Integer version = MessagingService.instance().getVersion(endpoint);
-        if (!Gossiper.instance.usesHostId(endpoint))
-            tokens = Arrays.asList(getPartitioner().getTokenFactory().fromString(pieces[1]));
-        else
-            tokens = getTokensFor(endpoint);
+        tokens = getTokensFor(endpoint, pieces[1]);
 
         if (logger.isDebugEnabled())
             logger.debug("Node " + endpoint + " state left, tokens " + tokens);


Mime
View raw message