Search in sources :

Example 66 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestServerCrashProcedure method testRecoveryAndDoubleExecutionOnline.

/**
   * Run server crash procedure steps twice to test idempotency and that we are persisting all
   * needed state.
   * @throws Exception
   */
@Test(timeout = 300000)
public void testRecoveryAndDoubleExecutionOnline() throws Exception {
    final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecutionOnline");
    this.util.createTable(tableName, HBaseTestingUtility.COLUMNS, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
    try (Table t = this.util.getConnection().getTable(tableName)) {
        // Load the table with a bit of data so some logs to split and some edits in each region.
        this.util.loadTable(t, HBaseTestingUtility.COLUMNS[0]);
        int count = util.countRows(t);
        // Run the procedure executor outside the master so we can mess with it. Need to disable
        // Master's running of the server crash processing.
        HMaster master = this.util.getHBaseCluster().getMaster();
        final ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
        master.setServerCrashProcessingEnabled(false);
        // Kill a server. Master will notice but do nothing other than add it to list of dead servers.
        HRegionServer hrs = this.util.getHBaseCluster().getRegionServer(0);
        boolean carryingMeta = master.getAssignmentManager().isCarryingMeta(hrs.getServerName());
        this.util.getHBaseCluster().killRegionServer(hrs.getServerName());
        hrs.join();
        // here so ServerManager gets notice and adds expired server to appropriate queues.
        while (!master.getServerManager().isServerDead(hrs.getServerName())) Threads.sleep(10);
        // Now, reenable processing else we can't get a lock on the ServerCrashProcedure.
        master.setServerCrashProcessingEnabled(true);
        // Do some of the master processing of dead servers so when SCP runs, it has expected 'state'.
        master.getServerManager().moveFromOnlineToDeadServers(hrs.getServerName());
        // Enable test flags and then queue the crash procedure.
        ProcedureTestingUtility.waitNoProcedureRunning(procExec);
        ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
        long procId = procExec.submitProcedure(new ServerCrashProcedure(procExec.getEnvironment(), hrs.getServerName(), true, carryingMeta));
        // Now run through the procedure twice crashing the executor on each step...
        MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
        // Assert all data came back.
        assertEquals(count, util.countRows(t));
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) HMaster(org.apache.hadoop.hbase.master.HMaster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 67 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestMasterProcedureEvents method testServerCrashProcedureEvent.

@Test(timeout = 30000)
public void testServerCrashProcedureEvent() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
    while (!master.isServerCrashProcessingEnabled() || !master.isInitialized() || master.getAssignmentManager().getRegionStates().isRegionsInTransition()) {
        Thread.sleep(25);
    }
    UTIL.createTable(tableName, HBaseTestingUtility.COLUMNS[0]);
    try (Table t = UTIL.getConnection().getTable(tableName)) {
        // Load the table with a bit of data so some logs to split and some edits in each region.
        UTIL.loadTable(t, HBaseTestingUtility.COLUMNS[0]);
    }
    // fake it, set back later
    master.setServerCrashProcessingEnabled(false);
    // Kill a server. Master will notice but do nothing other than add it to list of dead servers.
    HRegionServer hrs = getServerWithRegions();
    boolean carryingMeta = master.getAssignmentManager().isCarryingMeta(hrs.getServerName());
    UTIL.getHBaseCluster().killRegionServer(hrs.getServerName());
    hrs.join();
    // here so ServerManager gets notice and adds expired server to appropriate queues.
    while (!master.getServerManager().isServerDead(hrs.getServerName())) Thread.sleep(10);
    // Do some of the master processing of dead servers so when SCP runs, it has expected 'state'.
    master.getServerManager().moveFromOnlineToDeadServers(hrs.getServerName());
    // check event wait/wake
    testProcedureEventWaitWake(master, master.getServerCrashProcessingEnabledEvent(), new ServerCrashProcedure(procExec.getEnvironment(), hrs.getServerName(), true, carryingMeta));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) HMaster(org.apache.hadoop.hbase.master.HMaster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 68 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestSimpleRegionNormalizerOnCluster method testRegionNormalizationMergeOnCluster.

@Test(timeout = 60000)
@SuppressWarnings("deprecation")
public void testRegionNormalizationMergeOnCluster() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster m = cluster.getMaster();
    // create 5 regions with sizes to trigger merge of small regions
    try (Table ht = TEST_UTIL.createMultiRegionTable(tableName, FAMILYNAME, 5)) {
        // Need to get sorted list of regions here
        List<HRegion> generatedRegions = TEST_UTIL.getHBaseCluster().getRegions(tableName);
        Collections.sort(generatedRegions, new Comparator<HRegion>() {

            @Override
            public int compare(HRegion o1, HRegion o2) {
                return o1.getRegionInfo().compareTo(o2.getRegionInfo());
            }
        });
        HRegion region = generatedRegions.get(0);
        generateTestData(region, 1);
        region.flush(true);
        region = generatedRegions.get(1);
        generateTestData(region, 1);
        region.flush(true);
        region = generatedRegions.get(2);
        generateTestData(region, 3);
        region.flush(true);
        region = generatedRegions.get(3);
        generateTestData(region, 3);
        region.flush(true);
        region = generatedRegions.get(4);
        generateTestData(region, 5);
        region.flush(true);
    }
    HTableDescriptor htd = admin.getTableDescriptor(tableName);
    htd.setNormalizationEnabled(true);
    admin.modifyTable(tableName, htd);
    admin.flush(tableName);
    assertEquals(5, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName));
    // Now trigger a merge and stop when the merge is in progress
    // to let region load to update
    Thread.sleep(5000);
    m.normalizeRegions();
    while (MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName) > 4) {
        LOG.info("Waiting for normalization merge to complete");
        Thread.sleep(100);
    }
    assertEquals(4, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName));
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Table(org.apache.hadoop.hbase.client.Table) HMaster(org.apache.hadoop.hbase.master.HMaster) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 69 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project phoenix by apache.

