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

Fix scrub_test.py #3960

Open
wants to merge 1 commit into
base: cassandra-5.0
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
import java.util.Collections;
import java.util.List;

import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.PartitionPosition;
import org.apache.cassandra.io.sstable.format.SSTableReader;
import org.apache.cassandra.utils.Interval;
import org.apache.cassandra.utils.IntervalTree;

import static com.google.common.base.Preconditions.checkState;

public class SSTableIntervalTree extends IntervalTree<PartitionPosition, SSTableReader, Interval<PartitionPosition, SSTableReader>>
{
private static final SSTableIntervalTree EMPTY = new SSTableIntervalTree(null);
Expand Down Expand Up @@ -75,8 +78,28 @@ public static Interval<PartitionPosition, SSTableReader>[] buildIntervalsArray(C
return IntervalTree.EMPTY_ARRAY;
Interval<PartitionPosition, SSTableReader>[] intervals = new Interval[sstables.size()];
int i = 0;
int missingIntervals = 0;
for (SSTableReader sstable : sstables)
intervals[i++] = sstable.getInterval();
{
Interval<PartitionPosition, SSTableReader> interval = sstable.getInterval();
if (interval == null)
{
missingIntervals++;
continue;
}
intervals[i++] = interval;
}

// Offline (scrub) tools create SSTableReader without a first and last key and the old interval tree
// built a corrupt tree that couldn't be searched so continue to do that rather than complicate Tracker/View
if (missingIntervals > 0)
{
checkState(DatabaseDescriptor.isToolInitialized(), "Can only safely build an interval tree on sstables with missing first and last for offline tools");
Interval<PartitionPosition, SSTableReader>[] replacementIntervals = new Interval[intervals.length - missingIntervals];
System.arraycopy(intervals, 0, replacementIntervals, 0, replacementIntervals.length);
return replacementIntervals;
}

return intervals;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ protected SSTableReader(Builder<?, ?> builder, Owner owner)
this.openReason = builder.getOpenReason();
this.first = builder.getFirst();
this.last = builder.getLast();
this.interval = Interval.create(first, last, this);
this.interval = first == null || last == null ? null : Interval.create(first, last, this);
this.bounds = first == null || last == null || AbstractBounds.strictlyWrapsAround(first.getToken(), last.getToken())
? null // this will cause the validation to fail, but the reader is opened with no validation,
// e.g. for scrubbing, we should accept screwed bounds
Expand Down
4 changes: 4 additions & 0 deletions src/java/org/apache/cassandra/utils/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.google.common.base.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

public class Interval<C, D>
{
public final C min;
Expand All @@ -27,6 +29,8 @@ public class Interval<C, D>

public Interval(C min, C max, D data)
{
checkNotNull(min, "min is null");
checkNotNull(max, "max is null");
this.min = min;
this.max = max;
this.data = data;
Expand Down