cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Always gossip DC and Rack information
Date Wed, 17 Oct 2012 16:53:02 GMT
Updated Branches:
  refs/heads/trunk 954dc5e5b -> eb775fe7c


Always gossip DC and Rack information

patch by slebresne; reviewed by driftx for CASSANDRA-4814


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

Branch: refs/heads/trunk
Commit: eb775fe7c225699a8ea61901b6dc887716780909
Parents: 954dc5e
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Oct 17 18:52:16 2012 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Oct 17 18:52:16 2012 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +-
 .../org/apache/cassandra/config/CFMetaData.java    |    4 ++-
 src/java/org/apache/cassandra/db/SystemTable.java  |    8 +++++-
 .../org/apache/cassandra/locator/Ec2Snitch.java    |    9 --------
 .../locator/GossipingPropertyFileSnitch.java       |   16 ++++++--------
 .../cassandra/locator/PropertyFileSnitch.java      |    2 +
 .../apache/cassandra/service/StorageService.java   |   11 ++++++++++
 7 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 902b8b4..922e808 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -25,7 +25,7 @@
  * Support repairing only the local DC nodes (CASSANDRA-4747)
  * Use rpc_address for binary protocol and change default port (CASSANRA-4751)
  * Fix use of collections in prepared statements (CASSANDRA-4739)
- * Store more information into peers table (CASSANDRA-4351)
+ * Store more information into peers table (CASSANDRA-4351, 4814)
  * Configurable bucket size for size tiered compaction (CASSANDRA-4704)
  * Run leveled compaction in parallel (CASSANDRA-4310)
  * Fix potential NPE during CFS reload (CASSANDRA-4786)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index fb5681b..899ba75 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -177,7 +177,9 @@ public final class CFMetaData
                                                          + "ring_id uuid,"
                                                          + "release_version text,"
                                                          + "thrift_version text,"
-                                                         + "cql_version text"
+                                                         + "cql_version text,"
+                                                         + "data_center text,"
+                                                         + "rack text"
                                                          + ") WITH COMMENT='information about
the local node'");
 
     public static final CFMetaData TraceSessionsCf = compile(14, "CREATE TABLE " + Tracing.SESSIONS_CF
+ " ("

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/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 61b27d5..e21e266 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -43,6 +43,7 @@ import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.marshal.UTF8Type;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.locator.IEndpointSnitch;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.Constants;
 import org.apache.cassandra.utils.ByteBufferUtil;
@@ -125,12 +126,15 @@ public class SystemTable
 
     private static void setupVersion()
     {
-        String req = "INSERT INTO system.%s (key, release_version, cql_version, thrift_version)
VALUES ('%s', '%s', '%s', '%s')";
+        String req = "INSERT INTO system.%s (key, release_version, cql_version, thrift_version,
data_center, rack) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')";
+        IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
         processInternal(String.format(req, LOCAL_CF,
                                          LOCAL_KEY,
                                          FBUtilities.getReleaseVersionString(),
                                          QueryProcessor.CQL_VERSION.toString(),
-                                         Constants.VERSION));
+                                         Constants.VERSION,
+                                         snitch.getDatacenter(FBUtilities.getBroadcastAddress()),
+                                         snitch.getRack(FBUtilities.getBroadcastAddress())));
     }
 
     /** if system data becomes incompatible across versions of cassandra, that logic (and
associated purging) is managed here */

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/src/java/org/apache/cassandra/locator/Ec2Snitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
index 5485977..eec47fc 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -105,13 +105,4 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
             return DEFAULT_DC;
         return state.getApplicationState(ApplicationState.DC).value;
     }
-
-    @Override
-    public void gossiperStarting()
-    {
-        // Share EC2 info via gossip.  We have to wait until Gossiper is initialized though.
-        logger.info("Ec2Snitch adding ApplicationState ec2region=" + ec2region + " ec2zone="
+ ec2zone);
-        Gossiper.instance.addLocalApplicationState(ApplicationState.DC, StorageService.instance.valueFactory.datacenter(ec2region));
-        Gossiper.instance.addLocalApplicationState(ApplicationState.RACK, StorageService.instance.valueFactory.rack(ec2zone));
-    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/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 c66e0f9..249512d 100644
--- a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
+++ b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
@@ -24,6 +24,7 @@ import org.apache.cassandra.gms.EndpointState;
 import org.apache.cassandra.gms.Gossiper;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.FBUtilities;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -99,6 +100,9 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
      */
     public String getDatacenter(InetAddress endpoint)
     {
+        if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+            return myDC;
+
         EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
         if (epState == null || epState.getApplicationState(ApplicationState.DC) == null)
         {
@@ -118,6 +122,9 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
      */
     public String getRack(InetAddress endpoint)
     {
+        if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+            return myRack;
+
         EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
         if (epState == null || epState.getApplicationState(ApplicationState.RACK) == null)
         {
@@ -128,13 +135,4 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
         }
         return epState.getApplicationState(ApplicationState.RACK).value;
     }
-
-    @Override
-    public void gossiperStarting()
-    {
-        // Share info via gossip.
-        logger.info("Adding ApplicationState DC=" + myDC + " rack=" + myRack);
-        Gossiper.instance.addLocalApplicationState(ApplicationState.DC, StorageService.instance.valueFactory.datacenter(myDC));
-        Gossiper.instance.addLocalApplicationState(ApplicationState.RACK, StorageService.instance.valueFactory.rack(myRack));
-    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java b/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
index d337b58..a30334d 100644
--- a/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
+++ b/src/java/org/apache/cassandra/locator/PropertyFileSnitch.java
@@ -184,5 +184,7 @@ public class PropertyFileSnitch extends AbstractNetworkTopologySnitch
         endpointMap = reloadedMap;
         if (StorageService.instance != null) // null check tolerates circular dependency;
see CASSANDRA-4145
             StorageService.instance.getTokenMetadata().invalidateCaches();
+
+        StorageService.instance.gossipSnitchInfo();
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eb775fe7/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 8de0bd2..422b673 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -506,6 +506,8 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         // gossip network proto version
         Gossiper.instance.addLocalApplicationState(ApplicationState.NET_VERSION, valueFactory.networkVersion());
         Gossiper.instance.addLocalApplicationState(ApplicationState.HOST_ID, valueFactory.hostId(SystemTable.getLocalHostId()));
+        // gossip snitch infos (local DC and rack)
+        gossipSnitchInfo();
         // gossip schema version when gossiper is running
         Schema.instance.updateVersionAndAnnounce();
         // add rpc listening info
@@ -725,6 +727,15 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         }
     }
 
+    public void gossipSnitchInfo()
+    {
+        IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
+        String dc = snitch.getDatacenter(FBUtilities.getBroadcastAddress());
+        String rack = snitch.getRack(FBUtilities.getBroadcastAddress());
+        Gossiper.instance.addLocalApplicationState(ApplicationState.DC, StorageService.instance.valueFactory.datacenter(dc));
+        Gossiper.instance.addLocalApplicationState(ApplicationState.RACK, StorageService.instance.valueFactory.rack(rack));
+    }
+
     public synchronized void joinRing() throws IOException, ConfigurationException
     {
         if (!joined)


Mime
View raw message