Search in sources :

Example 1 with Verifier

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

the class VerifyTest method testOutOfRangeTokens.

@Test(expected = RuntimeException.class)
public void testOutOfRangeTokens() throws IOException {
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    fillCF(cfs, 100);
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    byte[] tk1 = new byte[1], tk2 = new byte[1];
    tk1[0] = 2;
    tk2[0] = 1;
    tmd.updateNormalToken(new ByteOrderedPartitioner.BytesToken(tk1), InetAddressAndPort.getByName("127.0.0.1"));
    tmd.updateNormalToken(new ByteOrderedPartitioner.BytesToken(tk2), InetAddressAndPort.getByName("127.0.0.2"));
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().checkOwnsTokens(true).extendedVerification(true).build())) {
        verifier.verify();
    } finally {
        StorageService.instance.getTokenMetadata().clearUnsafe();
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Verifier(org.apache.cassandra.db.compaction.Verifier) ByteOrderedPartitioner(org.apache.cassandra.dht.ByteOrderedPartitioner) Test(org.junit.Test)

Example 2 with Verifier

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

the class VerifyTest method testVerifyMutateRepairStatus.

@Test
public void testVerifyMutateRepairStatus() throws IOException, WriteTimeoutException {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
    cfs.truncateBlocking();
    fillCF(cfs, 2);
    Util.getAll(Util.cmd(cfs).build());
    // make the sstable repaired:
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    sstable.descriptor.getMetadataSerializer().mutateRepairMetadata(sstable.descriptor, System.currentTimeMillis(), sstable.getPendingRepair(), sstable.isTransient());
    sstable.reloadSSTableMetadata();
    // break the sstable:
    Long correctChecksum;
    try (RandomAccessReader file = RandomAccessReader.open(new File(sstable.descriptor.filenameFor(Component.DIGEST)))) {
        correctChecksum = file.readLong();
    }
    writeChecksum(++correctChecksum, sstable.descriptor.filenameFor(Component.DIGEST));
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().mutateRepairStatus(false).invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
        fail("Expected a CorruptSSTableException to be thrown");
    } catch (CorruptSSTableException err) {
    }
    assertTrue(sstable.isRepaired());
    // now the repair status should be changed:
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().mutateRepairStatus(true).invokeDiskFailurePolicy(true).build())) {
        verifier.verify();
        fail("Expected a CorruptSSTableException to be thrown");
    } catch (CorruptSSTableException err) {
    }
    assertFalse(sstable.isRepaired());
}
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 3 with Verifier

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

the class VerifyTest method testVerifyCorrect.

@Test
public void testVerifyCorrect() {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    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)

Example 4 with Verifier

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

the class VerifyTest method testVerifyLocalPartitioner.

@Test
public void testVerifyLocalPartitioner() throws UnknownHostException {
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    byte[] tk1 = new byte[1], tk2 = new byte[1];
    tk1[0] = 2;
    tk2[0] = 1;
    tmd.updateNormalToken(new ByteOrderedPartitioner.BytesToken(tk1), InetAddressAndPort.getByName("127.0.0.1"));
    tmd.updateNormalToken(new ByteOrderedPartitioner.BytesToken(tk2), InetAddressAndPort.getByName("127.0.0.2"));
    // write some bogus to a localpartitioner table
    Batch bogus = Batch.createLocal(UUID.randomUUID(), 0, Collections.emptyList());
    BatchlogManager.store(bogus);
    ColumnFamilyStore cfs = Keyspace.open("system").getColumnFamilyStore("batches");
    cfs.forceBlockingFlush();
    for (SSTableReader sstable : cfs.getLiveSSTables()) {
        try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().checkOwnsTokens(true).build())) {
            verifier.verify();
        }
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Batch(org.apache.cassandra.batchlog.Batch) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Verifier(org.apache.cassandra.db.compaction.Verifier) ByteOrderedPartitioner(org.apache.cassandra.dht.ByteOrderedPartitioner) Test(org.junit.Test)

Example 5 with Verifier

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

the class VerifyTest method testMutateRepair.

@Test
public void testMutateRepair() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
    fillCF(cfs, 2);
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    sstable.descriptor.getMetadataSerializer().mutateRepairMetadata(sstable.descriptor, 1, sstable.getPendingRepair(), sstable.isTransient());
    sstable.reloadSSTableMetadata();
    cfs.getTracker().notifySSTableRepairedStatusChanged(Collections.singleton(sstable));
    assertTrue(sstable.isRepaired());
    cfs.forceMajorCompaction();
    sstable = cfs.getLiveSSTables().iterator().next();
    Long correctChecksum;
    try (RandomAccessReader file = RandomAccessReader.open(new File(sstable.descriptor.filenameFor(Component.DIGEST)))) {
        correctChecksum = file.readLong();
    }
    writeChecksum(++correctChecksum, sstable.descriptor.filenameFor(Component.DIGEST));
    try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).mutateRepairStatus(true).build())) {
        verifier.verify();
        fail("should be corrupt");
    } catch (CorruptSSTableException e) {
    }
    assertFalse(sstable.isRepaired());
}
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)

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