Search in sources :

Example 1 with SplitTableRegionProcedure

use of org.apache.hadoop.hbase.master.procedure.SplitTableRegionProcedure in project hbase by apache.

the class TestHBaseFsckOneRS method testCleanUpDaughtersNotInMetaAfterFailedSplit.

@Test(timeout = 180000)
public void testCleanUpDaughtersNotInMetaAfterFailedSplit() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    try {
        HTableDescriptor desc = new HTableDescriptor(tableName);
        desc.addFamily(new HColumnDescriptor(Bytes.toBytes("f")));
        createTable(TEST_UTIL, desc, null);
        tbl = connection.getTable(desc.getTableName());
        for (int i = 0; i < 5; i++) {
            Put p1 = new Put(("r" + i).getBytes());
            p1.addColumn(Bytes.toBytes("f"), "q1".getBytes(), "v".getBytes());
            tbl.put(p1);
        }
        admin.flush(desc.getTableName());
        List<HRegion> regions = cluster.getRegions(desc.getTableName());
        int serverWith = cluster.getServerWith(regions.get(0).getRegionInfo().getRegionName());
        HRegionServer regionServer = cluster.getRegionServer(serverWith);
        byte[] parentRegionName = regions.get(0).getRegionInfo().getRegionName();
        cluster.getServerWith(parentRegionName);
        // Create daughters without adding to META table
        MasterProcedureEnv env = cluster.getMaster().getMasterProcedureExecutor().getEnvironment();
        SplitTableRegionProcedure splitR = new SplitTableRegionProcedure(env, regions.get(0).getRegionInfo(), Bytes.toBytes("r3"));
        splitR.prepareSplitRegion(env);
        splitR.setRegionStateToSplitting(env);
        splitR.closeParentRegionForSplit(env);
        splitR.createDaughterRegions(env);
        AssignmentManager am = cluster.getMaster().getAssignmentManager();
        for (RegionState state : am.getRegionStates().getRegionsInTransition()) {
            am.regionOffline(state.getRegion());
        }
        Map<HRegionInfo, ServerName> regionsMap = new HashMap<>();
        regionsMap.put(regions.get(0).getRegionInfo(), regionServer.getServerName());
        am.assign(regionsMap);
        am.waitForAssignment(regions.get(0).getRegionInfo());
        HBaseFsck hbck = doFsck(conf, false);
        assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED });
        // holes are separate from overlap groups
        assertEquals(0, hbck.getOverlapGroups(tableName).size());
        // fix hole
        assertErrors(doFsck(conf, false, true, false, false, false, false, false, false, false, false, false, false, null), new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED });
        // check that hole fixed
        assertNoErrors(doFsck(conf, false));
        assertEquals(5, countRows());
    } finally {
        if (tbl != null) {
            tbl.close();
            tbl = null;
        }
        cleanupTable(tableName);
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HashMap(java.util.HashMap) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) SplitTableRegionProcedure(org.apache.hadoop.hbase.master.procedure.SplitTableRegionProcedure) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionState(org.apache.hadoop.hbase.master.RegionState) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)1 ServerName (org.apache.hadoop.hbase.ServerName)1 TableName (org.apache.hadoop.hbase.TableName)1 Put (org.apache.hadoop.hbase.client.Put)1 AssignmentManager (org.apache.hadoop.hbase.master.AssignmentManager)1 RegionState (org.apache.hadoop.hbase.master.RegionState)1 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)1 SplitTableRegionProcedure (org.apache.hadoop.hbase.master.procedure.SplitTableRegionProcedure)1 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)1 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)1 Test (org.junit.Test)1