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: GPFS loads dc/rack info from saved state if needed. Patch by brandonwilliams, reviewed by vijay for CASSANDRA-5133
Date Wed, 16 Jan 2013 00:43:35 GMT
GPFS loads dc/rack info from saved state if needed.
Patch by brandonwilliams, reviewed by vijay for CASSANDRA-5133


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

Branch: refs/heads/trunk
Commit: 1108ede0ff459d62add74487aa949139ed11d3ab
Parents: fac299f
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Tue Jan 15 18:41:54 2013 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Tue Jan 15 18:43:15 2013 -0600

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 src/java/org/apache/cassandra/db/SystemTable.java  |   20 +++++++++++++++
 .../locator/GossipingPropertyFileSnitch.java       |   15 +++++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1108ede0/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f57f656..e3e40b6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 1.2.1
+ * GossipingPropertyFileSnitch loads saved dc/rack info if needed (CASSANDRA-5133)
  * drain should flush system CFs too (CASSANDRA-4446)
  * add inter_dc_tcp_nodelay setting (CASSANDRA-5148)
  * re-allow wrapping ranges for start_token/end_token range pairing (CASSANDRA-5106)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1108ede0/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 18a2666..84d6e78 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -395,6 +395,26 @@ public class SystemTable
     }
 
     /**
+     * Return a map of IP addresses containing a map of dc and rack info
+     */
+    public static Map<InetAddress, Map<String,String>> loadDcRackInfo()
+    {
+        Map<InetAddress, Map<String, String>> result = new HashMap<InetAddress,
Map<String, String>>();
+        for (UntypedResultSet.Row row : processInternal("SELECT peer, data_center, rack from
system." + PEERS_CF))
+        {
+            InetAddress peer = row.getInetAddress("peer");
+            if (row.has("data_center"))
+            {
+                Map<String, String> dcRack = new HashMap<String, String>();
+                dcRack.put("data_center", row.getString("data_center"));
+                dcRack.put("rack", row.getString("rack"));
+                result.put(peer, dcRack);
+            }
+        }
+        return result;
+    }
+
+    /**
      * One of three things will happen if you try to read the system table:
      * 1. files are present and you can read them: great
      * 2. no files are there: great (new node is assumed)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1108ede0/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
index aa4c4e6..b16c136 100644
--- a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
+++ b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
@@ -19,7 +19,9 @@
 package org.apache.cassandra.locator;
 
 import java.net.InetAddress;
+import java.util.Map;
 
+import org.apache.cassandra.db.SystemTable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,6 +38,7 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
     private PropertyFileSnitch psnitch;
     private String myDC;
     private String myRack;
+    private Map<InetAddress, Map<String, String>> savedEndpoints;
 
     public GossipingPropertyFileSnitch() throws ConfigurationException
     {
@@ -69,7 +72,13 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
         if (epState == null || epState.getApplicationState(ApplicationState.DC) == null)
         {
             if (psnitch == null)
+            {
+                if (savedEndpoints == null)
+                    savedEndpoints = SystemTable.loadDcRackInfo();
+                if (savedEndpoints.containsKey(endpoint))
+                    return savedEndpoints.get(endpoint).get("data_center");
                 throw new RuntimeException("Could not retrieve DC for " + endpoint + " from
gossip and PFS compatibility is disabled");
+            }
             else
                 return psnitch.getDatacenter(endpoint);
         }
@@ -91,7 +100,13 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
         if (epState == null || epState.getApplicationState(ApplicationState.RACK) == null)
         {
             if (psnitch == null)
+            {
+                if (savedEndpoints == null)
+                    savedEndpoints = SystemTable.loadDcRackInfo();
+                if (savedEndpoints.containsKey(endpoint))
+                    return savedEndpoints.get(endpoint).get("rack");
                 throw new RuntimeException("Could not retrieve rack for " + endpoint + "
from gossip and PFS compatibility is disabled");
+            }
             else
                 return psnitch.getRack(endpoint);
         }


Mime
View raw message