use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class KeeperSingleDc method createSlave.
private RedisMeta createSlave(String masterIp, Integer masterPort) {
RedisMeta slave = new RedisMeta();
slave.setMaster(String.format("%s:%d", masterIp, masterPort));
slave.setPort(randomPort());
return slave;
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class KeeperMultiDcChangePrimary method testChangePrimary.
@Test
public void testChangePrimary() throws Exception {
String primaryDc = getPrimaryDc();
String backupDc = getBackupDc();
// change backup to primary
when(dcMetaCache.getShardRedises(getClusterId(), getShardId())).thenReturn(getDcRedises(backupDc, getClusterId(), getShardId()));
when(currentMetaManager.getSurviveKeepers(getClusterId(), getShardId())).thenReturn(getDcKeepers(backupDc, getClusterId(), getShardId()));
logger.info(remarkableMessage("[make dc primary]change dc primary to:" + backupDc));
BecomePrimaryAction becomePrimaryAction = new BecomePrimaryAction(dcMetaCache, currentMetaManager, sentinelManager, offsetWaiter, new ExecutionLog(currentTestName()), getXpipeNettyClientKeyedObjectPool(), newMasterChooser, scheduled, executors);
PrimaryDcChangeMessage message = becomePrimaryAction.changePrimaryDc(getClusterId(), getShardId(), backupDc, new MasterInfo());
logger.info("{}", message);
sleep(2000);
logger.info(remarkableMessage("[make dc backup]change dc primary to:" + backupDc));
when(dcMetaCache.getPrimaryDc(getClusterId(), getShardId())).thenReturn(backupDc);
when(multiDcService.getActiveKeeper(backupDc, getClusterId(), getShardId())).thenReturn(getDcKeepers(backupDc, getClusterId(), getShardId()).get(0));
when(dcMetaCache.getShardRedises(getClusterId(), getShardId())).thenReturn(getDcRedises(primaryDc, getClusterId(), getShardId()));
when(currentMetaManager.getKeeperActive(getClusterId(), getShardId())).thenReturn(getKeeperActive(primaryDc));
when(currentMetaManager.getSurviveKeepers(getClusterId(), getShardId())).thenReturn(getDcKeepers(primaryDc, getClusterId(), getShardId()));
BecomeBackupAction becomeBackupAction = new BecomeBackupAction(dcMetaCache, currentMetaManager, sentinelManager, new ExecutionLog(currentTestName()), getXpipeNettyClientKeyedObjectPool(), multiDcService, scheduled, executors);
message = becomeBackupAction.changePrimaryDc(getClusterId(), getShardId(), backupDc, new MasterInfo());
logger.info("{}", message);
sleep(2000);
RedisMeta newRedisMaster = newMasterChooser.getLastChoosenMaster();
List<RedisMeta> allRedises = getRedises(primaryDc);
allRedises.addAll(getRedises(backupDc));
allRedises.remove(newRedisMaster);
logger.info("{}\n{}", newRedisMaster, allRedises);
sendMesssageToMasterAndTest(newRedisMaster, allRedises);
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class KeeperPsync2Continue method testExchangeMasterSlave.
@Test
public void testExchangeMasterSlave() throws Exception {
RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
int slaveChosen = 0;
long fullSyncCount = redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount();
for (int i = 0; i < testRound; i++) {
logger.info(remarkableMessage("round:{}"), i);
RedisMeta slaveToPromote = slaves.get(0);
xslaveof(activeKeeper.getIp(), activeKeeper.getPort(), redisMaster);
xslaveof(null, 0, slaveToPromote);
setKeeperState(activeKeeper, KeeperState.ACTIVE, slaveToPromote.getIp(), slaveToPromote.getPort());
sleep(3000);
Assert.assertEquals(fullSyncCount, redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount());
RedisMeta tmpRedisMaster = redisMaster;
redisMaster = slaveToPromote;
slaves.remove(slaveChosen);
slaves.add(0, tmpRedisMaster);
}
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class XRedisXpipeCommandTest method testReplall.
@Test
public void testReplall() throws IOException {
RedisMeta redis = new RedisMeta().setIp("127.0.0.1").setPort(6379);
RedisMeta redisSlave = new RedisMeta().setIp("127.0.0.1").setPort(6479);
RedisMeta redisSlaveSlave = new RedisMeta().setIp("127.0.0.1").setPort(6579);
startRedis(redis);
startRedis(redisSlave, redis);
startRedis(redisSlaveSlave, redisSlave);
Jedis jedisSlave = createJedis(redisSlave);
Jedis jedisSlaveSlave = createJedis(redisSlaveSlave);
jedisSlave.configSet("slave-read-only", "no");
assertReplicate(jedisSlave, false, jedisSlaveSlave);
jedisSlave.configSet("slave-repl-all", "yes");
assertReplicate(jedisSlave, true, jedisSlaveSlave);
jedisSlave.configSet("slave-repl-all", "no");
assertReplicate(jedisSlave, false, jedisSlaveSlave);
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class XRedisXpipeCommandTest method testRefullsync.
@Test
public void testRefullsync() throws Exception {
RedisMeta redis = new RedisMeta().setIp("127.0.0.1").setPort(6379);
RedisMeta redisSlave = new RedisMeta().setIp("127.0.0.1").setPort(6479);
startRedis(redis);
startRedis(redisSlave, redis);
Integer beforeFullSync = getSyncFull(redis);
String result = new RefullSync(redis.getIp(), redis.getPort(), scheduled).execute().get(1, TimeUnit.SECONDS);
sleep(1500);
Integer afterFullSync = getSyncFull(redis);
Assert.assertEquals(beforeFullSync + 1, afterFullSync.intValue());
sendMesssageToMasterAndTest(redis, Lists.newArrayList(redisSlave));
}
Aggregations