From 073e00c0053cb351dbba265112a6e756c932f875 Mon Sep 17 00:00:00 2001 From: ramkrishna Date: Wed, 6 Jan 2016 10:38:27 +0530 Subject: [PATCH] HBASE-14221 Reduce the number of time row comparison is done in a Scan (Ram) --- .../hbase/regionserver/ScanQueryMatcher.java | 36 +++++++++++-------- .../hbase/regionserver/StoreScanner.java | 11 +++--- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java index 47d8c8fa5ba..c220b5cc8d0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScanQueryMatcher.java @@ -283,27 +283,33 @@ public class ScanQueryMatcher { if (filter != null && filter.filterAllRemaining()) { return MatchCode.DONE_SCAN; } - int ret = this.rowComparator.compareRows(curCell, cell); - if (!this.isReversed) { - if (ret <= -1) { - return MatchCode.DONE; - } else if (ret >= 1) { - // could optimize this, if necessary? - // Could also be called SEEK_TO_CURRENT_ROW, but this - // should be rare/never happens. - return MatchCode.SEEK_NEXT_ROW; + if (curCell != null) { + int ret = this.rowComparator.compareRows(curCell, cell); + if (!this.isReversed) { + if (ret <= -1) { + return MatchCode.DONE; + } else if (ret >= 1) { + // could optimize this, if necessary? + // Could also be called SEEK_TO_CURRENT_ROW, but this + // should be rare/never happens. + return MatchCode.SEEK_NEXT_ROW; + } + } else { + if (ret <= -1) { + return MatchCode.SEEK_NEXT_ROW; + } else if (ret >= 1) { + return MatchCode.DONE; + } } } else { - if (ret <= -1) { - return MatchCode.SEEK_NEXT_ROW; - } else if (ret >= 1) { - return MatchCode.DONE; - } + // Since the curCell is null it means we are already sure that we have moved over to the next row + return MatchCode.DONE; } // optimize case. - if (this.stickyNextRow) + if (this.stickyNextRow) { return MatchCode.SEEK_NEXT_ROW; + } if (this.columns.done()) { stickyNextRow = true; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java index 5fdfa79a8ce..3049608ce64 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java @@ -507,8 +507,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner // If no limits exists in the scope LimitScope.Between_Cells then we are sure we are changing // rows. Else it is possible we are still traversing the same row so we must perform the row // comparison. - if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.curCell == null - || !CellUtil.matchingRow(cell, matcher.curCell)) { + if (!scannerContext.hasAnyLimit(LimitScope.BETWEEN_CELLS) || matcher.curCell == null) { this.countPerRow = 0; matcher.setToNewRow(cell); } @@ -534,7 +533,6 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner if (prevCell != cell) ++kvsScanned; // Do object compare - we set prevKV from the same heap. checkScanOrder(prevCell, cell, comparator); prevCell = cell; - ScanQueryMatcher.MatchCode qcode = matcher.match(cell); qcode = optimize(qcode, cell); switch (qcode) { @@ -553,6 +551,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner if (!matcher.moreRowsMayExistAfter(cell)) { return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues(); } + matcher.curCell = null; seekToNextRow(cell); break LOOP; } @@ -580,6 +579,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner if (!matcher.moreRowsMayExistAfter(cell)) { return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues(); } + matcher.curCell = null; seekToNextRow(cell); } else if (qcode == ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL) { seekAsDirection(matcher.getKeyForNextColumn(cell)); @@ -596,6 +596,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner continue; case DONE: + matcher.curCell = null; return scannerContext.setScannerState(NextState.MORE_VALUES).hasMoreValues(); case DONE_SCAN: @@ -608,7 +609,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner if (!matcher.moreRowsMayExistAfter(cell)) { return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues(); } - + matcher.curCell = null; seekToNextRow(cell); break; @@ -751,7 +752,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner } if ((matcher.curCell == null) || !CellUtil.matchingRows(cell, matcher.curCell)) { this.countPerRow = 0; - matcher.reset(); + // The setToNewRow will call reset internally matcher.setToNewRow(cell); } }