use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultKeeperActiveElectAlgorithm method select.
@Override
public KeeperMeta select(String clusterId, String shardId, List<KeeperMeta> toBeSelected) {
if (toBeSelected.size() > 0) {
KeeperMeta result = toBeSelected.get(0);
result.setActive(true);
return result;
}
return null;
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class BackupDcKeeperMasterChooserAlgorithm method doChoose.
@Override
protected Pair<String, Integer> doChoose() {
String dcName = dcMetaCache.getPrimaryDc(clusterId, shardId);
KeeperMeta keeperMeta = multiDcService.getActiveKeeper(dcName, clusterId, shardId);
logger.debug("[doChooseKeeperMaster]{}, {}, {}, {}", dcName, clusterId, shardId, keeperMeta);
if (keeperMeta == null) {
return null;
}
return new Pair<>(keeperMeta.getIp(), keeperMeta.getPort());
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class AbstractRedisKeeperServerState method setShardStatus.
@Override
public void setShardStatus(ShardStatus shardStatus) throws IOException {
if (shardStatus.getRedisMaster() != null && shardStatus.getUpstreamKeeper() != null) {
logger.error("[setShardStatus][active keeper and upstream keeper both not null]{}, {}", shardStatus.getActiveKeeper(), shardStatus.getUpstreamKeeper());
return;
}
KeeperMeta currentKeeperMeta = redisKeeperServer.getCurrentKeeperMeta();
KeeperMeta activeKeeper = shardStatus.getActiveKeeper();
if (activeKeeper == null) {
logger.info("[setShardStatus][active keeper null]");
return;
}
if (activeKeeper.getIp().equals(currentKeeperMeta.getIp()) && activeKeeper.getPort().equals(currentKeeperMeta.getPort())) {
RedisMeta redisMaster = shardStatus.getRedisMaster();
KeeperMeta upstreamKeeer = shardStatus.getUpstreamKeeper();
InetSocketAddress masterAddress = null;
if (redisMaster != null) {
masterAddress = new InetSocketAddress(redisMaster.getIp(), redisMaster.getPort());
}
if (upstreamKeeer != null) {
masterAddress = new InetSocketAddress(upstreamKeeer.getIp(), upstreamKeeer.getPort());
}
becomeActive(masterAddress);
} else {
becomeBackup(new InetSocketAddress(activeKeeper.getIp(), activeKeeper.getPort()));
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class KeeperContainerService method add.
public RedisKeeperServer add(KeeperTransMeta keeperTransMeta) {
KeeperMeta keeperMeta = keeperTransMeta.getKeeperMeta();
enrichKeeperMetaFromKeeperTransMeta(keeperMeta, keeperTransMeta);
String keeperServerKey = assembleKeeperServerKey(keeperTransMeta);
if (!redisKeeperServers.containsKey(keeperServerKey)) {
synchronized (this) {
if (!redisKeeperServers.containsKey(keeperServerKey)) {
if (runningPorts.contains(keeperMeta.getPort())) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Add keeper for cluster %s shard %s failed since port %d is already used", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId(), keeperMeta.getPort())), null);
}
try {
RedisKeeperServer redisKeeperServer = doAdd(keeperTransMeta, keeperMeta);
cacheKeeper(keeperServerKey, redisKeeperServer);
return redisKeeperServer;
} catch (Throwable ex) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Add keeper for cluster %s shard %s failed", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), ex);
}
}
}
}
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Keeper already exists for cluster %s shard %s", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), null);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultXpipeMetaManagerTest method testUpdateKeeperActive.
@Test
public void testUpdateKeeperActive() throws MetaException {
List<KeeperMeta> backups = metaManager.getKeeperBackup(dc, clusterId, shardId);
Assert.assertNotNull(metaManager.getKeeperActive(dc, clusterId, shardId));
;
KeeperMeta backup = backups.get(0);
metaManager.updateKeeperActive(dc, clusterId, shardId, backups.get(0));
KeeperMeta newActive = metaManager.getKeeperActive(dc, clusterId, shardId);
Assert.assertEquals(backup.getIp(), newActive.getIp());
Assert.assertEquals(backup.getPort(), newActive.getPort());
metaManager.updateKeeperActive(dc, clusterId, shardId, new KeeperMeta());
Assert.assertNull(metaManager.getKeeperActive(dc, clusterId, shardId));
}
Aggregations