Skip to content

Commit

Permalink
Make bulk load mapping matching more strict #1260 (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-turner authored Jul 15, 2019
1 parent 3ef2b9b commit 9a5ec83
Showing 1 changed file with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.NoSuchElementException;
import java.util.Set;

import org.apache.accumulo.core.client.BatchWriter;
Expand Down Expand Up @@ -340,27 +341,53 @@ private long loadFiles(TableId tableId, Path bulkDir, LoadMappingIterator loadMa
return sleepTime;
}

private static final Comparator<Text> PREV_COMP = Comparator.nullsFirst(Text::compareTo);
private static final Comparator<Text> END_COMP = Comparator.nullsLast(Text::compareTo);

/**
* Find all the tablets within the provided bulk load mapping range.
*/
private List<TabletMetadata> findOverlappingTablets(KeyExtent loadRange,
Iterator<TabletMetadata> tabletIter) {
List<TabletMetadata> tablets = new ArrayList<>();
TabletMetadata currentTablet = tabletIter.next();

// skip tablets until we find the prevEndRow of loadRange
while (!Objects.equals(currentTablet.getPrevEndRow(), loadRange.getPrevEndRow())) {
currentTablet = tabletIter.next();
}
// we have found the first tablet in the range, add it to the list
tablets.add(currentTablet);

// find the remaining tablets within the loadRange by
// adding tablets to the list until the endRow matches the loadRange
while (!Objects.equals(currentTablet.getEndRow(), loadRange.getEndRow())) {
currentTablet = tabletIter.next();
tablets.add(currentTablet);
TabletMetadata currTablet = null;

try {

List<TabletMetadata> tablets = new ArrayList<>();
currTablet = tabletIter.next();

int cmp;

// skip tablets until we find the prevEndRow of loadRange
while ((cmp = PREV_COMP.compare(currTablet.getPrevEndRow(), loadRange.getPrevEndRow())) < 0) {
currTablet = tabletIter.next();
}

if (cmp != 0) {
throw new IllegalStateException("Unexpected prev end row " + currTablet + " " + loadRange);
}

// we have found the first tablet in the range, add it to the list
tablets.add(currTablet);

// find the remaining tablets within the loadRange by
// adding tablets to the list until the endRow matches the loadRange
while ((cmp = END_COMP.compare(currTablet.getEndRow(), loadRange.getEndRow())) < 0) {
currTablet = tabletIter.next();
tablets.add(currTablet);
}

if (cmp != 0) {
throw new IllegalStateException("Unexpected end row " + currTablet + " " + loadRange);
}

return tablets;
} catch (NoSuchElementException e) {
NoSuchElementException ne2 = new NoSuchElementException(
"Failed to find overlapping tablets " + currTablet + " " + loadRange);
ne2.initCause(e);
throw ne2;
}
return tablets;
}
}

0 comments on commit 9a5ec83

Please sign in to comment.