From 30e13bd0d414fde39e3f9d3fe561178a328288af Mon Sep 17 00:00:00 2001 From: Stefan Miklosovic Date: Wed, 19 Jul 2023 12:01:14 +0200 Subject: [PATCH] exclude system tables and fix bug with default compressor when setting enabled to true --- .../schema/AlterTableStatement.java | 6 +- .../statements/schema/AlterViewStatement.java | 4 +- .../schema/CreateTableStatement.java | 6 +- .../schema/CreateViewStatement.java | 4 +- .../statements/schema/TableAttributes.java | 16 +-- .../cassandra/db/ColumnFamilyStore.java | 2 +- .../cassandra/schema/CompressionParams.java | 24 ++-- .../cassandra/schema/SchemaKeyspace.java | 11 +- .../cassandra/schema/TableMetadata.java | 8 +- .../apache/cassandra/schema/TableParams.java | 10 +- .../test/SSTableCompressionTest.java | 133 ++++++++++-------- .../apache/cassandra/db/ReadCommandTest.java | 4 +- .../service/paxos/PaxosStateTest.java | 2 +- .../cassandra/utils/CassandraGenerators.java | 2 +- 14 files changed, 134 insertions(+), 98 deletions(-) diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java index ee5c3281807d..62e148e85c31 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java @@ -526,14 +526,14 @@ public void validate(ClientState state) Guardrails.tableProperties.guard(attrs.updatedProperties(), attrs::removeProperty, state); - validateDefaultTimeToLive(attrs.asNewTableParams()); + validateDefaultTimeToLive(attrs.asNewTableParams(keyspaceName, tableName)); } public KeyspaceMetadata apply(KeyspaceMetadata keyspace, TableMetadata table) { - attrs.validate(); + attrs.validate(keyspaceName, tableName); - TableParams params = attrs.asAlteredTableParams(table.params); + TableParams params = attrs.asAlteredTableParams(table.params, keyspaceName, tableName); if (table.isCounter() && params.defaultTimeToLive > 0) throw ire("Cannot set default_time_to_live on a table with counters"); diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java index 7e707f476bed..5d461c4c25e3 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java @@ -68,12 +68,12 @@ public Keyspaces apply(Keyspaces schema) throw ire("Materialized view '%s.%s' doesn't exist", keyspaceName, viewName); } - attrs.validate(); + attrs.validate(keyspaceName, viewName); // Guardrails on table properties Guardrails.tableProperties.guard(attrs.updatedProperties(), attrs::removeProperty, state); - TableParams params = attrs.asAlteredTableParams(view.metadata.params); + TableParams params = attrs.asAlteredTableParams(view.metadata.params, keyspaceName, viewName); if (params.gcGraceSeconds == 0) { diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java index c0a1783221ee..82465c18eb72 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/CreateTableStatement.java @@ -150,7 +150,7 @@ public void validate(ClientState state) if (useCompactStorage) Guardrails.compactTablesEnabled.ensureEnabled(state); - validateDefaultTimeToLive(attrs.asNewTableParams()); + validateDefaultTimeToLive(attrs.asNewTableParams(keyspaceName, tableName)); rawColumns.forEach((name, raw) -> raw.validate(state, name)); } @@ -184,8 +184,8 @@ public String toString() public TableMetadata.Builder builder(Types types) { - attrs.validate(); - TableParams params = attrs.asNewTableParams(); + attrs.validate(keyspaceName, tableName); + TableParams params = attrs.asNewTableParams(keyspaceName, tableName); // use a TreeMap to preserve ordering across JDK versions (see CASSANDRA-9492) - important for stable unit tests Map columns = new TreeMap<>(comparing(o -> o.bytes)); diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java index ed7a9a11907a..34236f78113f 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java @@ -305,7 +305,7 @@ public Keyspaces apply(Keyspaces schema) * Validate WITH params */ - attrs.validate(); + attrs.validate(keyspaceName, viewName); if (attrs.hasOption(TableParams.Option.DEFAULT_TIME_TO_LIVE) && attrs.getInt(TableParams.Option.DEFAULT_TIME_TO_LIVE.toString(), 0) != 0) @@ -324,7 +324,7 @@ public Keyspaces apply(Keyspaces schema) if (attrs.hasProperty(TableAttributes.ID)) builder.id(attrs.getId()); - builder.params(attrs.asNewTableParams()) + builder.params(attrs.asNewTableParams(keyspaceName, viewName)) .kind(TableMetadata.Kind.VIEW); partitionKeyColumns.stream() diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/TableAttributes.java b/src/java/org/apache/cassandra/cql3/statements/schema/TableAttributes.java index c55d79e452ec..01a152ff493d 100644 --- a/src/java/org/apache/cassandra/cql3/statements/schema/TableAttributes.java +++ b/src/java/org/apache/cassandra/cql3/statements/schema/TableAttributes.java @@ -54,22 +54,22 @@ public final class TableAttributes extends PropertyDefinitions obsoleteKeywords = ImmutableSet.of(); } - public void validate() + public void validate(String keyspace, String table) { validate(validKeywords, obsoleteKeywords); - build(TableParams.builder()).validate(); + build(TableParams.builder(), keyspace, table).validate(); } - TableParams asNewTableParams() + TableParams asNewTableParams(String keyspace, String table) { - return build(TableParams.builder()); + return build(TableParams.builder(), keyspace, table); } - TableParams asAlteredTableParams(TableParams previous) + TableParams asAlteredTableParams(TableParams previous, String keyspaceName, String tableName) { if (getId() != null) throw new ConfigurationException("Cannot alter table id."); - return build(previous.unbuild()); + return build(previous.unbuild(), keyspaceName, tableName); } public TableId getId() throws ConfigurationException @@ -95,7 +95,7 @@ public static Set allKeywords() return Sets.union(validKeywords, obsoleteKeywords); } - private TableParams build(TableParams.Builder builder) + private TableParams build(TableParams.Builder builder, String keyspace, String table) { if (hasOption(Option.ALLOW_AUTO_SNAPSHOT)) builder.allowAutoSnapshot(getBoolean(Option.ALLOW_AUTO_SNAPSHOT.toString(), true)); @@ -161,7 +161,7 @@ private TableParams build(TableParams.Builder builder) if (hasOption(READ_REPAIR)) builder.readRepair(ReadRepairStrategy.fromString(getString(READ_REPAIR))); - return builder.build(); + return builder.build(keyspace, table); } public boolean hasOption(Option option) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 97a4a27bdf79..6c04f010c125 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -2964,7 +2964,7 @@ public void setCrcCheckChance(double crcCheckChance) { try { - TableParams.builder().crcCheckChance(crcCheckChance).build().validate(); + TableParams.builder().crcCheckChance(crcCheckChance).build(keyspace.getName(), name).validate(); for (ColumnFamilyStore cfs : concatWithIndexes()) { cfs.crcCheckChance.set(crcCheckChance); diff --git a/src/java/org/apache/cassandra/schema/CompressionParams.java b/src/java/org/apache/cassandra/schema/CompressionParams.java index e44a7d2699bb..893ebfae0519 100644 --- a/src/java/org/apache/cassandra/schema/CompressionParams.java +++ b/src/java/org/apache/cassandra/schema/CompressionParams.java @@ -230,21 +230,27 @@ private static CompressionParams fromClassAndOptions(String sstableCompressionCl max_compressed_length_in_bytes = CompressionParams.calcMaxCompressedLength(chunk_length_in_bytes, min_compress_ratio); } - // try to set compressor type - CompressorType compressorType = StringUtils.isEmpty(sstableCompressionClass) ? DEFAULT_COMPRESSION_TYPE : null; - if (compressorType == null) + CompressorType compressorType = null; + try { - try + compressorType = CompressorType.valueOf(sstableCompressionClass); + } + catch (Exception e) + { + // intentionally empty + } + + Function, ICompressor> creator = compressorType != null ? compressorType.creator : (opt) -> { + if (sstableCompressionClass != null) { - compressorType = CompressorType.valueOf(sstableCompressionClass); + return FBUtilities.newCompressor(parseCompressorClass(sstableCompressionClass), opt); } - catch (IllegalArgumentException expected) + else { - compressorType = CompressorType.forClass(sstableCompressionClass); + return FBUtilities.newCompressor(parseCompressorClass(defaultParams().klass().getName()), opt); } - } + }; - Function, ICompressor> creator = compressorType != null ? compressorType.creator : (opt) -> FBUtilities.newCompressor(parseCompressorClass(sstableCompressionClass), opt); CompressionParams cp = new CompressionParams(enabled ? creator.apply(options) : null, chunk_length_in_bytes, max_compressed_length_in_bytes, min_compress_ratio, options); if (enabled && compressorType != CompressorType.none) { diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java index f7044b55f7fa..f1eefc750133 100644 --- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java +++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java @@ -1070,7 +1070,16 @@ static TableParams createTableParamsFromRow(UntypedResultSet.Row row) if (row.has("incremental_backups")) builder.incrementalBackups(row.getBoolean("incremental_backups")); - return builder.build(); + String tableName = null; + + if (row.has("table_name")) + tableName = row.getString("table_name"); + else if (row.has("view_name")) + tableName = row.getString("view_name"); + + assert tableName != null; + + return builder.build(row.getString("keyspace_name"), tableName); } private static List fetchColumns(String keyspace, String table, Types types, UserFunctions functions) diff --git a/src/java/org/apache/cassandra/schema/TableMetadata.java b/src/java/org/apache/cassandra/schema/TableMetadata.java index ed2deacd8c76..f714739dcf66 100644 --- a/src/java/org/apache/cassandra/schema/TableMetadata.java +++ b/src/java/org/apache/cassandra/schema/TableMetadata.java @@ -191,7 +191,7 @@ protected TableMetadata(Builder builder) partitioner = builder.partitioner; kind = builder.kind; - params = builder.params.build(); + params = builder.params.build(keyspace, name); indexName = kind == Kind.INDEX ? name.substring(name.indexOf('.') + 1) : null; @@ -641,7 +641,11 @@ public TableMetadata updateIndexTableMetadata(TableParams baseTableParams) // Row caching is never enabled; see CASSANDRA-5732 builder.caching(baseTableParams.caching.cacheKeys() ? CachingParams.CACHE_KEYS : CachingParams.CACHE_NOTHING); - return unbuild().params(builder.build()).build(); + Builder unbuilt = unbuild(); + String keyspace = unbuilt.keyspace; + String table = unbuilt.name; + + return unbuilt.params(builder.build(keyspace, table)).build(); } boolean referencesUserType(ByteBuffer name) diff --git a/src/java/org/apache/cassandra/schema/TableParams.java b/src/java/org/apache/cassandra/schema/TableParams.java index 3431679bbf89..a6ae60d66b34 100644 --- a/src/java/org/apache/cassandra/schema/TableParams.java +++ b/src/java/org/apache/cassandra/schema/TableParams.java @@ -350,7 +350,7 @@ public static final class Builder private SpeculativeRetryPolicy additionalWritePolicy = PercentileSpeculativeRetryPolicy.NINETY_NINE_P; private CachingParams caching = CachingParams.DEFAULT; private CompactionParams compaction = CompactionParams.DEFAULT; - private CompressionParams compression = CompressionParams.defaultParams(); + private CompressionParams compression = null; private MemtableParams memtable = MemtableParams.DEFAULT; private ImmutableMap extensions = ImmutableMap.of(); private boolean cdc; @@ -360,8 +360,14 @@ public Builder() { } - public TableParams build() + public TableParams build(String keyspace, String name) { + if (compression == null) + if (SchemaConstants.getLocalAndReplicatedSystemKeyspaceNames().contains(keyspace)) + compression = CompressionParams.DEFAULT; + else + compression = CompressionParams.defaultParams(); + return new TableParams(this); } diff --git a/test/distributed/org/apache/cassandra/distributed/test/SSTableCompressionTest.java b/test/distributed/org/apache/cassandra/distributed/test/SSTableCompressionTest.java index 114b5de27a11..9f893bade24e 100644 --- a/test/distributed/org/apache/cassandra/distributed/test/SSTableCompressionTest.java +++ b/test/distributed/org/apache/cassandra/distributed/test/SSTableCompressionTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,6 +35,7 @@ import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.distributed.Cluster; import org.apache.cassandra.distributed.api.IInstanceConfig; import org.apache.cassandra.distributed.api.IInvokableInstance; @@ -51,9 +53,12 @@ import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL; import static org.apache.cassandra.distributed.api.Feature.NETWORK; import static org.apache.cassandra.distributed.test.ExecUtil.rethrow; +import static org.apache.cassandra.schema.SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES; +import static org.apache.cassandra.schema.SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMES; import static org.apache.commons.io.FileUtils.readFileToString; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; public class SSTableCompressionTest @@ -64,9 +69,9 @@ public class SSTableCompressionTest static int STORAGE_PORT; static int SSL_STORAGE_PORT; - private static String FAST_PARAM = "WITH compression = {'class': 'SnappyCompressor'}"; - private static String SLOW_PARAM = "WITH compression = {'class': 'DeflateCompressor'}"; - private static String DEFAULT_PARAM = ""; + private static final String FAST_PARAM = "WITH compression = {'class': 'SnappyCompressor'}"; + private static final String SLOW_PARAM = "WITH compression = {'class': 'DeflateCompressor'}"; + private static final String DEFAULT_PARAM = ""; private static final String KEYSPACE = "sstable_compression_test"; @@ -88,6 +93,12 @@ public class SSTableCompressionTest c.set("sstable_compression", ImmutableMap.builder().put("class_name", "deflate").build()); }; + private static final Consumer ZSTD_CONFIG = c -> { + c.with(NATIVE_PROTOCOL, NETWORK, GOSSIP); // need gossip to get hostid for Java driver + c.set("flush_compression", "fast"); // this is default + c.set("sstable_compression", ImmutableMap.builder().put("class_name", "zstd").build()); + }; + public static Path setupCluster(Consumer config, Path root) throws IOException { Cluster.Builder builder = Cluster.build().withNodes(1).withConfig(config); @@ -182,36 +193,36 @@ public void configChangeIsolation() throws Throwable /** * This tests shows that defining a table with a different compressor works and that changing - * the default compressor between starts does not change the compressors associated with the + * the default compressor between starts does not change the compressors associated with the * saved (snapshotted) systems. */ @Test public void compressionNotChangedInSnapshotIO() throws Throwable { - String tableName = "test_table"; try { Path root = setupCluster(DEFAULT_CONFIG, null); CLUSTER.schemaChange(format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}", KEYSPACE)); - createSSTable(tableName, "WITH compression = {'class': 'ZstdCompressor'}"); - populateTable(tableName); + createSSTable("different_compress", "WITH compression = {'class': 'ZstdCompressor'}"); + + populateTable("different_compress"); flushTables(); - Map parameters = getCompressionParameters(CLUSTER.get(1), tableName); + Map parameters = getCompressionParameters(CLUSTER.get(1), "different_compress"); assertEquals(ZstdCompressor.class.getName(), parameters.get("class")); - Set snapshot = snapshot(CLUSTER.get(1), tableName, "test"); + Set snapshot1 = snapshot(CLUSTER.get(1), "different_compress", "test"); - // shutdown but do not delete files + // shutdown but do not delete files. CLUSTER.close(false); // restart with Deflate compression definition setupCluster(SLOW_CONFIG, root); - restore(CLUSTER.get(1), snapshot, tableName); + restore(CLUSTER.get(1), snapshot1, "different_compress"); - assertSnapshotCompression(snapshot(CLUSTER.get(1), tableName, "backup1"), ImmutableSet.of(LZ4Compressor.class.getSimpleName())); - parameters = getCompressionParameters(CLUSTER.get(1), tableName); + assertSnapshotCompression(snapshot(CLUSTER.get(1), "different_compress", "backup1"), ImmutableSet.of("LZ4Compressor")); + parameters = getCompressionParameters(CLUSTER.get(1), "different_compress"); assertEquals(ZstdCompressor.class.getName(), parameters.get("class")); } finally @@ -221,56 +232,39 @@ public void compressionNotChangedInSnapshotIO() throws Throwable } @Test - public void testUsageOfFastDefaultCompressorUponFlushing() throws Throwable + public void testEnableDisableCompression() throws Throwable { try { - Path root = setupCluster(FAST_CONFIG, null); - CLUSTER.schemaChange(format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}", KEYSPACE)); - createSSTable("different_compress", "WITH compression = {'class': 'ZstdCompressor'}"); - populateTable("different_compress"); - flushTables(); - - Map parameters = getCompressionParameters(CLUSTER.get(1), "different_compress"); - assertEquals(ZstdCompressor.class.getName(), parameters.get("class")); - - // snappy is fast so it will use that one for flushing - Set snapshot = snapshot(CLUSTER.get(1), "different_compress", "test2"); - // global default is snappy and snappy is fast so flushing will use the configured fast compressor - assertSnapshotCompression(snapshot, ImmutableSet.of(SnappyCompressor.class.getSimpleName())); + setupCluster(ZSTD_CONFIG, null); - // shutdown but do not delete files - CLUSTER.close(false); - - // restart with Deflate compression definition, deflate is not fast - setupCluster(SLOW_CONFIG, root); + CLUSTER.schemaChange(format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}", KEYSPACE)); + createSSTable("sometable", DEFAULT_PARAM); - restore(CLUSTER.get(1), snapshot, "different_compress"); + assertEquals(ZstdCompressor.class.getName(), getCompressionParameters(CLUSTER.get(1), "sometable").get("class")); - // snappy upon restoration is preserved - assertSnapshotCompression(snapshot(CLUSTER.get(1), "different_compress", "backup2"), - ImmutableSet.of(SnappyCompressor.class.getSimpleName())); + // if we transition from false to true, it will use the default compressor in sstable_compression + CLUSTER.schemaChange(format("ALTER TABLE %s.%s WITH compression = {'enabled': false}", KEYSPACE, "sometable")); + CLUSTER.schemaChange(format("ALTER TABLE %s.%s WITH compression = {'enabled': true}", KEYSPACE, "sometable")); - // parameters on table were not changed - parameters = getCompressionParameters(CLUSTER.get(1), "different_compress"); - assertEquals(ZstdCompressor.class.getName(), parameters.get("class")); - - // populate table with more data and flush, - // we changed the default sstable compressor to "deflate", - // but "deflate" is general compressor, not fast, - // so it will use fast compressor for flush_compression which is LZ4Compressor - populateTable("different_compress"); - flushTables(); + assertEquals(ZstdCompressor.class.getName(), getCompressionParameters(CLUSTER.get(1), "sometable").get("class")); + } + finally + { + tearDownCluster(); + } + } - // here we expect that sstables of a snapshot are compressed both with snappy (the original run) - // as well as with LZ4 compressor because we used general default compressor (deflate) which is not fast - // but lz4 is and flush_compression is set to "fast" - assertSnapshotCompression(snapshot(CLUSTER.get(1), "different_compress", "backup3"), - ImmutableSet.of(SnappyCompressor.class.getSimpleName(), - LZ4Compressor.class.getSimpleName())); + @Test + public void testDefaultCompressionDoesNotApplyToSystemKeyspaces() throws Throwable + { + try + { + setupCluster(ZSTD_CONFIG, null); - parameters = getCompressionParameters(CLUSTER.get(1), "different_compress"); - assertEquals(ZstdCompressor.class.getName(), parameters.get("class")); + for (Map.Entry> entry : getCompressionParametersForSystemKeyspaces(CLUSTER.get(1)).entrySet()) + assertNotEquals(format("compression for table %s should not be changed by sstable_compression for system keyspaces!", entry.getKey()), + ZstdCompressor.class.getName(), entry.getValue().get("class")); } finally { @@ -278,7 +272,7 @@ public void testUsageOfFastDefaultCompressorUponFlushing() throws Throwable } } - private void testCreate(String table, String tableArgs, Map expected) throws IOException + private void testCreate(String table, String tableArgs, Map expected) { createSSTable(table, tableArgs); Map parameters = getCompressionParameters(CLUSTER.get(1), table); @@ -296,7 +290,7 @@ private Map createDefaultMap(Class clazz) }}; } - private void testLZ4() throws IOException + private void testLZ4() { Map expected = createDefaultMap(LZ4Compressor.class); testCreate("lz4", "", expected); @@ -311,14 +305,14 @@ private void testLZ4() throws IOException testCreate("lz4_arg_type", "WITH compression = {'class': 'LZ4Compressor', 'lz4_compressor_type':'fast' }", expected); } - private void testDisabled() throws IOException + private void testDisabled() { Map expected = new HashMap<>(); expected.put("enabled", "false"); testCreate("default_disabled", "WITH compression = { 'enabled':'false'}", expected); } - private void testDeflate() throws IOException + private void testDeflate() { Map expected = createDefaultMap(DeflateCompressor.class); testCreate("dflt", SLOW_PARAM, expected); @@ -326,7 +320,7 @@ private void testDeflate() throws IOException testCreate("dflt_chunk", "WITH compression = {'class':'DeflateCompressor', 'chunk_length_in_kb' : '8'}", expected); } - private void testNoop() throws IOException + private void testNoop() { Map expected = createDefaultMap(NoopCompressor.class); testCreate("noop", "WITH compression = {'class': 'NoopCompressor'}", expected); @@ -334,7 +328,7 @@ private void testNoop() throws IOException testCreate("noop_chunk", "WITH compression = {'class':'NoopCompressor', 'chunk_length_in_kb' : '8'}", expected); } - private void testSnappy() throws IOException + private void testSnappy() { Map expected = createDefaultMap(SnappyCompressor.class); testCreate("snappy", FAST_PARAM, expected); @@ -342,7 +336,7 @@ private void testSnappy() throws IOException testCreate("snappy_chunk", "WITH compression = {'class':'SnappyCompressor', 'chunk_length_in_kb' : '8'}", expected); } - private void testZstd() throws IOException + private void testZstd() { Map expected = createDefaultMap(ZstdCompressor.class); testCreate("zstd", "WITH compression = {'class': 'ZstdCompressor'}", expected); @@ -414,6 +408,23 @@ private void restore(IInvokableInstance instance, Set dirs, String targe assertThat(failedImports).isEmpty(); } + private Map> getCompressionParametersForSystemKeyspaces(IInvokableInstance instance) + { + try + { + return instance.callOnInstance(() -> Keyspace.allExisting() + .filter(ks -> LOCAL_SYSTEM_KEYSPACE_NAMES.contains(ks.getName()) || REPLICATED_SYSTEM_KEYSPACE_NAMES.contains(ks.getName())) + .map(Keyspace::getColumnFamilyStores) + .flatMap(Collection::stream) + .collect(Collectors.toMap(e -> e.getKeyspaceName() + '.' + e.getTableName(), + ColumnFamilyStore::getCompressionParameters))); + } + catch (Exception e) + { + throw new RuntimeException("error getting parameters for all tables", e); + } + } + private Map getCompressionParameters(IInvokableInstance instance, String tableName) { try diff --git a/test/unit/org/apache/cassandra/db/ReadCommandTest.java b/test/unit/org/apache/cassandra/db/ReadCommandTest.java index 16de3f061c75..334d69ebb800 100644 --- a/test/unit/org/apache/cassandra/db/ReadCommandTest.java +++ b/test/unit/org/apache/cassandra/db/ReadCommandTest.java @@ -878,7 +878,7 @@ public void testRepairedDataOverreadMetrics() cfs.disableAutoCompaction(); cfs.metadata().withSwapped(cfs.metadata().params.unbuild() .caching(CachingParams.CACHE_NOTHING) - .build()); + .build(KEYSPACE, CF9)); // Insert and repair insert(cfs, IntStream.range(0, 10), () -> IntStream.range(0, 10)); Util.flush(cfs); @@ -929,7 +929,7 @@ public void testRepairedDataOverreadMetrics() private void setGCGrace(ColumnFamilyStore cfs, int gcGrace) { - TableParams newParams = cfs.metadata().params.unbuild().gcGraceSeconds(gcGrace).build(); + TableParams newParams = cfs.metadata().params.unbuild().gcGraceSeconds(gcGrace).build(cfs.keyspace.getName(), cfs.name); KeyspaceMetadata keyspaceMetadata = Schema.instance.getKeyspaceMetadata(cfs.metadata().keyspace); SchemaTestUtil.addOrUpdateKeyspace(keyspaceMetadata.withSwapped(keyspaceMetadata.tables.withSwapped(cfs.metadata().withSwapped(newParams))), true); } diff --git a/test/unit/org/apache/cassandra/service/paxos/PaxosStateTest.java b/test/unit/org/apache/cassandra/service/paxos/PaxosStateTest.java index 893b1d2f0c34..48ff17c73db1 100644 --- a/test/unit/org/apache/cassandra/service/paxos/PaxosStateTest.java +++ b/test/unit/org/apache/cassandra/service/paxos/PaxosStateTest.java @@ -57,7 +57,7 @@ public static void setUpClass() throws Throwable SchemaLoader.loadSchema(); SchemaLoader.schemaDefinition("PaxosStateTest"); metadata = Keyspace.open("PaxosStateTestKeyspace1").getColumnFamilyStore("Standard1").metadata.get(); - metadata.withSwapped(metadata.params.unbuild().gcGraceSeconds(3600).build()); + metadata.withSwapped(metadata.params.unbuild().gcGraceSeconds(3600).build("PaxosStateTestKeyspace1", "Standard1")); } @AfterClass diff --git a/test/unit/org/apache/cassandra/utils/CassandraGenerators.java b/test/unit/org/apache/cassandra/utils/CassandraGenerators.java index 49701859b9bb..d07eb18eba61 100644 --- a/test/unit/org/apache/cassandra/utils/CassandraGenerators.java +++ b/test/unit/org/apache/cassandra/utils/CassandraGenerators.java @@ -324,7 +324,7 @@ public TableMetadata build(RandomnessSource rnd) .partitioner(PARTITIONER_GEN.generate(rnd)) .kind(tableKindGen.generate(rnd)) .isCounter(BOOLEAN_GEN.generate(rnd)) - .params(params.build()); + .params(params.build(ks, tableName)); int numPartitionColumns = numPartitionColumnsGen.generate(rnd); int numClusteringColumns = numClusteringColumnsGen.generate(rnd);