Search in sources :

Example 1 with ByteOrderedPartitioner

use of org.apache.cassandra.dht.ByteOrderedPartitioner 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);
    }
}
Also used : SSTableTxnWriter(org.apache.cassandra.io.sstable.SSTableTxnWriter) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) Scrubber(org.apache.cassandra.db.compaction.Scrubber) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Descriptor(org.apache.cassandra.io.sstable.Descriptor) Component(org.apache.cassandra.io.sstable.Component) File(org.apache.cassandra.io.util.File) ByteOrderedPartitioner(org.apache.cassandra.dht.ByteOrderedPartitioner) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) IPartitioner(org.apache.cassandra.dht.IPartitioner) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 Scrubber (org.apache.cassandra.db.compaction.Scrubber)1 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)1 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)1 ByteOrderedPartitioner (org.apache.cassandra.dht.ByteOrderedPartitioner)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Component (org.apache.cassandra.io.sstable.Component)1 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)1 Descriptor (org.apache.cassandra.io.sstable.Descriptor)1 SSTableTxnWriter (org.apache.cassandra.io.sstable.SSTableTxnWriter)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 File (org.apache.cassandra.io.util.File)1 Test (org.junit.Test)1