Search in sources :

Example 41 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore in project cassandra by apache.

the class LogTransactionTest method testCommitOnlyOld.

@Test
public void testCommitOnlyOld() throws Throwable {
    ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE);
    File dataFolder = new Directories(cfs.metadata()).getDirectoryForNewSSTables();
    SSTableReader sstable = sstable(dataFolder, cfs, 0, 128);
    LogTransaction log = new LogTransaction(OperationType.COMPACTION);
    assertNotNull(log);
    LogTransaction.SSTableTidier tidier = log.obsoleted(sstable);
    assertNotNull(tidier);
    log.finish();
    sstable.markObsolete(tidier);
    sstable.selfRef().release();
    assertFiles(dataFolder.getPath(), new HashSet<>());
}
Also used : Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 42 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore 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 43 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore 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 44 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore 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 45 with ColumnFamilyStore

use of org.apache.cassandra.db.ColumnFamilyStore 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)

Aggregations

ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)175 Test (org.junit.Test)110 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)90 Keyspace (org.apache.cassandra.db.Keyspace)64 File (java.io.File)30 Directories (org.apache.cassandra.db.Directories)25 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)24 DecoratedKey (org.apache.cassandra.db.DecoratedKey)22 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)20 AbstractTransactionalTest (org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)20 RandomAccessFile (java.io.RandomAccessFile)19 CompactionController (org.apache.cassandra.db.compaction.CompactionController)14 ArrayList (java.util.ArrayList)13 ByteBuffer (java.nio.ByteBuffer)12 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)12 Range (org.apache.cassandra.dht.Range)11 Table (org.apache.cassandra.db.Table)9 Token (org.apache.cassandra.dht.Token)9 Descriptor (org.apache.cassandra.io.sstable.Descriptor)9 StatsMetadata (org.apache.cassandra.io.sstable.metadata.StatsMetadata)9