use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class RedisKeeperServerStateUnknownTest method testActive.
@Test
public void testActive() throws IOException {
// active
KeeperMeta keeperMeta = redisKeeperServer.getCurrentKeeperMeta();
ShardStatus shardStatus = createShardStatus(keeperMeta, null, redisMasterMeta);
unknown.setShardStatus(shardStatus);
RedisKeeperServerState newState = redisKeeperServer.getRedisKeeperServerState();
Assert.assertTrue(newState instanceof RedisKeeperServerStateActive);
Assert.assertEquals(new InetSocketAddress(redisMasterMeta.getIp(), redisMasterMeta.getPort()), newState.getMaster().getSocketAddress());
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class RedisKeeperServerStateUnknownTest method testBackup.
@Test
public void testBackup() throws IOException {
// active
KeeperMeta keeperMeta = SerializationUtils.clone(redisKeeperServer.getCurrentKeeperMeta());
keeperMeta.setPort(keeperMeta.getPort() + 1);
ShardStatus shardStatus = createShardStatus(keeperMeta, null, redisMasterMeta);
unknown.setShardStatus(shardStatus);
RedisKeeperServerState newState = redisKeeperServer.getRedisKeeperServerState();
Assert.assertTrue(newState instanceof RedisKeeperServerStateBackup);
Assert.assertEquals(new InetSocketAddress(keeperMeta.getIp(), keeperMeta.getPort()), newState.getMaster().getSocketAddress());
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class RedisMetaServiceImpl method getKeeperMeta.
@Override
public KeeperMeta getKeeperMeta(ShardMeta shardMeta, RedisTbl redisInfo) {
KeeperMeta keeperMeta = new KeeperMeta();
if (null != redisInfo) {
keeperMeta.setId(redisInfo.getRunId());
keeperMeta.setIp(redisInfo.getRedisIp());
keeperMeta.setPort(redisInfo.getRedisPort());
keeperMeta.setKeeperContainerId(redisInfo.getKeepercontainerId());
}
keeperMeta.setParent(shardMeta);
return keeperMeta;
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class AbstractChangePrimaryDcAction method makeKeepersOk.
protected void makeKeepersOk(String clusterId, String shardId, Pair<String, Integer> newMaster) {
List<KeeperMeta> keepers = currentMetaManager.getSurviveKeepers(clusterId, shardId);
executionLog.info("[makeKeepersOk]" + keepers);
KeeperStateChangeJob job = new KeeperStateChangeJob(keepers, new Pair<String, Integer>(newMaster.getKey(), newMaster.getValue()), keyedObjectPool, 1000, 1, scheduled, executors);
try {
job.execute().get(waitTimeoutSeconds / 2, TimeUnit.SECONDS);
executionLog.info("[makeKeepersOk]success");
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("[makeKeepersOk]" + e.getMessage());
executionLog.info("[makeKeepersOk][fail]" + e.getMessage());
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta 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());
}
Aggregations