Skip to content

Commit 70626d6

Browse files
author
ssekaran
committed
CASSANDRA-21177- Adding option for randomizing memtable type in Simulator tests
1 parent a3ad539 commit 70626d6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/simulator/main/org/apache/cassandra/simulator/ClusterSimulation.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
import com.google.common.util.concurrent.AsyncFunction;
3939
import com.google.common.util.concurrent.FutureCallback;
4040

41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
43+
4144
import org.apache.cassandra.concurrent.ExecutorFactory;
4245
import org.apache.cassandra.config.ParameterizedClass;
4346
import org.apache.cassandra.distributed.Cluster;
@@ -112,6 +115,8 @@
112115
@SuppressWarnings("RedundantCast")
113116
public class ClusterSimulation<S extends Simulation> implements AutoCloseable
114117
{
118+
private static final Logger logger = LoggerFactory.getLogger(ClusterSimulation.class);
119+
115120
public static final Class<?>[] SHARE = new Class[]
116121
{
117122
AsyncFunction.class,
@@ -188,6 +193,7 @@ public static abstract class Builder<S extends Simulation>
188193
protected HeapPool.Logged.Listener memoryListener;
189194
protected SimulatedTime.Listener timeListener = (i1, i2) -> {};
190195
protected LongConsumer onThreadLocalRandomCheck;
196+
protected Boolean useTrieMemtable = null; // null = random
191197

192198
public Debug debug()
193199
{
@@ -516,6 +522,12 @@ public Builder<S> onThreadLocalRandomCheck(LongConsumer runnable)
516522
return this;
517523
}
518524

525+
public Builder<S> useTrieMemtable(boolean useTrie)
526+
{
527+
this.useTrieMemtable = useTrie;
528+
return this;
529+
}
530+
519531
public abstract ClusterSimulation<S> create(long seed) throws IOException;
520532
}
521533

@@ -654,6 +666,12 @@ public ClusterSimulation(RandomSource random, long seed, int uniqueNum,
654666

655667
execution = new SimulatedExecution();
656668

669+
boolean useTrieMemtable = builder.useTrieMemtable != null
670+
? builder.useTrieMemtable
671+
: random.uniform(0, 2) == 0; // 50/50 chance
672+
logger.info("Seed 0x{} using memtable: {}", Long.toHexString(seed),
673+
useTrieMemtable ? "TrieMemtable" : "SkipListMemtable");
674+
657675
KindOfSequence kindOfDriftSequence = Choices.uniform(KindOfSequence.values()).choose(random);
658676
KindOfSequence kindOfDiscontinuitySequence = Choices.uniform(KindOfSequence.values()).choose(random);
659677
time = new SimulatedTime(numOfNodes, random, 1577836800000L /*Jan 1st UTC*/, builder.clockDriftNanos, kindOfDriftSequence,
@@ -700,6 +718,14 @@ public ClusterSimulation(RandomSource random, long seed, int uniqueNum,
700718

701719
if (commitlogCompressed)
702720
config.set("commitlog_compression", new ParameterizedClass(LZ4Compressor.class.getName(), emptyMap()));
721+
722+
if (useTrieMemtable)
723+
{
724+
config.set("memtable", Map.of(
725+
"configurations", Map.of(
726+
"default", Map.of("class_name", "TrieMemtable"))));
727+
}
728+
703729
configUpdater.accept(threadAllocator.update(config));
704730
})
705731
.withInstanceInitializer(new IInstanceInitializer()

0 commit comments

Comments
 (0)