Skip to content

Commit 5f9f96b

Browse files
committed
Make all queries to system.local use WHERE clause
Full scan requests slower even when only one record there is
1 parent 48a9ea0 commit 5f9f96b

28 files changed

+89
-85
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
class ProtocolInitHandler extends ConnectInitHandler {
8484
private static final Logger LOG = LoggerFactory.getLogger(ProtocolInitHandler.class);
8585
private static final Query CLUSTER_NAME_QUERY =
86-
new Query("SELECT cluster_name FROM system.local");
86+
new Query("SELECT cluster_name FROM system.local WHERE key='local'");
8787

8888
private final InternalDriverContext context;
8989
private final long timeoutMillis;

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/DefaultTopologyMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ public CompletionStage<Iterable<NodeInfo>> refreshNodeList() {
170170

171171
savePort(channel);
172172

173-
CompletionStage<AdminResult> localQuery = query(channel, "SELECT * FROM system.local");
173+
CompletionStage<AdminResult> localQuery =
174+
query(channel, "select * from system.local where key='local'");
174175
CompletionStage<AdminResult> peersV2Query = query(channel, "SELECT * FROM system.peers_v2");
175176
CompletableFuture<AdminResult> peersQuery = new CompletableFuture<>();
176177

core/src/test/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public void should_check_cluster_name_if_provided() {
434434
requestFrame = readOutboundFrame();
435435
assertThat(requestFrame.message).isInstanceOf(Query.class);
436436
Query query = (Query) requestFrame.message;
437-
assertThat(query.query).isEqualTo("SELECT cluster_name FROM system.local");
437+
assertThat(query.query).isEqualTo("SELECT cluster_name FROM system.local WHERE key='local'");
438438
assertThat(connectFuture).isNotDone();
439439

440440
writeInboundFrame(requestFrame, TestResponses.clusterNameResponse("expectedClusterName"));

core/src/test/java/com/datastax/oss/driver/internal/core/metadata/DefaultTopologyMonitorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void should_refresh_node_list_from_local_and_peers() {
337337
AdminRow peer3 = mockPeersRow(3, UUID.randomUUID());
338338
AdminRow peer2 = mockPeersRow(2, node2.getHostId());
339339
topologyMonitor.stubQueries(
340-
new StubbedQuery("SELECT * FROM system.local", mockResult(local)),
340+
new StubbedQuery("select * from system.local where key='local'", mockResult(local)),
341341
new StubbedQuery("SELECT * FROM system.peers_v2", Collections.emptyMap(), null, true),
342342
new StubbedQuery("SELECT * FROM system.peers", mockResult(peer3, peer2)));
343343

@@ -447,7 +447,7 @@ public void should_warn_when_control_host_found_in_system_peers() {
447447
AdminRow peer2 = mockPeersRow(2, node2.getHostId());
448448
AdminRow peer1 = mockPeersRow(1, node2.getHostId()); // invalid
449449
topologyMonitor.stubQueries(
450-
new StubbedQuery("SELECT * FROM system.local", mockResult(local)),
450+
new StubbedQuery("select * from system.local where key='local'", mockResult(local)),
451451
new StubbedQuery("SELECT * FROM system.peers_v2", Collections.emptyMap(), null, true),
452452
new StubbedQuery("SELECT * FROM system.peers", mockResult(peer3, peer2, peer1)));
453453

@@ -478,7 +478,7 @@ public void should_warn_when_control_host_found_in_system_peers_v2() {
478478
AdminRow peer2 = mockPeersRow(2, node2.getHostId());
479479
AdminRow peer1 = mockPeersRow(1, node2.getHostId()); // invalid
480480
topologyMonitor.stubQueries(
481-
new StubbedQuery("SELECT * FROM system.local", mockResult(local)),
481+
new StubbedQuery("select * from system.local where key='local'", mockResult(local)),
482482
new StubbedQuery("SELECT * FROM system.peers_v2", mockResult(peer3, peer2, peer1)));
483483

484484
// When

examples/src/main/java/com/datastax/oss/driver/examples/astra/AstraReadCassandraVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void main(String[] args) {
6464

6565
// We use execute to send a query to Cassandra. This returns a ResultSet, which
6666
// is essentially a collection of Row objects.
67-
ResultSet rs = session.execute("select release_version from system.local");
67+
ResultSet rs = session.execute("select release_version from system.local WHERE key='local'");
6868
// Extract the first row (which is the only one in this case).
6969
Row row = rs.one();
7070

examples/src/main/java/com/datastax/oss/driver/examples/basic/ReadCassandraVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void main(String[] args) {
4545
try (CqlSession session = CqlSession.builder().build()) {
4646
// We use execute to send a query to Cassandra. This returns a ResultSet, which
4747
// is essentially a collection of Row objects.
48-
ResultSet rs = session.execute("select release_version from system.local");
48+
ResultSet rs = session.execute("select release_version from system.local where key='local'");
4949
// Extract the first row (which is the only one in this case).
5050
Row row = rs.one();
5151

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DseGssApiAuthProviderAlternateIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static Object[][] saslSystemProperties() {
7474
"keyTab",
7575
ads.getUserKeytab().getAbsolutePath()))
7676
.build())) {
77-
Row row = session.execute("select * from system.local").one();
77+
Row row = session.execute("select * from system.local where key='local'").one();
7878
assertThat(row).isNotNull();
7979
} finally {
8080
System.clearProperty(saslSystemProperty);
@@ -104,7 +104,7 @@ public void should_authenticate_using_kerberos_with_keytab_and_alternate_service
104104
"keyTab",
105105
ads.getUserKeytab().getAbsolutePath()))
106106
.build())) {
107-
Row row = session.execute("select * from system.local").one();
107+
Row row = session.execute("select * from system.local where key='local'").one();
108108
assertThat(row).isNotNull();
109109
}
110110
}

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DseGssApiAuthProviderIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class DseGssApiAuthProviderIT {
5050
@Test
5151
public void should_authenticate_using_kerberos_with_keytab() {
5252
try (CqlSession session = ads.newKeyTabSession()) {
53-
ResultSet set = session.execute("select * from system.local");
53+
ResultSet set = session.execute("select * from system.local where key='local'");
5454
assertThat(set).isNotNull();
5555
}
5656
}
@@ -67,7 +67,7 @@ public void should_authenticate_using_kerberos_with_ticket() throws Exception {
6767
Assume.assumeTrue(isUnix);
6868
acquireTicket(ads.getUserPrincipal(), ads.getUserKeytab(), ads.getAdsServer());
6969
try (CqlSession session = ads.newTicketSession()) {
70-
ResultSet set = session.execute("select * from system.local");
70+
ResultSet set = session.execute("select * from system.local where key='local'");
7171
assertThat(set).isNotNull();
7272
} finally {
7373
destroyTicket(ads);
@@ -133,7 +133,7 @@ public void should_authenticate_using_kerberos_with_keytab_programmatically() {
133133
.withAuthProvider(new ProgrammaticDseGssApiAuthProvider(builder.build()))
134134
.build()) {
135135

136-
ResultSet set = session.execute("select * from system.local");
136+
ResultSet set = session.execute("select * from system.local where key='local'");
137137
assertThat(set).isNotNull();
138138
}
139139
}

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DsePlainTextAuthProviderIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void should_connect_dse_plaintext_auth() {
7373
.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, "cassandra")
7474
.withClass(DefaultDriverOption.AUTH_PROVIDER_CLASS, PlainTextAuthProvider.class)
7575
.build())) {
76-
session.execute("select * from system.local");
76+
session.execute("select * from system.local where key='local'");
7777
}
7878
}
7979

@@ -84,7 +84,7 @@ public void should_connect_dse_plaintext_auth_programmatically() {
8484
.addContactEndPoints(ccm.getContactPoints())
8585
.withAuthCredentials("cassandra", "cassandra")
8686
.build()) {
87-
session.execute("select * from system.local");
87+
session.execute("select * from system.local where key='local'");
8888
}
8989
}
9090

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DseProxyAuthenticationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void should_allow_plain_text_authorized_user_to_login_as_programmatically
114114
.addContactEndPoints(ads.ccm.getContactPoints())
115115
.withAuthCredentials("ben", "fakePasswordForBen", "alice")
116116
.build()) {
117-
session.execute("select * from system.local");
117+
session.execute("select * from system.local where key='local'");
118118
}
119119
}
120120

0 commit comments

Comments
 (0)