This is an automated email from the ASF dual-hosted git repository.
stack pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1 by this push:
new fdf01ca HBASE-22230 REST Server drops connection on long scan
fdf01ca is described below
commit fdf01ca7f8de28fe2da2dd663a5249c23bec5fbe
Author: Pankaj <[email protected]>
AuthorDate: Sun Apr 21 01:13:36 2019 +0530
HBASE-22230 REST Server drops connection on long scan
Signed-off-by: stack <[email protected]>
---
.../org/apache/hadoop/hbase/rest/RESTServlet.java | 11 +++-
.../hadoop/hbase/rest/ScannerInstanceResource.java | 3 ++
.../hadoop/hbase/rest/client/TestRemoteTable.java | 60 +++++++++++++++++++++-
3 files changed, 70 insertions(+), 4 deletions(-)
diff --git
a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java
b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java
index 411ced8..518849f 100644
--- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java
+++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java
@@ -46,8 +46,8 @@ public class RESTServlet implements Constants {
private final UserGroupInformation realUser;
private final JvmPauseMonitor pauseMonitor;
- static final String CLEANUP_INTERVAL =
"hbase.rest.connection.cleanup-interval";
- static final String MAX_IDLETIME = "hbase.rest.connection.max-idletime";
+ public static final String CLEANUP_INTERVAL =
"hbase.rest.connection.cleanup-interval";
+ public static final String MAX_IDLETIME =
"hbase.rest.connection.max-idletime";
static final String HBASE_REST_SUPPORT_PROXYUSER =
"hbase.rest.support.proxyuser";
UserGroupInformation getRealUser() {
@@ -63,6 +63,13 @@ public class RESTServlet implements Constants {
}
/**
+ * @return the ConnectionCache instance
+ */
+ public ConnectionCache getConnectionCache() {
+ return connectionCache;
+ }
+
+ /**
* @param conf Existing configuration to use in rest servlet
* @param userProvider the login user provider
* @return the RESTServlet singleton instance
diff --git
a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java
b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java
index 49a2ef1..88827cd 100644
---
a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java
+++
b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerInstanceResource.java
@@ -83,6 +83,9 @@ public class ScannerInstanceResource extends ResourceBase {
return Response.status(Response.Status.NOT_FOUND)
.type(MIMETYPE_TEXT).entity("Not found" + CRLF)
.build();
+ } else {
+ // Updated the connection access time for each client next() call
+
RESTServlet.getInstance().getConnectionCache().updateConnectionAccessTime();
}
CellSetModel model = new CellSetModel();
RowModel rowModel = null;
diff --git
a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java
b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java
index 28f3798..9613e9f 100644
---
a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java
+++
b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java
@@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility;
+import org.apache.hadoop.hbase.rest.RESTServlet;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.AfterClass;
@@ -570,6 +571,61 @@ public class TestRemoteTable {
response.setBody(Bytes.toBytes("body"));
assertTrue(response.hasBody());
}
-
-}
+ /**
+ * Tests keeping a HBase scanner alive for long periods of time. Each call
to next() should reset
+ * the ConnectionCache timeout for the scanner's connection
+ * @throws Exception
+ */
+ @Test
+ public void testLongLivedScan() throws Exception {
+ int numTrials = 6;
+ int trialPause = 1000;
+ int cleanUpInterval = 100;
+
+ // Shutdown the Rest Servlet container
+ REST_TEST_UTIL.shutdownServletContainer();
+
+ // Set the ConnectionCache timeout to trigger halfway through the trials
+ TEST_UTIL.getConfiguration().setLong(RESTServlet.MAX_IDLETIME, (numTrials
/ 2) * trialPause);
+ TEST_UTIL.getConfiguration().setLong(RESTServlet.CLEANUP_INTERVAL,
cleanUpInterval);
+
+ // Start the Rest Servlet container
+ REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
+
+ // Truncate the test table for inserting test scenarios rows keys
+ TEST_UTIL.getHBaseAdmin().disableTable(TABLE);
+ TEST_UTIL.getHBaseAdmin().truncateTable(TABLE, false);
+
+ remoteTable = new RemoteHTable(
+ new Client(new Cluster().add("localhost",
REST_TEST_UTIL.getServletPort())),
+ TEST_UTIL.getConfiguration(), TABLE.toBytes());
+
+ String row = "testrow";
+
+ try (Table table = TEST_UTIL.getConnection().getTable(TABLE)) {
+ List<Put> puts = new ArrayList<Put>();
+ Put put = null;
+ for (int i = 1; i <= numTrials; i++) {
+ put = new Put(Bytes.toBytes(row + i));
+ put.addColumn(COLUMN_1, QUALIFIER_1, TS_2, Bytes.toBytes("testvalue" +
i));
+ puts.add(put);
+ }
+ table.put(puts);
+ }
+
+ Scan scan = new Scan();
+ scan.setCaching(1);
+ scan.setBatch(1);
+
+ ResultScanner scanner = remoteTable.getScanner(scan);
+ Result result = null;
+ // get scanner and rows
+ for (int i = 1; i <= numTrials; i++) {
+ // Make sure that the Scanner doesn't throw an exception after the
ConnectionCache timeout
+ result = scanner.next();
+ assertEquals(row + i, Bytes.toString(result.getRow()));
+ Thread.sleep(trialPause);
+ }
+ }
+}