use of com.ctrip.xpipe.api.server.Server.SERVER_ROLE in project x-pipe by ctripcorp.
the class AbstractIntegratedTestTemplate method failOverTestTemplate.
@SuppressWarnings("unused")
protected void failOverTestTemplate() throws Exception {
RedisMeta redisMaster = getRedisMaster();
stopServerListeningPort(redisMaster.getPort());
RedisKeeperServer redisKeeperServer = getRedisKeeperServerActive(activeDc().getId());
RedisMeta slave = getRedisSlaves(activeDc().getId()).get(0);
SERVER_ROLE role = getRedisServerRole(slave);
Assert.assertEquals(SERVER_ROLE.SLAVE, role);
logger.info(remarkableMessage("[testRedisFailover][promote]{}:{})"), slave.getIp(), slave.getPort());
String clusterId = redisMaster.parent().parent().getId();
String shardId = redisMaster.parent().getId();
DefaultMetaServer metaServer = getDcInfos().get(activeDc().getId()).getApplicationContext().getBean(DefaultMetaServer.class);
// metaServer.promoteRedisMaster(clusterId, shardId, slave.getIp(), slave.getPort());
sleep(6000);
role = getRedisServerRole(slave);
Assert.assertEquals(SERVER_ROLE.MASTER, role);
Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
changeRedisMaster(redisMaster, slave);
sendMessageToMasterAndTestSlaveRedis();
}
use of com.ctrip.xpipe.api.server.Server.SERVER_ROLE in project x-pipe by ctripcorp.
the class AbstractNewMasterChooser method getMasters.
protected Pair<List<RedisMeta>, List<RedisMeta>> getMasters(List<RedisMeta> allRedises) {
List<RedisMeta> masters = new LinkedList<>();
List<RedisMeta> tmpAliveServers = new LinkedList<>();
CountDownLatch latch = new CountDownLatch(allRedises.size());
for (RedisMeta redisMeta : allRedises) {
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
try {
SERVER_ROLE role = serverRole(redisMeta);
if (role == SERVER_ROLE.MASTER) {
synchronized (masters) {
masters.add(redisMeta);
}
}
if (role != SERVER_ROLE.UNKNOWN) {
synchronized (tmpAliveServers) {
tmpAliveServers.add(redisMeta);
}
}
} finally {
latch.countDown();
}
}
});
}
try {
latch.await(CHECK_NEW_MASTER_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.error("[getMasters]" + allRedises, e);
}
List<RedisMeta> aliveServers = sortAccording(allRedises, tmpAliveServers);
return new Pair<>(masters, aliveServers);
}
Aggregations