Java Code Examples for org.apache.hadoop.hbase.master.HMaster#getMasterProcedureExecutor()

The following examples show how to use org.apache.hadoop.hbase.master.HMaster#getMasterProcedureExecutor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestReopenTableRegionsProcedureInfiniteLoop.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testInfiniteLoop() throws IOException {
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  AssignmentManager am = master.getAssignmentManager();
  ProcedureExecutor<MasterProcedureEnv> exec = master.getMasterProcedureExecutor();
  RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0);
  RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo);
  long procId;
  ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME);
  regionNode.lock();
  try {
    procId = exec.submitProcedure(proc);
    UTIL.waitFor(30000, () -> proc.hasLock());
    TransitRegionStateProcedure trsp =
      TransitRegionStateProcedure.reopen(exec.getEnvironment(), regionInfo);
    regionNode.setProcedure(trsp);
    exec.submitProcedure(trsp);
  } finally {
    regionNode.unlock();
  }
  UTIL.waitFor(60000, () -> exec.isFinished(procId));
}
 
Example 2
Source File: TestMasterProcedureEvents.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testMasterInitializedEvent() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();

  RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).build();
  TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build();

  while (!master.isInitialized()) {
    Thread.sleep(250);
  }
  master.setInitialized(false); // fake it, set back later

  // check event wait/wake
  testProcedureEventWaitWake(master, master.getInitializedEvent(),
    new CreateTableProcedure(procExec.getEnvironment(), htd, new RegionInfo[] { hri }));
}
 
Example 3
Source File: TestRecoverStandbyProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  UTIL.startMiniCluster(RS_NUMBER);
  UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
  conf = UTIL.getConfiguration();
  HMaster master = UTIL.getHBaseCluster().getMaster();
  fs = master.getMasterFileSystem().getWALFileSystem();
  syncReplicationReplayWALManager = master.getSyncReplicationReplayWALManager();
  procExec = master.getMasterProcedureExecutor();
}
 
Example 4
Source File: TestTransitRegionStateProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void testRecoveryAndDoubleExcution(TransitRegionStateProcedure proc) throws Exception {
  HMaster master = UTIL.getHBaseCluster().getMaster();
  AssignmentManager am = master.getAssignmentManager();
  RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(proc.getRegion());
  assertFalse(regionNode.isInTransition());
  regionNode.setProcedure(proc);
  assertTrue(regionNode.isInTransition());
  ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
  long procId = procExec.submitProcedure(proc);
  MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
  regionNode = am.getRegionStates().getRegionStateNode(proc.getRegion());
  assertFalse(regionNode.isInTransition());
}
 
Example 5
Source File: TestSCP.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcurrentSCPForSameServer() throws Exception {
  final TableName tableName = TableName.valueOf("testConcurrentSCPForSameServer");
  try (Table t = createTable(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]);
    final int count = HBaseTestingUtility.countRows(t);
    assertTrue("expected some rows", count > 0);
    // find the first server that match the request and executes the test
    ServerName rsToKill = null;
    for (RegionInfo hri : util.getAdmin().getRegions(tableName)) {
      final ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(util, hri);
      if (AssignmentTestingUtil.isServerHoldingMeta(util, serverName) == true) {
        rsToKill = serverName;
        break;
      }
    }
    HMaster master = util.getHBaseCluster().getMaster();
    final ProcedureExecutor<MasterProcedureEnv> pExecutor = master.getMasterProcedureExecutor();
    ServerCrashProcedure procB =
      new ServerCrashProcedure(pExecutor.getEnvironment(), rsToKill, false, false);
    AssignmentTestingUtil.killRs(util, rsToKill);
    long procId = getSCPProcId(pExecutor);
    Procedure<?> procA = pExecutor.getProcedure(procId);
    LOG.info("submit SCP procedureA");
    util.waitFor(5000, () -> procA.hasLock());
    LOG.info("procedureA acquired the lock");
    assertEquals(Procedure.LockState.LOCK_EVENT_WAIT,
      procB.acquireLock(pExecutor.getEnvironment()));
    LOG.info("procedureB should not be able to get the lock");
    util.waitFor(60000,
      () -> procB.acquireLock(pExecutor.getEnvironment()) == Procedure.LockState.LOCK_ACQUIRED);
    LOG.info("when procedure B get the lock, procedure A should be finished");
    assertTrue(procA.isFinished());
  }
}
 
Example 6
Source File: TestSCPBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
  MiniHBaseCluster cluster = this.util.getHBaseCluster();
  HMaster master = cluster == null ? null : cluster.getMaster();
  if (master != null && master.getMasterProcedureExecutor() != null) {
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(master.getMasterProcedureExecutor(),
      false);
  }
  this.util.shutdownMiniCluster();
}
 
