use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class OneDcKeepers method testKeeperChangeState.
@Test
public void testKeeperChangeState() throws Exception {
int round = 1000;
scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
sendMessageToMaster(getRedisMaster(), 100);
}
}, 0, 500, TimeUnit.SECONDS.MILLISECONDS);
RedisMeta redisMaster = getRedisMaster();
KeeperMeta currentActive = activeKeeper;
KeeperMeta currentBackup = backupKeeper;
for (int i = 0; i < round; i++) {
logger.info(remarkableMessage("round: {}"), i);
setKeeperState(currentBackup, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
setKeeperState(currentActive, KeeperState.BACKUP, currentBackup.getIp(), currentBackup.getPort());
sleep(1000);
KeeperMeta tmp = currentActive;
currentActive = currentBackup;
currentBackup = tmp;
}
waitForAnyKey();
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta 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.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class AbstractKeeperIntegratedSingleDc method endPrepareRedisConfig.
@Override
protected void endPrepareRedisConfig(RedisMeta redisMeta, StringBuilder sb) {
if (redisMeta.isMaster()) {
return;
}
KeeperMeta activeKeeper = getKeeperActive();
sb.append(String.format("slaveof %s %d\r\n", activeKeeper.getIp(), activeKeeper.getPort()));
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class ClusterServersApiTest method testGetActiveKeeper.
@Test
public void testGetActiveKeeper() throws Exception {
createMetaServers(metaServerCount);
sleep(waitForMetaServerOkTime);
logger.info(remarkableMessage("[testUpdateUpstream][begin send upstream update message]"));
for (TestMetaServer server : getServers()) {
String path = META_SERVER_SERVICE.GET_ACTIVE_KEEPER.getRealPath(server.getAddress());
logger.info("[testGetActiveKeeper]{}", path);
KeeperMeta keeperMeta = restTemplate.getForObject(path, KeeperMeta.class, "cluster1", "shard1");
logger.info("[testGetActiveKeeper]{}", keeperMeta);
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class KeeperStateChangeJob method doExecute.
@Override
protected void doExecute() throws CommandExecutionException {
KeeperMeta activeKeeper = null;
for (KeeperMeta keeperMeta : keepers) {
if (keeperMeta.isActive()) {
activeKeeper = keeperMeta;
break;
}
}
if (activeKeeper == null) {
future().setFailure(new Exception("can not find active keeper:" + keepers));
}
SequenceCommandChain chain = new SequenceCommandChain(false);
if (activeKeeperMaster != null) {
Command<?> setActiveCommand = createKeeperSetStateCommand(activeKeeper, activeKeeperMaster);
addActiveCommandHook(setActiveCommand);
chain.add(setActiveCommand);
}
ParallelCommandChain backupChain = new ParallelCommandChain(executors);
for (KeeperMeta keeperMeta : keepers) {
if (!keeperMeta.isActive()) {
Command<?> backupCommand = createKeeperSetStateCommand(keeperMeta, new Pair<String, Integer>(activeKeeper.getIp(), activeKeeper.getPort()));
backupChain.add(backupCommand);
}
}
chain.add(backupChain);
chain.execute().addListener(new CommandFutureListener<Object>() {
@Override
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
future().setSuccess(null);
} else {
future().setFailure(commandFuture.cause());
}
}
});
}
Aggregations