use of org.apache.cassandra.io.sstable.SSTableTxnWriter in project cassandra by apache.
the class ScrubTest method testScrubOutOfOrder.
@Test
public void testScrubOutOfOrder() {
// This test assumes ByteOrderPartitioner to create out-of-order SSTable
IPartitioner oldPartitioner = DatabaseDescriptor.getPartitioner();
DatabaseDescriptor.setPartitionerUnsafe(new ByteOrderedPartitioner());
// Create out-of-order SSTable
File tempDir = FileUtils.createTempFile("ScrubTest.testScrubOutOfOrder", "").parent();
// create ks/cf directory
File tempDataDir = new File(tempDir, String.join(File.pathSeparator(), ksName, CF));
assertTrue(tempDataDir.tryCreateDirectories());
try {
CompactionManager.instance.disableAutoCompaction();
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
List<String> keys = Arrays.asList("t", "a", "b", "z", "c", "y", "d");
Descriptor desc = cfs.newSSTableDescriptor(tempDataDir);
try (LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.WRITE);
SSTableTxnWriter writer = new SSTableTxnWriter(txn, createTestWriter(desc, keys.size(), cfs.metadata, txn))) {
for (String k : keys) {
PartitionUpdate update = UpdateBuilder.create(cfs.metadata(), Util.dk(k)).newRow("someName").add("val", "someValue").build();
writer.append(update.unfilteredIterator());
}
writer.finish(false);
}
try {
SSTableReader.open(desc, cfs.metadata);
fail("SSTR validation should have caught the out-of-order rows");
} catch (CorruptSSTableException ise) {
/* this is expected */
}
// open without validation for scrubbing
Set<Component> components = new HashSet<>();
if (new File(desc.filenameFor(Component.COMPRESSION_INFO)).exists())
components.add(Component.COMPRESSION_INFO);
components.add(Component.DATA);
components.add(Component.PRIMARY_INDEX);
components.add(Component.FILTER);
components.add(Component.STATS);
components.add(Component.SUMMARY);
components.add(Component.TOC);
SSTableReader sstable = SSTableReader.openNoValidation(desc, components, cfs);
if (sstable.last.compareTo(sstable.first) < 0)
sstable.last = sstable.first;
try (LifecycleTransaction scrubTxn = LifecycleTransaction.offline(OperationType.SCRUB, sstable);
Scrubber scrubber = new Scrubber(cfs, scrubTxn, false, true)) {
scrubber.scrub();
}
LifecycleTransaction.waitForDeletions();
cfs.loadNewSSTables();
assertOrderedAll(cfs, 7);
} finally {
FileUtils.deleteRecursive(tempDataDir);
// reset partitioner
DatabaseDescriptor.setPartitionerUnsafe(oldPartitioner);
}
}
Aggregations