Example 7
Source File: TestRegisterPeerWorkerWhenRestarting.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testRestart() throws Exception {
  UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.STANDBY);
  UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.ACTIVE);

  UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
  write(UTIL1, 0, 100);
  Thread.sleep(2000);
  // peer is disabled so no data have been replicated
  verifyNotReplicatedThroughRegion(UTIL2, 0, 100);

  // transit the A to DA first to avoid too many error logs.
  UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.DOWNGRADE_ACTIVE);
  HMaster master = UTIL2.getHBaseCluster().getMaster();
  // make sure the transiting can not succeed
  FAIL = true;
  ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
  Thread t = new Thread() {

    @Override
    public void run() {
      try {
        UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
          SyncReplicationState.DOWNGRADE_ACTIVE);
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    }
  };
  t.start();
  // wait until we are in the states where we need to register peer worker when restarting
  UTIL2.waitFor(60000,
    () -> procExec.getProcedures().stream().filter(p -> p instanceof RecoverStandbyProcedure)
      .map(p -> (RecoverStandbyProcedure) p)
      .anyMatch(p -> p.getCurrentStateId() == DISPATCH_WALS_VALUE ||
        p.getCurrentStateId() == UNREGISTER_PEER_FROM_WORKER_STORAGE_VALUE));
  // failover to another master
  MasterThread mt = UTIL2.getMiniHBaseCluster().getMasterThread();
  mt.getMaster().abort("for testing");
  mt.join();
  FAIL = false;
  t.join();
  // make sure the new master can finish the transition
  UTIL2.waitFor(60000, () -> UTIL2.getAdmin()
    .getReplicationPeerSyncReplicationState(PEER_ID) == SyncReplicationState.DOWNGRADE_ACTIVE);
  verify(UTIL2, 0, 100);
}
 
Example 8
Source File: TestTransitPeerSyncReplicationStateProcedureRetry.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecoveryAndDoubleExecution() throws Exception {
  UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.STANDBY);
  UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.ACTIVE);

  UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
  write(UTIL1, 0, 100);
  Thread.sleep(2000);
  // peer is disabled so no data have been replicated
  verifyNotReplicatedThroughRegion(UTIL2, 0, 100);

  // transit the A to DA first to avoid too many error logs.
  UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.DOWNGRADE_ACTIVE);
  HMaster master = UTIL2.getHBaseCluster().getMaster();
  ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
  // Enable test flags and then queue the procedure.
  ProcedureTestingUtility.waitNoProcedureRunning(procExec);
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
  Thread t = new Thread() {

    @Override
    public void run() {
      try {
        UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
          SyncReplicationState.DOWNGRADE_ACTIVE);
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    }
  };
  t.start();
  UTIL2.waitFor(30000, () -> procExec.getProcedures().stream()
    .anyMatch(p -> p instanceof TransitPeerSyncReplicationStateProcedure && !p.isFinished()));
  long procId = procExec.getProcedures().stream()
    .filter(p -> p instanceof TransitPeerSyncReplicationStateProcedure && !p.isFinished())
    .mapToLong(Procedure::getProcId).min().getAsLong();
  MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
  assertEquals(SyncReplicationState.DOWNGRADE_ACTIVE,
    UTIL2.getAdmin().getReplicationPeerSyncReplicationState(PEER_ID));
  verify(UTIL2, 0, 100);
}
 
Example 9
Source File: TestMasterProcedureEvents.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void testProcedureEventWaitWake(final HMaster master, final ProcedureEvent<?> event,
    final Procedure<MasterProcedureEnv> proc) throws Exception {
  final ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
  final MasterProcedureScheduler procSched = procExec.getEnvironment().getProcedureScheduler();

  final long startPollCalls = procSched.getPollCalls();
  final long startNullPollCalls = procSched.getNullPollCalls();

  // check that nothing is in the event queue
  LOG.debug("checking " + event);
  assertEquals(false, event.isReady());
  assertEquals(0, event.getSuspendedProcedures().size());

  // submit the procedure
  LOG.debug("submit " + proc);
  long procId = procExec.submitProcedure(proc);

  // wait until the event is in the queue (proc executed and got into suspended state)
  LOG.debug("wait procedure suspended on " + event);
  while (event.getSuspendedProcedures().size() < 1) Thread.sleep(25);

  // check that the proc is in the event queue
  LOG.debug("checking " + event + " size=" + event.getSuspendedProcedures().size());
  assertEquals(false, event.isReady());
  assertEquals(1, event.getSuspendedProcedures().size());

  // wake the event
  LOG.debug("wake " + event);
  event.wake(procSched);
  assertEquals(true, event.isReady());

  // wait until proc completes
  LOG.debug("waiting " + proc);
  ProcedureTestingUtility.waitProcedure(procExec, procId);

  // check that nothing is in the event queue and the event is not suspended
  assertEquals(true, event.isReady());
  assertEquals(0, event.getSuspendedProcedures().size());
  LOG.debug("completed execution of " + proc +
    " pollCalls=" + (procSched.getPollCalls() - startPollCalls) +
    " nullPollCalls=" + (procSched.getNullPollCalls() - startNullPollCalls));
}