From 5c7c425e34a8306f70354f4910a2e686230320f4 Mon Sep 17 00:00:00 2001 From: Lars Hofhansl Date: Thu, 13 Dec 2018 11:56:39 -0800 Subject: [PATCH] HBASE-21590 Optimize trySkipToNextColumn in StoreScanner a bit. (cherry picked from commit 11193d7cc1f5a0a7ffb73777da7ce5c1b6af6c8c) --- .../hadoop/hbase/regionserver/StoreScanner.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 be226fed047..bc457df6eac 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 @@ -808,12 +808,16 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner @VisibleForTesting protected boolean trySkipToNextRow(Cell cell) throws IOException { Cell nextCell = null; + // used to guard against a changed next indexed key by doing a identity comparison + // when the identity changes we need to compare the bytes again + Cell previousIndexedKey = null; do { Cell nextIndexedKey = getNextIndexedKey(); if (nextIndexedKey != null && nextIndexedKey != KeyValueScanner.NO_NEXT_INDEXED_KEY - && matcher.compareKeyForNextRow(nextIndexedKey, cell) >= 0) { + && (nextIndexedKey == previousIndexedKey || matcher.compareKeyForNextRow(nextIndexedKey, cell) >= 0)) { this.heap.next(); ++kvsScanned; + previousIndexedKey = nextIndexedKey; } else { return false; } @@ -829,12 +833,16 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner @VisibleForTesting protected boolean trySkipToNextColumn(Cell cell) throws IOException { Cell nextCell = null; + // used to guard against a changed next indexed key by doing a identity comparison + // when the identity changes we need to compare the bytes again + Cell previousIndexedKey = null; do { Cell nextIndexedKey = getNextIndexedKey(); if (nextIndexedKey != null && nextIndexedKey != KeyValueScanner.NO_NEXT_INDEXED_KEY - && matcher.compareKeyForNextColumn(nextIndexedKey, cell) >= 0) { + && (nextIndexedKey == previousIndexedKey || matcher.compareKeyForNextColumn(nextIndexedKey, cell) >= 0)) { this.heap.next(); ++kvsScanned; + previousIndexedKey = nextIndexedKey; } else { return false; }