Search in sources :

Example 16 with SSTableAddedNotification

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

the class CompactionStrategyManagerPendingRepairTest method cleanupCompactionFailed.

/**
 * Tests that failed repairs result in cleanup compaction tasks
 * which reclassify the sstables as unrepaired
 */
@Test
public void cleanupCompactionFailed() {
    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.failUnsafe(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.assertFalse(repairedContains(sstable));
    Assert.assertTrue(unrepairedContains(sstable));
    Assert.assertFalse(hasPendingStrategiesFor(repairID));
    Assert.assertFalse(hasTransientStrategiesFor(repairID));
    // sstable should have pendingRepair cleared, and repairedAt set correctly
    Assert.assertFalse(sstable.isPendingRepair());
    Assert.assertFalse(sstable.isRepaired());
    Assert.assertEquals(ActiveRepairService.UNREPAIRED_SSTABLE, 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 17 with SSTableAddedNotification

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

the class CompactionStrategyManagerTest method testSSTablesAssignedToCorrectCompactionStrategy.

public void testSSTablesAssignedToCorrectCompactionStrategy(int numSSTables, int numDisks) {
    // Create a mock CFS with the given number of disks
    MockCFS cfs = createJBODMockCFS(numDisks);
    // Check that CFS will contain numSSTables
    assertEquals(numSSTables, cfs.getLiveSSTables().size());
    // Creates a compaction strategy manager with an external boundary supplier
    final Integer[] boundaries = computeBoundaries(numSSTables, numDisks);
    MockBoundaryManager mockBoundaryManager = new MockBoundaryManager(cfs, boundaries);
    logger.debug("Boundaries for {} disks is {}", numDisks, Arrays.toString(boundaries));
    CompactionStrategyManager csm = new CompactionStrategyManager(cfs, mockBoundaryManager::getBoundaries, true);
    // Check that SSTables are assigned to the correct Compaction Strategy
    for (SSTableReader reader : cfs.getLiveSSTables()) {
        verifySSTableIsAssignedToCorrectStrategy(boundaries, csm, reader);
    }
    for (int delta = 1; delta <= 3; delta++) {
        // Update disk boundaries
        Integer[] previousBoundaries = Arrays.copyOf(boundaries, boundaries.length);
        updateBoundaries(mockBoundaryManager, boundaries, delta);
        // Check that SSTables are still assigned to the previous boundary layout
        logger.debug("Old boundaries: {} New boundaries: {}", Arrays.toString(previousBoundaries), Arrays.toString(boundaries));
        for (SSTableReader reader : cfs.getLiveSSTables()) {
            verifySSTableIsAssignedToCorrectStrategy(previousBoundaries, csm, reader);
        }
        // Reload CompactionStrategyManager so new disk boundaries will be loaded
        csm.maybeReloadDiskBoundaries();
        for (SSTableReader reader : cfs.getLiveSSTables()) {
            // Check that SSTables are assigned to the new boundary layout
            verifySSTableIsAssignedToCorrectStrategy(boundaries, csm, reader);
            // Remove SSTable and check that it will be removed from the correct compaction strategy
            csm.handleNotification(new SSTableDeletingNotification(reader), this);
            assertFalse(((SizeTieredCompactionStrategy) csm.compactionStrategyFor(reader)).sstables.contains(reader));
            // Add SSTable again and check that is correctly assigned
            csm.handleNotification(new SSTableAddedNotification(Collections.singleton(reader), null), this);
            verifySSTableIsAssignedToCorrectStrategy(boundaries, csm, reader);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableDeletingNotification(org.apache.cassandra.notifications.SSTableDeletingNotification) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification)

Example 18 with SSTableAddedNotification

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

the class LeveledCompactionStrategy method handleNotification.

public void handleNotification(INotification notification, Object sender) {
    if (notification instanceof SSTableAddedNotification) {
        SSTableAddedNotification flushedNotification = (SSTableAddedNotification) notification;
        manifest.add(flushedNotification.added);
    } else if (notification instanceof SSTableListChangedNotification) {
        SSTableListChangedNotification listChangedNotification = (SSTableListChangedNotification) notification;
        manifest.promote(listChangedNotification.removed, listChangedNotification.added);
    }
}
Also used : SSTableListChangedNotification(org.apache.cassandra.notifications.SSTableListChangedNotification) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification)

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