use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultDynamicStateManager method add.
@Override
public void add(ClusterMeta clusterMeta) {
clusterMetas.put(clusterMeta.getId(), clusterMeta);
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
for (KeeperMeta keeperMeta : shardMeta.getKeepers()) {
final KeeperKey keeperKey = createKeeperKey(clusterMeta.getId(), shardMeta.getId(), keeperMeta);
@SuppressWarnings("unused") KeeperHeartBeatManager keeperHeartBeatManager = MapUtils.getOrCreate(keepers, keeperKey, new ObjectFactory<KeeperHeartBeatManager>() {
@Override
public KeeperHeartBeatManager create() {
KeeperHeartBeatManager keeperHeartBeatManager = new DefaultKeeperHeartBeatManager(keeperKey, scheduled);
keeperHeartBeatManager.addObserver(DefaultDynamicStateManager.this);
return keeperHeartBeatManager;
}
});
}
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultKeeperStateChangeHandler method keeperMasterChanged.
@Override
public void keeperMasterChanged(String clusterId, String shardId, Pair<String, Integer> newMaster) {
logger.info("[keeperMasterChanged]{},{},{}", clusterId, shardId, newMaster);
KeeperMeta activeKeeper = currentMetaManager.getKeeperActive(clusterId, shardId);
if (activeKeeper == null) {
logger.info("[keeperMasterChanged][no active keeper, do nothing]{},{},{}", clusterId, shardId, newMaster);
return;
}
if (!activeKeeper.isActive()) {
throw new IllegalStateException("[active keeper not active]{}" + activeKeeper);
}
logger.info("[keeperMasterChanged][set active keeper master]{}, {}", activeKeeper, newMaster);
List<KeeperMeta> keepers = new LinkedList<>();
keepers.add(activeKeeper);
keyedOneThreadTaskExecutor.execute(new Pair<String, String>(clusterId, shardId), new KeeperStateChangeJob(keepers, newMaster, clientPool, scheduled, executors));
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultKeeperStateChangeHandler method keeperActiveElected.
@Override
public void keeperActiveElected(String clusterId, String shardId, KeeperMeta activeKeeper) {
logger.info("[keeperActiveElected]{},{},{}", clusterId, shardId, activeKeeper);
List<KeeperMeta> keepers = currentMetaManager.getSurviveKeepers(clusterId, shardId);
if (keepers == null || keepers.size() == 0) {
logger.info("[keeperActiveElected][none keeper survive, do nothing]");
return;
}
Pair<String, Integer> activeKeeperMaster = currentMetaManager.getKeeperMaster(clusterId, shardId);
KeeperStateChangeJob keeperStateChangeJob = new KeeperStateChangeJob(keepers, activeKeeperMaster, clientPool, scheduled, executors);
if (!dcMetaCache.isCurrentDcPrimary(clusterId, shardId)) {
List<RedisMeta> slaves = dcMetaCache.getShardRedises(clusterId, shardId);
logger.info("[keeperActiveElected][current dc backup, set slave to new keeper]{},{},{}", clusterId, shardId, slaves);
keeperStateChangeJob.setActiveSuccessCommand(new DefaultSlaveOfJob(slaves, activeKeeper.getIp(), activeKeeper.getPort(), clientPool, scheduled, executors));
}
keyedOneThreadTaskExecutor.execute(new Pair<String, String>(clusterId, shardId), keeperStateChangeJob);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DefaultMultiDcService method getActiveKeeper.
@Override
public KeeperMeta getActiveKeeper(String dcName, String clusterId, String shardId) {
dcName = dcName.toLowerCase();
DcInfo dcInfo = metaServerConfig.getDcInofs().get(dcName);
if (dcInfo == null) {
logger.error("[doChooseKeeperMaster][dc info null]{}", dcName);
return null;
}
MetaServerMultiDcService metaServerMultiDcService = metaServerMultiDcServiceManager.getOrCreate(dcInfo.getMetaServerAddress());
KeeperMeta keeperMeta = metaServerMultiDcService.getActiveKeeper(clusterId, shardId);
return keeperMeta;
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class BackupDcClusterRedisStateAjust method doRun.
@Override
protected void doRun() throws Exception {
ClusterMeta clusterMeta = currentMetaManager.getClusterMeta(clusterId);
if (clusterMeta == null) {
logger.warn("[doRun][cluster null]{}", clusterId);
return;
}
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
logger.debug("[doRun]{}, {}", clusterId, shardMeta.getId());
KeeperMeta keeperActive = currentMetaManager.getKeeperActive(clusterId, shardMeta.getId());
if (keeperActive == null) {
logger.debug("[doRun][keeper active null]{}, {}", clusterId, shardMeta.getId());
continue;
}
List<RedisMeta> redisesNeedChange = getRedisesNeedToChange(shardMeta, keeperActive);
if (redisesNeedChange.size() == 0) {
continue;
}
logger.info("[doRun][change state]{}, {}, {}", clusterId, keeperActive, redisesNeedChange);
new DefaultSlaveOfJob(redisesNeedChange, keeperActive.getIp(), keeperActive.getPort(), pool, scheduled, executors).execute().addListener(new CommandFutureListener<Void>() {
@Override
public void operationComplete(CommandFuture<Void> commandFuture) throws Exception {
if (!commandFuture.isSuccess()) {
logger.error("[operationComplete][fail]" + commandFuture.command(), commandFuture.cause());
}
}
});
}
}
Aggregations