Skip to content
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

IndexSummaryRedistribution should unmark compacting SSTables in batch #3755

Open
wants to merge 1 commit into
base: cassandra-4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
4.1.8
* IndexSummaryRedistribution should unmark compacting SSTables in batch (CASSANDRA-20159)
* Add nodetool checktokenmetadata command that checks TokenMetadata is insync with Gossip endpointState (CASSANDRA-18758)
* Backport Java 11 support for Simulator (CASSANDRA-17178/CASSANDRA-19935)
* Equality check for Paxos.Electorate should not depend on collection types (CASSANDRA-19935)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,19 @@ else if (originals.contains(reader))
return select(reader, container);
}

private void verifySStableToBeCanceled(SSTableReader cancel)
{
assert originals.contains(cancel) : "may only cancel a reader in the 'original' set: " + cancel + " vs " + originals;
assert !(staged.contains(cancel) || logged.contains(cancel)) : "may only cancel a reader that has not been updated or obsoleted in this transaction: " + cancel;
}

/**
* remove the reader from the set we're modifying
*/
public void cancel(SSTableReader cancel)
{
logger.trace("Cancelling {} from transaction", cancel);
assert originals.contains(cancel) : "may only cancel a reader in the 'original' set: " + cancel + " vs " + originals;
assert !(staged.contains(cancel) || logged.contains(cancel)) : "may only cancel a reader that has not been updated or obsoleted in this transaction: " + cancel;
verifySStableToBeCanceled(cancel);
originals.remove(cancel);
marked.remove(cancel);
identities.remove(cancel.instanceId);
Expand All @@ -510,10 +515,19 @@ public void cancel(SSTableReader cancel)
/**
* remove the readers from the set we're modifying
*/
public void cancel(Iterable<SSTableReader> cancels)
public void cancel(Set<SSTableReader> cancels)
{
logger.trace("Cancelling {} from transaction", cancels);
Set<UniqueIdentifier> instanceIds = new HashSet<>();
for (SSTableReader cancel : cancels)
cancel(cancel);
{
verifySStableToBeCanceled(cancel);
instanceIds.add(cancel.instanceId);
}
originals.removeAll(cancels);
marked.removeAll(cancels);
identities.removeAll(instanceIds);
maybeFail(unmarkCompacting(cancels, null));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -153,6 +155,8 @@ private List<SSTableReader> adjustSamplingLevels(List<SSTableReader> sstables,
// Going from the coldest to the hottest sstables, try to give each sstable an amount of space proportional
// to the number of total reads/sec it handles.
remainingSpace = memoryPoolCapacity;
// group sstables to be cancelled by table id
Map<TableId, Set<SSTableReader>> sstablesToCancelByTableId = new HashMap<>();
for (SSTableReader sstable : sstables)
{
if (isStopRequested())
Expand Down Expand Up @@ -232,7 +236,7 @@ else if (targetNumEntries < currentNumEntries * DOWNSAMPLE_THESHOLD && newSampli
logger.trace("SSTable {} is within thresholds of ideal sampling", sstable);
remainingSpace -= sstable.getIndexSummaryOffHeapSize();
newSSTables.add(sstable);
transactions.get(sstable.metadata().id).cancel(sstable);
sstablesToCancelByTableId.computeIfAbsent(sstable.metadata().id, k -> new HashSet<>()).add(sstable);
}
totalReadsPerSec -= readsPerSec;
}
Expand All @@ -242,8 +246,15 @@ else if (targetNumEntries < currentNumEntries * DOWNSAMPLE_THESHOLD && newSampli
Pair<List<SSTableReader>, List<ResampleEntry>> result = distributeRemainingSpace(toDownsample, remainingSpace);
toDownsample = result.right;
newSSTables.addAll(result.left);
for (SSTableReader sstable : result.left)
transactions.get(sstable.metadata().id).cancel(sstable);
// group by tableId then do cancel in one-go
for (SSTableReader sstable : result.left) {
sstablesToCancelByTableId.computeIfAbsent(sstable.metadata().id, k -> new HashSet<>()).add(sstable);
}
}

// remove the sstables from Txn and unmark them from compacting in batch
for (Map.Entry<TableId, Set<SSTableReader>> entry : sstablesToCancelByTableId.entrySet()) {
transactions.get(entry.getKey()).cancel(entry.getValue());
}

// downsample first, then upsample
Expand Down