Search in sources :

Example 6 with Component

use of org.apache.cassandra.io.sstable.Component 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)

Example 7 with Component

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

the class ColumnFamilyStoreTest method testBackupAfterFlush.

@Test
public void testBackupAfterFlush() throws Throwable {
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE2).getColumnFamilyStore(CF_STANDARD1);
    new RowUpdateBuilder(cfs.metadata(), 0, ByteBufferUtil.bytes("key1")).clustering("Column1").add("val", "asdf").build().applyUnsafe();
    cfs.forceBlockingFlush();
    new RowUpdateBuilder(cfs.metadata(), 0, ByteBufferUtil.bytes("key2")).clustering("Column1").add("val", "asdf").build().applyUnsafe();
    cfs.forceBlockingFlush();
    for (int version = 1; version <= 2; ++version) {
        Descriptor existing = new Descriptor(cfs.getDirectories().getDirectoryForNewSSTables(), KEYSPACE2, CF_STANDARD1, version, SSTableFormat.Type.BIG);
        Descriptor desc = new Descriptor(Directories.getBackupsDirectory(existing), KEYSPACE2, CF_STANDARD1, version, SSTableFormat.Type.BIG);
        for (Component c : new Component[] { Component.DATA, Component.PRIMARY_INDEX, Component.FILTER, Component.STATS }) assertTrue("Cannot find backed-up file:" + desc.filenameFor(c), new File(desc.filenameFor(c)).exists());
    }
}
Also used : Descriptor(org.apache.cassandra.io.sstable.Descriptor) Component(org.apache.cassandra.io.sstable.Component) File(java.io.File) Test(org.junit.Test)

Example 8 with Component

use of org.apache.cassandra.io.sstable.Component in project eiger by wlloyd.

the class ColumnFamilyStoreTest method testBackupAfterFlush.

@Test
public void testBackupAfterFlush() throws Throwable {
    ColumnFamilyStore cfs = insertKey1Key2();
    for (int version = 1; version <= 2; ++version) {
        Descriptor existing = new Descriptor(cfs.directories.getDirectoryForNewSSTables(1), "Keyspace2", "Standard1", version, false);
        Descriptor desc = new Descriptor(Directories.getBackupsDirectory(existing), "Keyspace2", "Standard1", version, false);
        for (Component c : new Component[] { Component.DATA, Component.PRIMARY_INDEX, Component.FILTER, Component.STATS }) assertTrue("can not find backedup file:" + desc.filenameFor(c), new File(desc.filenameFor(c)).exists());
    }
}
Also used : Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Component(org.apache.cassandra.io.sstable.Component) File(java.io.File) Test(org.junit.Test)

Aggregations

Component (org.apache.cassandra.io.sstable.Component)8 Descriptor (org.apache.cassandra.io.sstable.Descriptor)7 File (java.io.File)6 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)4 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 Directories (org.apache.cassandra.db.Directories)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Pattern (java.util.regex.Pattern)1 CreateTableStatement (org.apache.cassandra.cql3.statements.CreateTableStatement)1 Keyspace (org.apache.cassandra.db.Keyspace)1 StartupException (org.apache.cassandra.exceptions.StartupException)1 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)1 MetadataCollector (org.apache.cassandra.io.sstable.metadata.MetadataCollector)1 MetadataComponent (org.apache.cassandra.io.sstable.metadata.MetadataComponent)1 StatsMetadata (org.apache.cassandra.io.sstable.metadata.StatsMetadata)1 CmdLineOptions (org.apache.cassandra.tools.BulkLoader.CmdLineOptions)1 AlwaysPresentFilter (org.apache.cassandra.utils.AlwaysPresentFilter)1