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

added validate method into TabletMetadata #5340

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -42,6 +42,7 @@
import org.apache.accumulo.core.clientImpl.ClientContext;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.dataImpl.KeyExtent;
Expand Down Expand Up @@ -558,6 +559,26 @@ private static Optional<TServerInstance> checkServer(ClientContext context, Stri
.map(address -> new TServerInstance(address, stat.getEphemeralOwner()));
}

public static void validate(TabletMetadata tm) {
if (!tm.fetchedCols.contains(ColumnType.FILES) || !tm.sawPrevEndRow) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we fetched files, may not see any files for a tablet can avoid some work by checking if the set is empty. The sawPrevEndRow is more for error checking. If we fetched the PREV_ROW then its always expeced that it will be seen, so can check if it was fetched. Other code will throw an error if prev row was fetched and not seen.

Suggested change
if (!tm.fetchedCols.contains(ColumnType.FILES) || !tm.sawPrevEndRow) {
if (files.isEmpty() || !tm.fetchedCols.contains(ColumnType.PREV_ROW)) {

return;
}

Collection<StoredTabletFile> files = tm.getFiles();
Range tabletRange = tm.getExtent().toDataRange();

for (StoredTabletFile file : files) {
if (!isFileRangeValid(file, tabletRange)) {
throw new IllegalStateException(
"File range " + file.getRange() + " does not overlap with tablet range " + tabletRange);
}
}
}

private static boolean isFileRangeValid(StoredTabletFile file, Range tabletRange) {
return !file.hasRange() || tabletRange.clip(file.getRange(), true) != null;
}

static class Builder {
private TableId tableId;
private Text prevEndRow;
Expand Down Expand Up @@ -682,7 +703,9 @@ void keyValue(Entry<Key,Value> kv) {

TabletMetadata build(EnumSet<ColumnType> fetchedCols) {
this.fetchedCols = fetchedCols;
return new TabletMetadata(this);
TabletMetadata tm = new TabletMetadata(this);
validate(tm);
return tm;
}
}
}