use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class RepairedDataTombstonesTest method readTestPartitionTombstones.
@Test
public void readTestPartitionTombstones() throws Throwable {
createTable("create table %s (id int, id2 int, t text, t2 text, primary key (id, id2)) with gc_grace_seconds=0 and compaction = {'class':'SizeTieredCompactionStrategy', 'only_purge_repaired_tombstones':true}");
for (int i = 0; i < 10; i++) {
execute("delete from %s where id=?", i);
}
flush();
SSTableReader repairedSSTable = getCurrentColumnFamilyStore().getSSTables(SSTableSet.LIVE).iterator().next();
repair(getCurrentColumnFamilyStore(), repairedSSTable);
Thread.sleep(2000);
for (int i = 10; i < 20; i++) {
execute("delete from %s where id=?", i);
}
flush();
Thread.sleep(1000);
ReadCommand cmd = Util.cmd(getCurrentColumnFamilyStore()).build();
int partitionsFound = 0;
try (ReadExecutionController executionController = cmd.executionController();
UnfilteredPartitionIterator iterator = cmd.executeLocally(executionController)) {
while (iterator.hasNext()) {
partitionsFound++;
try (UnfilteredRowIterator rowIter = iterator.next()) {
int val = ByteBufferUtil.toInt(rowIter.partitionKey().getKey());
assertTrue("val=" + val, val >= 10 && val < 20);
}
}
}
assertEquals(10, partitionsFound);
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class CompactionAwareWriterTest method testSplittingSizeTieredCompactionWriter.
@Test
public void testSplittingSizeTieredCompactionWriter() throws Throwable {
ColumnFamilyStore cfs = getColumnFamilyStore();
cfs.disableAutoCompaction();
int rowCount = 10000;
populate(rowCount);
LifecycleTransaction txn = cfs.getTracker().tryModify(cfs.getLiveSSTables(), OperationType.COMPACTION);
long beforeSize = txn.originals().iterator().next().onDiskLength();
CompactionAwareWriter writer = new SplittingSizeTieredCompactionWriter(cfs, cfs.getDirectories(), txn, txn.originals(), 0);
int rows = compact(cfs, txn, writer);
long expectedSize = beforeSize / 2;
List<SSTableReader> sortedSSTables = new ArrayList<>(cfs.getLiveSSTables());
Collections.sort(sortedSSTables, new Comparator<SSTableReader>() {
@Override
public int compare(SSTableReader o1, SSTableReader o2) {
return Longs.compare(o2.onDiskLength(), o1.onDiskLength());
}
});
for (SSTableReader sstable : sortedSSTables) {
// we dont create smaller files than this, everything will be in the last file
if (expectedSize > SplittingSizeTieredCompactionWriter.DEFAULT_SMALLEST_SSTABLE_BYTES)
// allow 1% diff in estimated vs actual size
assertEquals(expectedSize, sstable.onDiskLength(), expectedSize / 100);
expectedSize /= 2;
}
assertEquals(rowCount, rows);
validateData(cfs, rowCount);
cfs.truncateBlocking();
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class CompactionManagerGetSSTablesForValidationTest method legacyIncrementalRepair.
@Test
public void legacyIncrementalRepair() throws Exception {
makeSSTables();
registerRepair(true);
modifySSTables();
// get sstables for repair
Validator validator = new Validator(desc, coordinator, FBUtilities.nowInSeconds(), false);
Set<SSTableReader> sstables = Sets.newHashSet(CompactionManager.instance.getSSTablesToValidate(cfs, validator));
Assert.assertNotNull(sstables);
Assert.assertEquals(2, sstables.size());
Assert.assertTrue(sstables.contains(pendingRepair));
Assert.assertTrue(sstables.contains(unrepaired));
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class CompactionStrategyManagerPendingRepairTest method sstableListChangedAddAndRemove.
@Test
public void sstableListChangedAddAndRemove() {
UUID repairID = registerSession(cfs, true, true);
LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
SSTableReader sstable1 = makeSSTable(true);
mutateRepaired(sstable1, repairID);
SSTableReader sstable2 = makeSSTable(true);
mutateRepaired(sstable2, repairID);
Assert.assertFalse(repairedContains(sstable1));
Assert.assertFalse(unrepairedContains(sstable1));
Assert.assertFalse(repairedContains(sstable2));
Assert.assertFalse(unrepairedContains(sstable2));
csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
// add only
SSTableListChangedNotification notification;
notification = new SSTableListChangedNotification(Collections.singleton(sstable1), Collections.emptyList(), OperationType.COMPACTION);
csm.handleNotification(notification, cfs.getTracker());
csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
Assert.assertFalse(repairedContains(sstable1));
Assert.assertFalse(unrepairedContains(sstable1));
Assert.assertTrue(pendingContains(repairID, sstable1));
Assert.assertFalse(repairedContains(sstable2));
Assert.assertFalse(unrepairedContains(sstable2));
Assert.assertFalse(pendingContains(repairID, sstable2));
// remove and add
notification = new SSTableListChangedNotification(Collections.singleton(sstable2), Collections.singleton(sstable1), OperationType.COMPACTION);
csm.handleNotification(notification, cfs.getTracker());
Assert.assertFalse(repairedContains(sstable1));
Assert.assertFalse(unrepairedContains(sstable1));
Assert.assertFalse(pendingContains(repairID, sstable1));
Assert.assertFalse(repairedContains(sstable2));
Assert.assertFalse(unrepairedContains(sstable2));
Assert.assertTrue(pendingContains(repairID, sstable2));
}
use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.
the class ScrubTest method testScrubNoIndex.
@Test
public void testScrubNoIndex() throws IOException, ExecutionException, InterruptedException, ConfigurationException {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
cfs.clearUnsafe();
// insert data and verify we get it back w/ range query
fillCF(cfs, 10);
assertOrderedAll(cfs, 10);
for (SSTableReader sstable : cfs.getLiveSSTables()) new File(sstable.descriptor.filenameFor(Component.PRIMARY_INDEX)).delete();
CompactionManager.instance.performScrub(cfs, false, true, 2);
// check data is still there
assertOrderedAll(cfs, 10);
}
Aggregations