Search in sources :

Example 6 with Verifier

use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.

the class VerifyTest method testBrokenComponentHelper.

private void testBrokenComponentHelper(Component componentToBreak) throws IOException {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
    fillCF(cfs, 2);
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().build())) {
        // still not corrupt, should pass
        verifier.verify();
    }
    String filenameToCorrupt = sstable.descriptor.filenameFor(componentToBreak);
    try (FileChannel fileChannel = new File(filenameToCorrupt).newReadWriteChannel()) {
        fileChannel.truncate(3);
    }
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
        fail("should throw exception");
    } catch (CorruptSSTableException e) {
    // expected
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) FileChannel(java.nio.channels.FileChannel) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Verifier(org.apache.cassandra.db.compaction.Verifier) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) File(org.apache.cassandra.io.util.File)

Example 7 with Verifier

use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.

the class VerifyTest method testQuick.

@Test
public void testQuick() throws IOException {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF);
    fillCF(cfs, 2);
    Util.getAll(Util.cmd(cfs).build());
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    try (RandomAccessReader file = RandomAccessReader.open(new File(sstable.descriptor.filenameFor(Component.DIGEST)))) {
        Long correctChecksum = file.readLong();
        writeChecksum(++correctChecksum, sstable.descriptor.filenameFor(Component.DIGEST));
    }
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
        fail("Expected a CorruptSSTableException to be thrown");
    } catch (CorruptSSTableException err) {
    }
    try (// with quick = true we don't verify the digest
    Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).quick(true).build())) {
        verifier.verify();
    }
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
        fail("Expected a RuntimeException to be thrown");
    } catch (CorruptSSTableException err) {
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Verifier(org.apache.cassandra.db.compaction.Verifier) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) File(org.apache.cassandra.io.util.File) Test(org.junit.Test)

Example 8 with Verifier

use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.

the class VerifyTest method testExtendedVerifyCounterCorrectUncompressed.

@Test
public void testExtendedVerifyCounterCorrectUncompressed() {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(COUNTER_CF4);
    fillCounterCF(cfs, 2);
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().extendedVerification(true).invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
    } catch (CorruptSSTableException err) {
        fail("Unexpected CorruptSSTableException");
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Verifier(org.apache.cassandra.db.compaction.Verifier) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) Test(org.junit.Test)

Example 9 with Verifier

use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.

the class VerifyTest method testVerifyCorruptRowCorrectDigest.

@Test
public void testVerifyCorruptRowCorrectDigest() throws IOException, WriteTimeoutException {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
    fillCF(cfs, 2);
    Util.getAll(Util.cmd(cfs).build());
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    // overwrite one row with garbage
    long row0Start = sstable.getPosition(PartitionPosition.ForKey.get(ByteBufferUtil.bytes("0"), cfs.getPartitioner()), SSTableReader.Operator.EQ).position;
    long row1Start = sstable.getPosition(PartitionPosition.ForKey.get(ByteBufferUtil.bytes("1"), cfs.getPartitioner()), SSTableReader.Operator.EQ).position;
    long startPosition = row0Start < row1Start ? row0Start : row1Start;
    long endPosition = row0Start < row1Start ? row1Start : row0Start;
    FileChannel file = new File(sstable.getFilename()).newReadWriteChannel();
    file.position(startPosition);
    file.write(ByteBufferUtil.bytes(StringUtils.repeat('z', 2)));
    file.close();
    if (ChunkCache.instance != null)
        ChunkCache.instance.invalidateFile(sstable.getFilename());
    // Update the Digest to have the right Checksum
    writeChecksum(simpleFullChecksum(sstable.getFilename()), sstable.descriptor.filenameFor(Component.DIGEST));
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
        // First a simple verify checking digest, which should succeed
        try {
            verifier.verify();
        } catch (CorruptSSTableException err) {
            fail("Simple verify should have succeeded as digest matched");
        }
    }
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).extendedVerification(true).build())) {
        // Now try extended verify
        try {
            verifier.verify();
        } catch (CorruptSSTableException err) {
            return;
        }
        fail("Expected a CorruptSSTableException to be thrown");
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) FileChannel(java.nio.channels.FileChannel) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Verifier(org.apache.cassandra.db.compaction.Verifier) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) File(org.apache.cassandra.io.util.File) Test(org.junit.Test)

Example 10 with Verifier

use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.

the class VerifyTest method testVerifyCorrectUncompressed.

@Test
public void testVerifyCorrectUncompressed() {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF3);
    fillCF(cfs, 2);
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
    } catch (CorruptSSTableException err) {
        fail("Unexpected CorruptSSTableException");
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Verifier(org.apache.cassandra.db.compaction.Verifier) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) Test(org.junit.Test)

Aggregations

Verifier (org.apache.cassandra.db.compaction.Verifier)21 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)21 Test (org.junit.Test)18 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)17 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)15 File (org.apache.cassandra.io.util.File)8 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)4 FileChannel (java.nio.channels.FileChannel)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 ByteOrderedPartitioner (org.apache.cassandra.dht.ByteOrderedPartitioner)2 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1