Skip to content

Commit 75faaa7

Browse files
HBASE-29253: Avoid allocating a new closure on every row processed by StoreScanner
1 parent 8c97c51 commit 75faaa7

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Optional;
2626
import java.util.concurrent.CountDownLatch;
2727
import java.util.concurrent.locks.ReentrantLock;
28+
import java.util.function.IntConsumer;
2829
import org.apache.hadoop.hbase.Cell;
2930
import org.apache.hadoop.hbase.CellComparator;
3031
import org.apache.hadoop.hbase.CellUtil;
@@ -588,6 +589,13 @@ public boolean next(List<? super ExtendedCell> outResult, ScannerContext scanner
588589

589590
Optional<RpcCall> rpcCall =
590591
matcher.isUserScan() ? RpcServer.getCurrentCall() : Optional.empty();
592+
// re-useable closure to avoid allocations
593+
IntConsumer recordBlockSize = blockSize -> {
594+
if (rpcCall.isPresent()) {
595+
rpcCall.get().incrementBlockBytesScanned(blockSize);
596+
}
597+
scannerContext.incrementBlockProgress(blockSize);
598+
};
591599

592600
int count = 0;
593601
long totalBytesRead = 0;
@@ -629,12 +637,7 @@ public boolean next(List<? super ExtendedCell> outResult, ScannerContext scanner
629637
scannerContext.returnImmediately();
630638
}
631639

632-
heap.recordBlockSize(blockSize -> {
633-
if (rpcCall.isPresent()) {
634-
rpcCall.get().incrementBlockBytesScanned(blockSize);
635-
}
636-
scannerContext.incrementBlockProgress(blockSize);
637-
});
640+
heap.recordBlockSize(recordBlockSize);
638641

639642
prevCell = cell;
640643
scannerContext.setLastPeekedCell(cell);

0 commit comments

Comments
 (0)