Search in sources :

Example 11 with SSTableAddedNotification

use of org.apache.cassandra.notifications.SSTableAddedNotification in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method cleanupCompactionFinalized.

/**
 * Tests that finalized repairs result in cleanup compaction tasks
 * which reclassify the sstables as repaired
 */
@Test
public void cleanupCompactionFinalized() throws NoSuchRepairSessionException {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    SSTableReader sstable = makeSSTable(true);
    mutateRepaired(sstable, repairID, false);
    csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable), null), cfs.getTracker());
    LocalSessionAccessor.finalizeUnsafe(repairID);
    Assert.assertTrue(hasPendingStrategiesFor(repairID));
    Assert.assertFalse(hasTransientStrategiesFor(repairID));
    Assert.assertTrue(pendingContains(sstable));
    Assert.assertTrue(sstable.isPendingRepair());
    Assert.assertFalse(sstable.isRepaired());
    // enable compaction to fetch next background task
    cfs.getCompactionStrategyManager().enable();
    AbstractCompactionTask compactionTask = csm.getNextBackgroundTask(FBUtilities.nowInSeconds());
    Assert.assertNotNull(compactionTask);
    Assert.assertSame(PendingRepairManager.RepairFinishedCompactionTask.class, compactionTask.getClass());
    // run the compaction
    compactionTask.execute(ActiveCompactionsTracker.NOOP);
    Assert.assertTrue(repairedContains(sstable));
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertFalse(pendingContains(sstable));
    Assert.assertFalse(hasPendingStrategiesFor(repairID));
    Assert.assertFalse(hasTransientStrategiesFor(repairID));
    // sstable should have pendingRepair cleared, and repairedAt set correctly
    long expectedRepairedAt = ActiveRepairService.instance.getParentRepairSession(repairID).repairedAt;
    Assert.assertFalse(sstable.isPendingRepair());
    Assert.assertTrue(sstable.isRepaired());
    Assert.assertEquals(expectedRepairedAt, sstable.getSSTableMetadata().repairedAt);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 12 with SSTableAddedNotification

use of org.apache.cassandra.notifications.SSTableAddedNotification in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method finalizedSessionTransientCleanup.

@Test
public void finalizedSessionTransientCleanup() {
    Assert.assertTrue(cfs.getLiveSSTables().isEmpty());
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    SSTableReader sstable = makeSSTable(true);
    mutateRepaired(sstable, repairID, true);
    csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable), null), cfs.getTracker());
    LocalSessionAccessor.finalizeUnsafe(repairID);
    Assert.assertFalse(hasPendingStrategiesFor(repairID));
    Assert.assertTrue(hasTransientStrategiesFor(repairID));
    Assert.assertTrue(transientContains(sstable));
    Assert.assertFalse(pendingContains(sstable));
    Assert.assertFalse(repairedContains(sstable));
    Assert.assertFalse(unrepairedContains(sstable));
    // enable compaction to fetch next background task
    cfs.getCompactionStrategyManager().enable();
    AbstractCompactionTask compactionTask = csm.getNextBackgroundTask(FBUtilities.nowInSeconds());
    Assert.assertNotNull(compactionTask);
    Assert.assertSame(PendingRepairManager.RepairFinishedCompactionTask.class, compactionTask.getClass());
    // run the compaction
    compactionTask.execute(ActiveCompactionsTracker.NOOP);
    Assert.assertTrue(cfs.getLiveSSTables().isEmpty());
    Assert.assertFalse(hasPendingStrategiesFor(repairID));
    Assert.assertFalse(hasTransientStrategiesFor(repairID));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with SSTableAddedNotification

use of org.apache.cassandra.notifications.SSTableAddedNotification in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method sstableDeleted.

@Test
public void sstableDeleted() {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    SSTableReader sstable = makeSSTable(true);
    mutateRepaired(sstable, repairID, false);
    csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable), null), cfs.getTracker());
    Assert.assertTrue(pendingContains(sstable));
    // delete sstable
    SSTableDeletingNotification notification = new SSTableDeletingNotification(sstable);
    csm.handleNotification(notification, cfs.getTracker());
    Assert.assertFalse(pendingContains(sstable));
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertFalse(repairedContains(sstable));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableDeletingNotification(org.apache.cassandra.notifications.SSTableDeletingNotification) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with SSTableAddedNotification

use of org.apache.cassandra.notifications.SSTableAddedNotification in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method getStrategies.

/**
 * CompactionStrategyManager.getStrategies should include
 * pending repair strategies when appropriate
 */
@Test
public void getStrategies() {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    List<List<AbstractCompactionStrategy>> strategies;
    strategies = csm.getStrategies();
    Assert.assertEquals(3, strategies.size());
    Assert.assertTrue(strategies.get(2).isEmpty());
    SSTableReader sstable = makeSSTable(true);
    mutateRepaired(sstable, repairID, false);
    csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable), null), cfs.getTracker());
    strategies = csm.getStrategies();
    Assert.assertEquals(3, strategies.size());
    Assert.assertFalse(strategies.get(2).isEmpty());
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) List(java.util.List) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Example 15 with SSTableAddedNotification

use of org.apache.cassandra.notifications.SSTableAddedNotification in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method sstableAdded.

/**
 * Pending repair strategy should be created when we encounter a new pending id
 */
@Test
public void sstableAdded() {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    Assert.assertTrue(Iterables.isEmpty(csm.getPendingRepairsUnsafe().allStrategies()));
    SSTableReader sstable = makeSSTable(true);
    Assert.assertFalse(sstable.isRepaired());
    Assert.assertFalse(sstable.isPendingRepair());
    mutateRepaired(sstable, repairID, false);
    Assert.assertFalse(sstable.isRepaired());
    Assert.assertTrue(sstable.isPendingRepair());
    Assert.assertFalse(hasPendingStrategiesFor(repairID));
    Assert.assertFalse(hasTransientStrategiesFor(repairID));
    // add the sstable
    csm.handleNotification(new SSTableAddedNotification(Collections.singleton(sstable), null), cfs.getTracker());
    Assert.assertFalse(repairedContains(sstable));
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertTrue(pendingContains(sstable));
    Assert.assertTrue(hasPendingStrategiesFor(repairID));
    Assert.assertFalse(hasTransientStrategiesFor(repairID));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

SSTableAddedNotification (org.apache.cassandra.notifications.SSTableAddedNotification)18 Test (org.junit.Test)14 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)13 UUID (java.util.UUID)7 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 SSTableDeletingNotification (org.apache.cassandra.notifications.SSTableDeletingNotification)3 List (java.util.List)2 SSTableListChangedNotification (org.apache.cassandra.notifications.SSTableListChangedNotification)2 SSTableRepairStatusChanged (org.apache.cassandra.notifications.SSTableRepairStatusChanged)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 UpdateBuilder (org.apache.cassandra.UpdateBuilder)1 INotification (org.apache.cassandra.notifications.INotification)1 INotificationConsumer (org.apache.cassandra.notifications.INotificationConsumer)1 SSTableMetadataChanged (org.apache.cassandra.notifications.SSTableMetadataChanged)1