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");
});
}
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;
}
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());
}
}
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));
}
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));
}
Aggregations