Search in sources :

Example 1 with PendingAntiCompaction

use of org.apache.cassandra.db.repair.PendingAntiCompaction in project cassandra by apache.

the class CancelCompactionsTest method testAnticompaction.

@Test
public void testAnticompaction() throws InterruptedException, ExecutionException {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    List<SSTableReader> sstables = createSSTables(cfs, 10, 0);
    List<SSTableReader> alreadyRepairedSSTables = createSSTables(cfs, 10, 10);
    for (SSTableReader sstable : alreadyRepairedSSTables) AbstractPendingRepairTest.mutateRepaired(sstable, System.currentTimeMillis());
    assertEquals(20, cfs.getLiveSSTables().size());
    List<TestCompactionTask> tcts = new ArrayList<>();
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(0, 2))));
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(3, 4))));
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(5, 7))));
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(8, 9))));
    List<TestCompactionTask> nonAffectedTcts = new ArrayList<>();
    nonAffectedTcts.add(new TestCompactionTask(cfs, new HashSet<>(alreadyRepairedSSTables)));
    try {
        tcts.forEach(TestCompactionTask::start);
        nonAffectedTcts.forEach(TestCompactionTask::start);
        List<CompactionInfo.Holder> activeCompactions = getActiveCompactionsForTable(cfs);
        assertEquals(5, activeCompactions.size());
        // make sure that sstables are fully contained so that the metadata gets mutated
        Range<Token> range = new Range<>(token(-1), token(49));
        UUID prsid = UUID.randomUUID();
        ActiveRepairService.instance.registerParentRepairSession(prsid, InetAddressAndPort.getLocalHost(), Collections.singletonList(cfs), Collections.singleton(range), true, 1, true, PreviewKind.NONE);
        InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort();
        RangesAtEndpoint rae = RangesAtEndpoint.builder(local).add(new Replica(local, range, true)).build();
        PendingAntiCompaction pac = new PendingAntiCompaction(prsid, Collections.singleton(cfs), rae, Executors.newSingleThreadExecutor(), () -> false);
        Future<?> fut = pac.run();
        Thread.sleep(600);
        List<TestCompactionTask> toAbort = new ArrayList<>();
        for (CompactionInfo.Holder holder : getActiveCompactionsForTable(cfs)) {
            if (holder.getCompactionInfo().getSSTables().stream().anyMatch(sstable -> sstable.intersects(Collections.singleton(range)) && !sstable.isRepaired() && !sstable.isPendingRepair())) {
                assertTrue(holder.isStopRequested());
                for (TestCompactionTask tct : tcts) if (tct.sstables.equals(holder.getCompactionInfo().getSSTables()))
                    toAbort.add(tct);
            } else
                assertFalse(holder.isStopRequested());
        }
        assertEquals(2, toAbort.size());
        toAbort.forEach(TestCompactionTask::abort);
        fut.get();
        for (SSTableReader sstable : sstables) assertTrue(!sstable.intersects(Collections.singleton(range)) || sstable.isPendingRepair());
    } finally {
        tcts.forEach(TestCompactionTask::abort);
        nonAffectedTcts.forEach(TestCompactionTask::abort);
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica(org.apache.cassandra.locator.Replica) PendingAntiCompaction(org.apache.cassandra.db.repair.PendingAntiCompaction) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 PendingAntiCompaction (org.apache.cassandra.db.repair.PendingAntiCompaction)1 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)1 Replica (org.apache.cassandra.locator.Replica)1 Test (org.junit.Test)1