use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class PrimaryDcKeeperMasterChooserAlgorithmTest method testMultiMaster.
@Test
public void testMultiMaster() throws Exception {
SlaveRole role = new SlaveRole(SERVER_ROLE.MASTER, "localhost", randomPort(), MASTER_STATE.REDIS_REPL_CONNECT, 0L);
for (RedisMeta redisMeta : redises) {
startServer(redisMeta.getPort(), ByteBufUtils.readToString(role.format()));
}
when(currentMetaManager.getKeeperMaster(clusterId, shardId)).thenReturn(null);
Assert.assertEquals(new Pair<String, Integer>(redises.get(0).getIp(), redises.get(0).getPort()), primaryAlgorithm.choose());
for (RedisMeta redisMeta : redises) {
Pair<String, Integer> currentMaster = new Pair<String, Integer>(redisMeta.getIp(), redisMeta.getPort());
when(currentMetaManager.getKeeperMaster(clusterId, shardId)).thenReturn(currentMaster);
Assert.assertEquals(currentMaster, primaryAlgorithm.choose());
}
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class RedisMetaServiceImpl method getRedisMeta.
@Override
public RedisMeta getRedisMeta(ShardMeta shardMeta, RedisTbl redisInfo) {
RedisMeta redisMeta = new RedisMeta();
if (null != redisInfo) {
redisMeta.setId(redisInfo.getRunId());
redisMeta.setIp(redisInfo.getRedisIp());
redisMeta.setPort(redisInfo.getRedisPort());
if (redisInfo.isMaster()) {
redisMeta.setMaster("");
} else {
redisMeta.setMaster(XPipeConsoleConstant.DEFAULT_ADDRESS);
}
}
redisMeta.setParent(shardMeta);
return redisMeta;
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class BecomeBackupAction method doChangePrimaryDc.
@Override
protected PrimaryDcChangeMessage doChangePrimaryDc(String clusterId, String shardId, String newPrimaryDc, MasterInfo masterInfo) {
doChangeMetaCache(clusterId, shardId, newPrimaryDc);
changeSentinel(clusterId, shardId, null);
Pair<String, Integer> newMaster = chooseNewMaster(clusterId, shardId);
if (newMaster == null) {
executionLog.error("[doChangePrimaryDc][new master null]");
return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.FAIL, executionLog.getLog());
}
executionLog.info(String.format("[chooseNewMaster]%s:%d", newMaster.getKey(), newMaster.getValue()));
makeKeepersOk(clusterId, shardId, newMaster);
List<RedisMeta> slaves = getAllSlaves(newMaster, dcMetaCache.getShardRedises(clusterId, shardId));
KeeperMeta activeKeeper = currentMetaManager.getKeeperActive(clusterId, shardId);
makeRedisesOk(new Pair<>(activeKeeper.getIp(), activeKeeper.getPort()), slaves);
return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.SUCCESS, executionLog.getLog());
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta 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);
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class BecomePrimaryAction method doChangePrimaryDc.
protected PrimaryDcChangeMessage doChangePrimaryDc(String clusterId, String shardId, String newPrimaryDc, MasterInfo masterInfo) {
doChangeMetaCache(clusterId, shardId, newPrimaryDc);
executionLog.info(String.format("[chooseNewMaster][begin]"));
Pair<String, Integer> newMaster = chooseNewMaster(clusterId, shardId);
executionLog.info(String.format("[chooseNewMaster]%s:%d", newMaster.getKey(), newMaster.getValue()));
// wait for slave to achieve master offset
offsetWaiter.tryWaitfor(new HostPort(newMaster.getKey(), newMaster.getValue()), masterInfo, executionLog);
List<RedisMeta> slaves = getAllSlaves(newMaster, dcMetaCache.getShardRedises(clusterId, shardId));
makeRedisesOk(newMaster, slaves);
makeKeepersOk(clusterId, shardId, newMaster);
changeSentinel(clusterId, shardId, newMaster);
return new PrimaryDcChangeMessage(executionLog.getLog(), newMaster.getKey(), newMaster.getValue());
}
Aggregations