Index: src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (revision e0fd38fd850cd61dc528125b2c69b4f427e21cb4) +++ src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (revision ) @@ -862,6 +862,22 @@ public int createMultiRegionsWithLegacyHRI(final Configuration c, final HTableDescriptor htd, + final byte [] family, int numRegions) + throws IOException { + if (numRegions < 3) throw new IOException("Must create at least 3 regions"); + byte [] startKey = Bytes.toBytes("aaaaa"); + byte [] endKey = Bytes.toBytes("zzzzz"); + byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3); + byte [][] regionStartKeys = new byte[splitKeys.length+1][]; + for (int i=0;i htds = MetaEditor.updateMetaWithNewRegionInfo( TEST_UTIL.getHBaseCluster().getMaster()); + MetaReader.fullScanMetaAndPrint(ct); assertEquals(3, htds.size()); // Assert that the flag in ROOT is updated to reflect the correct status boolean metaUpdated = miniHBaseCluster.getMaster().isMetaHRIUpdated(); @@ -111,27 +112,46 @@ } - //@Test - public void dtestUpdatesOnMetaWithNewHRI() throws Exception { - LOG.info("Starting testMetaWithLegacyHRI"); + /** + * This test assumes a master crash/failure during the meta migration process + * and attempts to continue the meta migration process when a new master takes over. + * When a master dies during the meta migration we will have some rows of + * META.CatalogFamily updated with new HRI, (i.e HRI with out HTD) and some + * still hanging with legacy HRI. (i.e HRI with HTD). When the backup master/ or + * fresh start of master attempts the migration it will encouter some rows of META + * already updated with new HRI and some still legacy. This test will simulate this + * scenario and validates that the migration process can safely skip the updated + * rows and migrate any pending rows at startup. + * @throws Exception + */ + @Test + public void testMasterCrashDuringMetaMigration() throws Exception { + LOG.info("Starting testMasterCrashDuringMetaMigration"); final byte[] FAMILY = Bytes.toBytes("family"); - HTableDescriptor htd = new HTableDescriptor("testMetaMigration"); + HTableDescriptor htd = new HTableDescriptor("testMasterCrashDuringMetaMigration"); HColumnDescriptor hcd = new HColumnDescriptor(FAMILY); htd.addFamily(hcd); Configuration conf = TEST_UTIL.getConfiguration(); - TEST_UTIL.createMultiRegionsWithNewHRI(conf, htd, FAMILY, - new byte[][]{ - HConstants.EMPTY_START_ROW, - Bytes.toBytes("region_a"), - Bytes.toBytes("region_b")}); + // Create 10 New regions. + TEST_UTIL.createMultiRegionsWithNewHRI(conf, htd, FAMILY, 10); + // Create 10 Legacy regions. + TEST_UTIL.createMultiRegionsWithLegacyHRI(conf, htd, FAMILY, 10); + CatalogTracker ct = miniHBaseCluster.getMaster().getCatalogTracker(); + // just for this test set it to false. + MetaEditor.updateRootWithMetaMigrationStatus(ct, false); + //MetaReader.fullScanMetaAndPrint(ct); + LOG.info("MEta Print completed.testUpdatesOnMetaWithLegacyHRI"); + List htds = MetaEditor.updateMetaWithNewRegionInfo( TEST_UTIL.getHBaseCluster().getMaster()); - assertEquals(3, htds.size()); + assertEquals(10, htds.size()); + // Assert that the flag in ROOT is updated to reflect the correct status + boolean metaUpdated = miniHBaseCluster.getMaster().isMetaHRIUpdated(); + assertEquals(true, metaUpdated); + LOG.info("END testMetaWithLegacyHRI"); + } - - - public static void assertEquals(int expected, int actual) { if (expected != actual) {