cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject svn commit: r1153683 - in /cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra: gms/ApplicationState.java gms/VersionedValue.java service/StorageService.java thrift/CassandraServer.java
Date Wed, 03 Aug 2011 21:44:54 GMT
Author: brandonwilliams
Date: Wed Aug  3 21:44:53 2011
New Revision: 1153683

URL: http://svn.apache.org/viewvc?rev=1153683&view=rev
Log:
describe_ring returns the interface thrift is bound to instead of the
one the storage proto is bound to.
Patch by brandonwilliams, reviewed by jbellis for CASSANDRA-1777

Modified:
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/ApplicationState.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/VersionedValue.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/service/StorageService.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/thrift/CassandraServer.java

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/ApplicationState.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/ApplicationState.java?rev=1153683&r1=1153682&r2=1153683&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/ApplicationState.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/ApplicationState.java
Wed Aug  3 21:44:53 2011
@@ -30,6 +30,7 @@ public enum ApplicationState
     RACK,
     RELEASE_VERSION,
     REMOVAL_COORDINATOR,
+    RPC_ADDRESS,
     // pad to allow adding new states to existing cluster
     X1,
     X2,

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/VersionedValue.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/VersionedValue.java?rev=1153683&r1=1153682&r2=1153683&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/VersionedValue.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/gms/VersionedValue.java
Wed Aug  3 21:44:53 2011
@@ -21,6 +21,7 @@ package org.apache.cassandra.gms;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.UUID;
 
 import org.apache.cassandra.dht.IPartitioner;
@@ -157,6 +158,11 @@ public class VersionedValue implements C
             return new VersionedValue(rackId);
         }
 
+        public VersionedValue rpcaddress(InetAddress endpoint)
+        {
+            return new VersionedValue(endpoint.toString());
+        }
+
         public VersionedValue releaseVersion()
         {
             return new VersionedValue(FBUtilities.getReleaseVersionString());

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/service/StorageService.java?rev=1153683&r1=1153682&r2=1153683&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/service/StorageService.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/service/StorageService.java
Wed Aug  3 21:44:53 2011
@@ -451,6 +451,12 @@ public class StorageService implements I
         Gossiper.instance.register(migrationManager);
         Gossiper.instance.start(SystemTable.incrementAndGetGeneration()); // needed for node-ring
gathering.
 
+        // add rpc listening info
+        if (DatabaseDescriptor.getRpcAddress() == null)
+            Gossiper.instance.addLocalApplicationState(ApplicationState.RPC_ADDRESS, valueFactory.rpcaddress(FBUtilities.getLocalAddress()));
+        else
+            Gossiper.instance.addLocalApplicationState(ApplicationState.RPC_ADDRESS, valueFactory.rpcaddress(DatabaseDescriptor.getRpcAddress()));
+
         MessagingService.instance().listen(FBUtilities.getLocalAddress());
         StorageLoadBalancer.instance.startBroadcasting();
         MigrationManager.passiveAnnounce(DatabaseDescriptor.getDefsVersion());
@@ -595,6 +601,35 @@ public class StorageService implements I
         return map;
     }
 
+    /**
+     * for a keyspace, return the ranges and corresponding RPC addresses for a given keyspace.
+     * @param keyspace
+     * @return
+     */
+    public Map<Range, List<String>> getRangeToRpcaddressMap(String keyspace)
+    {
+        // some people just want to get a visual representation of things. Allow null and
set it to the first
+        // non-system table.
+        if (keyspace == null)
+            keyspace = DatabaseDescriptor.getNonSystemTables().get(0);
+
+        /* All the ranges for the tokens */
+        Map<Range, List<String>> map = new HashMap<Range, List<String>>();
+        for (Map.Entry<Range,List<InetAddress>> entry : getRangeToAddressMap(keyspace).entrySet())
+        {
+            List<String> rpcaddrs = new ArrayList<String>();
+            for (InetAddress endpoint: entry.getValue())
+            {
+                if (endpoint.equals(FBUtilities.getLocalAddress()))
+                    rpcaddrs.add(DatabaseDescriptor.getRpcAddress().toString());
+                else
+                    rpcaddrs.add(Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.RPC_ADDRESS).value);
+            }
+            map.put(entry.getKey(), rpcaddrs);
+        }
+        return map;
+    }
+
     public Map<Range, List<String>> getPendingRangeToEndpointMap(String keyspace)
     {
         // some people just want to get a visual representation of things. Allow null and
set it to the first

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=1153683&r1=1153682&r2=1153683&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/thrift/CassandraServer.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/thrift/CassandraServer.java
Wed Aug  3 21:44:53 2011
@@ -728,7 +728,7 @@ public class CassandraServer implements 
             throw new InvalidRequestException("There is no ring for the keyspace: " + keyspace);
         List<TokenRange> ranges = new ArrayList<TokenRange>();
         Token.TokenFactory tf = StorageService.getPartitioner().getTokenFactory();
-        for (Map.Entry<Range, List<String>> entry : StorageService.instance.getRangeToEndpointMap(keyspace).entrySet())
+        for (Map.Entry<Range, List<String>> entry : StorageService.instance.getRangeToRpcaddressMap(keyspace).entrySet())
         {
             Range range = entry.getKey();
             List<String> endpoints = entry.getValue();



Mime
View raw message