Search in sources :

Example 11 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class CompactionManager method performCleanup.

public AllSSTableOpStatus performCleanup(final ColumnFamilyStore cfStore, int jobs) throws InterruptedException, ExecutionException {
    assert !cfStore.isIndex();
    Keyspace keyspace = cfStore.keyspace;
    if (!StorageService.instance.isJoined()) {
        logger.info("Cleanup cannot run before a node has joined the ring");
        return AllSSTableOpStatus.ABORTED;
    }
    // if local ranges is empty, it means no data should remain
    final RangesAtEndpoint replicas = StorageService.instance.getLocalReplicas(keyspace.getName());
    final Set<Range<Token>> allRanges = replicas.ranges();
    final Set<Range<Token>> transientRanges = replicas.onlyTransient().ranges();
    final Set<Range<Token>> fullRanges = replicas.onlyFull().ranges();
    final boolean hasIndexes = cfStore.indexManager.hasIndexes();
    return parallelAllSSTableOperation(cfStore, new OneSSTableOperation() {

        @Override
        public Iterable<SSTableReader> filterSSTables(LifecycleTransaction transaction) {
            List<SSTableReader> sortedSSTables = Lists.newArrayList(transaction.originals());
            Iterator<SSTableReader> sstableIter = sortedSSTables.iterator();
            int totalSSTables = 0;
            int skippedSStables = 0;
            while (sstableIter.hasNext()) {
                SSTableReader sstable = sstableIter.next();
                boolean needsCleanupFull = needsCleanup(sstable, fullRanges);
                boolean needsCleanupTransient = !transientRanges.isEmpty() && sstable.isRepaired() && needsCleanup(sstable, transientRanges);
                // If there are no ranges for which the table needs cleanup either due to lack of intersection or lack
                // of the table being repaired.
                totalSSTables++;
                if (!needsCleanupFull && !needsCleanupTransient) {
                    logger.debug("Skipping {} ([{}, {}]) for cleanup; all rows should be kept. Needs cleanup full ranges: {} Needs cleanup transient ranges: {} Repaired: {}", sstable, sstable.first.getToken(), sstable.last.getToken(), needsCleanupFull, needsCleanupTransient, sstable.isRepaired());
                    sstableIter.remove();
                    transaction.cancel(sstable);
                    skippedSStables++;
                }
            }
            logger.info("Skipping cleanup for {}/{} sstables for {}.{} since they are fully contained in owned ranges (full ranges: {}, transient ranges: {})", skippedSStables, totalSSTables, cfStore.keyspace.getName(), cfStore.getTableName(), fullRanges, transientRanges);
            sortedSSTables.sort(SSTableReader.sizeComparator);
            return sortedSSTables;
        }

        @Override
        public void execute(LifecycleTransaction txn) throws IOException {
            CleanupStrategy cleanupStrategy = CleanupStrategy.get(cfStore, allRanges, transientRanges, txn.onlyOne().isRepaired(), FBUtilities.nowInSeconds());
            doCleanupOne(cfStore, txn, cleanupStrategy, replicas.ranges(), hasIndexes);
        }
    }, jobs, OperationType.CLEANUP);
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) ILifecycleTransaction(org.apache.cassandra.db.lifecycle.ILifecycleTransaction) WrappedLifecycleTransaction(org.apache.cassandra.db.lifecycle.WrappedLifecycleTransaction) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator)

Example 12 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class LocalSessionTest method prepareCancellation.

/**
 * If the session is cancelled mid-prepare, the isCancelled boolean supplier should start returning true
 */
@Test
public void prepareCancellation() {
    UUID sessionID = registerSession();
    AtomicReference<BooleanSupplier> isCancelledRef = new AtomicReference<>();
    Promise<List<Void>> future = new AsyncPromise<>();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions() {

        Future<List<Void>> prepareSession(KeyspaceRepairManager repairManager, UUID sessionID, Collection<ColumnFamilyStore> tables, RangesAtEndpoint ranges, ExecutorService executor, BooleanSupplier isCancelled) {
            isCancelledRef.set(isCancelled);
            return future;
        }
    };
    sessions.start();
    sessions.handlePrepareMessage(PARTICIPANT1, new PrepareConsistentRequest(sessionID, COORDINATOR, PARTICIPANTS));
    BooleanSupplier isCancelled = isCancelledRef.get();
    Assert.assertNotNull(isCancelled);
    Assert.assertFalse(isCancelled.getAsBoolean());
    Assert.assertTrue(sessions.sentMessages.isEmpty());
    sessions.failSession(sessionID, false);
    Assert.assertTrue(isCancelled.getAsBoolean());
    // now that the session has failed, it send a negative response to the coordinator (even if the anti-compaction completed successfully)
    future.trySuccess(null);
    assertMessagesSent(sessions, COORDINATOR, new PrepareConsistentResponse(sessionID, PARTICIPANT1, false));
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsyncPromise(org.apache.cassandra.utils.concurrent.AsyncPromise) KeyspaceRepairManager(org.apache.cassandra.repair.KeyspaceRepairManager) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) BooleanSupplier(java.util.function.BooleanSupplier) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 13 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class MoveTransientTest method invokeCalculateRangesToFetchWithPreferredEndpoints.

