cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject git commit: make SS.getTokenToEndpointMap to sort tokens in ascending order. Patch by Yuki Morishita, reviewed by brandonwilliams for CASSANDRA-3863
Date Tue, 07 Feb 2012 17:32:31 GMT
Updated Branches:
  refs/heads/cassandra-1.1 58202a8ef -> 252287897


make SS.getTokenToEndpointMap to sort tokens in ascending order.
Patch by Yuki Morishita, reviewed by brandonwilliams for CASSANDRA-3863


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

Branch: refs/heads/cassandra-1.1
Commit: 252287897f18349df3340dbfb3c6040acdcf9ee5
Parents: 58202a8
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Tue Feb 7 11:22:55 2012 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Tue Feb 7 11:22:55 2012 -0600

----------------------------------------------------------------------
 .../apache/cassandra/service/StorageService.java   |    9 ++++++---
 .../cassandra/service/StorageServiceMBean.java     |    2 +-
 src/java/org/apache/cassandra/tools/NodeCmd.java   |    1 -
 3 files changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/25228789/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 441a9bc..98c3e7f 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -915,10 +915,13 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
     public Map<String, String> getTokenToEndpointMap()
     {
         Map<Token, InetAddress> mapInetAddress = tokenMetadata_.getTokenToEndpointMap();
-        Map<String, String> mapString = new HashMap<String, String>(mapInetAddress.size());
-        for (Map.Entry<Token, InetAddress> entry : mapInetAddress.entrySet())
+        // in order to preserve tokens in ascending order, we use LinkedHashMap here
+        Map<String, String> mapString = new LinkedHashMap<String, String>(mapInetAddress.size());
+        List<Token> tokens = new ArrayList<Token>(mapInetAddress.keySet());
+        Collections.sort(tokens);
+        for (Token token : tokens)
         {
-            mapString.put(entry.getKey().toString(), entry.getValue().getHostAddress());
+            mapString.put(token.toString(), mapInetAddress.get(token).getHostAddress());
         }
         return mapString;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/25228789/src/java/org/apache/cassandra/service/StorageServiceMBean.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageServiceMBean.java b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
index 6903cb2..c4c6f52 100644
--- a/src/java/org/apache/cassandra/service/StorageServiceMBean.java
+++ b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
@@ -143,7 +143,7 @@ public interface StorageServiceMBean
      * Retrieve a map of tokens to endpoints, including the bootstrapping
      * ones.
      *
-     * @return a map of tokens to endpoints
+     * @return a map of tokens to endpoints in ascending order
      */
     public Map<String, String> getTokenToEndpointMap();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/25228789/src/java/org/apache/cassandra/tools/NodeCmd.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeCmd.java b/src/java/org/apache/cassandra/tools/NodeCmd.java
index 3e47dea..870644b 100644
--- a/src/java/org/apache/cassandra/tools/NodeCmd.java
+++ b/src/java/org/apache/cassandra/tools/NodeCmd.java
@@ -203,7 +203,6 @@ public class NodeCmd
     {
         Map<String, String> tokenToEndpoint = probe.getTokenToEndpointMap();
         List<String> sortedTokens = new ArrayList<String>(tokenToEndpoint.keySet());
-        Collections.sort(sortedTokens);
 
         Collection<String> liveNodes = probe.getLiveNodes();
         Collection<String> deadNodes = probe.getUnreachableNodes();


Mime
View raw message