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: Remove endpoints from system.peers correctly. Patch by brandonwilliams reviewed by slebresne for CASSANDRA-5167
Date Fri, 18 Jan 2013 16:19:51 GMT
Remove endpoints from system.peers correctly.
Patch by brandonwilliams reviewed by slebresne for CASSANDRA-5167


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

Branch: refs/heads/trunk
Commit: e6b6eaa583e8fc15f03c3e27664bf7fc06b3af0a
Parents: 056f38c
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Fri Jan 18 10:19:00 2013 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Fri Jan 18 10:19:00 2013 -0600

----------------------------------------------------------------------
 src/java/org/apache/cassandra/db/SystemTable.java  |   18 +++---------
 .../apache/cassandra/service/StorageService.java   |   22 +++++++++------
 .../org/apache/cassandra/db/SystemTableTest.java   |    2 +-
 3 files changed, 19 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e6b6eaa5/src/java/org/apache/cassandra/db/SystemTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java
index 84d6e78..8d4bef2 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -249,7 +249,7 @@ public class SystemTable
     {
         if (ep.equals(FBUtilities.getBroadcastAddress()))
         {
-            removeTokens(tokens);
+            removeEndpoint(ep);
             return;
         }
 
@@ -301,18 +301,10 @@ public class SystemTable
     /**
      * Remove stored tokens being used by another node
      */
-    public static synchronized void removeTokens(Collection<Token> tokens)
+    public static synchronized void removeEndpoint(InetAddress ep)
     {
-        Set<Token> tokenSet = new HashSet<Token>(tokens);
-        for (Map.Entry<InetAddress, Collection<Token>> entry : loadTokens().asMap().entrySet())
-        {
-            Set<Token> toRemove = Sets.intersection(tokenSet, ((Set<Token>)entry.getValue())).immutableCopy();
-            if (toRemove.isEmpty())
-                continue;
-
-            String req = "UPDATE system.%s SET tokens = tokens - %s WHERE peer = '%s'";
-            processInternal(String.format(req, PEERS_CF, tokensAsSet(toRemove), entry.getKey().getHostAddress()));
-        }
+        String req = "DELETE FROM system.%s WHERE peer = '%s'";
+        processInternal(String.format(req, PEERS_CF, ep.getHostAddress()));
         forceBlockingFlush(PEERS_CF);
     }
 
@@ -321,7 +313,7 @@ public class SystemTable
     */
     public static synchronized void updateTokens(Collection<Token> tokens)
     {
-        assert !tokens.isEmpty() : "removeTokens should be used instead";
+        assert !tokens.isEmpty() : "removeEndpoint should be used instead";
         String req = "INSERT INTO system.%s (key, tokens) VALUES ('%s', %s)";
         processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, tokensAsSet(tokens)));
         forceBlockingFlush(LOCAL_CF);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e6b6eaa5/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 e57cfe4..4c0a9ce 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -443,7 +443,7 @@ public class StorageService extends NotificationBroadcasterSupport implements
IE
                 if (ep.equals(FBUtilities.getBroadcastAddress()))
                 {
                     // entry has been mistakenly added, delete it
-                    SystemTable.removeTokens(loadedTokens.get(ep));
+                    SystemTable.removeEndpoint(ep);
                 }
                 else
                 {
@@ -1387,7 +1387,7 @@ public class StorageService extends NotificationBroadcasterSupport implements
IE
 
         tokenMetadata.updateNormalTokens(tokensToUpdateInMetadata, endpoint);
         for (InetAddress ep : endpointsToRemove)
-            Gossiper.instance.removeEndpoint(ep);
+            removeEndpoint(ep);
         if (!tokensToUpdateInSystemTable.isEmpty())
             SystemTable.updateTokens(endpoint, tokensToUpdateInSystemTable);
         if (!localTokensToRemove.isEmpty())
@@ -1549,13 +1549,14 @@ public class StorageService extends NotificationBroadcasterSupport
implements IE
             }
         }
         else // now that the gossiper has told us about this nonexistent member, notify the
gossiper to remove it
-            Gossiper.instance.removeEndpoint(endpoint);
+            removeEndpoint(endpoint);
     }
 
     private void excise(Collection<Token> tokens, InetAddress endpoint)
     {
+        logger.info("Removing tokens " + tokens + " for " + endpoint);
         HintedHandOffManager.instance.deleteHintsForEndpoint(endpoint);
-        Gossiper.instance.removeEndpoint(endpoint);
+        removeEndpoint(endpoint);
         tokenMetadata.removeEndpoint(endpoint);
         tokenMetadata.removeBootstrapTokens(tokens);
         if (!isClientMode)
@@ -1564,11 +1565,6 @@ public class StorageService extends NotificationBroadcasterSupport
implements IE
                 subscriber.onLeaveCluster(endpoint);
         }
         calculatePendingRanges();
-        if (!isClientMode)
-        {
-            logger.info("Removing tokens " + tokens + " for " + endpoint);
-            SystemTable.removeTokens(tokens);
-        }
     }
 
     private void excise(Collection<Token> tokens, InetAddress endpoint, long expireTime)
@@ -1577,6 +1573,14 @@ public class StorageService extends NotificationBroadcasterSupport
implements IE
         excise(tokens, endpoint);
     }
 
+    /** unlike excise we just need this endpoint gone without going through any notifications
**/
+    private void removeEndpoint(InetAddress endpoint)
+    {
+        Gossiper.instance.removeEndpoint(endpoint);
+        if (!isClientMode)
+            SystemTable.removeEndpoint(endpoint);
+    }
+
     protected void addExpireTimeIfFound(InetAddress endpoint, long expireTime)
     {
         if (expireTime != 0L)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e6b6eaa5/test/unit/org/apache/cassandra/db/SystemTableTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/SystemTableTest.java b/test/unit/org/apache/cassandra/db/SystemTableTest.java
index 12d2e34..8854411 100644
--- a/test/unit/org/apache/cassandra/db/SystemTableTest.java
+++ b/test/unit/org/apache/cassandra/db/SystemTableTest.java
@@ -66,7 +66,7 @@ public class SystemTableTest
         InetAddress address = InetAddress.getByName("127.0.0.2");
         SystemTable.updateTokens(address, Collections.<Token>singletonList(token));
         assert SystemTable.loadTokens().get(address).contains(token);
-        SystemTable.removeTokens(Collections.<Token>singletonList(token));
+        SystemTable.removeEndpoint(address);
         assert !SystemTable.loadTokens().containsValue(token);
     }
 


Mime
View raw message