use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestZooKeeper method testRegionAssignmentAfterMasterRecoveryDueToZKExpiry.
/**
* Tests that the master does not call retainAssignment after recovery from expired zookeeper
* session. Without the HBASE-6046 fix master always tries to assign all the user regions by
* calling retainAssignment.
*/
@Test
public void testRegionAssignmentAfterMasterRecoveryDueToZKExpiry() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
cluster.startRegionServer();
cluster.waitForActiveAndReadyMaster(10000);
HMaster m = cluster.getMaster();
final ZKWatcher zkw = m.getZooKeeper();
// now the cluster is up. So assign some regions.
try (Admin admin = TEST_UTIL.getAdmin()) {
byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d"), Bytes.toBytes("e"), Bytes.toBytes("f"), Bytes.toBytes("g"), Bytes.toBytes("h"), Bytes.toBytes("i"), Bytes.toBytes("j") };
TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
admin.createTable(htd, SPLIT_KEYS);
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
m.getZooKeeper().close();
MockLoadBalancer.retainAssignCalled = false;
final int expectedNumOfListeners = countPermanentListeners(zkw);
m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException());
// Master doesn't recover any more
assertTrue(m.isStopped());
// The recovered master should not call retainAssignment, as it is not a
// clean startup.
assertFalse("Retain assignment should not be called", MockLoadBalancer.retainAssignCalled);
// number of listeners should be same as the value before master aborted
// wait for new master is initialized
cluster.waitForActiveAndReadyMaster(120000);
final HMaster newMaster = cluster.getMasterThread().getMaster();
assertEquals(expectedNumOfListeners, countPermanentListeners(newMaster.getZooKeeper()));
}
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestClientClusterStatus method testMasterAndBackupMastersStatus.
@Test
public void testMasterAndBackupMastersStatus() throws Exception {
// get all the master threads
List<MasterThread> masterThreads = CLUSTER.getMasterThreads();
int numActive = 0;
int activeIndex = 0;
ServerName activeName = null;
HMaster active = null;
for (int i = 0; i < masterThreads.size(); i++) {
if (masterThreads.get(i).getMaster().isActiveMaster()) {
numActive++;
activeIndex = i;
active = masterThreads.get(activeIndex).getMaster();
activeName = active.getServerName();
}
}
Assert.assertNotNull(active);
Assert.assertEquals(1, numActive);
Assert.assertEquals(MASTERS, masterThreads.size());
// Retrieve master and backup masters infos only.
EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
ClusterMetrics status = ADMIN.getClusterMetrics(options);
Assert.assertTrue(status.getMasterName().equals(activeName));
Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestFailedMetaReplicaAssigment method testFailedReplicaAssignment.
@Test
public void testFailedReplicaAssignment() throws InterruptedException {
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
// waiting for master to come up
TEST_UTIL.waitFor(30000, () -> master.isInitialized());
AssignmentManager am = master.getAssignmentManager();
// showing one of the replicas got assigned
RegionInfo metaReplicaHri = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 1);
// we use assignAsync so we need to wait a bit
TEST_UTIL.waitFor(30000, () -> {
RegionStateNode metaReplicaRegionNode = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri);
return metaReplicaRegionNode.getRegionLocation() != null;
});
// showing one of the replicas failed to be assigned
RegionInfo metaReplicaHri2 = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 2);
RegionStateNode metaReplicaRegionNode2 = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri2);
// wait for several seconds to make sure that it is not assigned
for (int i = 0; i < 3; i++) {
Thread.sleep(2000);
assertNull(metaReplicaRegionNode2.getRegionLocation());
}
// showing master is active and running
assertFalse(master.isStopping());
assertFalse(master.isStopped());
assertTrue(master.isActiveMaster());
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestTransitPeerSyncReplicationStateProcedureRetry method testRecoveryAndDoubleExecution.
@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);
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestSCP method testConcurrentSCPForSameServer.
@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, HBaseTestingUtil.COLUMNS[0]);
final int count = HBaseTestingUtil.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());
}
}
Aggregations