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);
}
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));
}
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);
}
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;
}
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;
}
Aggregations