This is an automated email from the ASF dual-hosted git repository.
smiklosovic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 0bcf4a1992 Add keyspace_name column to system_views.clients
0bcf4a1992 is described below
commit 0bcf4a199207966cfa892feb91541345edba181b
Author: nvharikrishna <[email protected]>
AuthorDate: Fri May 12 22:22:31 2023 +0530
Add keyspace_name column to system_views.clients
patch by nvharikrishna, reviewed by Stefan Miklosovic and Michael Semb
Wever for CASSANDRA-18525
---
CHANGES.txt | 1 +
.../apache/cassandra/db/virtual/ClientsTable.java | 5 +-
.../db/virtual/ClientsTableKeyspaceColTest.java | 132 +++++++++++++++++++++
3 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index e495dda4f2..4937943c78 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.0
+ * Add keyspace_name column to system_views.clients (CASSANDRA-18525)
* Moved system properties and envs to CassandraRelevantProperties and
CassandraRelevantEnv respectively (CASSANDRA-17797)
* Add sstablepartitions offline tool to find large partitions in sstables
(CASSANDRA-8720)
* Replace usages of json-simple dependency by Jackson (CASSANDRA-16855)
diff --git a/src/java/org/apache/cassandra/db/virtual/ClientsTable.java
b/src/java/org/apache/cassandra/db/virtual/ClientsTable.java
index d39c269fec..027bb9becd 100644
--- a/src/java/org/apache/cassandra/db/virtual/ClientsTable.java
+++ b/src/java/org/apache/cassandra/db/virtual/ClientsTable.java
@@ -40,6 +40,7 @@ final class ClientsTable extends AbstractVirtualTable
private static final String SSL_ENABLED = "ssl_enabled";
private static final String SSL_PROTOCOL = "ssl_protocol";
private static final String SSL_CIPHER_SUITE = "ssl_cipher_suite";
+ private static final String KEYSPACE_NAME = "keyspace_name";
ClientsTable(String keyspace)
{
@@ -60,6 +61,7 @@ final class ClientsTable extends AbstractVirtualTable
.addRegularColumn(SSL_ENABLED, BooleanType.instance)
.addRegularColumn(SSL_PROTOCOL, UTF8Type.instance)
.addRegularColumn(SSL_CIPHER_SUITE,
UTF8Type.instance)
+ .addRegularColumn(KEYSPACE_NAME, UTF8Type.instance)
.build());
}
@@ -83,7 +85,8 @@ final class ClientsTable extends AbstractVirtualTable
.column(REQUEST_COUNT, client.requestCount())
.column(SSL_ENABLED, client.sslEnabled())
.column(SSL_PROTOCOL, client.sslProtocol().orElse(null))
- .column(SSL_CIPHER_SUITE,
client.sslCipherSuite().orElse(null));
+ .column(SSL_CIPHER_SUITE,
client.sslCipherSuite().orElse(null))
+ .column(KEYSPACE_NAME, client.keyspace().orElse(null));
}
return result;
diff --git
a/test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java
b/test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java
new file mode 100644
index 0000000000..c282cac687
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/virtual/ClientsTableKeyspaceColTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.virtual;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.ServerTestUtils;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.service.EmbeddedCassandraService;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class ClientsTableKeyspaceColTest
+{
+
+ private static Cluster cluster;
+ private static EmbeddedCassandraService cassandra;
+ private static final String KS_NAME = "vts";
+
+ @BeforeClass
+ public static void setupClass() throws IOException
+ {
+ cassandra = ServerTestUtils.startEmbeddedCassandraService();
+
+ cluster = Cluster.builder().addContactPoint("127.0.0.1")
+ .withPort(DatabaseDescriptor.getNativeTransportPort())
+ .build();
+
+ ClientsTable table = new ClientsTable(KS_NAME);
+ VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME,
ImmutableList.of(table)));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ try
+ {
+ if (cluster != null)
+ cluster.close();
+ }
+ finally
+ {
+ if (cassandra != null)
+ cassandra.stop();
+ }
+ }
+
+ @Test
+ public void testWithoutConnectingToKeyspace()
+ {
+ try (Session session = cluster.connect())
+ {
+ List<Row> rows = session.execute("SELECT * from " + KS_NAME +
".clients").all();
+ assertTrue("At least one client should be returned.", rows.size()
> 0);
+ for (Row r : rows)
+ assertNull(r.getString("keyspace_name")); // No keyspace is
specifed while connecting. It should be null.
+ }
+ }
+
+ @Test
+ public void testChangingKeyspace()
+ {
+ String keyspace1 = "system_distributed";
+ String keyspace2 = "system_auth";
+ try (Session session = cluster.connect(keyspace1))
+ {
+
+ InetAddress poolConnection = null;
+ int port = -1;
+ for (Row r : session.execute("SELECT * from " + KS_NAME +
".clients").all())
+ {
+ // Keyspace is used for pool connection only (control
connection is not using keyspace).
+ // Using r["keyspace_name"] == keyspace1 as a hint to identify
a pool connection as we can't identify
+ // control connection based on information in this table.
+ String keyspace = r.getString("keyspace_name");
+ if (keyspace1.equals(keyspace))
+ {
+ poolConnection = r.getInet("address");
+ port = r.getInt("port");
+ break;
+ }
+ }
+
+ assertNotEquals(-1, port);
+ assertNotNull(poolConnection);
+
+ session.execute("USE " + keyspace2);
+
+ String usedKeyspace = null;
+ for (Row r : session.execute("SELECT * from " + KS_NAME +
".clients").all())
+ {
+ if (poolConnection.equals(r.getInet("address")) && port ==
r.getInt("port"))
+ {
+ usedKeyspace = r.getString("keyspace_name");
+ break;
+ }
+ }
+
+ assertEquals(keyspace2, usedKeyspace);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]