Skip to content

Commit d9617a6

Browse files
committed
simplified validate and isFileRangeValid
1 parent 7588c2b commit d9617a6

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

core/src/main/java/org/apache/accumulo/core/metadata/schema/TabletMetadata.java

+6-35
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.accumulo.core.clientImpl.ClientContext;
4343
import org.apache.accumulo.core.data.ByteSequence;
4444
import org.apache.accumulo.core.data.Key;
45-
import org.apache.accumulo.core.data.PartialKey;
4645
import org.apache.accumulo.core.data.Range;
4746
import org.apache.accumulo.core.data.TableId;
4847
import org.apache.accumulo.core.data.Value;
@@ -566,46 +565,18 @@ public static void validate(TabletMetadata tm) {
566565
}
567566

568567
Collection<StoredTabletFile> files = tm.getFiles();
569-
570-
Text prevEndRowText = tm.getPrevEndRow();
571-
Text endRowText = tm.getEndRow();
572-
573-
// Allow validation even if prevEndRow is missing, as long as endRowText exists
574-
Key prevEndRowKey = (prevEndRowText != null) ? new Key(prevEndRowText) : null;
575-
Key endRowKey = (endRowText != null) ? new Key(endRowText) : null;
568+
Range tabletRange = tm.getExtent().toDataRange();
576569

577570
for (StoredTabletFile file : files) {
578-
if (!isFileRangeValid(file, prevEndRowKey, endRowKey)) {
579-
throw new IllegalStateException("File range " + file.getRange()
580-
+ " does not overlap with tablet range [" + prevEndRowText + ", " + endRowText + "]");
571+
if (!isFileRangeValid(file, tabletRange)) {
572+
throw new IllegalStateException(
573+
"File range " + file.getRange() + " does not overlap with tablet range " + tabletRange);
581574
}
582575
}
583576
}
584577

585-
private static boolean isFileRangeValid(StoredTabletFile file, Key prevEndRowKey, Key endRowKey) {
586-
Range fileRange = file.getRange();
587-
588-
if (!file.hasRange()) {
589-
return true;
590-
}
591-
592-
Key fileStartKey = fileRange.getStartKey();
593-
Key fileEndKey = fileRange.getEndKey();
594-
595-
// If start key is null, assume it starts at the beginning of the tablet
596-
if (fileStartKey == null) {
597-
fileStartKey = prevEndRowKey != null ? prevEndRowKey.followingKey(PartialKey.ROW) : null;
598-
}
599-
600-
if (fileEndKey == null) {
601-
fileEndKey = endRowKey;
602-
}
603-
604-
if (prevEndRowKey != null
605-
&& fileStartKey.compareTo(prevEndRowKey.followingKey(PartialKey.ROW)) < 0) {
606-
return false;
607-
}
608-
return endRowKey == null || fileEndKey.compareTo(endRowKey) <= 0;
578+
private static boolean isFileRangeValid(StoredTabletFile file, Range tabletRange) {
579+
return !file.hasRange() || tabletRange.clip(file.getRange(), true) != null;
609580
}
610581

611582
static class Builder {

0 commit comments

Comments
 (0)