Skip to content

Commit 733e06c

Browse files
author
Nitsan Wakart
committed
Add support for stress testing new compaction code
1 parent 74c9827 commit 733e06c

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

test/unit/org/apache/cassandra/cql3/RandomSchemaTest.java

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,30 @@
3232

3333
import org.apache.cassandra.config.CassandraRelevantProperties;
3434
import org.apache.cassandra.config.DatabaseDescriptor;
35+
import org.apache.cassandra.db.ColumnFamilyStore;
36+
import org.apache.cassandra.db.compaction.CursorCompactor;
37+
import org.apache.cassandra.io.sstable.ISSTableScanner;
38+
import org.apache.cassandra.io.sstable.IVerifier;
3539
import org.apache.cassandra.io.sstable.format.SSTableFormat;
40+
import org.apache.cassandra.io.sstable.format.SSTableReader;
41+
import org.apache.cassandra.io.sstable.format.big.BigTableReader;
42+
import org.apache.cassandra.io.sstable.format.big.BigTableVerifier;
3643
import org.apache.cassandra.io.util.DataInputBuffer;
3744
import org.apache.cassandra.io.util.DataOutputBuffer;
3845
import org.apache.cassandra.schema.ColumnMetadata;
3946
import org.apache.cassandra.schema.TableMetadata;
4047
import org.apache.cassandra.tcm.ClusterMetadata;
4148
import org.apache.cassandra.tcm.membership.NodeVersion;
49+
import org.apache.cassandra.tools.JsonTransformer;
50+
import org.apache.cassandra.tools.Util;
4251
import org.apache.cassandra.utils.AbstractTypeGenerators;
4352
import org.apache.cassandra.utils.AbstractTypeGenerators.TypeGenBuilder;
4453
import org.apache.cassandra.utils.CassandraGenerators;
4554
import org.apache.cassandra.utils.CassandraGenerators.TableMetadataBuilder;
55+
import org.apache.cassandra.utils.Clock;
4656
import org.apache.cassandra.utils.FailingConsumer;
4757
import org.apache.cassandra.utils.Generators;
58+
import org.apache.cassandra.utils.OutputHandler;
4859
import org.quicktheories.core.Gen;
4960
import org.quicktheories.core.RandomnessSource;
5061
import org.quicktheories.generators.SourceDSL;
@@ -56,6 +67,7 @@
5667

5768
public class RandomSchemaTest extends CQLTester.InMemory
5869
{
70+
static final boolean STRESS_CURSOR_COMPACTION = false;
5971
static
6072
{
6173
// make sure blob is always the same
@@ -75,30 +87,34 @@ public void test()
7587
resetSchema();
7688

7789
// TODO : when table level override of sstable format is allowed, migrate to that
78-
DatabaseDescriptor.setSelectedSSTableFormat(sstableFormatGen.generate(random));
90+
if (!STRESS_CURSOR_COMPACTION) DatabaseDescriptor.setSelectedSSTableFormat(sstableFormatGen.generate(random));
7991

8092
Gen<String> udtName = Generators.unique(IDENTIFIER_GEN);
8193

8294
TypeGenBuilder withoutUnsafeEquality = AbstractTypeGenerators.withoutUnsafeEquality()
8395
.withUDTNames(udtName);
84-
TableMetadata metadata = new TableMetadataBuilder()
85-
.withKeyspaceName(KEYSPACE)
86-
.withTableKinds(TableMetadata.Kind.REGULAR)
87-
.withKnownMemtables()
88-
.withDefaultTypeGen(AbstractTypeGenerators.builder()
89-
.withoutEmpty()
90-
.withMaxDepth(2)
91-
.withDefaultSetKey(withoutUnsafeEquality)
92-
.withoutTypeKinds(AbstractTypeGenerators.TypeKind.COUNTER)
93-
.withUDTNames(udtName))
94-
.withPartitionColumnsCount(1)
95-
.withPrimaryColumnTypeGen(new TypeGenBuilder(withoutUnsafeEquality)
96-
// map of vector of map crossed the size cut-off for one of the tests, so changed max depth from 2 to 1, so we can't have the second map
97-
.withMaxDepth(1))
98-
.withClusteringColumnsBetween(1, 2)
99-
.withRegularColumnsBetween(1, 5)
100-
.withStaticColumnsBetween(0, 2)
101-
.build(random);
96+
TableMetadata metadata;
97+
do
98+
{
99+
metadata = new TableMetadataBuilder()
100+
.withKeyspaceName(KEYSPACE)
101+
.withTableKinds(TableMetadata.Kind.REGULAR)
102+
.withKnownMemtables()
103+
.withDefaultTypeGen(AbstractTypeGenerators.builder()
104+
.withoutEmpty()
105+
.withMaxDepth(2)
106+
.withDefaultSetKey(withoutUnsafeEquality)
107+
.withoutTypeKinds(AbstractTypeGenerators.TypeKind.COUNTER)
108+
.withUDTNames(udtName))
109+
.withPartitionColumnsCount(1)
110+
.withPrimaryColumnTypeGen(new TypeGenBuilder(withoutUnsafeEquality)
111+
// map of vector of map crossed the size cut-off for one of the tests, so changed max depth from 2 to 1, so we can't have the second map
112+
.withMaxDepth(1))
113+
.withClusteringColumnsBetween(1, 2)
114+
.withRegularColumnsBetween(1, 5)
115+
.withStaticColumnsBetween(0, 2)
116+
.build(random);
117+
} while (STRESS_CURSOR_COMPACTION && CursorCompactor.unsupportedMetadata(metadata));
102118
maybeCreateUDTs(metadata);
103119
String createTable = metadata.toCqlString(true, false, false);
104120
// just to make the CREATE TABLE stmt easier to read for CUSTOM types
@@ -129,6 +145,8 @@ public void test()
129145
// check sstable
130146
flush(KEYSPACE, metadata.name);
131147
compact(KEYSPACE, metadata.name);
148+
ColumnFamilyStore cfs = getColumnFamilyStore(KEYSPACE, metadata.name);
149+
verifyAndPrint(cfs, cfs.getLiveSSTables().iterator().next());
132150
assertRows(execute(selectStmt, (Object[]) rowKey), expected);
133151
assertRows(execute(tokenStmt, (Object[]) partitionKeys), partitionKeys);
134152
assertRowsNet(executeNet(selectStmt, (Object[]) rowKey), expected);
@@ -151,6 +169,20 @@ public void test()
151169
}
152170
});
153171
}
172+
private static void verifyAndPrint(ColumnFamilyStore cfs, SSTableReader sstable) throws IOException
173+
{
174+
try (IVerifier verifier = new BigTableVerifier(cfs, (BigTableReader) sstable,
175+
new OutputHandler.LogOutput(), false,
176+
IVerifier.options().invokeDiskFailurePolicy(true).extendedVerification(true).build()))
177+
{
178+
verifier.verify();
179+
}
180+
try (ISSTableScanner scanner = sstable.getScanner())
181+
{
182+
JsonTransformer.toJsonLines(scanner, Util.iterToStream(scanner), false, false, sstable.metadata(),
183+
Clock.Global.currentTimeMillis() / 1000, System.out);
184+
}
185+
}
154186

155187
private void serde(ClusterMetadata metadata, TableMetadata tableMetadata) throws IOException
156188
{

0 commit comments

Comments
 (0)