private void invokeCalculateRangesToFetchWithPreferredEndpoints(RangesAtEndpoint toFetch, Pair<TokenMetadata, TokenMetadata> tmds, EndpointsByReplica expectedResult) {
    DatabaseDescriptor.setTransientReplicationEnabledUnsafe(true);
    EndpointsByReplica result = RangeStreamer.calculateRangesToFetchWithPreferredEndpoints((address, replicas) -> replicas.sorted((a, b) -> b.endpoint().compareTo(a.endpoint())), simpleStrategy(tmds.left), toFetch, true, tmds.left, tmds.right, "TestKeyspace", sourceFilters);
    logger.info("Ranges to fetch with preferred endpoints");
    logger.info(result.toString());
    assertMultimapEqualsIgnoreOrder(expectedResult, result);
}
Also used : StorageServiceTest.assertMultimapEqualsIgnoreOrder(org.apache.cassandra.service.StorageServiceTest.assertMultimapEqualsIgnoreOrder) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) Range(org.apache.cassandra.dht.Range) ArrayList(java.util.ArrayList) RandomPartitioner(org.apache.cassandra.dht.RandomPartitioner) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) Token(org.apache.cassandra.dht.Token) AbstractEndpointSnitch(org.apache.cassandra.locator.AbstractEndpointSnitch) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Pair(org.apache.cassandra.utils.Pair) After(org.junit.After) SimpleStrategy(org.apache.cassandra.locator.SimpleStrategy) RangeStreamer(org.apache.cassandra.dht.RangeStreamer) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Logger(org.slf4j.Logger) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RangesByEndpoint(org.apache.cassandra.locator.RangesByEndpoint) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Replica(org.apache.cassandra.locator.Replica) Replica.transientReplica(org.apache.cassandra.locator.Replica.transientReplica) List(java.util.List) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Assert.assertEquals(org.junit.Assert.assertEquals) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Example 14 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class MoveTransientTest method calculateStreamAndFetchRangesMoveBackwardBetween.

public Pair<RangesAtEndpoint, RangesAtEndpoint> calculateStreamAndFetchRangesMoveBackwardBetween() throws Exception {
    Range<Token> aPrimeRange = new Range<>(elevenToken, fourteenToken);
    RangesAtEndpoint updated = RangesAtEndpoint.of(new Replica(address01, aPrimeRange, true), new Replica(address01, range_9_11, true), new Replica(address01, range_6_9, false));
    Pair<RangesAtEndpoint, RangesAtEndpoint> result = RangeRelocator.calculateStreamAndFetchRanges(current, updated);
    assertContentsIgnoreOrder(result.left, fullReplica(address01, oneToken, threeToken), fullReplica(address01, fourteenToken, oneToken));
    assertContentsIgnoreOrder(result.right, transientReplica(address01, sixToken, nineToken), fullReplica(address01, nineToken, elevenToken));
    return result;
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) Replica.transientReplica(org.apache.cassandra.locator.Replica.transientReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Example 15 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class MoveTransientTest method calculateStreamAndFetchRangesMoveForwardBetween.

/**
 * Ring with start A 1-3 B 3-6 C 6-9 D 9-11 E 11-1
 * A's moves from 3 to 7
 *
 * @throws Exception
 */
private Pair<RangesAtEndpoint, RangesAtEndpoint> calculateStreamAndFetchRangesMoveForwardBetween() throws Exception {
    Range<Token> aPrimeRange = new Range<>(sixToken, sevenToken);
    Range<Token> bPrimeRange = new Range<>(oneToken, sixToken);
    RangesAtEndpoint updated = RangesAtEndpoint.of(new Replica(address01, aPrimeRange, true), new Replica(address01, bPrimeRange, true), new Replica(address01, range_11_1, false));
    Pair<RangesAtEndpoint, RangesAtEndpoint> result = RangeRelocator.calculateStreamAndFetchRanges(current, updated);
    assertContentsIgnoreOrder(result.left, fullReplica(address01, elevenToken, oneToken), transientReplica(address01, nineToken, elevenToken));
    assertContentsIgnoreOrder(result.right, fullReplica(address01, threeToken, sixToken), fullReplica(address01, sixToken, sevenToken));
    return result;
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) Replica.transientReplica(org.apache.cassandra.locator.Replica.transientReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Aggregations

RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)32 Token (org.apache.cassandra.dht.Token)22 Range (org.apache.cassandra.dht.Range)20 Replica (org.apache.cassandra.locator.Replica)17 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)10 EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Test (org.junit.Test)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Collection (java.util.Collection)8 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)8 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Set (java.util.Set)7 UUID (java.util.UUID)7 Replica.fullReplica (org.apache.cassandra.locator.Replica.fullReplica)7 IOException (java.io.IOException)6 Replica.transientReplica (org.apache.cassandra.locator.Replica.transientReplica)6