use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.
the class TestRegionReplicaReplicationEndpointNoMaster method testReplayCallable.
@Test(timeout = 240000)
public void testReplayCallable() throws Exception {
// tests replaying the edits to a secondary region replica using the Callable directly
openRegion(HTU, rs0, hriSecondary);
ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(HTU.getConfiguration());
//load some data to primary
HTU.loadNumericRows(table, f, 0, 1000);
Assert.assertEquals(1000, entries.size());
// replay the edits to the secondary using replay callable
replicateUsingCallable(connection, entries);
Region region = rs0.getFromOnlineRegions(hriSecondary.getEncodedName());
HTU.verifyNumericRows(region, f, 0, 1000);
HTU.deleteNumericRows(table, f, 0, 1000);
closeRegion(HTU, rs0, hriSecondary);
connection.close();
}
use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.
the class TestRegionReplicaReplicationEndpointNoMaster method testRegionReplicaReplicationEndpointReplicate.
@Test(timeout = 240000)
public void testRegionReplicaReplicationEndpointReplicate() throws Exception {
// tests replaying the edits to a secondary region replica using the RRRE.replicate()
openRegion(HTU, rs0, hriSecondary);
ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(HTU.getConfiguration());
RegionReplicaReplicationEndpoint replicator = new RegionReplicaReplicationEndpoint();
ReplicationEndpoint.Context context = mock(ReplicationEndpoint.Context.class);
when(context.getConfiguration()).thenReturn(HTU.getConfiguration());
when(context.getMetrics()).thenReturn(mock(MetricsSource.class));
replicator.init(context);
replicator.start();
//load some data to primary
HTU.loadNumericRows(table, f, 0, 1000);
Assert.assertEquals(1000, entries.size());
// replay the edits to the secondary using replay callable
final String fakeWalGroupId = "fakeWALGroup";
replicator.replicate(new ReplicateContext().setEntries(Lists.newArrayList(entries)).setWalGroupId(fakeWalGroupId));
Region region = rs0.getFromOnlineRegions(hriSecondary.getEncodedName());
HTU.verifyNumericRows(region, f, 0, 1000);
HTU.deleteNumericRows(table, f, 0, 1000);
closeRegion(HTU, rs0, hriSecondary);
connection.close();
}
use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.
the class ServerCrashProcedure method isMetaAssignedQuickTest.
/**
* A quick test that hbase:meta is assigned; blocks for short time only.
* @return True if hbase:meta location is available and verified as good.
* @throws InterruptedException
* @throws IOException
*/
private boolean isMetaAssignedQuickTest(final MasterProcedureEnv env) throws InterruptedException, IOException {
ZooKeeperWatcher zkw = env.getMasterServices().getZooKeeper();
MetaTableLocator mtl = env.getMasterServices().getMetaTableLocator();
boolean metaAssigned = false;
// Is hbase:meta location available yet?
if (mtl.isLocationAvailable(zkw)) {
ClusterConnection connection = env.getMasterServices().getClusterConnection();
// Is hbase:meta location good yet?
long timeout = env.getMasterConfiguration().getLong(KEY_SHORT_WAIT_ON_META, DEFAULT_SHORT_WAIT_ON_META);
if (mtl.verifyMetaRegionLocation(connection, zkw, timeout)) {
metaAssigned = true;
}
}
return metaAssigned;
}
use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.
the class TestClockSkewDetection method testClockSkewDetection.
@Test
public void testClockSkewDetection() throws Exception {
final Configuration conf = HBaseConfiguration.create();
ServerManager sm = new ServerManager(new MockNoopMasterServices(conf) {
@Override
public ClusterConnection getClusterConnection() {
ClusterConnection conn = mock(ClusterConnection.class);
when(conn.getRpcControllerFactory()).thenReturn(mock(RpcControllerFactory.class));
return conn;
}
}, true);
LOG.debug("regionServerStartup 1");
InetAddress ia1 = InetAddress.getLocalHost();
RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
request.setPort(1234);
request.setServerStartCode(-1);
request.setServerCurrentTime(System.currentTimeMillis());
sm.regionServerStartup(request.build(), ia1);
final Configuration c = HBaseConfiguration.create();
long maxSkew = c.getLong("hbase.master.maxclockskew", 30000);
long warningSkew = c.getLong("hbase.master.warningclockskew", 1000);
try {
//Master Time > Region Server Time
LOG.debug("Test: Master Time > Region Server Time");
LOG.debug("regionServerStartup 2");
InetAddress ia2 = InetAddress.getLocalHost();
request = RegionServerStartupRequest.newBuilder();
request.setPort(1235);
request.setServerStartCode(-1);
request.setServerCurrentTime(System.currentTimeMillis() - maxSkew * 2);
sm.regionServerStartup(request.build(), ia2);
fail("HMaster should have thrown a ClockOutOfSyncException but didn't.");
} catch (ClockOutOfSyncException e) {
//we want an exception
LOG.info("Recieved expected exception: " + e);
}
try {
// Master Time < Region Server Time
LOG.debug("Test: Master Time < Region Server Time");
LOG.debug("regionServerStartup 3");
InetAddress ia3 = InetAddress.getLocalHost();
request = RegionServerStartupRequest.newBuilder();
request.setPort(1236);
request.setServerStartCode(-1);
request.setServerCurrentTime(System.currentTimeMillis() + maxSkew * 2);
sm.regionServerStartup(request.build(), ia3);
fail("HMaster should have thrown a ClockOutOfSyncException but didn't.");
} catch (ClockOutOfSyncException e) {
// we want an exception
LOG.info("Recieved expected exception: " + e);
}
// make sure values above warning threshold but below max threshold don't kill
LOG.debug("regionServerStartup 4");
InetAddress ia4 = InetAddress.getLocalHost();
request = RegionServerStartupRequest.newBuilder();
request.setPort(1237);
request.setServerStartCode(-1);
request.setServerCurrentTime(System.currentTimeMillis() - warningSkew * 2);
sm.regionServerStartup(request.build(), ia4);
// make sure values above warning threshold but below max threshold don't kill
LOG.debug("regionServerStartup 5");
InetAddress ia5 = InetAddress.getLocalHost();
request = RegionServerStartupRequest.newBuilder();
request.setPort(1238);
request.setServerStartCode(-1);
request.setServerCurrentTime(System.currentTimeMillis() + warningSkew * 2);
sm.regionServerStartup(request.build(), ia5);
}
use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.
the class TestRSGroupsBase method testRegionMove.
@Test
public void testRegionMove() throws Exception {
final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 1);
final byte[] familyNameBytes = Bytes.toBytes("f");
// All the regions created below will be assigned to the default group.
TEST_UTIL.createMultiRegionTable(tableName, familyNameBytes, 6);
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
List<String> regions = getTableRegionMap().get(tableName);
if (regions == null)
return false;
return getTableRegionMap().get(tableName).size() >= 6;
}
});
//get target region to move
Map<ServerName, List<String>> assignMap = getTableServerRegionMap().get(tableName);
String targetRegion = null;
for (ServerName server : assignMap.keySet()) {
targetRegion = assignMap.get(server).size() > 0 ? assignMap.get(server).get(0) : null;
if (targetRegion != null) {
break;
}
}
//get server which is not a member of new group
ServerName targetServer = null;
for (ServerName server : admin.getClusterStatus().getServers()) {
if (!newGroup.containsServer(server.getAddress())) {
targetServer = server;
break;
}
}
final AdminProtos.AdminService.BlockingInterface targetRS = ((ClusterConnection) admin.getConnection()).getAdmin(targetServer);
//move target server to group
rsGroupAdmin.moveServers(Sets.newHashSet(targetServer.getAddress()), newGroup.getName());
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return ProtobufUtil.getOnlineRegions(targetRS).size() <= 0;
}
});
// Lets move this region to the new group.
TEST_UTIL.getAdmin().move(Bytes.toBytes(HRegionInfo.encodeRegionName(Bytes.toBytes(targetRegion))), Bytes.toBytes(targetServer.getServerName()));
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return getTableRegionMap().get(tableName) != null && getTableRegionMap().get(tableName).size() == 6 && admin.getClusterStatus().getRegionsInTransition().size() < 1;
}
});
//verify that targetServer didn't open it
assertFalse(ProtobufUtil.getOnlineRegions(targetRS).contains(targetRegion));
}
Aggregations