the class PhoenixServerRpcIT method ensureTablesOnDifferentRegionServers.

/**
 * Verifies that the given tables each have a single region and are on
 * different region servers. If they are on the same server moves tableName2
 * to the other region server.
 */
private void ensureTablesOnDifferentRegionServers(String tableName1, String tableName2) throws Exception {
    byte[] table1 = Bytes.toBytes(tableName1);
    byte[] table2 = Bytes.toBytes(tableName2);
    HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin();
    HBaseTestingUtility util = getUtility();
    MiniHBaseCluster cluster = util.getHBaseCluster();
    HMaster master = cluster.getMaster();
    AssignmentManager am = master.getAssignmentManager();
    // verify there is only a single region for data table
    List<HRegionInfo> tableRegions = admin.getTableRegions(table1);
    assertEquals("Expected single region for " + table1, tableRegions.size(), 1);
    HRegionInfo hri1 = tableRegions.get(0);
    // verify there is only a single region for index table
    tableRegions = admin.getTableRegions(table2);
    HRegionInfo hri2 = tableRegions.get(0);
    assertEquals("Expected single region for " + table2, tableRegions.size(), 1);
    ServerName serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1);
    ServerName serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2);
    // if data table and index table are on same region server, move the index table to the other region server
    if (serverName1.equals(serverName2)) {
        HRegionServer server1 = util.getHBaseCluster().getRegionServer(0);
        HRegionServer server2 = util.getHBaseCluster().getRegionServer(1);
        HRegionServer dstServer = null;
        HRegionServer srcServer = null;
        if (server1.getServerName().equals(serverName2)) {
            dstServer = server2;
            srcServer = server1;
        } else {
            dstServer = server1;
            srcServer = server2;
        }
        byte[] encodedRegionNameInBytes = hri2.getEncodedNameAsBytes();
        admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName()));
        while (dstServer.getOnlineRegion(hri2.getRegionName()) == null || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || master.getAssignmentManager().getRegionStates().isRegionsInTransition()) {
            // wait for the move to be finished
            Thread.sleep(1);
        }
    }
    hri1 = admin.getTableRegions(table1).get(0);
    serverName1 = am.getRegionStates().getRegionServerOfRegion(hri1);
    hri2 = admin.getTableRegions(table2).get(0);
    serverName2 = am.getRegionStates().getRegionServerOfRegion(hri2);
    // verify index and data tables are on different servers
    assertNotEquals("Tables " + tableName1 + " and " + tableName2 + " should be on different region servers", serverName1, serverName2);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 70 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class MasterDumpServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
    assert master != null : "No Master in context!";
    response.setContentType("text/plain");
    OutputStream os = response.getOutputStream();
    try (PrintWriter out = new PrintWriter(os)) {
        out.println("Master status for " + master.getServerName() + " as of " + new Date());
        out.println("\n\nVersion Info:");
        out.println(LINE);
        dumpVersionInfo(out);
        out.println("\n\nTasks:");
        out.println(LINE);
        TaskMonitor.get().dumpAsText(out);
        out.println("\n\nServers:");
        out.println(LINE);
        dumpServers(master, out);
        out.println("\n\nRegions-in-transition:");
        out.println(LINE);
        dumpRIT(master, out);
        out.println("\n\nExecutors:");
        out.println(LINE);
        dumpExecutors(master.getExecutorService(), out);
        out.println("\n\nStacks:");
        out.println(LINE);
        out.flush();
        PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
        Threads.printThreadInfo(ps, "");
        ps.flush();
        out.println("\n\nMaster configuration:");
        out.println(LINE);
        Configuration conf = master.getConfiguration();
        out.flush();
        conf.writeXml(os);
        os.flush();
        out.println("\n\nRecent regionserver aborts:");
        out.println(LINE);
        master.getRegionServerFatalLogBuffer().dumpTo(out);
        out.println("\n\nLogs");
        out.println(LINE);
        long tailKb = getTailKbParam(request);
        LogMonitoring.dumpTailOfLogs(out, tailKb);
        out.flush();
    }
}
Also used : PrintStream(java.io.PrintStream) Configuration(org.apache.hadoop.conf.Configuration) OutputStream(java.io.OutputStream) HMaster(org.apache.hadoop.hbase.master.HMaster) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

HMaster (org.apache.hadoop.hbase.master.HMaster)132 Test (org.junit.Test)91 TableName (org.apache.hadoop.hbase.TableName)42 IOException (java.io.IOException)33 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)31 ServerName (org.apache.hadoop.hbase.ServerName)24 Admin (org.apache.hadoop.hbase.client.Admin)23 Table (org.apache.hadoop.hbase.client.Table)23 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)22 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Configuration (org.apache.hadoop.conf.Configuration)13 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 BeforeClass (org.junit.BeforeClass)11 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)10 List (java.util.List)9 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)9 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ClassRule (org.junit.ClassRule)9