Search in sources :

Example 16 with CorruptSSTableException

use of org.apache.cassandra.io.sstable.CorruptSSTableException in project cassandra by apache.

the class StandaloneVerifier method main.

public static void main(String[] args) {
    Options options = Options.parseArgs(args);
    Util.initDatabaseDescriptor();
    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);
        boolean extended = options.extended;
        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);
            }
        }
        for (SSTableReader sstable : sstables) {
            try {
                try (Verifier verifier = new Verifier(cfs, sstable, handler, true)) {
                    verifier.verify(extended);
                } catch (CorruptSSTableException cs) {
                    System.err.println(String.format("Error verifying %s: %s", sstable, cs.getMessage()));
                    hasFailed = true;
                }
            } catch (Exception e) {
                System.err.println(String.format("Error verifying %s: %s", sstable, e.getMessage()));
                e.printStackTrace(System.err);
            }
        }
        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 : CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) 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) OutputHandler(org.apache.cassandra.utils.OutputHandler) Component(org.apache.cassandra.io.sstable.Component)

Aggregations

CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)16 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)11 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)10 Verifier (org.apache.cassandra.db.compaction.Verifier)10 Test (org.junit.Test)10 IOException (java.io.IOException)4 EOFException (java.io.EOFException)3 FSReadError (org.apache.cassandra.io.FSReadError)2 BufferPoolMetricSet (com.codahale.metrics.jvm.BufferPoolMetricSet)1 FileDescriptorRatioGauge (com.codahale.metrics.jvm.FileDescriptorRatioGauge)1 GarbageCollectorMetricSet (com.codahale.metrics.jvm.GarbageCollectorMetricSet)1 MemoryUsageGaugeSet (com.codahale.metrics.jvm.MemoryUsageGaugeSet)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 CRC32 (java.util.zip.CRC32)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Directories (org.apache.cassandra.db.Directories)1 Keyspace (org.apache.cassandra.db.Keyspace)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 StartupException (org.apache.cassandra.exceptions.StartupException)1