Search in sources :

Example 51 with SSTableReader

use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.

the class HelpersTest method testSetupDeletionNotification.

@Test
public void testSetupDeletionNotification() {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    Iterable<SSTableReader> readers = Lists.newArrayList(MockSchema.sstable(1, cfs), MockSchema.sstable(2, cfs));
    Throwable accumulate = Helpers.setReplaced(readers, null);
    Assert.assertNull(accumulate);
    for (SSTableReader reader : readers) Assert.assertTrue(reader.isReplaced());
    accumulate = Helpers.setReplaced(readers, null);
    assertNotNull(accumulate);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 52 with SSTableReader

use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.

the class LifecycleTransactionTest method testSplit.

@Test
public void testSplit() {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    Tracker tracker = new Tracker(null, false);
    List<SSTableReader> readers = readers(0, 4, cfs);
    tracker.addInitialSSTables(readers);
    LifecycleTransaction txn = tracker.tryModify(readers, OperationType.UNKNOWN);
    txn.cancel(readers.get(3));
    LifecycleTransaction txn2 = txn.split(readers.subList(0, 1));
    Assert.assertEquals(2, txn.originals().size());
    Assert.assertTrue(all(readers.subList(1, 3), in(txn.originals())));
    Assert.assertEquals(1, txn2.originals().size());
    Assert.assertTrue(all(readers.subList(0, 1), in(txn2.originals())));
    txn.update(readers(1, 2, cfs).get(0), true);
    boolean failed = false;
    try {
        txn.split(readers.subList(2, 3));
    } catch (Throwable t) {
        failed = true;
    }
    Assert.assertTrue(failed);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 53 with SSTableReader

use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.

the class LifecycleTransactionTest method testCancellation.

@Test
public void testCancellation() {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    Tracker tracker = new Tracker(null, false);
    List<SSTableReader> readers = readers(0, 3, cfs);
    tracker.addInitialSSTables(readers);
    LifecycleTransaction txn = tracker.tryModify(readers, OperationType.UNKNOWN);
    SSTableReader cancel = readers.get(0);
    SSTableReader update = readers(1, 2, cfs).get(0);
    SSTableReader fresh = readers(3, 4, cfs).get(0);
    SSTableReader notPresent = readers(4, 5, cfs).get(0);
    txn.cancel(cancel);
    txn.update(update, true);
    txn.update(fresh, false);
    testBadCancel(txn, cancel);
    testBadCancel(txn, update);
    testBadCancel(txn, fresh);
    testBadCancel(txn, notPresent);
    Assert.assertEquals(2, txn.originals().size());
    Assert.assertEquals(2, tracker.getView().compacting.size());
    Assert.assertTrue(all(readers.subList(1, 3), idIn(tracker.getView().compacting)));
    txn.checkpoint();
    testBadCancel(txn, cancel);
    testBadCancel(txn, update);
    testBadCancel(txn, fresh);
    testBadCancel(txn, notPresent);
    Assert.assertEquals(2, txn.originals().size());
    Assert.assertEquals(3, tracker.getView().compacting.size());
    Assert.assertEquals(3, size(txn.current()));
    Assert.assertTrue(all(concat(readers.subList(1, 3), of(fresh)), idIn(tracker.getView().compacting)));
    txn.cancel(readers.get(2));
    Assert.assertEquals(1, txn.originals().size());
    Assert.assertEquals(2, tracker.getView().compacting.size());
    Assert.assertEquals(2, size(txn.current()));
    Assert.assertTrue(all(of(readers.get(1), fresh), idIn(tracker.getView().compacting)));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 54 with SSTableReader

use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.

the class LifecycleTransactionTest method testUpdates.

@Test
public // (including obsoletion)
void testUpdates() {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    Tracker tracker = new Tracker(null, false);
    SSTableReader[] readers = readersArray(0, 3, cfs);
    SSTableReader[] readers2 = readersArray(0, 4, cfs);
    SSTableReader[] readers3 = readersArray(0, 4, cfs);
    tracker.addInitialSSTables(copyOf(readers));
    LifecycleTransaction txn = tracker.tryModify(copyOf(readers), OperationType.UNKNOWN);
    txn.update(readers2[0], true);
    txn.obsolete(readers[1]);
    Assert.assertTrue(txn.isObsolete(readers[1]));
    Assert.assertFalse(txn.isObsolete(readers[0]));
    // same reader && instances
    testBadUpdate(txn, readers2[0], true);
    // staged obsolete; cannot update
    testBadUpdate(txn, readers2[1], true);
    // same reader, diff instances
    testBadUpdate(txn, readers3[0], true);
    // incorrectly declared original status
    testBadUpdate(txn, readers2[2], false);
    // incorrectly declared original status
    testBadUpdate(txn, readers2[3], true);
    // staged obsolete; cannot obsolete again
    testBadObsolete(txn, readers[1]);
    // staged update; cannot obsolete
    testBadObsolete(txn, readers2[0]);
    txn.update(readers2[3], false);
    Assert.assertEquals(3, tracker.getView().compacting.size());
    txn.checkpoint();
    Assert.assertTrue(txn.isObsolete(readers[1]));
    Assert.assertFalse(txn.isObsolete(readers[0]));
    Assert.assertEquals(4, tracker.getView().compacting.size());
    Assert.assertEquals(3, tracker.getView().sstables.size());
    Assert.assertEquals(3, size(txn.current()));
    Assert.assertTrue(all(of(readers2[0], readers[2], readers2[3]), idIn(tracker.getView().sstablesMap)));
    Assert.assertTrue(all(txn.current(), idIn(tracker.getView().sstablesMap)));
    // logged obsolete; cannot obsolete again
    testBadObsolete(txn, readers[1]);
    // never seen instance; cannot obsolete
    testBadObsolete(txn, readers2[2]);
    // non-original; cannot obsolete
    testBadObsolete(txn, readers2[3]);
    // logged obsolete; cannot update
    testBadUpdate(txn, readers3[1], true);
    // same instance as logged update
    testBadUpdate(txn, readers2[0], true);
    // same reader as logged update, different instance
    txn.update(readers3[0], true);
    txn.checkpoint();
    Assert.assertEquals(4, tracker.getView().compacting.size());
    Assert.assertEquals(3, tracker.getView().sstables.size());
    Assert.assertEquals(3, size(txn.current()));
    Assert.assertTrue(all(of(readers3[0], readers[2], readers2[3]), idIn(tracker.getView().sstablesMap)));
    Assert.assertTrue(all(txn.current(), idIn(tracker.getView().sstablesMap)));
    // not current version of sstable
    testBadObsolete(txn, readers2[0]);
    txn.obsoleteOriginals();
    txn.checkpoint();
    Assert.assertEquals(1, tracker.getView().sstables.size());
    // should be no-op
    txn.obsoleteOriginals();
    txn.checkpoint();
    Assert.assertEquals(1, tracker.getView().sstables.size());
    Assert.assertEquals(4, tracker.getView().compacting.size());
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 55 with SSTableReader

use of org.apache.cassandra.io.sstable.format.SSTableReader in project cassandra by apache.

the class PendingRepairManagerTest method needsCleanupFailed.

/**
     * If a local session has failed, it should be cleaned up
     */
@Test
public void needsCleanupFailed() {
    PendingRepairManager prm = csm.getPendingRepairManagers().get(0);
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    SSTableReader sstable = makeSSTable(true);
    mutateRepaired(sstable, repairID);
    prm.addSSTable(sstable);
    Assert.assertNotNull(prm.get(repairID));
    LocalSessionAccessor.failUnsafe(repairID);
    Assert.assertTrue(prm.canCleanup(repairID));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) UUID(java.util.UUID) 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