Search in sources :

Example 16 with SSTableReader

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);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) Test(org.junit.Test)

Example 17 with SSTableReader

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();
}
Also used : CompactionAwareWriter(org.apache.cassandra.db.compaction.writers.CompactionAwareWriter) SplittingSizeTieredCompactionWriter(org.apache.cassandra.db.compaction.writers.SplittingSizeTieredCompactionWriter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 18 with SSTableReader

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));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Validator(org.apache.cassandra.repair.Validator) Test(org.junit.Test)

Example 19 with SSTableReader

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));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableListChangedNotification(org.apache.cassandra.notifications.SSTableListChangedNotification) Assert(org.junit.Assert) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with SSTableReader

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);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Test(org.junit.Test)

Aggregations

SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)289 Test (org.junit.Test)159 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)91 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)55 Keyspace (org.apache.cassandra.db.Keyspace)49 File (java.io.File)45 UUID (java.util.UUID)28 Range (org.apache.cassandra.dht.Range)28 Directories (org.apache.cassandra.db.Directories)27 Token (org.apache.cassandra.dht.Token)24 RandomAccessFile (java.io.RandomAccessFile)22 AbstractTransactionalTest (org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)20 ArrayList (java.util.ArrayList)18 ByteBuffer (java.nio.ByteBuffer)17 HashSet (java.util.HashSet)16 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)16 DecoratedKey (org.apache.cassandra.db.DecoratedKey)16 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 CompactionController (org.apache.cassandra.db.compaction.CompactionController)14 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)13