You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2024/05/18 14:45:44 UTC
(hbase) branch branch-3 updated: HBASE-28595: check seq id of scan RPCs for closed scanners (#5910)
This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-3 by this push:
new 7efc19b3f75 HBASE-28595: check seq id of scan RPCs for closed scanners (#5910)
7efc19b3f75 is described below
commit 7efc19b3f750baebed7c54ab09a2c935f72a92a6
Author: csringhofer <cs...@cloudera.com>
AuthorDate: Fri May 17 20:55:53 2024 +0200
HBASE-28595: check seq id of scan RPCs for closed scanners (#5910)
Signed-off-by: Duo Zhang <zh...@apache.org>
Signed-off-by: Tak Lon (Stephen) Wu <ta...@apache.org>
(cherry picked from commit a3ff01d890b6d220f9056e508aeb1956d2768ff3)
---
.../hadoop/hbase/regionserver/RSRpcServices.java | 33 +++++++++++++++-------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
index babaa56170a..66c97fb9401 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
@@ -303,10 +303,11 @@ public class RSRpcServices extends HBaseRpcServicesBase<HRegionServer>
private ScannerIdGenerator scannerIdGenerator;
private final ConcurrentMap<String, RegionScannerHolder> scanners = new ConcurrentHashMap<>();
- // Hold the name of a closed scanner for a while. This is used to keep compatible for old clients
- // which may send next or close request to a region scanner which has already been exhausted. The
- // entries will be removed automatically after scannerLeaseTimeoutPeriod.
- private final Cache<String, String> closedScanners;
+ // Hold the name and last sequence number of a closed scanner for a while. This is used
+ // to keep compatible for old clients which may send next or close request to a region
+ // scanner which has already been exhausted. The entries will be removed automatically
+ // after scannerLeaseTimeoutPeriod.
+ private final Cache<String, Long> closedScanners;
/**
* The lease timeout period for client scanners (milliseconds).
*/
@@ -3083,8 +3084,18 @@ public class RSRpcServices extends HBaseRpcServicesBase<HRegionServer>
RegionScannerHolder rsh = this.scanners.get(scannerName);
if (rsh == null) {
// just ignore the next or close request if scanner does not exists.
- if (closedScanners.getIfPresent(scannerName) != null) {
- throw SCANNER_ALREADY_CLOSED;
+ Long lastCallSeq = closedScanners.getIfPresent(scannerName);
+ if (lastCallSeq != null) {
+ // Check the sequence number to catch if the last call was incorrectly retried.
+ // The only allowed scenario is when the scanner is exhausted and one more scan
+ // request arrives - in this case returning 0 rows is correct.
+ if (request.hasNextCallSeq() && request.getNextCallSeq() != lastCallSeq + 1) {
+ throw new OutOfOrderScannerNextException("Expected nextCallSeq for closed request: "
+ + (lastCallSeq + 1) + " But the nextCallSeq got from client: "
+ + request.getNextCallSeq() + "; request=" + TextFormat.shortDebugString(request));
+ } else {
+ throw SCANNER_ALREADY_CLOSED;
+ }
} else {
LOG.warn("Client tried to access missing scanner " + scannerName);
throw new UnknownScannerException(
@@ -3690,7 +3701,7 @@ public class RSRpcServices extends HBaseRpcServicesBase<HRegionServer>
}
if (!builder.getMoreResults() || !builder.getMoreResultsInRegion() || closeScanner) {
scannerClosed = true;
- closeScanner(region, scanner, scannerName, rpcCall);
+ closeScanner(region, scanner, scannerName, rpcCall, false);
}
// There's no point returning to a timed out client. Throwing ensures scanner is closed
@@ -3706,7 +3717,7 @@ public class RSRpcServices extends HBaseRpcServicesBase<HRegionServer>
// The scanner state might be left in a dirty state, so we will tell the Client to
// fail this RPC and close the scanner while opening up another one from the start of
// row that the client has last seen.
- closeScanner(region, scanner, scannerName, rpcCall);
+ closeScanner(region, scanner, scannerName, rpcCall, true);
// If it is a DoNotRetryIOException already, throw as it is. Unfortunately, DNRIOE is
// used in two different semantics.
@@ -3770,7 +3781,7 @@ public class RSRpcServices extends HBaseRpcServicesBase<HRegionServer>
}
private void closeScanner(HRegion region, RegionScanner scanner, String scannerName,
- RpcCallContext context) throws IOException {
+ RpcCallContext context, boolean isError) throws IOException {
if (region.getCoprocessorHost() != null) {
if (region.getCoprocessorHost().preScannerClose(scanner)) {
// bypass the actual close.
@@ -3787,7 +3798,9 @@ public class RSRpcServices extends HBaseRpcServicesBase<HRegionServer>
if (region.getCoprocessorHost() != null) {
region.getCoprocessorHost().postScannerClose(scanner);
}
- closedScanners.put(scannerName, scannerName);
+ if (!isError) {
+ closedScanners.put(scannerName, rsh.getNextCallSeq());
+ }
}
}