From a06f2b6a6682436ebf4ecf851f5716774c73a8ff Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Wed, 28 Mar 2018 16:31:52 +1100 Subject: [PATCH] store FBUtilities.getJustBroadcastNativeAddress() in system.local for rpc_address column patch by Chang Liu; reviewed by Alexei Zotov and Stefan Miklosovic for CASSANDRA-11181 --- CHANGES.txt | 2 ++ .../apache/cassandra/db/SystemKeyspace.java | 2 +- .../cassandra/db/SystemKeyspaceTest.java | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index bc7c54125e..318ae746ca 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -20,6 +20,8 @@ Merged from 3.0: * Backport CASSANDRA-10508: Remove hard-coded SSL cipher suites (CASSANDRA-18575) * Suppress CVE-2023-2976 (CASSANDRA-18562) * Remove dh_python use in Debian packaging (CASSANDRA-18558) +Backported from 4.1: + * Add broadcast_rpc_address to system.local (CASSANDRA-11181) 4.0.10 diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java index 7655257759..f0502f5c59 100644 --- a/src/java/org/apache/cassandra/db/SystemKeyspace.java +++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java @@ -538,7 +538,7 @@ public static void persistLocalMetadata(Supplier nodeIdSupplier) snitch.getLocalDatacenter(), snitch.getLocalRack(), DatabaseDescriptor.getPartitioner().getClass().getName(), - DatabaseDescriptor.getRpcAddress(), + FBUtilities.getJustBroadcastNativeAddress(), DatabaseDescriptor.getNativeTransportPort(), FBUtilities.getJustBroadcastAddress(), DatabaseDescriptor.getStoragePort(), diff --git a/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java b/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java index 97f3874fe4..4a325b096d 100644 --- a/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java +++ b/test/unit/org/apache/cassandra/db/SystemKeyspaceTest.java @@ -33,11 +33,16 @@ import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken; import org.apache.cassandra.dht.Token; +import org.apache.cassandra.transport.ProtocolVersion; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.CassandraVersion; +import static java.lang.String.format; +import static org.apache.cassandra.cql3.QueryProcessor.executeInternal; +import static org.apache.cassandra.db.SystemKeyspace.LOCAL; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class SystemKeyspaceTest @@ -155,6 +160,31 @@ public void snapshotSystemKeyspaceIfUpgrading() throws IOException Keyspace.clearSnapshot(null, SchemaConstants.SYSTEM_KEYSPACE_NAME); } + @Test + public void testPersistLocalMetadata() + { + SystemKeyspace.persistLocalMetadata(); + + UntypedResultSet result = executeInternal(format("SELECT * FROM system.%s WHERE key='%s'", LOCAL, LOCAL)); + + assertNotNull(result); + UntypedResultSet.Row row = result.one(); + + assertEquals(DatabaseDescriptor.getClusterName(), row.getString("cluster_name")); + assertEquals(FBUtilities.getReleaseVersionString(), row.getString("release_version")); + assertEquals(QueryProcessor.CQL_VERSION.toString(), row.getString("cql_version")); + assertEquals(String.valueOf(ProtocolVersion.CURRENT.asInt()), row.getString("native_protocol_version")); + assertEquals(DatabaseDescriptor.getEndpointSnitch().getLocalDatacenter(), row.getString("data_center")); + assertEquals(DatabaseDescriptor.getEndpointSnitch().getLocalRack(), row.getString("rack")); + assertEquals(DatabaseDescriptor.getPartitioner().getClass().getName(), row.getString("partitioner")); + assertEquals(FBUtilities.getJustBroadcastNativeAddress(), row.getInetAddress("rpc_address")); + assertEquals(DatabaseDescriptor.getNativeTransportPort(), row.getInt("rpc_port")); + assertEquals(FBUtilities.getJustBroadcastAddress(), row.getInetAddress("broadcast_address")); + assertEquals(DatabaseDescriptor.getStoragePort(), row.getInt("broadcast_port")); + assertEquals(FBUtilities.getJustLocalAddress(), row.getInetAddress("listen_address")); + assertEquals(DatabaseDescriptor.getStoragePort(), row.getInt("listen_port")); + } + private String getOlderVersionString() { String version = FBUtilities.getReleaseVersionString();