Skip to content

Commit

Permalink
Make all queries to system.local use WHERE clause (#436)
Browse files Browse the repository at this point in the history
Full scan requests slower even when only one record there is
  • Loading branch information
dkropachev authored Feb 14, 2025
1 parent 1e0eae9 commit 663064f
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void main(String[] args) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) {
try (CqlSession session = CqlSession.builder().build()) {
// We use execute to send a query to Cassandra. This returns a ResultSet, which
// is essentially a collection of Row objects.
ResultSet rs = session.execute("select release_version from system.local");
ResultSet rs = session.execute("select release_version from system.local where key='local'");
// Extract the first row (which is the only one in this case).
Row row = rs.one();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Object[][] saslSystemProperties() {
"keyTab",
ads.getUserKeytab().getAbsolutePath()))
.build())) {
Row row = session.execute("select * from system.local").one();
Row row = session.execute("select * from system.local where key='local'").one();
assertThat(row).isNotNull();
} finally {
System.clearProperty(saslSystemProperty);
Expand Down Expand Up @@ -104,7 +104,7 @@ public void should_authenticate_using_kerberos_with_keytab_and_alternate_service
"keyTab",
ads.getUserKeytab().getAbsolutePath()))
.build())) {
Row row = session.execute("select * from system.local").one();
Row row = session.execute("select * from system.local where key='local'").one();
assertThat(row).isNotNull();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class DseGssApiAuthProviderIT {
@Test
public void should_authenticate_using_kerberos_with_keytab() {
try (CqlSession session = ads.newKeyTabSession()) {
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
assertThat(set).isNotNull();
}
}
Expand All @@ -67,7 +67,7 @@ public void should_authenticate_using_kerberos_with_ticket() throws Exception {
Assume.assumeTrue(isUnix);
acquireTicket(ads.getUserPrincipal(), ads.getUserKeytab(), ads.getAdsServer());
try (CqlSession session = ads.newTicketSession()) {
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
assertThat(set).isNotNull();
} finally {
destroyTicket(ads);
Expand Down Expand Up @@ -133,7 +133,7 @@ public void should_authenticate_using_kerberos_with_keytab_programmatically() {
.withAuthProvider(new ProgrammaticDseGssApiAuthProvider(builder.build()))
.build()) {

ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
assertThat(set).isNotNull();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void should_connect_dse_plaintext_auth() {
.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, "cassandra")
.withClass(DefaultDriverOption.AUTH_PROVIDER_CLASS, PlainTextAuthProvider.class)
.build())) {
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -84,7 +84,7 @@ public void should_connect_dse_plaintext_auth_programmatically() {
.addContactEndPoints(ccm.getContactPoints())
.withAuthCredentials("cassandra", "cassandra")
.build()) {
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void should_allow_plain_text_authorized_user_to_login_as_programmatically
.addContactEndPoints(ads.ccm.getContactPoints())
.withAuthCredentials("ben", "fakePasswordForBen", "alice")
.build()) {
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void should_connect_to_proxy_using_path() {
.withAuthCredentials("cassandra", "cassandra")
.withCloudSecureConnectBundle(bundle)
.build()) {
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -96,7 +96,7 @@ public void should_connect_and_log_info_that_config_json_with_username_password_
.withAuthCredentials("cassandra", "cassandra")
.withCloudSecureConnectBundle(bundle)
.build()) {
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
verify(logger.appender, timeout(500).atLeast(1))
.doAppend(logger.loggingEventCaptor.capture());
assertThat(
Expand Down Expand Up @@ -135,7 +135,7 @@ public void should_connect_to_proxy_without_credentials() {
.withCloudSecureConnectBundle(bundle)
.withAuthCredentials("cassandra", "cassandra")
.build()) {
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -149,7 +149,7 @@ public void should_connect_to_proxy_using_non_normalized_path() {
.withAuthCredentials("cassandra", "cassandra")
.withCloudSecureConnectBundle(bundle)
.build()) {
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -163,7 +163,7 @@ public void should_connect_to_proxy_using_input_stream() throws IOException {
.withAuthCredentials("cassandra", "cassandra")
.withCloudSecureConnectBundle(bundle)
.build()) {
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand Down Expand Up @@ -191,7 +191,7 @@ public void should_connect_to_proxy_using_URL() throws IOException {
.build()) {

// then
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -213,7 +213,7 @@ public void should_connect_to_proxy_using_absolute_path_provided_in_the_session_
.build()) {

// then
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -236,7 +236,7 @@ public void should_connect_to_proxy_using_non_normalized_path_provided_in_the_se
.build()) {

// then
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -259,7 +259,7 @@ public void should_connect_to_proxy_using_non_normalized_path_provided_in_the_se
.build()) {

// then
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand Down Expand Up @@ -290,7 +290,7 @@ public void should_connect_to_proxy_using_url_with_http_protocol_provided_in_the
.build()) {

// then
set = session.execute("select * from system.local");
set = session.execute("select * from system.local where key='local'");
}
assertThat(set).isNotNull();
}
Expand All @@ -311,7 +311,7 @@ public void should_connect_to_proxy_using_url_with_http_protocol_provided_in_the
.build(); ) {

// when
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
// then
assertThat(set).isNotNull();
verify(logger.appender, timeout(500).atLeast(1))
Expand Down Expand Up @@ -348,7 +348,7 @@ public void should_connect_and_log_info_when_contact_points_and_secure_bundle_us
.build(); ) {

// when
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
// then
assertThat(set).isNotNull();
verify(logger.appender, timeout(500).atLeast(1))
Expand Down Expand Up @@ -379,7 +379,7 @@ public void should_connect_and_log_info_when_ssl_context_and_secure_bundle_used_
.withSslContext(SSLContext.getInstance("SSL"))
.build()) {
// when
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
// then
assertThat(set).isNotNull();
verify(logger.appender, timeout(500).atLeast(1))
Expand Down Expand Up @@ -415,7 +415,7 @@ public void should_error_when_ssl_context_and_secure_bundle_used_config()
.withAuthCredentials("cassandra", "cassandra")
.build()) {
// when
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
// then
assertThat(set).isNotNull();
verify(logger.appender, timeout(500).atLeast(1))
Expand Down Expand Up @@ -451,7 +451,7 @@ public void should_error_when_ssl_context_and_secure_bundle_used_config()
.build(); ) {

// when
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
// then
assertThat(set).isNotNull();
verify(logger.appender, timeout(500).atLeast(1))
Expand Down Expand Up @@ -482,7 +482,7 @@ public void should_connect_and_log_info_when_local_data_center_and_secure_bundle
.build(); ) {

// when
ResultSet set = session.execute("select * from system.local");
ResultSet set = session.execute("select * from system.local where key='local'");
// then
assertThat(set).isNotNull();
verify(logger.appender, timeout(500).atLeast(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void reschedule(AsyncResultSet asyncResultSet, Throwable throwable) {
}
SESSION_RULE
.session()
.executeAsync("SELECT release_version FROM system.local")
.executeAsync("SELECT release_version FROM system.local WHERE key='local'")
.whenComplete(this::reschedule);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ProtocolVersionInitialNegotiationIT {
public void should_downgrade_to_v3() {
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(3);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -81,7 +81,7 @@ public void should_downgrade_to_v3() {
public void should_downgrade_to_v4() {
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -96,7 +96,7 @@ public void should_downgrade_to_v4() {
public void should_downgrade_to_v5_oss() {
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(5);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -109,7 +109,7 @@ public void should_downgrade_to_v5_oss() {
public void should_downgrade_to_dse_v1() {
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion()).isEqualTo(DseProtocolVersion.DSE_V1);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ public void should_fail_if_provided_dse_v2_is_not_supported() {
public void should_not_downgrade_if_server_supports_latest_version() {
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion()).isEqualTo(ProtocolVersion.V5);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -235,7 +235,7 @@ public void should_not_downgrade_if_server_supports_latest_version() {
public void should_not_downgrade_if_server_supports_latest_version_dse() {
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion()).isEqualTo(ProtocolVersion.DSE_V2);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -255,7 +255,7 @@ public void should_use_explicitly_provided_v3() {
.build();
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(3);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -275,7 +275,7 @@ public void should_use_explicitly_provided_v4() {
.build();
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -298,7 +298,7 @@ public void should_use_explicitly_provided_v5() {
.build();
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(5);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -314,7 +314,7 @@ public void should_use_explicitly_provided_dse_v1() {
.build();
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
assertThat(session.getContext().getProtocolVersion()).isEqualTo(DseProtocolVersion.DSE_V1);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}

Expand All @@ -330,7 +330,7 @@ public void should_use_explicitly_provided_dse_v2() {
.build();
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
assertThat(session.getContext().getProtocolVersion()).isEqualTo(DseProtocolVersion.DSE_V2);
session.execute("select * from system.local");
session.execute("select * from system.local where key='local'");
}
}
}
Loading

0 comments on commit 663064f

Please sign in to comment.