From 58ec4f8e6853064f547a01ce6f75c22b414df53f Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 1 Apr 2013 16:32:02 +0000 Subject: [PATCH] HBASE-8164 TestTableLockManager fails intermittently in trunk builds git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1463194 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/HBaseTestingUtility.java | 23 +++++++++++-------- .../hbase/master/TestTableLockManager.java | 14 +++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 23048d2c8b6..5b767fef271 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -1943,15 +1943,20 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { attempted.clear(); } regCount = regions.size(); - idx = random.nextInt(regions.size()); - // if we have just tried this region, there is no need to try again - if (attempted.contains(idx)) continue; - try { - regions.get(idx).checkSplit(); - return regions.get(idx); - } catch (Exception ex) { - LOG.warn("Caught exception", ex); - attempted.add(idx); + // There are chances that before we get the region for the table from an RS the region may + // be going for CLOSE. This may be because online schema change is enabled + if (regCount > 0) { + idx = random.nextInt(regCount); + // if we have just tried this region, there is no need to try again + if (attempted.contains(idx)) + continue; + try { + regions.get(idx).checkSplit(); + return regions.get(idx); + } catch (Exception ex) { + LOG.warn("Caught exception", ex); + attempted.add(idx); + } } attempts++; } while (maxAttempts == -1 || attempts < maxAttempts); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java index c0533de51f3..bc477532b00 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java @@ -355,10 +355,16 @@ public class TestTableLockManager { public void chore() { try { HRegion region = TEST_UTIL.getSplittableRegion(tableName, -1); - byte[] regionName = region.getRegionName(); - admin.flush(regionName); - admin.compact(regionName); - admin.split(regionName); + if (region != null) { + byte[] regionName = region.getRegionName(); + admin.flush(regionName); + admin.compact(regionName); + admin.split(regionName); + } else { + LOG.warn("Could not find suitable region for the table. Possibly the " + + "region got closed and the attempts got over before " + + "the region could have got reassigned."); + } } catch (NotServingRegionException nsre) { // the region may be in transition LOG.warn("Caught exception", nsre);