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 aa5db64..7cad55a 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 @@ -40,6 +40,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.NavigableMap; import java.util.NavigableSet; import java.util.Random; import java.util.Set; @@ -1071,6 +1072,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc, startKey, endKey, numRegions); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(getConfiguration(), tableName); } @@ -1095,6 +1098,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(c, tableName); } @@ -1117,6 +1122,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(c, tableName); } @@ -1150,6 +1157,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(new Configuration(getConfiguration()), tableName); } @@ -1171,6 +1180,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(new Configuration(getConfiguration()), tableName); } @@ -1194,6 +1205,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { i++; } getHBaseAdmin().createTable(desc); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(new Configuration(getConfiguration()), tableName); } @@ -1211,6 +1224,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { HColumnDescriptor hcd = new HColumnDescriptor(family); desc.addFamily(hcd); getHBaseAdmin().createTable(desc, splitRows); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(getConfiguration(), tableName); } @@ -1230,6 +1245,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { desc.addFamily(hcd); } getHBaseAdmin().createTable(desc, splitRows); + // HBaseAdmin only waits for regions to appear in META we should wait until they are assigned + waitUntilAllRegionsAssigned(tableName); return new HTable(getConfiguration(), tableName); } @@ -2116,7 +2133,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { /** * Waits for a table to be 'enabled'. Enabled means that table is set as 'enabled' and the - * regions have been all assigned. + * regions have been all assigned and they are fully open out on the regionservers. * @see #waitTableAvailable(byte[]) * @param table Table to wait on. * @param timeoutMillis Time to wait on it being marked enabled. @@ -2134,6 +2151,20 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { System.currentTimeMillis() - remainder < timeoutMillis); Thread.sleep(200); } + // Finally make sure all regions are fully open and online out on the cluster. Regions may be + // in the .META. table and almost open on all regionservers but there setting the region + // online in the regionserver is the very last thing done and can take a little while to happen. + // Below we do a get. The get will retry if a NotServeringRegionException or a + // RegionOpeningException. It is crass but when done all will be online. + HTable t = new HTable(getConfiguration(), table); + try { + NavigableMap locations = t.getRegionLocations(); + for (Map.Entry e: locations.entrySet()) { + t.get(new Get(e.getKey().getStartKey())); + } + } finally { + t.close(); + } } /**