This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch branch-2.6 in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.6 by this push: new 10c612d3876 HBASE-28540 Cache Results in org.apache.hadoop.hbase.rest.client.RemoteHTable.Scanner (#5846) 10c612d3876 is described below commit 10c612d3876ff9b063342b0c144efad602f198c7 Author: Istvan Toth <st...@apache.org> AuthorDate: Fri Jun 7 08:33:29 2024 +0200 HBASE-28540 Cache Results in org.apache.hadoop.hbase.rest.client.RemoteHTable.Scanner (#5846) Signed-off-by: Duo Zhang <zhang...@apache.org> (cherry picked from commit 092ce0dca0b64155f38871cc734244e5022b45e9) --- .../hadoop/hbase/rest/client/RemoteHTable.java | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java index 714b4da2661..15f9fddd8fb 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java @@ -26,6 +26,7 @@ import java.io.InterruptedIOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -512,6 +513,8 @@ public class RemoteHTable implements Table { class Scanner implements ResultScanner { String uri; + private Result[] cachedResults; + private int nextCachedResultsRow = 0; public Scanner(Scan scan) throws IOException { ScannerModel model; @@ -547,11 +550,8 @@ public class RemoteHTable implements Table { throw new IOException("scan request timed out"); } - @Override - public Result[] next(int nbRows) throws IOException { + public Result[] nextBatch() throws IOException { StringBuilder sb = new StringBuilder(uri); - sb.append("?n="); - sb.append(nbRows); for (int i = 0; i < maxRetries; i++) { Response response = client.get(sb.toString(), Constants.MIMETYPE_PROTOBUF); int code = response.getCode(); @@ -577,13 +577,31 @@ public class RemoteHTable implements Table { throw new IOException("scanner.next request timed out"); } + private boolean updateCachedResults() throws IOException { + if (cachedResults == null || nextCachedResultsRow >= cachedResults.length) { + nextCachedResultsRow = 0; + cachedResults = nextBatch(); + } + return !(cachedResults == null || cachedResults.length < 1); + } + + @Override + public Result[] next(int nbRows) throws IOException { + if (!updateCachedResults()) { + return null; + } + int endIndex = Math.min(cachedResults.length, nextCachedResultsRow + nbRows); + Result[] chunk = Arrays.copyOfRange(cachedResults, nextCachedResultsRow, endIndex); + nextCachedResultsRow = endIndex; + return chunk; + } + @Override public Result next() throws IOException { - Result[] results = next(1); - if (results == null || results.length < 1) { + if (!updateCachedResults()) { return null; } - return results[0]; + return cachedResults[nextCachedResultsRow++]; } class Iter implements Iterator<Result> {