virajjasani commented on a change in pull request #2574:
URL: https://github.com/apache/hbase/pull/2574#discussion_r512006608
##
File path:
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
##
@@ -7364,4 +7366,157 @@ protected HStoreForTesting(final HRegion region,
return super.doCompaction(cr, filesToCompact, user, compactionStartTime,
newFiles);
}
}
+
+ @Test
+ public void testCloseNoInterrupt() throws Exception {
+byte[] cf1 = Bytes.toBytes("CF1");
+byte[][] families = { cf1 };
+
+Configuration conf = new Configuration(CONF);
+// Disable close thread interrupt and server abort behavior
+conf.setBoolean(HRegion.CLOSE_WAIT_ABORT, false);
+region = initHRegion(tableName, method, conf, families);
+
+final CountDownLatch latch = new CountDownLatch(1);
+final AtomicBoolean holderInterrupted = new AtomicBoolean();
+Thread holder = new Thread(new Runnable() {
+ @Override
+ public void run() {
+try {
+ LOG.info("Starting region operation holder");
+ region.startRegionOperation(Operation.SCAN);
+ latch.countDown();
+ try {
+Thread.sleep(10*1000);
+ } catch (InterruptedException e) {
+LOG.info("Interrupted");
+holderInterrupted.set(true);
+ }
+} catch (Exception e) {
+ throw new RuntimeException(e);
+} finally {
+ try {
+region.closeRegionOperation();
+ } catch (IOException e) {
+ }
+ LOG.info("Stopped region operation holder");
+}
+ }
+});
+
+holder.start();
+latch.await();
+region.close();
+holder.join();
+region = null;
+
+assertFalse("Region lock holder should not have been interrupted",
holderInterrupted.get());
+ }
+
+ @Test
+ public void testCloseInterrupt() throws Exception {
+byte[] cf1 = Bytes.toBytes("CF1");
+byte[][] families = { cf1 };
+
+Configuration conf = new Configuration(CONF);
+// Enable close thread interrupt and server abort behavior
+conf.setBoolean(HRegion.CLOSE_WAIT_ABORT, true);
+region = initHRegion(tableName, method, conf, families);
+
+final CountDownLatch latch = new CountDownLatch(1);
+final AtomicBoolean holderInterrupted = new AtomicBoolean();
+Thread holder = new Thread(new Runnable() {
+ @Override
+ public void run() {
+try {
+ LOG.info("Starting region operation holder");
+ region.startRegionOperation(Operation.SCAN);
+ latch.countDown();
+ try {
+Thread.sleep(10*1000);
+ } catch (InterruptedException e) {
+LOG.info("Interrupted");
+holderInterrupted.set(true);
+ }
+} catch (Exception e) {
+ throw new RuntimeException(e);
+} finally {
+ try {
+region.closeRegionOperation();
+ } catch (IOException e) {
+ }
+ LOG.info("Stopped region operation holder");
+}
+ }
+});
+
+holder.start();
+latch.await();
+region.close();
+holder.join();
+region = null;
+
+assertTrue("Region lock holder was not interrupted",
holderInterrupted.get());
+ }
+
+ @Test
+ public void testCloseAbort() throws Exception {
+byte[] cf1 = Bytes.toBytes("CF1");
+byte[][] families = { cf1 };
+
+Configuration conf = new Configuration(CONF);
+// Enable close thread interrupt and server abort behavior
+// Set the close lock acquisition wait time to 5 seconds
+conf.setBoolean(HRegion.CLOSE_WAIT_ABORT, true);
+conf.setInt(HRegion.CLOSE_WAIT_TIME, 5*1000);
+region = initHRegion(tableName, method, conf, families);
+RegionServerServices rsServices = mock(RegionServerServices.class);
+region.rsServices = rsServices;
+
+final CountDownLatch latch = new CountDownLatch(1);
+Thread holder = new Thread(new Runnable() {
+ @Override
+ public void run() {
+try {
+ LOG.info("Starting region operation holder");
+ region.startRegionOperation(Operation.SCAN);
+ latch.countDown();
+ // Hold the lock for 10 seconds no matter how many times we are
interrupted
+ int timeRemaining = 10 * 1000;
+ while (timeRemaining > 0) {
+long start = EnvironmentEdgeManager.currentTime();
Review comment:
nit: if the only usage is to find diff b/ `end` and `start`, directly
using `System.currentTimeMillis()` might be preferred option?
##
File path:
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
##
@@ -7364,4 +7366,157 @@ protected HStoreForTesting(final HRegion region,
return super.doCompaction(cr, filesToCompact, user, compactionStartTime,
newFiles);
}
}
+
+ @Test
+ public void testCloseNoInterrupt() throws Exception {
+byte[] cf1 = Bytes.toBytes("CF1");
+