HBASE-26688 Threads shared EMPTY_RESULT may lead to unexpected client job down (#4073)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Yutong Xiao 2022-02-15 20:28:00 +08:00 committed by Duo Zhang
parent a69e41d850
commit 3f315d7e93
2 changed files with 9 additions and 9 deletions

View File

@ -913,7 +913,7 @@ public class Result implements CellScannable, CellScanner {
@Override
public Cell current() {
if (cells == null
if (isEmpty()
|| cellScannerIndex == INITIAL_CELLSCANNER_INDEX
|| cellScannerIndex >= cells.length)
return null;
@ -922,7 +922,9 @@ public class Result implements CellScannable, CellScanner {
@Override
public boolean advance() {
if (cells == null) return false;
if (isEmpty()) {
return false;
}
cellScannerIndex++;
if (cellScannerIndex < this.cells.length) {
return true;

View File

@ -125,14 +125,12 @@ public class TestResult extends TestCase {
assertNull(r.current());
}
public void testAdvanceTwiceOnEmptyCell() throws IOException {
public void testAdvanceMultipleOnEmptyCell() throws IOException {
Result r = Result.create(new Cell[0]);
// After HBASE-26688, advance of result with empty cell list will always return false.
// Here 10 is an arbitrary number to test the logic.
for (int i = 0; i < 10; i++) {
assertFalse(r.advance());
try {
r.advance();
fail("NoSuchElementException should have been thrown!");
} catch (NoSuchElementException ex) {
LOG.debug("As expected: " + ex.getMessage());
}
}