Search in sources :

Example 1 with NO_PENDING_REPAIR

use of org.apache.cassandra.service.ActiveRepairService.NO_PENDING_REPAIR in project cassandra by apache.

the class AntiCompactionTest method antiCompactRanges.

private SSTableStats antiCompactRanges(ColumnFamilyStore store, RangesAtEndpoint ranges) throws IOException {
    UUID sessionID = UUID.randomUUID();
    Collection<SSTableReader> sstables = getUnrepairedSSTables(store);
    try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION);
        Refs<SSTableReader> refs = Refs.ref(sstables)) {
        if (txn == null)
            throw new IllegalStateException();
        registerParentRepairSession(sessionID, ranges.ranges(), FBUtilities.nowInSeconds(), sessionID);
        CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, sessionID, () -> false);
    }
    SSTableStats stats = new SSTableStats();
    stats.numLiveSSTables = store.getLiveSSTables().size();
    Predicate<Token> fullContains = t -> Iterables.any(ranges.onlyFull().ranges(), r -> r.contains(t));
    Predicate<Token> transContains = t -> Iterables.any(ranges.onlyTransient().ranges(), r -> r.contains(t));
    for (SSTableReader sstable : store.getLiveSSTables()) {
        assertFalse(sstable.isRepaired());
        assertEquals(sstable.isPendingRepair() ? sessionID : NO_PENDING_REPAIR, sstable.getPendingRepair());
        try (ISSTableScanner scanner = sstable.getScanner()) {
            while (scanner.hasNext()) {
                UnfilteredRowIterator row = scanner.next();
                Token token = row.partitionKey().getToken();
                if (sstable.isPendingRepair() && !sstable.isTransient()) {
                    assertTrue(fullContains.test(token));
                    assertFalse(transContains.test(token));
                    stats.pendingKeys++;
                } else if (sstable.isPendingRepair() && sstable.isTransient()) {
                    assertTrue(transContains.test(token));
                    assertFalse(fullContains.test(token));
                    stats.transKeys++;
                } else {
                    assertFalse(fullContains.test(token));
                    assertFalse(transContains.test(token));
                    stats.unrepairedKeys++;
                }
            }
        }
    }
    for (SSTableReader sstable : store.getLiveSSTables()) {
        assertFalse(sstable.isMarkedCompacted());
        assertEquals(1, sstable.selfRef().globalCount());
    }
    assertEquals(0, store.getTracker().getCompacting().size());
    return stats;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Arrays(java.util.Arrays) Util.assertOnDiskState(org.apache.cassandra.Util.assertOnDiskState) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) File(org.apache.cassandra.io.util.File) org.apache.cassandra.db(org.apache.cassandra.db) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert.assertThat(org.junit.Assert.assertThat) NO_PENDING_REPAIR(org.apache.cassandra.service.ActiveRepairService.NO_PENDING_REPAIR) After(org.junit.After) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) Transactional(org.apache.cassandra.utils.concurrent.Transactional) ImmutableSet(com.google.common.collect.ImmutableSet) FBUtilities(org.apache.cassandra.utils.FBUtilities) org.apache.cassandra.io.sstable(org.apache.cassandra.io.sstable) Predicate(java.util.function.Predicate) UNREPAIRED_SSTABLE(org.apache.cassandra.service.ActiveRepairService.UNREPAIRED_SSTABLE) Collection(java.util.Collection) KeyspaceParams(org.apache.cassandra.schema.KeyspaceParams) Set(java.util.Set) UUID(java.util.UUID) Sets(com.google.common.collect.Sets) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) UUIDGen(org.apache.cassandra.utils.UUIDGen) List(java.util.List) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Assert.assertFalse(org.junit.Assert.assertFalse) TableMetadata(org.apache.cassandra.schema.TableMetadata) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) Range(org.apache.cassandra.dht.Range) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Lists(com.google.common.collect.Lists) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Refs(org.apache.cassandra.utils.concurrent.Refs) UpdateBuilder(org.apache.cassandra.UpdateBuilder) Iterator(java.util.Iterator) MockSchema(org.apache.cassandra.schema.MockSchema) Assert.assertNotNull(org.junit.Assert.assertNotNull) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Replica(org.apache.cassandra.locator.Replica) SchemaLoader(org.apache.cassandra.SchemaLoader) PreviewKind(org.apache.cassandra.streaming.PreviewKind) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Token(org.apache.cassandra.dht.Token) UUID(java.util.UUID)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Predicate (java.util.function.Predicate)1 SchemaLoader (org.apache.cassandra.SchemaLoader)1 UpdateBuilder (org.apache.cassandra.UpdateBuilder)1 Util.assertOnDiskState (org.apache.cassandra.Util.assertOnDiskState)1 org.apache.cassandra.db (org.apache.cassandra.db)1 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)1 SSTableSet (org.apache.cassandra.db.lifecycle.SSTableSet)1