Search in sources :

Example 26 with Descriptor

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

the class SSTableRepairedAtSetter method main.

/**
     * @param args a list of sstables whose metadata we are changing
     */
public static void main(final String[] args) throws IOException {
    PrintStream out = System.out;
    if (args.length == 0) {
        out.println("This command should be run with Cassandra stopped!");
        out.println("Usage: sstablerepairedset [--is-repaired | --is-unrepaired] [-f <sstable-list> | <sstables>]");
        System.exit(1);
    }
    if (args.length < 3 || !args[0].equals("--really-set") || (!args[1].equals("--is-repaired") && !args[1].equals("--is-unrepaired"))) {
        out.println("This command should be run with Cassandra stopped, otherwise you will get very strange behavior");
        out.println("Verify that Cassandra is not running and then execute the command like this:");
        out.println("Usage: sstablerepairedset --really-set [--is-repaired | --is-unrepaired] [-f <sstable-list> | <sstables>]");
        System.exit(1);
    }
    Util.initDatabaseDescriptor();
    boolean setIsRepaired = args[1].equals("--is-repaired");
    List<String> fileNames;
    if (args[2].equals("-f")) {
        fileNames = Files.readAllLines(Paths.get(args[3]), Charset.defaultCharset());
    } else {
        fileNames = Arrays.asList(args).subList(2, args.length);
    }
    for (String fname : fileNames) {
        Descriptor descriptor = Descriptor.fromFilename(fname);
        if (!descriptor.version.isCompatible()) {
            System.err.println("SSTable " + fname + " is in a old and unsupported format");
            continue;
        }
        if (setIsRepaired) {
            FileTime f = Files.getLastModifiedTime(new File(descriptor.filenameFor(Component.DATA)).toPath());
            descriptor.getMetadataSerializer().mutateRepaired(descriptor, f.toMillis(), null);
        } else {
            descriptor.getMetadataSerializer().mutateRepaired(descriptor, 0, null);
        }
    }
}
Also used : Descriptor(org.apache.cassandra.io.sstable.Descriptor) FileTime(java.nio.file.attribute.FileTime)

Example 27 with Descriptor

use of org.apache.cassandra.io.sstable.Descriptor 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 28 with Descriptor

use of org.apache.cassandra.io.sstable.Descriptor 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 29 with Descriptor

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

the class DirectoriesTest method testStandardDirs.

@Test
public void testStandardDirs() throws IOException {
    for (TableMetadata cfm : CFM) {
        Directories directories = new Directories(cfm);
        assertEquals(cfDir(cfm), directories.getDirectoryForNewSSTables());
        Descriptor desc = new Descriptor(cfDir(cfm), KS, cfm.name, 1, SSTableFormat.Type.BIG);
        File snapshotDir = new File(cfDir(cfm), File.separator + Directories.SNAPSHOT_SUBDIR + File.separator + "42");
        assertEquals(snapshotDir.getCanonicalFile(), Directories.getSnapshotDirectory(desc, "42"));
        File backupsDir = new File(cfDir(cfm), File.separator + Directories.BACKUPS_SUBDIR);
        assertEquals(backupsDir.getCanonicalFile(), Directories.getBackupsDirectory(desc));
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) File(java.io.File) Test(org.junit.Test)

Example 30 with Descriptor

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

the class DirectoriesTest method testMTSnapshots.

@Test
public void testMTSnapshots() throws Exception {
    for (final TableMetadata cfm : CFM) {
        final Directories directories = new Directories(cfm);
        assertEquals(cfDir(cfm), directories.getDirectoryForNewSSTables());
        final String n = Long.toString(System.nanoTime());
        Callable<File> directoryGetter = new Callable<File>() {

            public File call() throws Exception {
                Descriptor desc = new Descriptor(cfDir(cfm), KS, cfm.name, 1, SSTableFormat.Type.BIG);
                return Directories.getSnapshotDirectory(desc, n);
            }
        };
        List<Future<File>> invoked = Executors.newFixedThreadPool(2).invokeAll(Arrays.asList(directoryGetter, directoryGetter));
        for (Future<File> fut : invoked) {
            assertTrue(fut.get().exists());
        }
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Future(java.util.concurrent.Future) File(java.io.File) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

Descriptor (org.apache.cassandra.io.sstable.Descriptor)38 File (java.io.File)24 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)15 Test (org.junit.Test)12 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)9 Component (org.apache.cassandra.io.sstable.Component)8 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)8 TableMetadata (org.apache.cassandra.schema.TableMetadata)6 Pair (org.apache.cassandra.utils.Pair)6 IOException (java.io.IOException)5 Map (java.util.Map)4 Directories (org.apache.cassandra.db.Directories)4 Keyspace (org.apache.cassandra.db.Keyspace)4 PrintStream (java.io.PrintStream)3 ByteBuffer (java.nio.ByteBuffer)3 Set (java.util.Set)3 DecoratedKey (org.apache.cassandra.db.DecoratedKey)3 SerializationHeader (org.apache.cassandra.db.SerializationHeader)3 NonBlockingHashMap (org.cliffc.high_scale_lib.NonBlockingHashMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2