Repository: cassandra
Updated Branches:
  refs/heads/trunk 127cfff26 -> cb67bfc16


Client TOPOLOGY_CHANGE  messages have wrong port.

Patch by Ariel Weisberg; Reviewed by Greg Bestland for CASSANDRA-14398


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

Branch: refs/heads/trunk
Commit: cb67bfc1639ded1b6937e7347ad42177ea3f24e3
Parents: 127cfff
Author: Ariel Weisberg <[email protected]>
Authored: Wed Apr 18 18:09:17 2018 -0400
Committer: Ariel Weisberg <[email protected]>
Committed: Thu Apr 19 12:15:27 2018 -0400

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/service/StorageService.java       |  2 +-
 .../service/StorageServiceServerTest.java       | 26 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/cb67bfc1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6c9e30a..a8dbbba 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0
+ * Client TOPOLOGY_CHANGE messages have wrong port. (CASSANDRA-14398)
  * Add ability to load new SSTables from a separate directory (CASSANDRA-6719)
  * Eliminate background repair and probablistic read_repair_chance table 
options
    (CASSANDRA-13910)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cb67bfc1/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 6cbc49a..4f62dd5 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -1699,7 +1699,7 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
         {
             try
             {
-                InetAddressAndPort address = 
InetAddressAndPort.getByName(Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.RPC_ADDRESS).value);
+                InetAddressAndPort address = 
InetAddressAndPort.getByName(Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.NATIVE_ADDRESS_AND_PORT).value);
                 return address.getHostAddress(withPort);
             }
             catch (UnknownHostException e)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cb67bfc1/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java 
b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
index 3884f5a..8c4f5f6 100644
--- a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
+++ b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.InetAddress;
 import java.util.*;
 
 import com.google.common.collect.HashMultimap;
@@ -34,6 +35,9 @@ import org.junit.runner.RunWith;
 import org.apache.cassandra.OrderedJUnit4ClassRunner;
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
 import org.apache.cassandra.locator.InetAddressAndPort;
 import org.apache.cassandra.schema.SchemaConstants;
 import org.apache.cassandra.schema.KeyspaceMetadata;
@@ -592,4 +596,26 @@ public class StorageServiceServerTest
         repairRangeFrom = 
StorageService.instance.createRepairRangeFrom("2000", "2000");
         assert repairRangeFrom.size() == 0;
     }
+
+    /**
+     * Test that StorageService.getNativeAddress returns the correct value 
based on available yaml and gossip state
+     * @throws Exception
+     */
+    @Test
+    public void testGetNativeAddress() throws Exception
+    {
+        String internalAddressString = "127.0.0.2:666";
+        InetAddressAndPort internalAddress = 
InetAddressAndPort.getByName(internalAddressString);
+        Gossiper.instance.addSavedEndpoint(internalAddress);
+        //Default to using the provided address with the configured port
+        assertEquals("127.0.0.2:" + 
DatabaseDescriptor.getNativeTransportPort(), 
StorageService.instance.getNativeaddress(internalAddress, true));
+
+        VersionedValue.VersionedValueFactory valueFactory =  new 
VersionedValue.VersionedValueFactory(Murmur3Partitioner.instance);
+        //If we don't have the port use the gossip address, but with the 
configured port
+        
Gossiper.instance.getEndpointStateForEndpoint(internalAddress).addApplicationState(ApplicationState.RPC_ADDRESS,
 valueFactory.rpcaddress(InetAddress.getByName("127.0.0.3")));
+        assertEquals("127.0.0.3:" + 
DatabaseDescriptor.getNativeTransportPort(), 
StorageService.instance.getNativeaddress(internalAddress, true));
+        //If we have the address and port in gossip use that
+        
Gossiper.instance.getEndpointStateForEndpoint(internalAddress).addApplicationState(ApplicationState.NATIVE_ADDRESS_AND_PORT,
 
valueFactory.nativeaddressAndPort(InetAddressAndPort.getByName("127.0.0.3:666")));
+        assertEquals("127.0.0.3:666", 
StorageService.instance.getNativeaddress(internalAddress, true));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to