[GitHub] [hbase] virajjasani commented on a change in pull request #2574: HBASE-25212 Optionally abort requests in progress after deciding a region should close

2020-10-29 Thread GitBox


virajjasani commented on a change in pull request #2574:
URL: https://github.com/apache/hbase/pull/2574#discussion_r514160584



##
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
##
@@ -9000,6 +9173,51 @@ public long getReadPoint() {
 return getReadPoint(IsolationLevel.READ_COMMITTED);
   }
 
+  /**
+   * Interrupt any region options that have acquired the region lock via
+   * {@link 
#startRegionOperation(org.apache.hadoop.hbase.regionserver.Region.Operation)},
+   * or {@link #startBulkRegionOperation(boolean)}.
+   */
+  private void interruptRegionOperations() {
+for (Map.Entry entry: regionLockHolders.entrySet()) {
+  // An entry in this map will have a boolean value indicating if it is 
currently
+  // eligible for interrupt; if so, we should interrupt it.
+  if (entry.getValue().booleanValue()) {

Review comment:
   nit: `entry.getValue()` is enough





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] virajjasani commented on a change in pull request #2574: HBASE-25212 Optionally abort requests in progress after deciding a region should close

2020-10-26 Thread GitBox


virajjasani commented on a change in pull request #2574:
URL: https://github.com/apache/hbase/pull/2574#discussion_r512174196



##
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);

Review comment:
   Oh yes, nvm, current approach is better.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [hbase] virajjasani commented on a change in pull request #2574: HBASE-25212 Optionally abort requests in progress after deciding a region should close

2020-10-26 Thread GitBox


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");
+