Search in sources :

Example 11 with Verifier

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

the class VerifyTest method testVerifyBrokenSSTableMetadata.

@Test
public void testVerifyBrokenSSTableMetadata() 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());
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    String filenameToCorrupt = sstable.descriptor.filenameFor(Component.STATS);
    FileChannel file = new File(filenameToCorrupt).newReadWriteChannel();
    file.position(0);
    file.write(ByteBufferUtil.bytes(StringUtils.repeat('z', 2)));
    file.close();
    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 (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(false).build())) {
        verifier.verify();
        fail("Expected a RuntimeException to be thrown");
    } catch (CorruptSSTableException err) {
        fail("wrong exception thrown");
    } catch (RuntimeException err) {
    }
}
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 12 with Verifier

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

the class SSTableImporter method verifySSTableForImport.

/**
 * Verify an sstable for import, throws exception if there is a failure verifying.
 *
 * @param verifyTokens to verify that the tokens are owned by the current node
 * @param verifySSTables to verify the sstables given. If this is false a "quick" verification will be run, just deserializing metadata
 * @param extendedVerify to validate the values in the sstables
 */
private void verifySSTableForImport(Descriptor descriptor, Set<Component> components, boolean verifyTokens, boolean verifySSTables, boolean extendedVerify) {
    SSTableReader reader = null;
    try {
        reader = SSTableReader.open(descriptor, components, cfs.metadata);
        Verifier.Options verifierOptions = Verifier.options().extendedVerification(extendedVerify).checkOwnsTokens(verifyTokens).quick(!verifySSTables).invokeDiskFailurePolicy(false).mutateRepairStatus(false).build();
        try (Verifier verifier = new Verifier(cfs, reader, false, verifierOptions)) {
            verifier.verify();
        }
    } catch (Throwable t) {
        throw new RuntimeException("Can't import sstable " + descriptor, t);
    } finally {
        if (reader != null)
            reader.selfRef().release();
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Verifier(org.apache.cassandra.db.compaction.Verifier)

Example 13 with Verifier

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

the class StandaloneVerifier method main.

public static void main(String[] args) {
    Options options = Options.parseArgs(args);
    initDatabaseDescriptorForTool();
    System.out.println("sstableverify using the following options: " + options);
    try {
        // load keyspace descriptions.
        Schema.instance.loadFromDisk(false);
        boolean hasFailed = false;
        if (Schema.instance.getTableMetadataRef(options.keyspaceName, options.cfName) == null)
            throw new IllegalArgumentException(String.format("Unknown keyspace/table %s.%s", options.keyspaceName, options.cfName));
        // Do not load sstables since they might be broken
        Keyspace keyspace = Keyspace.openWithoutSSTables(options.keyspaceName);
        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(options.cfName);
        OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
        Directories.SSTableLister lister = cfs.getDirectories().sstableLister(Directories.OnTxnErr.THROW).skipTemporary(true);
        List<SSTableReader> sstables = new ArrayList<>();
        // Verify sstables
        for (Map.Entry<Descriptor, Set<Component>> entry : lister.list().entrySet()) {
            Set<Component> components = entry.getValue();
            if (!components.contains(Component.DATA) || !components.contains(Component.PRIMARY_INDEX))
                continue;
            try {
                SSTableReader sstable = SSTableReader.openNoValidation(entry.getKey(), components, cfs);
                sstables.add(sstable);
            } catch (Exception e) {
                JVMStabilityInspector.inspectThrowable(e);
                System.err.println(String.format("Error Loading %s: %s", entry.getKey(), e.getMessage()));
                if (options.debug)
                    e.printStackTrace(System.err);
                System.exit(1);
            }
        }
        Verifier.Options verifyOptions = Verifier.options().invokeDiskFailurePolicy(false).extendedVerification(options.extended).checkVersion(options.checkVersion).mutateRepairStatus(options.mutateRepairStatus).checkOwnsTokens(!options.tokens.isEmpty()).tokenLookup(ignore -> options.tokens).build();
        handler.output("Running verifier with the following options: " + verifyOptions);
        for (SSTableReader sstable : sstables) {
            try (Verifier verifier = new Verifier(cfs, sstable, handler, true, verifyOptions)) {
                verifier.verify();
            } catch (Exception e) {
                handler.warn(String.format("Error verifying %s: %s", sstable, e.getMessage()), e);
                hasFailed = true;
            }
        }
        CompactionManager.instance.finishCompactionsAndShutdown(5, TimeUnit.MINUTES);
        // We need that to stop non daemonized threads
        System.exit(hasFailed ? 1 : 0);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        if (options.debug)
            e.printStackTrace(System.err);
        System.exit(1);
    }
}
Also used : CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) Range(org.apache.cassandra.dht.Range) HelpFormatter(org.apache.commons.cli.HelpFormatter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) GnuParser(org.apache.commons.cli.GnuParser) Token(org.apache.cassandra.dht.Token) Map(java.util.Map) OutputHandler(org.apache.cassandra.utils.OutputHandler) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) Component(org.apache.cassandra.io.sstable.Component) CommandLine(org.apache.commons.cli.CommandLine) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) Keyspace(org.apache.cassandra.db.Keyspace) CommandLineParser(org.apache.commons.cli.CommandLineParser) Collection(java.util.Collection) Set(java.util.Set) CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) ParseException(org.apache.commons.cli.ParseException) Collections(java.util.Collections) Directories(org.apache.cassandra.db.Directories) Verifier(org.apache.cassandra.db.compaction.Verifier) CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) Set(java.util.Set) ArrayList(java.util.ArrayList) Verifier(org.apache.cassandra.db.compaction.Verifier) ParseException(org.apache.commons.cli.ParseException) Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) OutputHandler(org.apache.cassandra.utils.OutputHandler) Component(org.apache.cassandra.io.sstable.Component) Map(java.util.Map)

Example 14 with Verifier

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

the class VerifyTest method testVerifyIncorrectDigest.

@Test
public void testVerifyIncorrectDigest() throws IOException, WriteTimeoutException {
    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 (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(false).build())) {
        verifier.verify();
        fail("Expected a RuntimeException to be thrown");
    } catch (RuntimeException 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 15 with Verifier

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

the class VerifyTest method testExtendedVerifyCorrect.

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