Skip to content

Commit

Permalink
JAVA-2189: Exclude virtual keyspaces from token map computation
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed Mar 12, 2019
1 parent bebff8b commit d451ef9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/README.md
Expand Up @@ -4,6 +4,7 @@

### 4.0.0 (in progress)

- [bug] JAVA-2189: Exclude virtual keyspaces from token map computation
- [improvement] JAVA-2183: Enable materialized views when testing against Cassandra 4
- [improvement] JAVA-2182: Add insertInto().json() variant that takes an object in QueryBuilder
- [improvement] JAVA-2161: Annotate mutating methods with `@CheckReturnValue`
Expand Down
Expand Up @@ -275,7 +275,9 @@ private static Map<CqlIdentifier, Map<String, String>> buildReplicationConfigs(
Collection<? extends KeyspaceMetadata> keyspaces, String logPrefix) {
ImmutableMap.Builder<CqlIdentifier, Map<String, String>> builder = ImmutableMap.builder();
for (KeyspaceMetadata keyspace : keyspaces) {
builder.put(keyspace.getName(), keyspace.getReplication());
if (!keyspace.isVirtual()) {
builder.put(keyspace.getName(), keyspace.getReplication());
}
}
ImmutableMap<CqlIdentifier, Map<String, String>> result = builder.build();
LOG.debug("[{}] Computing keyspace-level data for {}", logPrefix, result);
Expand Down
Expand Up @@ -34,6 +34,8 @@
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.api.testinfra.utils.ConditionChecker;
import com.datastax.oss.driver.categories.ParallelizableTests;
import com.datastax.oss.protocol.internal.util.Bytes;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Map;
import org.junit.AssumptionViolatedException;
Expand All @@ -46,6 +48,8 @@
@Category(ParallelizableTests.class)
public class SchemaIT {

private static final Version DSE_MIN_VIRTUAL_TABLES = Version.parse("6.7.0");

private CcmRule ccmRule = CcmRule.getInstance();

private SessionRule<CqlSession> sessionRule = SessionRule.builder(ccmRule).build();
Expand Down Expand Up @@ -180,14 +184,9 @@ public void should_refresh_schema_manually() {
@CassandraRequirement(min = "4.0", description = "virtual tables introduced in 4.0")
@Test
public void should_get_virtual_metadata() {
skipIfDse60();

Metadata md = sessionRule.session().getMetadata();
// Special case: DSE 6.0 reports C* 4.0 but does not support virtual tables
if (ccmRule.getDseVersion().isPresent()) {
Version dseVersion = ccmRule.getDseVersion().get();
if (dseVersion.compareTo(Version.parse("6.7.0")) < 0) {
throw new AssumptionViolatedException("DSE 6.0 does not support virtual tables");
}
}
KeyspaceMetadata kmd = md.getKeyspace("system_views").get();

// Keyspace name should be set, marked as virtual, and have at least sstable_tasks table.
Expand Down Expand Up @@ -241,4 +240,33 @@ public void should_get_virtual_metadata() {
assertThat(cm.getType()).isEqualTo(DataTypes.BIGINT);
assertThat(cm.getName().toString()).isEqualTo("progress");
}

@CassandraRequirement(min = "4.0", description = "virtual tables introduced in 4.0")
@Test
public void should_exclude_virtual_keyspaces_from_token_map() {
skipIfDse60();

Metadata metadata = sessionRule.session().getMetadata();
Map<CqlIdentifier, ? extends KeyspaceMetadata> keyspaces = metadata.getKeyspaces();
assertThat(keyspaces)
.containsKey(CqlIdentifier.fromCql("system_views"))
.containsKey(CqlIdentifier.fromCql("system_virtual_schema"));

TokenMap tokenMap = metadata.getTokenMap().orElseThrow(AssertionError::new);
ByteBuffer partitionKey = Bytes.fromHexString("0x00"); // value does not matter
assertThat(tokenMap.getReplicas("system_views", partitionKey)).isEmpty();
assertThat(tokenMap.getReplicas("system_virtual_schema", partitionKey)).isEmpty();
// Check that a non-virtual keyspace is present
assertThat(tokenMap.getReplicas(sessionRule.keyspace(), partitionKey)).isNotEmpty();
}

private void skipIfDse60() {
// Special case: DSE 6.0 reports C* 4.0 but does not support virtual tables
if (ccmRule.getDseVersion().isPresent()) {
Version dseVersion = ccmRule.getDseVersion().get();
if (dseVersion.compareTo(DSE_MIN_VIRTUAL_TABLES) < 0) {
throw new AssumptionViolatedException("DSE 6.0 does not support virtual tables");
}
}
}
}

0 comments on commit d451ef9

Please sign in to comment.