Skip to content

Commit 27a1b24

Browse files
committed
Adds ability to change compaction default in YAML
and switches to UCS for the trie unit test suite
1 parent 8a727a0 commit 27a1b24

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

src/java/org/apache/cassandra/config/Config.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ public enum PaxosOnLinearizabilityViolation
10831083
public volatile long min_tracked_partition_tombstone_count = 5000;
10841084
public volatile boolean top_partitions_enabled = true;
10851085

1086+
/**
1087+
* Default compaction configuration, used if a table does not specify any.
1088+
*/
1089+
public ParameterizedClass default_compaction = null;
1090+
10861091
public static Supplier<Config> getOverrideLoadConfig()
10871092
{
10881093
return overrideLoadConfig;

src/java/org/apache/cassandra/config/DatabaseDescriptor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,4 +4677,9 @@ public static void setClientRequestSizeMetricsEnabled(boolean enabled)
46774677
{
46784678
return Objects.requireNonNull(sstableFormatFactories, "Forgot to initialize DatabaseDescriptor?");
46794679
}
4680+
4681+
public static ParameterizedClass getDefaultCompaction()
4682+
{
4683+
return conf != null ? conf.default_compaction : null;
4684+
}
46804685
}

src/java/org/apache/cassandra/schema/CompactionParams.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232

33+
import org.apache.cassandra.config.DatabaseDescriptor;
34+
import org.apache.cassandra.config.ParameterizedClass;
3335
import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
3436
import org.apache.cassandra.db.compaction.LeveledCompactionStrategy;
3537
import org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy;
@@ -84,8 +86,23 @@ public static Optional<TombstoneOption> forName(String name)
8486
ImmutableMap.of(Option.MIN_THRESHOLD.toString(), Integer.toString(DEFAULT_MIN_THRESHOLD),
8587
Option.MAX_THRESHOLD.toString(), Integer.toString(DEFAULT_MAX_THRESHOLD));
8688

87-
public static final CompactionParams DEFAULT =
88-
new CompactionParams(SizeTieredCompactionStrategy.class, DEFAULT_THRESHOLDS, DEFAULT_ENABLED, DEFAULT_PROVIDE_OVERLAPPING_TOMBSTONES);
89+
public static final CompactionParams DEFAULT;
90+
static
91+
{
92+
ParameterizedClass defaultCompaction = DatabaseDescriptor.getDefaultCompaction();
93+
if (defaultCompaction == null)
94+
{
95+
DEFAULT = new CompactionParams(SizeTieredCompactionStrategy.class,
96+
DEFAULT_THRESHOLDS,
97+
DEFAULT_ENABLED,
98+
DEFAULT_PROVIDE_OVERLAPPING_TOMBSTONES);
99+
}
100+
else
101+
{
102+
DEFAULT = create(classFromName(defaultCompaction.class_name),
103+
defaultCompaction.parameters);
104+
}
105+
}
89106

90107
private final Class<? extends AbstractCompactionStrategy> klass;
91108
private final ImmutableMap<String, String> options;

test/conf/trie_memtable.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
# Change default memtable implementation to TrieMemtable
1819
# Note: this attaches at the end of cassandra.yaml, where the memtable configuration setting must be.
1920
default:
2021
inherits: trie
22+
23+
# Change default compaction to UCS
24+
default_compaction:
25+
class_name: UnifiedCompactionStrategy
26+
parameters:
27+
base_shard_count: 1

test/unit/org/apache/cassandra/cql3/statements/DescribeStatementTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cassandra.cql3.statements;
1919

2020
import java.util.Iterator;
21+
import java.util.Map;
2122
import java.util.Optional;
2223

2324
import com.google.common.collect.ImmutableList;
@@ -34,9 +35,11 @@
3435

3536
import org.apache.cassandra.config.DatabaseDescriptor;
3637
import org.apache.cassandra.cql3.CQLTester;
38+
import org.apache.cassandra.cql3.CqlBuilder;
3739
import org.apache.cassandra.dht.Token;
3840
import org.apache.cassandra.locator.InetAddressAndPort;
3941
import org.apache.cassandra.locator.TokenMetadata;
42+
import org.apache.cassandra.schema.CompactionParams;
4043
import org.apache.cassandra.schema.Schema;
4144
import org.apache.cassandra.schema.TableId;
4245
import org.apache.cassandra.service.StorageService;
@@ -844,21 +847,26 @@ private static String tableParametersCql()
844847
" AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}\n" +
845848
" AND cdc = false\n" +
846849
" AND comment = ''\n" +
847-
" AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}\n" +
850+
" AND compaction = " + cqlQuoted(CompactionParams.DEFAULT.asMap()) + "\n" +
848851
" AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}\n" +
849852
" AND memtable = 'default'\n" +
850853
" AND crc_check_chance = 1.0\n" +
851854
" AND default_time_to_live = 0\n" +
852855
" AND extensions = {}\n" +
853856
" AND gc_grace_seconds = 864000\n" +
854-
" AND incremental_backups = true\n" +
857+
" AND incremental_backups = true\n" +
855858
" AND max_index_interval = 2048\n" +
856859
" AND memtable_flush_period_in_ms = 0\n" +
857860
" AND min_index_interval = 128\n" +
858861
" AND read_repair = 'BLOCKING'\n" +
859862
" AND speculative_retry = '99p';";
860863
}
861864

865+
private static String cqlQuoted(Map<String, String> map)
866+
{
867+
return new CqlBuilder().append(map).toString();
868+
}
869+
862870
private static String mvParametersCql()
863871
{
864872
return "additional_write_policy = '99p'\n" +
@@ -867,7 +875,7 @@ private static String mvParametersCql()
867875
" AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}\n" +
868876
" AND cdc = false\n" +
869877
" AND comment = ''\n" +
870-
" AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}\n" +
878+
" AND compaction = " + cqlQuoted(CompactionParams.DEFAULT.asMap()) + "\n" +
871879
" AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}\n" +
872880
" AND memtable = 'default'\n" +
873881
" AND crc_check_chance = 1.0\n" +

0 commit comments

Comments
 (0)