Skip to content

Commit 7b6f2d4

Browse files
authored
Make all queries to system.local contain WHERE clause (#437)
FUll scan queries are slower even when only one record in the table
1 parent f5c2583 commit 7b6f2d4

File tree

14 files changed

+35
-25
lines changed

14 files changed

+35
-25
lines changed

driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public void onTestContextInitialized() {
7373
/** Checks that a cancelled query releases the connection (JAVA-407). */
7474
@Test(groups = "short")
7575
public void cancelled_query_should_release_the_connection() throws InterruptedException {
76-
ResultSetFuture future = session().executeAsync("select release_version from system.local");
76+
ResultSetFuture future =
77+
session().executeAsync("select release_version from system.local where key='local'");
7778
future.cancel(true);
7879
assertTrue(future.isCancelled());
7980

@@ -98,7 +99,8 @@ public void should_init_cluster_and_session_if_needed() throws Exception {
9899
// Neither cluster2 nor session2 are initialized at this point
99100
assertThat(cluster2.manager.metadata).isNull();
100101

101-
ResultSetFuture future = session2.executeAsync("select release_version from system.local");
102+
ResultSetFuture future =
103+
session2.executeAsync("select release_version from system.local where key='local'");
102104
Row row = Uninterruptibles.getUninterruptibly(future).one();
103105

104106
assertThat(row.getString(0)).isNotEmpty();
@@ -152,14 +154,15 @@ public void should_propagate_error_to_chained_query_if_session_init_fails() thro
152154
@Test(groups = "short")
153155
public void should_fail_when_synchronous_call_on_io_thread() throws Exception {
154156
for (int i = 0; i < 1000; i++) {
155-
ResultSetFuture f = session().executeAsync("select release_version from system.local");
157+
ResultSetFuture f =
158+
session().executeAsync("select release_version from system.local where key='local'");
156159
ListenableFuture<Thread> f2 =
157160
GuavaCompatibility.INSTANCE.transform(
158161
f,
159162
new Function<ResultSet, Thread>() {
160163
@Override
161164
public Thread apply(ResultSet input) {
162-
session().execute("select release_version from system.local");
165+
session().execute("select release_version from system.local where key='local'");
163166
return Thread.currentThread();
164167
}
165168
});
@@ -176,14 +179,15 @@ public void should_fail_when_synchronous_call_on_io_thread_with_session_wrapper(
176179
throws Exception {
177180
final Session session = new SessionWrapper(session());
178181
for (int i = 0; i < 1000; i++) {
179-
ResultSetFuture f = session.executeAsync("select release_version from system.local");
182+
ResultSetFuture f =
183+
session.executeAsync("select release_version from system.local where key='local'");
180184
ListenableFuture<Thread> f2 =
181185
GuavaCompatibility.INSTANCE.transform(
182186
f,
183187
new Function<ResultSet, Thread>() {
184188
@Override
185189
public Thread apply(ResultSet input) {
186-
session.execute("select release_version from system.local");
190+
session.execute("select release_version from system.local where key='local'");
187191
return Thread.currentThread();
188192
}
189193
});

driver-core/src/test/java/com/datastax/driver/core/DelegatingClusterIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class DelegatingClusterIntegrationTest extends CCMTestsSupport {
2525
public void should_allow_subclass_to_delegate_to_other_instance() {
2626
SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(cluster());
2727

28-
ResultSet rs = delegatingCluster.connect().execute("select * from system.local");
28+
ResultSet rs =
29+
delegatingCluster.connect().execute("select * from system.local where key='local'");
2930

3031
assertThat(rs.all()).hasSize(1);
3132
}

driver-core/src/test/java/com/datastax/driver/core/DnsEndpointTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void replace_cluster_test() {
4141
.build();
4242
session = cluster.connect();
4343

44-
ResultSet rs = session.execute("select * from system.local");
44+
ResultSet rs = session.execute("select * from system.local where key='local'");
4545
Row row = rs.one();
4646
String address = row.getInet("broadcast_address").toString();
4747
logger.info("Queried node has broadcast_address: {}}", address);
@@ -64,7 +64,7 @@ public void replace_cluster_test() {
6464
.build();
6565
bridgeB.start();
6666
Thread.sleep(1000 * 92);
67-
ResultSet rs = session.execute("select * from system.local");
67+
ResultSet rs = session.execute("select * from system.local where key='local'");
6868
Row row = rs.one();
6969
String address = row.getInet("broadcast_address").toString();
7070
logger.info("Queried node has broadcast_address: {}}", address);
@@ -89,7 +89,7 @@ public void should_connect_with_mocked_hostname() {
8989
.build()) {
9090
ccmBridge.start();
9191
Session session = cluster.connect();
92-
ResultSet rs = session.execute("SELECT * FROM system.local");
92+
ResultSet rs = session.execute("SELECT * FROM system.local WHERE key='local'");
9393
List<Row> rows = rs.all();
9494
assertThat(rows).hasSize(1);
9595
Row row = rows.get(0);

driver-core/src/test/java/com/datastax/driver/core/HostTargetingTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public void should_use_host_on_statement() {
9191
Host host = TestUtils.findHost(cluster, hostIndex);
9292

9393
// given a statement with host explicitly set.
94-
Statement statement = new SimpleStatement("select * system.local").setHost(host);
94+
Statement statement =
95+
new SimpleStatement("select * system.local where key='local'").setHost(host);
9596

9697
// when statement is executed
9798
ResultSet result = session.execute(statement);
@@ -136,7 +137,8 @@ public void should_fail_if_host_fails_query() {
136137
public void should_fail_if_host_is_not_connected() {
137138
// given a statement with host explicitly set that for which we have no active pool.
138139
Host host4 = TestUtils.findHost(cluster, 4);
139-
Statement statement = new SimpleStatement("select * system.local").setHost(host4);
140+
Statement statement =
141+
new SimpleStatement("select * system.local where key='local'").setHost(host4);
140142

141143
try {
142144
// when statement is executed

driver-core/src/test/java/com/datastax/driver/core/ProtocolV1Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void beforeTestClass(Object testInstance) throws Exception {
4545
*/
4646
@Test(groups = "short")
4747
public void should_execute_query_with_no_variables() throws Exception {
48-
session().execute("select * from system.local");
48+
session().execute("select * from system.local where key='local'");
4949
}
5050

5151
/**

driver-core/src/test/java/com/datastax/driver/core/ReusedStreamIdTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void should_not_receive_wrong_response_when_callbacks_block_io_thread() {
9191
}
9292
semaphore.acquire();
9393
final String column = columnsToGrab.get(i % columnsToGrab.size()).getName();
94-
String query = String.format("select %s from system.local", column);
94+
String query = String.format("select %s from system.local where key='local'", column);
9595
ResultSetFuture future = session().executeAsync(query);
9696

9797
GuavaCompatibility.INSTANCE.addCallback(

driver-core/src/test/java/com/datastax/driver/core/SchemaAgreementTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void should_set_flag_on_successful_agreement() {
4343
public void should_set_flag_on_non_schema_altering_statement() {
4444
ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
4545
protocolOptions.maxSchemaAgreementWaitSeconds = 10;
46-
ResultSet rs = session().execute("select release_version from system.local");
46+
ResultSet rs = session().execute("select release_version from system.local where key='local'");
4747
assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
4848
}
4949

@@ -68,7 +68,8 @@ public void should_check_agreement_through_cluster_metadata() {
6868
Cluster controlCluster = register(TestUtils.buildControlCluster(cluster(), ccm()));
6969
Session controlSession = controlCluster.connect();
7070

71-
Row localRow = controlSession.execute("SELECT schema_version FROM system.local").one();
71+
Row localRow =
72+
controlSession.execute("SELECT schema_version FROM system.local WHERE key='local'").one();
7273
UUID localVersion = localRow.getUUID("schema_version");
7374
Row peerRow = controlSession.execute("SELECT peer, schema_version FROM system.peers").one();
7475
InetAddress peerAddress = peerRow.getInet("peer");

driver-core/src/test/java/com/datastax/driver/core/SingleConnectionPoolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void run() {
5454

5555
// Generate the load
5656
for (int i = 0; i < 10000; i++)
57-
session().executeAsync("SELECT release_version FROM system.local");
57+
session().executeAsync("SELECT release_version FROM system.local WHERE key='local'");
5858

5959
openConnectionsWatcherExecutor.shutdownNow();
6060
if (excessInflightQueriesSpotted.get()) {

driver-core/src/test/java/com/datastax/driver/core/StatementSizeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void should_measure_size_of_bound_statement() {
154154

155155
@Test(groups = "unit")
156156
public void should_measure_size_of_batch_statement() {
157-
String queryString = "SELECT release_version FROM system.local";
157+
String queryString = "SELECT release_version FROM system.local WHERE key='local'";
158158
SimpleStatement statement1 = new SimpleStatement(queryString);
159159

160160
BoundStatement statement2 =

driver-core/src/test/java/com/datastax/driver/core/StatementWrapperTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Cluster.Builder createClusterBuilder() {
6060
public void should_pass_wrapped_statement_to_load_balancing_policy() {
6161
loadBalancingPolicy.customStatementsHandled.set(0);
6262

63-
SimpleStatement s = new SimpleStatement("select * from system.local");
63+
SimpleStatement s = new SimpleStatement("select * from system.local where key='local'");
6464
session().execute(s);
6565
assertThat(loadBalancingPolicy.customStatementsHandled.get()).isEqualTo(0);
6666

@@ -133,7 +133,7 @@ public void should_reuse_wrapped_bound_statement_for_multipage_query() {
133133
public void should_pass_wrapped_statement_to_speculative_execution_policy() {
134134
speculativeExecutionPolicy.customStatementsHandled.set(0);
135135

136-
SimpleStatement s = new SimpleStatement("select * from system.local");
136+
SimpleStatement s = new SimpleStatement("select * from system.local where key='local'");
137137
session().execute(s);
138138
assertThat(speculativeExecutionPolicy.customStatementsHandled.get()).isEqualTo(0);
139139

@@ -148,7 +148,8 @@ public void should_pass_wrapped_statement_to_retry_policy() {
148148
// Set CL TWO with only one node, so the statement will always cause UNAVAILABLE,
149149
// which our custom policy ignores.
150150
Statement s =
151-
new SimpleStatement("select * from system.local").setConsistencyLevel(ConsistencyLevel.TWO);
151+
new SimpleStatement("select * from system.local where key='local'")
152+
.setConsistencyLevel(ConsistencyLevel.TWO);
152153

153154
session().execute(s);
154155
assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(0);

0 commit comments

Comments
 (0)