Skip to content

Commit d2d3c14

Browse files
committed
HBASE-14227 Reduce the number of time row comparison is done in a Scan
(Ram)
1 parent d49e54a commit d2d3c14

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,27 @@ public MatchCode match(Cell cell) throws IOException {
278278
if (filter != null && filter.filterAllRemaining()) {
279279
return MatchCode.DONE_SCAN;
280280
}
281-
int ret = this.rowComparator.compareRows(row, this.rowOffset, this.rowLength,
281+
if (row != null) {
282+
int ret = this.rowComparator.compareRows(row, this.rowOffset, this.rowLength,
282283
cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
283-
if (!this.isReversed) {
284-
if (ret <= -1) {
285-
return MatchCode.DONE;
286-
} else if (ret >= 1) {
287-
// could optimize this, if necessary?
288-
// Could also be called SEEK_TO_CURRENT_ROW, but this
289-
// should be rare/never happens.
290-
return MatchCode.SEEK_NEXT_ROW;
284+
if (!this.isReversed) {
285+
if (ret <= -1) {
286+
return MatchCode.DONE;
287+
} else if (ret >= 1) {
288+
// could optimize this, if necessary?
289+
// Could also be called SEEK_TO_CURRENT_ROW, but this
290+
// should be rare/never happens.
291+
return MatchCode.SEEK_NEXT_ROW;
292+
}
293+
} else {
294+
if (ret <= -1) {
295+
return MatchCode.SEEK_NEXT_ROW;
296+
} else if (ret >= 1) {
297+
return MatchCode.DONE;
298+
}
291299
}
292300
} else {
293-
if (ret <= -1) {
294-
return MatchCode.SEEK_NEXT_ROW;
295-
} else if (ret >= 1) {
296-
return MatchCode.DONE;
297-
}
301+
return MatchCode.DONE;
298302
}
299303

300304
// optimize case.

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
511511
// If no limits exists in the scope LimitScope.Between_Cells then we are sure we are changing
512512
// rows. Else it is possible we are still traversing the same row so we must perform the row
513513
// comparison.
514-
if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.row == null ||
515-
!Bytes.equals(row, offset, length, matcher.row, matcher.rowOffset, matcher.rowLength)) {
514+
if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.row == null) {
516515
this.countPerRow = 0;
517516
matcher.setRow(row, offset, length);
518517
}
@@ -560,6 +559,10 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
560559
if (!matcher.moreRowsMayExistAfter(cell)) {
561560
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
562561
}
562+
// Setting the matcher.row = null, will mean that after the subsequent seekToNextRow()
563+
// the heap.peek() will any way be in the next row. So the SQM.match(cell) need do
564+
// another compareRow to say the current row is DONE
565+
matcher.row = null;
563566
seekToNextRow(cell);
564567
break LOOP;
565568
}
@@ -587,6 +590,10 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
587590
if (!matcher.moreRowsMayExistAfter(cell)) {
588591
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
589592
}
593+
// Setting the matcher.row = null, will mean that after the subsequent seekToNextRow()
594+
// the heap.peek() will any way be in the next row. So the SQM.match(cell) need do
595+
// another compareRow to say the current row is DONE
596+
matcher.row = null;
590597
seekToNextRow(cell);
591598
} else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) {
592599
seekAsDirection(matcher.getKeyForNextColumn(cell));
@@ -603,6 +610,10 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
603610
continue;
604611

605612
case DONE:
613+
// We are sure that this row is done and we are in the next row.
614+
// So subsequent StoresScanner.next() call need not do another compare
615+
// and set the matcher.row
616+
matcher.row = null;
606617
return scannerContext.setScannerState(NextState.MORE_VALUES).hasMoreValues();
607618

608619
case DONE_SCAN:
@@ -615,7 +626,10 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
615626
if (!matcher.moreRowsMayExistAfter(cell)) {
616627
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
617628
}
618-
629+
// Setting the matcher.row = null, will mean that after the subsequent seekToNextRow()
630+
// the heap.peek() will any way be in the next row. So the SQM.match(cell) need do
631+
// another compareRow to say the current row is DONE
632+
matcher.row = null;
619633
seekToNextRow(cell);
620634
break;
621635

0 commit comments

Comments
 (0)