Search in sources :

Example 21 with Component

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

the class MultipleDataDirectoryTest method setupMisplacedSSTables.

// by moving all sstables from the first data directory to the second.
private void setupMisplacedSSTables() {
    NODE.runOnInstance(() -> {
        ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore("cf");
        Assert.assertNotEquals(0, cfs.getLiveSSTables().size());
        Iterator<SSTableReader> sstables = cfs.getLiveSSTables().iterator();
        // finding 2 descriptors that live in different data directory
        Descriptor first = sstables.next().descriptor;
        Descriptor second = null;
        while (sstables.hasNext() && second == null) {
            second = sstables.next().descriptor;
            if (first.directory.equals(second.directory))
                second = null;
        }
        Assert.assertNotNull("There should be SSTables in multiple data directories", second);
        // getting a new file index in order to move SSTable between directories.
        second = cfs.newSSTableDescriptor(second.directory);
        // now we just move all sstables from first to second
        for (Component component : SSTableReader.componentsFor(first)) {
            File file = new File(first.filenameFor(component));
            if (file.exists()) {
                try {
                    Files.copy(file.toPath(), new File(second.filenameFor(component)).toPath());
                } catch (IOException e) {
                    throw new RuntimeException("Something wrong with copying sstables", e);
                }
            }
        }
        ColumnFamilyStore.loadNewSSTables(KEYSPACE, "cf");
    });
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) IOException(java.io.IOException) Component(org.apache.cassandra.io.sstable.Component) File(org.apache.cassandra.io.util.File)

Example 22 with Component

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

the class DirectoriesTest method createFakeSSTable.

private static List<File> createFakeSSTable(Descriptor desc) throws IOException {
    List<File> components = new ArrayList<>(3);
    for (Component c : new Component[] { Component.DATA, Component.PRIMARY_INDEX, Component.FILTER }) {
        File f = new File(desc.filenameFor(c));
        f.createFileIfNotExists();
        components.add(f);
    }
    return components;
}
Also used : Component(org.apache.cassandra.io.sstable.Component) File(org.apache.cassandra.io.util.File)

Example 23 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(org.apache.cassandra.io.util.File) Test(org.junit.Test)

Example 24 with Component

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

the class SSTableWriter method hardlink.

public static void hardlink(Descriptor tmpdesc, Descriptor newdesc, Set<Component> components) {
    for (Component component : Sets.difference(components, Sets.newHashSet(Component.DATA, Component.SUMMARY))) {
        FileUtils.createHardLinkWithConfirm(tmpdesc.filenameFor(component), newdesc.filenameFor(component));
    }
    // do -Data last because -Data present should mean the sstable was completely copied before crash
    FileUtils.createHardLinkWithConfirm(tmpdesc.filenameFor(Component.DATA), newdesc.filenameFor(Component.DATA));
    // copy it without confirmation because summary can be available for loadNewSSTables but not for closeAndOpenReader
    FileUtils.createHardLinkWithoutConfirm(tmpdesc.filenameFor(Component.SUMMARY), newdesc.filenameFor(Component.SUMMARY));
}
Also used : Component(org.apache.cassandra.io.sstable.Component) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent)

Example 25 with Component

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

the class SSTableWriter method copy.

public static void copy(Descriptor tmpdesc, Descriptor newdesc, Set<Component> components) {
    for (Component component : Sets.difference(components, Sets.newHashSet(Component.DATA, Component.SUMMARY))) {
        FileUtils.copyWithConfirm(tmpdesc.filenameFor(component), newdesc.filenameFor(component));
    }
    // do -Data last because -Data present should mean the sstable was completely copied before crash
    FileUtils.copyWithConfirm(tmpdesc.filenameFor(Component.DATA), newdesc.filenameFor(Component.DATA));
    // copy it without confirmation because summary can be available for loadNewSSTables but not for closeAndOpenReader
    FileUtils.copyWithOutConfirm(tmpdesc.filenameFor(Component.SUMMARY), newdesc.filenameFor(Component.SUMMARY));
}
Also used : Component(org.apache.cassandra.io.sstable.Component) MetadataComponent(org.apache.cassandra.io.sstable.metadata.MetadataComponent)

Aggregations

Component (org.apache.cassandra.io.sstable.Component)26 Descriptor (org.apache.cassandra.io.sstable.Descriptor)16 File (org.apache.cassandra.io.util.File)15 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)12 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)10 IOException (java.io.IOException)5 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)5 Test (org.junit.Test)5 File (java.io.File)4 Directories (org.apache.cassandra.db.Directories)4 StatsMetadata (org.apache.cassandra.io.sstable.metadata.StatsMetadata)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Set (java.util.Set)3 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)3 MetadataCollector (org.apache.cassandra.io.sstable.metadata.MetadataCollector)3 AlwaysPresentFilter (org.apache.cassandra.utils.AlwaysPresentFilter)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Path (java.nio.file.Path)2 Collection (java.util.Collection)2