use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob in project x-pipe by ctripcorp.
the class AbstractKeeperIntegratedMultiDc method makeKeeperRight.
private void makeKeeperRight() throws Exception {
logger.info(remarkableMessage("makeKeeperRight"));
DcMeta dcMeta = activeDc();
List<KeeperMeta> keepers = getDcKeepers(dcMeta.getId(), getClusterId(), getShardId());
RedisMeta redisMaster = getRedisMaster();
KeeperStateChangeJob job = new KeeperStateChangeJob(keepers, new Pair<String, Integer>(redisMaster.getIp(), redisMaster.getPort()), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
job.execute().sync();
for (DcMeta backupDc : backupDcs()) {
List<KeeperMeta> backupKeepers = getDcKeepers(backupDc.getId(), getClusterId(), getShardId());
job = new KeeperStateChangeJob(backupKeepers, new Pair<String, Integer>(activeDcKeeperActive.getIp(), activeDcKeeperActive.getPort()), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
job.execute().sync();
}
}
use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob in project x-pipe by ctripcorp.
the class AbstractKeeperIntegratedSingleDc method makeKeeperRight.
protected void makeKeeperRight() throws Exception {
List<KeeperMeta> keepers = getDcKeepers(dc, getClusterId(), getShardId());
RedisMeta redisMaster = getRedisMaster();
KeeperStateChangeJob job = new KeeperStateChangeJob(keepers, new Pair<String, Integer>(redisMaster.getIp(), redisMaster.getPort()), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
job.execute().sync();
}
use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob 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.meta.server.job.KeeperStateChangeJob 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.meta.server.job.KeeperStateChangeJob 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);
}
Aggregations