Search in sources :

Example 26 with ColumnFamilyStore

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

the class RealTransactionsTest method testRewriteAborted.

@Test
public void testRewriteAborted() throws IOException {
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(REWRITE_ABORTED_CF);
    SSTableReader oldSSTable = getSSTable(cfs, 1);
    LifecycleTransaction txn = cfs.getTracker().tryModify(oldSSTable, OperationType.COMPACTION);
    replaceSSTable(cfs, txn, true);
    LogTransaction.waitForDeletions();
    assertFiles(oldSSTable.descriptor.directory.getPath(), new HashSet<>(oldSSTable.getAllFilePaths()));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 27 with ColumnFamilyStore

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

the class RealTransactionsTest method testRewriteFinished.

@Test
public void testRewriteFinished() throws IOException {
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(REWRITE_FINISHED_CF);
    SSTableReader oldSSTable = getSSTable(cfs, 1);
    LifecycleTransaction txn = cfs.getTracker().tryModify(oldSSTable, OperationType.COMPACTION);
    SSTableReader newSSTable = replaceSSTable(cfs, txn, false);
    LogTransaction.waitForDeletions();
    // both sstables are in the same folder
    assertFiles(oldSSTable.descriptor.directory.getPath(), new HashSet<>(newSSTable.getAllFilePaths()));
    assertFiles(newSSTable.descriptor.directory.getPath(), new HashSet<>(newSSTable.getAllFilePaths()));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 28 with ColumnFamilyStore

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

the class TrackerTest method testTryModify.

@Test
public void testTryModify() {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    Tracker tracker = new Tracker(null, false);
    List<SSTableReader> readers = ImmutableList.of(MockSchema.sstable(0, true, cfs), MockSchema.sstable(1, cfs), MockSchema.sstable(2, cfs));
    tracker.addInitialSSTables(copyOf(readers));
    Assert.assertNull(tracker.tryModify(ImmutableList.of(MockSchema.sstable(0, cfs)), OperationType.COMPACTION));
    try (LifecycleTransaction txn = tracker.tryModify(readers.get(0), OperationType.COMPACTION)) {
        Assert.assertNotNull(txn);
        Assert.assertNull(tracker.tryModify(readers.get(0), OperationType.COMPACTION));
        Assert.assertEquals(1, txn.originals().size());
        Assert.assertTrue(txn.originals().contains(readers.get(0)));
    }
    try (LifecycleTransaction txn = tracker.tryModify(Collections.<SSTableReader>emptyList(), OperationType.COMPACTION)) {
        Assert.assertNotNull(txn);
        Assert.assertEquals(0, txn.originals().size());
    }
    readers.get(0).selfRef().release();
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 29 with ColumnFamilyStore

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

the class TrackerTest method testMemtableReplacement.

@Test
public void testMemtableReplacement() {
    boolean backups = DatabaseDescriptor.isIncrementalBackupsEnabled();
    DatabaseDescriptor.setIncrementalBackupsEnabled(false);
    ColumnFamilyStore cfs = MockSchema.newCFS();
    MockListener listener = new MockListener(false);
    Tracker tracker = cfs.getTracker();
    tracker.subscribe(listener);
    Memtable prev1 = tracker.switchMemtable(true, new Memtable(new AtomicReference<>(CommitLog.instance.getCurrentPosition()), cfs));
    OpOrder.Group write1 = cfs.keyspace.writeOrder.getCurrent();
    OpOrder.Barrier barrier1 = cfs.keyspace.writeOrder.newBarrier();
    prev1.setDiscarding(barrier1, new AtomicReference<>(CommitLog.instance.getCurrentPosition()));
    barrier1.issue();
    Memtable prev2 = tracker.switchMemtable(false, new Memtable(new AtomicReference<>(CommitLog.instance.getCurrentPosition()), cfs));
    OpOrder.Group write2 = cfs.keyspace.writeOrder.getCurrent();
    OpOrder.Barrier barrier2 = cfs.keyspace.writeOrder.newBarrier();
    prev2.setDiscarding(barrier2, new AtomicReference<>(CommitLog.instance.getCurrentPosition()));
    barrier2.issue();
    Memtable cur = tracker.getView().getCurrentMemtable();
    OpOrder.Group writecur = cfs.keyspace.writeOrder.getCurrent();
    Assert.assertEquals(prev1, tracker.getMemtableFor(write1, CommitLogPosition.NONE));
    Assert.assertEquals(prev2, tracker.getMemtableFor(write2, CommitLogPosition.NONE));
    Assert.assertEquals(cur, tracker.getMemtableFor(writecur, CommitLogPosition.NONE));
    Assert.assertEquals(2, listener.received.size());
    Assert.assertTrue(listener.received.get(0) instanceof MemtableRenewedNotification);
    Assert.assertTrue(listener.received.get(1) instanceof MemtableSwitchedNotification);
    listener.received.clear();
    tracker.markFlushing(prev2);
    Assert.assertEquals(1, tracker.getView().flushingMemtables.size());
    Assert.assertTrue(tracker.getView().flushingMemtables.contains(prev2));
    tracker.markFlushing(prev1);
    Assert.assertTrue(tracker.getView().flushingMemtables.contains(prev1));
    Assert.assertEquals(2, tracker.getView().flushingMemtables.size());
    tracker.replaceFlushed(prev1, Collections.emptyList());
    Assert.assertEquals(1, tracker.getView().flushingMemtables.size());
    Assert.assertTrue(tracker.getView().flushingMemtables.contains(prev2));
    SSTableReader reader = MockSchema.sstable(0, 10, false, cfs);
    tracker.replaceFlushed(prev2, singleton(reader));
    Assert.assertEquals(1, tracker.getView().sstables.size());
    Assert.assertEquals(2, listener.received.size());
    Assert.assertEquals(prev2, ((MemtableDiscardedNotification) listener.received.get(0)).memtable);
    Assert.assertEquals(singleton(reader), ((SSTableAddedNotification) listener.received.get(1)).added);
    listener.received.clear();
    Assert.assertTrue(reader.isKeyCacheSetup());
    Assert.assertEquals(10, cfs.metric.liveDiskSpaceUsed.getCount());
    // test invalidated CFS
    cfs = MockSchema.newCFS();
    tracker = cfs.getTracker();
    listener = new MockListener(false);
    tracker.subscribe(listener);
    prev1 = tracker.switchMemtable(false, new Memtable(new AtomicReference<>(CommitLog.instance.getCurrentPosition()), cfs));
    tracker.markFlushing(prev1);
    reader = MockSchema.sstable(0, 10, true, cfs);
    cfs.invalidate(false);
    tracker.replaceFlushed(prev1, singleton(reader));
    Assert.assertEquals(0, tracker.getView().sstables.size());
    Assert.assertEquals(0, tracker.getView().flushingMemtables.size());
    Assert.assertEquals(0, cfs.metric.liveDiskSpaceUsed.getCount());
    Assert.assertEquals(5, listener.received.size());
    Assert.assertEquals(prev1, ((MemtableSwitchedNotification) listener.received.get(0)).memtable);
    Assert.assertEquals(prev1, ((MemtableDiscardedNotification) listener.received.get(1)).memtable);
    Assert.assertEquals(singleton(reader), ((SSTableAddedNotification) listener.received.get(2)).added);
    Assert.assertTrue(listener.received.get(3) instanceof SSTableDeletingNotification);
    Assert.assertEquals(1, ((SSTableListChangedNotification) listener.received.get(4)).removed.size());
    DatabaseDescriptor.setIncrementalBackupsEnabled(backups);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Memtable(org.apache.cassandra.db.Memtable) Test(org.junit.Test)

Example 30 with ColumnFamilyStore

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

the class ViewTest method testSSTablesInBounds.

@Test
public void testSSTablesInBounds() {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    View initialView = fakeView(0, 5, cfs);
    for (int i = 0; i < 5; i++) {
        for (int j = i; j < 5; j++) {
            PartitionPosition min = MockSchema.readerBounds(i);
            PartitionPosition max = MockSchema.readerBounds(j);
            for (//, false} )
            boolean minInc : //, false} )
            new boolean[] { true }) {
                for (//, false} )
                boolean maxInc : //, false} )
                new boolean[] { true }) {
                    if (i == j && !(minInc && maxInc))
                        continue;
                    AbstractBounds<PartitionPosition> bounds = AbstractBounds.bounds(min, minInc, max, maxInc);
                    List<SSTableReader> r = ImmutableList.copyOf(initialView.liveSSTablesInBounds(bounds.left, bounds.right));
                    Assert.assertEquals(String.format("%d(%s) %d(%s)", i, minInc, j, maxInc), j - i + (minInc ? 0 : -1) + (maxInc ? 1 : 0), r.size());
                }
            }
        }
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) PartitionPosition(org.apache.cassandra.db.PartitionPosition) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

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