HBASE-20928 Rewrite calculation of midpoint in binarySearch functions to prevent overflow
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
a888af3dc9
commit
3a3855aade
|
@ -126,10 +126,10 @@ public class RowIndexSeekerV1 extends AbstractEncodedSeeker {
|
|||
private int binarySearch(Cell seekCell, boolean seekBefore) {
|
||||
int low = 0;
|
||||
int high = rowNumber - 1;
|
||||
int mid = (low + high) >>> 1;
|
||||
int mid = low + ((high - low) >> 1);
|
||||
int comp = 0;
|
||||
while (low <= high) {
|
||||
mid = (low + high) >>> 1;
|
||||
mid = low + ((high - low) >> 1);
|
||||
ByteBuffer row = getRow(mid);
|
||||
comp = compareRows(row, seekCell);
|
||||
if (comp < 0) {
|
||||
|
|
|
@ -527,7 +527,7 @@ public abstract class ByteBuff {
|
|||
int high = toIndex - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) >>> 1;
|
||||
int mid = low + ((high - low) >> 1);
|
||||
int midVal = a.get(mid) & 0xff;
|
||||
|
||||
if (midVal < unsignedKey) {
|
||||
|
|
|
@ -2029,7 +2029,7 @@ public class Bytes implements Comparable<Bytes> {
|
|||
int high = arr.length - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) >>> 1;
|
||||
int mid = low + ((high - low) >> 1);
|
||||
// we have to compare in this order, because the comparator order
|
||||
// has special logic when the 'left side' is a special key.
|
||||
int cmp = Bytes.BYTES_RAWCOMPARATOR
|
||||
|
@ -2104,7 +2104,7 @@ public class Bytes implements Comparable<Bytes> {
|
|||
int low = 0;
|
||||
int high = arr.length - 1;
|
||||
while (low <= high) {
|
||||
int mid = (low+high) >>> 1;
|
||||
int mid = low + ((high - low) >> 1);
|
||||
// we have to compare in this order, because the comparator order
|
||||
// has special logic when the 'left side' is a special key.
|
||||
int cmp = comparator.compare(key, arr[mid]);
|
||||
|
@ -2278,7 +2278,7 @@ public class Bytes implements Comparable<Bytes> {
|
|||
int high = toIndex - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) >>> 1;
|
||||
int mid = low + ((high - low) >> 1);
|
||||
int midVal = a[mid] & 0xff;
|
||||
|
||||
if (midVal < unsignedKey) {
|
||||
|
|
|
@ -745,7 +745,7 @@ public class HFileBlockIndex {
|
|||
ByteBufferKeyOnlyKeyValue nonRootIndexkeyOnlyKV = new ByteBufferKeyOnlyKeyValue();
|
||||
ObjectIntPair<ByteBuffer> pair = new ObjectIntPair<>();
|
||||
while (low <= high) {
|
||||
mid = (low + high) >>> 1;
|
||||
mid = low + ((high - low) >> 1);
|
||||
|
||||
// Midkey's offset relative to the end of secondary index
|
||||
int midKeyRelOffset = nonRootIndex.getIntAfterPosition(Bytes.SIZEOF_INT * (mid + 1));
|
||||
|
|
|
@ -83,7 +83,7 @@ public abstract class CellFlatMap implements NavigableMap<Cell,Cell> {
|
|||
int end = maxCellIdx - 1;
|
||||
|
||||
while (begin <= end) {
|
||||
int mid = (begin + end) >>> 1;
|
||||
int mid = begin + ((end - begin) >> 1);
|
||||
Cell midCell = getCell(mid);
|
||||
int compareRes = comparator.compare(midCell, needle);
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ public class BoundedPriorityBlockingQueue<E> extends AbstractQueue<E> implements
|
|||
|
||||
private int upperBound(int start, int end, E key) {
|
||||
while (start < end) {
|
||||
int mid = (start + end) >>> 1;
|
||||
int mid = start + ((end - start) >> 1);
|
||||
E mitem = objects[mid];
|
||||
int cmp = comparator.compare(mitem, key);
|
||||
if (cmp > 0) {
|
||||
|
|
Loading…
Reference in New Issue