-
Notifications
You must be signed in to change notification settings - Fork 3.9k
CASSANDRA-19433 Nodetool cleanup can drop data Accord might need #4692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alanwang67
wants to merge
18
commits into
apache:trunk
Choose a base branch
from
alanwang67:alanwang599/CASSANDRA-19433/trunk
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
32bec7b
added check to make sure ranges that are still used by Accord are not…
alanwang67 b072804
special case sstable with single key
alanwang67 e3bd0f8
removed unused imports
alanwang67 3d752e3
fix up tests
alanwang67 b20db8f
comments
alanwang67 5a892a4
moved test to cql test base
alanwang67 ecbf66f
add additional test and check if accord service is on
alanwang67 33ecb95
cleanup on retirement rather than on command store deletion
alanwang67 b5934f8
refactor tests
alanwang67 d826bee
Rather than checking SSTable intersection, add in use Accord Ranges t…
alanwang67 804e6dd
added incomplete operation
alanwang67 5742a4c
Handle nodeprobe + add check for transient range + change inUseRanges…
alanwang67 6e55ae1
remove new line
alanwang67 b0311b8
fix bug
alanwang67 564e227
set incompleteOperation based off iterating SSTables
alanwang67 cc5c8a1
removed lock
alanwang67 f4b283c
Accord module changes
alanwang67 62ce86a
addressed comments
alanwang67 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| [submodule "modules/accord"] | ||
| path = modules/accord | ||
| url = https://github.com/apache/cassandra-accord.git | ||
| branch = trunk | ||
| url = https://github.com/alanwang67/cassandra-accord.git | ||
| branch = CASSANDRA-19433 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| import java.util.function.Predicate; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import javax.management.openmbean.OpenDataException; | ||
| import javax.management.openmbean.TabularData; | ||
|
|
@@ -114,9 +115,11 @@ | |
| import org.apache.cassandra.repair.NoSuchRepairSessionException; | ||
| import org.apache.cassandra.schema.CompactionParams.TombstoneOption; | ||
| import org.apache.cassandra.schema.Schema; | ||
| import org.apache.cassandra.schema.TableId; | ||
| import org.apache.cassandra.schema.TableMetadata; | ||
| import org.apache.cassandra.service.ActiveRepairService; | ||
| import org.apache.cassandra.service.StorageService; | ||
| import org.apache.cassandra.service.accord.AccordService; | ||
| import org.apache.cassandra.streaming.PreviewKind; | ||
| import org.apache.cassandra.tcm.ClusterMetadata; | ||
| import org.apache.cassandra.tcm.ownership.DataPlacement; | ||
|
|
@@ -133,6 +136,7 @@ | |
| import org.apache.cassandra.utils.concurrent.Promise; | ||
| import org.apache.cassandra.utils.concurrent.Refs; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkState; | ||
| import static java.util.Collections.singleton; | ||
| import static org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory; | ||
| import static org.apache.cassandra.concurrent.FutureTask.callable; | ||
|
|
@@ -612,7 +616,14 @@ public Object call() throws Exception | |
| FBUtilities.waitOnFutures(futures); | ||
| assert compacting.originals().isEmpty(); | ||
| logger.info("Finished {} for {}.{} successfully", operationType, keyspace, table); | ||
| return AllSSTableOpStatus.SUCCESSFUL; | ||
|
|
||
| if (operation.incompleteOperation()) | ||
| { | ||
| logger.info("Operation incomplete for {}.{}", keyspace, table); | ||
| return AllSSTableOpStatus.INCOMPLETE; | ||
| } | ||
| else | ||
| return AllSSTableOpStatus.SUCCESSFUL; | ||
| } | ||
| finally | ||
| { | ||
|
|
@@ -636,13 +647,18 @@ private static interface OneSSTableOperation | |
| { | ||
| Iterable<SSTableReader> filterSSTables(LifecycleTransaction transaction); | ||
| void execute(LifecycleTransaction input) throws IOException; | ||
| default boolean incompleteOperation() | ||
| { | ||
| return false; | ||
| }; | ||
| } | ||
|
|
||
| public enum AllSSTableOpStatus | ||
| { | ||
| SUCCESSFUL(0), | ||
| ABORTED(1), | ||
| UNABLE_TO_CANCEL(2); | ||
| UNABLE_TO_CANCEL(2), | ||
| INCOMPLETE(3); | ||
|
|
||
| public final int statusCode; | ||
|
|
||
|
|
@@ -789,12 +805,17 @@ public AllSSTableOpStatus performCleanup(final ColumnFamilyStore cfStore, int jo | |
| if (partitioner.getClass() == LocalPartitioner.class) | ||
| localWrites = RangesAtEndpoint.of(Replica.fullReplica(local, new Range<>(partitioner.getMinimumToken(), partitioner.getMinimumToken()))); | ||
|
|
||
| final Set<Range<Token>> allRanges = new HashSet<>(localWrites.ranges()); | ||
| InUseRanges inUseRanges = getInUseRanges(cfStore.getTableId(), localWrites); | ||
|
|
||
| final List<Range<Token>> noLongerOwnedRangesInUseByAccord = inUseRanges.noLongerOwnedRangesInUseByAccord; | ||
| final List<Range<Token>> allRanges = inUseRanges.allRanges; | ||
| final Set<Range<Token>> transientRanges = new HashSet<>(localWrites.onlyTransient().ranges()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not something you changed but I don't get why these are wrapped in new HashSet, it should be ImmmutableSet.copyOf. |
||
| final Set<Range<Token>> fullRanges = new HashSet<>(localWrites.onlyFull().ranges()); | ||
|
|
||
| return parallelAllSSTableOperation(cfStore, new OneSSTableOperation() | ||
| { | ||
| boolean incompleteOperation = false; | ||
|
|
||
| @Override | ||
| public Iterable<SSTableReader> filterSSTables(LifecycleTransaction transaction) | ||
|
aweisberg marked this conversation as resolved.
|
||
| { | ||
|
|
@@ -807,6 +828,8 @@ public Iterable<SSTableReader> filterSSTables(LifecycleTransaction transaction) | |
| SSTableReader sstable = sstableIter.next(); | ||
| boolean needsCleanupFull = needsCleanup(sstable, fullRanges); | ||
| boolean needsCleanupTransient = !transientRanges.isEmpty() && sstable.isRepaired() && needsCleanup(sstable, transientRanges); | ||
| boolean needsCleanupAccord = needsCleanup(sstable, noLongerOwnedRangesInUseByAccord); | ||
|
|
||
| //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++; | ||
|
|
@@ -823,7 +846,15 @@ public Iterable<SSTableReader> filterSSTables(LifecycleTransaction transaction) | |
| transaction.cancel(sstable); | ||
| skippedSStables++; | ||
| } | ||
| else if (!needsCleanupAccord) | ||
| { | ||
| sstableIter.remove(); | ||
| transaction.cancel(sstable); | ||
| skippedSStables++; | ||
| this.incompleteOperation = true; | ||
| } | ||
| } | ||
|
|
||
| logger.info("Skipping cleanup for {}/{} sstables for {}.{} since they are fully contained in owned ranges (full ranges: {}, transient ranges: {})", | ||
| skippedSStables, totalSSTables, cfStore.getKeyspaceName(), cfStore.getTableName(), fullRanges, transientRanges); | ||
| sortedSSTables.sort(SSTableReader.sizeComparator); | ||
|
|
@@ -834,11 +865,50 @@ public Iterable<SSTableReader> filterSSTables(LifecycleTransaction transaction) | |
| public void execute(LifecycleTransaction txn) throws IOException | ||
| { | ||
| CleanupStrategy cleanupStrategy = CleanupStrategy.get(cfStore, allRanges, transientRanges, txn.onlyOne().isRepaired(), FBUtilities.nowInSeconds()); | ||
| doCleanupOne(cfStore, txn, cleanupStrategy, allRanges, hasIndexes); | ||
| this.incompleteOperation |= (doCleanupOne(cfStore, txn, cleanupStrategy, allRanges, hasIndexes, this.incompleteOperation, noLongerOwnedRangesInUseByAccord)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean incompleteOperation() | ||
| { | ||
| return this.incompleteOperation; | ||
| } | ||
| }, jobs, OperationType.CLEANUP); | ||
| } | ||
|
|
||
| public static class InUseRanges | ||
| { | ||
| public List<Range<Token>> noLongerOwnedRangesInUseByAccord; | ||
| public List<Range<Token>> allRanges; | ||
|
|
||
| public InUseRanges(List<Range<Token>> noLongerOwnedRangesInUseByAccord, List<Range<Token>> allRanges) | ||
| { | ||
| this.noLongerOwnedRangesInUseByAccord = noLongerOwnedRangesInUseByAccord; | ||
| this.allRanges = allRanges; | ||
| } | ||
| } | ||
|
|
||
| private InUseRanges getInUseRanges(TableId tableId, RangesAtEndpoint localWrites) | ||
| { | ||
| List<Range<Token>> noLongerOwnedRangesInUseByAccord = new ArrayList<>(); | ||
| TableMetadata metadata = Schema.instance.getTableMetadata(tableId); | ||
|
|
||
| if (metadata != null && metadata.isAccordEnabled()) | ||
| { | ||
| checkState(localWrites.onlyTransient().ranges().isEmpty(), "Transient Replication is not supported with Accord"); | ||
| Map<TableId, Set<Range<Token>>> inUseRanges = AccordService.instance().getInUseRanges(); | ||
| if (inUseRanges.containsKey(tableId)) | ||
| { | ||
| Set<Range<Token>> accordOwnedTableRanges = inUseRanges.get(tableId); | ||
| for (Range<Token> range : accordOwnedTableRanges) | ||
| noLongerOwnedRangesInUseByAccord.addAll(range.subtractAll(localWrites.ranges())); | ||
| } | ||
| } | ||
|
|
||
| Collection<Range<Token>> allRanges = Stream.concat(localWrites.ranges().stream(), noLongerOwnedRangesInUseByAccord.stream()).collect(Collectors.toSet()); | ||
| return new InUseRanges(Range.normalize(noLongerOwnedRangesInUseByAccord), Range.normalize(allRanges)); | ||
| } | ||
|
|
||
| public AllSSTableOpStatus performGarbageCollection(final ColumnFamilyStore cfStore, TombstoneOption tombstoneOption, int jobs) throws InterruptedException, ExecutionException | ||
| { | ||
| assert !cfStore.isIndex(); | ||
|
|
@@ -1391,8 +1461,13 @@ public void forceUserDefinedCleanup(String dataFiles) | |
| ColumnFamilyStore cfs = entry.getKey(); | ||
| Keyspace keyspace = cfs.keyspace; | ||
| final RangesAtEndpoint replicas = StorageService.instance.getLocalReplicas(keyspace.getName()); | ||
| final Set<Range<Token>> allRanges = replicas.ranges(); | ||
|
|
||
| InUseRanges inUseRanges = getInUseRanges(cfs.getTableId(), replicas); | ||
|
|
||
| final List<Range<Token>> noLongerOwnedRangesInUseByAccord = inUseRanges.noLongerOwnedRangesInUseByAccord; | ||
| final List<Range<Token>> allRanges = inUseRanges.allRanges; | ||
| final Set<Range<Token>> transientRanges = replicas.onlyTransient().ranges(); | ||
|
|
||
| boolean hasIndexes = cfs.indexManager.hasIndexes(); | ||
| SSTableReader sstable = lookupSSTable(cfs, entry.getValue()); | ||
|
|
||
|
|
@@ -1405,7 +1480,7 @@ public void forceUserDefinedCleanup(String dataFiles) | |
| CleanupStrategy cleanupStrategy = CleanupStrategy.get(cfs, allRanges, transientRanges, sstable.isRepaired(), FBUtilities.nowInSeconds()); | ||
| try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstable, OperationType.CLEANUP)) | ||
| { | ||
| doCleanupOne(cfs, txn, cleanupStrategy, allRanges, hasIndexes); | ||
| doCleanupOne(cfs, txn, cleanupStrategy, allRanges, hasIndexes, false, noLongerOwnedRangesInUseByAccord); | ||
| } | ||
| catch (IOException e) | ||
| { | ||
|
|
@@ -1605,13 +1680,16 @@ public static boolean needsCleanup(SSTableReader sstable, Collection<Range<Token | |
| * | ||
| * @throws IOException | ||
| */ | ||
| private void doCleanupOne(final ColumnFamilyStore cfs, | ||
| LifecycleTransaction txn, | ||
| CleanupStrategy cleanupStrategy, | ||
| Collection<Range<Token>> allRanges, | ||
| boolean hasIndexes) throws IOException | ||
| private boolean doCleanupOne(final ColumnFamilyStore cfs, | ||
| LifecycleTransaction txn, | ||
| CleanupStrategy cleanupStrategy, | ||
| Collection<Range<Token>> allRanges, | ||
| boolean hasIndexes, | ||
| boolean alreadyIncomplete, | ||
| Collection<Range<Token>> noLongerOwnedRangesInUseByAccord) throws IOException | ||
| { | ||
| assert !cfs.isIndex(); | ||
| boolean incompleteOperation = alreadyIncomplete; | ||
|
|
||
| SSTableReader sstable = txn.onlyOne(); | ||
|
|
||
|
|
@@ -1621,7 +1699,7 @@ private void doCleanupOne(final ColumnFamilyStore cfs, | |
| txn.obsoleteOriginals(); | ||
| txn.finish(); | ||
| logger.info("SSTable {} ([{}, {}]) does not intersect the owned ranges ({}), dropping it", sstable, sstable.getFirst().getToken(), sstable.getLast().getToken(), allRanges); | ||
| return; | ||
| return incompleteOperation; | ||
| } | ||
|
|
||
| long start = nanoTime(); | ||
|
|
@@ -1662,6 +1740,10 @@ private void doCleanupOne(final ColumnFamilyStore cfs, | |
| if (notCleaned == null) | ||
| continue; | ||
|
|
||
| if (!noLongerOwnedRangesInUseByAccord.isEmpty() && !incompleteOperation | ||
| && Range.isInRanges(partition.partitionKey().getToken(), noLongerOwnedRangesInUseByAccord)) | ||
| incompleteOperation = true; | ||
|
|
||
| if (writer.append(notCleaned) != null) | ||
| totalkeysWritten++; | ||
|
|
||
|
|
@@ -1692,6 +1774,7 @@ private void doCleanupOne(final ColumnFamilyStore cfs, | |
| FBUtilities.prettyPrintMemory(endsize), (int) (ratio * 100), totalkeysWritten, dTime)); | ||
| } | ||
|
|
||
| return incompleteOperation; | ||
| } | ||
|
|
||
| protected void compactionRateLimiterAcquire(RateLimiter limiter, long bytesScanned, long lastBytesScanned, double compressionRatio) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nodeprobe doesn't handle this. Cleanup should signal an error if some data wasn't cleaned up since what was requested didn't fully happen.