final CFMetaData cfmeta = Schema.instance.getCFMetaData(ks, cf);
Directories dir = new Directories(cfmeta);
ByteBuffer key = bytes("key");
// 1st sstable
SSTableSimpleWriter writer = new SSTableSimpleWriter(dir.getDirectoryForCompactedSSTables(), cfmeta, StorageService.getPartitioner());
writer.newRow(key);
writer.addColumn(bytes("col"), bytes("val"), 1);
writer.close();
Map<Descriptor, Set<Component>> sstables = dir.sstableLister().list();
assertEquals(1, sstables.size());
Map.Entry<Descriptor, Set<Component>> sstableToOpen = sstables.entrySet().iterator().next();
final SSTableReader sstable1 = SSTableReader.open(sstableToOpen.getKey());
// simulate incomplete compaction
writer = new SSTableSimpleWriter(dir.getDirectoryForCompactedSSTables(),
cfmeta, StorageService.getPartitioner())
{
protected SSTableWriter getWriter()
{
MetadataCollector collector = new MetadataCollector(cfmeta.comparator);
collector.addAncestor(sstable1.descriptor.generation); // add ancestor from previously written sstable
return new SSTableWriter(makeFilename(directory, metadata.ksName, metadata.cfName),
0,
ActiveRepairService.UNREPAIRED_SSTABLE,
metadata,
StorageService.getPartitioner(),
collector);
}
};
writer.newRow(key);
writer.addColumn(bytes("col"), bytes("val"), 1);
writer.close();
// should have 2 sstables now
sstables = dir.sstableLister().list();
assertEquals(2, sstables.size());