conn.commit();
// find a RS which doesn't has CATALOG table
byte[] catalogTable = Bytes.toBytes("SYSTEM.CATALOG");
byte[] indexTable = Bytes.toBytes(INDEX_TABLE_FULL_NAME);
final HBaseCluster cluster = util.getHBaseCluster();
Collection<ServerName> rss = cluster.getClusterStatus().getServers();
HBaseAdmin admin = util.getHBaseAdmin();
List<HRegionInfo> regions = admin.getTableRegions(catalogTable);
ServerName catalogRS = cluster.getServerHoldingRegion(regions.get(0).getRegionName());
ServerName metaRS = cluster.getServerHoldingMeta();
ServerName rsToBeKilled = null;
// find first RS isn't holding META or CATALOG table
for(ServerName curRS : rss) {
if(!curRS.equals(catalogRS) && !metaRS.equals(curRS)) {
rsToBeKilled = curRS;
break;
}
}
assertTrue(rsToBeKilled != null);
regions = admin.getTableRegions(indexTable);
final HRegionInfo indexRegion = regions.get(0);
final ServerName dstRS = rsToBeKilled;
admin.move(indexRegion.getEncodedNameAsBytes(), Bytes.toBytes(rsToBeKilled.getServerName()));
long started = System.currentTimeMillis();
while(true) {
ServerName sn = cluster.getServerHoldingRegion(indexRegion.getRegionName());
if (sn != null && sn.equals(dstRS)) {
break;
}
if((System.currentTimeMillis() - started) > 30000) {
assertTrue("Timeout waiting for " + indexRegion + " move to " + rsToBeKilled, false);
}
Thread.sleep(200);
}
// use timer sending updates in every 10ms
this.scheduleTimer = new Timer(true);
this.scheduleTimer.schedule(new SendingUpdatesScheduleTask(conn), 0, 10);
// let timer sending some updates
Thread.sleep(100);
// kill RS hosting index table
util.getHBaseCluster().killRegionServer(rsToBeKilled);
// wait for index table completes recovery
util.waitUntilAllRegionsAssigned(indexTable);
// Verify the metadata for index is correct.
do {
Thread.sleep(15 * 1000); // sleep 15 secs
rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(SCHEMA_NAME), INDEX_TABLE_NAME,
new String[] { PTableType.INDEX.toString() });
assertTrue(rs.next());
if(PIndexState.ACTIVE.toString().equals(rs.getString("INDEX_STATE"))){
break;
}
} while(true);
this.scheduleTimer.cancel();
assertEquals(cluster.getClusterStatus().getDeadServers(), 1);
}