Search in sources :

Example 1 with SSTableRepairStatusChanged

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

the class CompactionStrategyManagerPendingRepairTest method sstableRepairStatusChanged.

@Test
public void sstableRepairStatusChanged() {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    // add as unrepaired
    SSTableReader sstable = makeSSTable(false);
    Assert.assertTrue(unrepairedContains(sstable));
    Assert.assertFalse(repairedContains(sstable));
    csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
    SSTableRepairStatusChanged notification;
    // change to pending repaired
    mutateRepaired(sstable, repairID);
    notification = new SSTableRepairStatusChanged(Collections.singleton(sstable));
    csm.handleNotification(notification, cfs.getTracker());
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertFalse(repairedContains(sstable));
    csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
    Assert.assertTrue(pendingContains(repairID, sstable));
    // change to repaired
    mutateRepaired(sstable, System.currentTimeMillis());
    notification = new SSTableRepairStatusChanged(Collections.singleton(sstable));
    csm.handleNotification(notification, cfs.getTracker());
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertTrue(repairedContains(sstable));
    Assert.assertFalse(pendingContains(repairID, sstable));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert(org.junit.Assert) SSTableRepairStatusChanged(org.apache.cassandra.notifications.SSTableRepairStatusChanged) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with SSTableRepairStatusChanged

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

the class LeveledCompactionStrategyTest method testNewRepairedSSTable.

@Test
public void testNewRepairedSSTable() throws Exception {
    byte[] b = new byte[100 * 1024];
    new Random().nextBytes(b);
    // 100 KB value, make it easy to have multiple files
    ByteBuffer value = ByteBuffer.wrap(b);
    // Enough data to have a level 1 and 2
    int rows = 40;
    int columns = 20;
    // Adds enough data to trigger multiple sstable per level
    for (int r = 0; r < rows; r++) {
        UpdateBuilder update = UpdateBuilder.create(cfs.metadata(), String.valueOf(r));
        for (int c = 0; c < columns; c++) update.newRow("column" + c).add("val", value);
        update.applyUnsafe();
        cfs.forceBlockingFlush();
    }
    waitForLeveling(cfs);
    cfs.disableAutoCompaction();
    while (CompactionManager.instance.isCompacting(Arrays.asList(cfs))) Thread.sleep(100);
    CompactionStrategyManager manager = cfs.getCompactionStrategyManager();
    List<List<AbstractCompactionStrategy>> strategies = manager.getStrategies();
    LeveledCompactionStrategy repaired = (LeveledCompactionStrategy) strategies.get(0).get(0);
    LeveledCompactionStrategy unrepaired = (LeveledCompactionStrategy) strategies.get(1).get(0);
    assertEquals(0, repaired.manifest.getLevelCount());
    assertEquals(2, unrepaired.manifest.getLevelCount());
    assertTrue(manager.getSSTableCountPerLevel()[1] > 0);
    assertTrue(manager.getSSTableCountPerLevel()[2] > 0);
    for (SSTableReader sstable : cfs.getLiveSSTables()) assertFalse(sstable.isRepaired());
    int sstableCount = 0;
    for (List<SSTableReader> level : unrepaired.manifest.generations) sstableCount += level.size();
    // we only have unrepaired sstables:
    assertEquals(sstableCount, cfs.getLiveSSTables().size());
    SSTableReader sstable1 = unrepaired.manifest.generations[2].get(0);
    SSTableReader sstable2 = unrepaired.manifest.generations[1].get(0);
    sstable1.descriptor.getMetadataSerializer().mutateRepaired(sstable1.descriptor, System.currentTimeMillis(), null);
    sstable1.reloadSSTableMetadata();
    assertTrue(sstable1.isRepaired());
    manager.handleNotification(new SSTableRepairStatusChanged(Arrays.asList(sstable1)), this);
    int repairedSSTableCount = 0;
    for (List<SSTableReader> level : repaired.manifest.generations) repairedSSTableCount += level.size();
    assertEquals(1, repairedSSTableCount);
    // make sure the repaired sstable ends up in the same level in the repaired manifest:
    assertTrue(repaired.manifest.generations[2].contains(sstable1));
    // and that it is gone from unrepaired
    assertFalse(unrepaired.manifest.generations[2].contains(sstable1));
    unrepaired.removeSSTable(sstable2);
    manager.handleNotification(new SSTableAddedNotification(singleton(sstable2)), this);
    assertTrue(unrepaired.manifest.getLevel(1).contains(sstable2));
    assertFalse(repaired.manifest.getLevel(1).contains(sstable2));
}
Also used : UpdateBuilder(org.apache.cassandra.UpdateBuilder) SSTableAddedNotification(org.apache.cassandra.notifications.SSTableAddedNotification) ByteBuffer(java.nio.ByteBuffer) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableRepairStatusChanged(org.apache.cassandra.notifications.SSTableRepairStatusChanged) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 SSTableRepairStatusChanged (org.apache.cassandra.notifications.SSTableRepairStatusChanged)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 UUID (java.util.UUID)1 UpdateBuilder (org.apache.cassandra.UpdateBuilder)1 SSTableAddedNotification (org.apache.cassandra.notifications.SSTableAddedNotification)1 Assert (org.junit.Assert)1