use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperSingleDcSlaveof method testSlaveofBackup.
@Test
public void testSlaveofBackup() throws Exception {
sendMessageToMasterAndTestSlaveRedis();
// test backupKeeper partial sync
RedisKeeperServer backupKeeperServer = getRedisKeeperServer(backupKeeper);
Set<RedisSlave> currentSlaves = backupKeeperServer.slaves();
Assert.assertEquals(0, currentSlaves.size());
logger.info(remarkableMessage("make slave slaves slaveof backup keeper"));
new XSlaveofJob(slaves, backupKeeper.getIp(), backupKeeper.getPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors).execute();
logger.info(remarkableMessage("make backup keeper active"));
// make backup active
setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
sleep(1000);
currentSlaves = backupKeeperServer.slaves();
Assert.assertEquals(slaves.size(), currentSlaves.size());
for (RedisSlave redisSlave : currentSlaves) {
Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisSlave.partialState());
}
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class XRedisPartialTest method testContinueWhenKeeperRefusedConnectionWhenAnsweringPsyncCommand.
@Test
public void testContinueWhenKeeperRefusedConnectionWhenAnsweringPsyncCommand() throws Exception {
RedisMeta slaveMeta = getRedisSlaves().get(0);
String xRedisVersion = getXRedisVersion(slaveMeta);
if (!VersionUtils.ge(xRedisVersion, versionCheckContinueMin)) {
logger.info("do not check xredis version below than {}", versionCheckContinueMin);
return;
}
RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
int backlogActiveCount = getBackLogActiveCount(slaveMeta);
Assert.assertEquals(1, backlogActiveCount);
Jedis slaveJedis = createJedis(slaveMeta);
String slaveof = slaveJedis.slaveof("127.0.0.1", randomPort());
sleep(1100);
slaveJedis.slaveof("127.0.0.1", activeKeeper.getPort());
sleep(1100);
backlogActiveCount = getBackLogActiveCount(slaveMeta);
logger.info("[getBackLogActiveCount]{}", backlogActiveCount);
Assert.assertEquals(1, backlogActiveCount);
// be sure slave can accpet partial sync
Jedis master = createJedis(redisMaster);
master.slaveof("127.0.0.1", 0);
int syncFull1 = Integer.parseInt(getInfoKey(slaveMeta, "stats", "sync_full"));
int syncPartialOk1 = Integer.parseInt(getInfoKey(slaveMeta, "stats", "sync_partial_ok"));
logger.info("{}, {}", syncFull1, syncPartialOk1);
slaveJedis.slaveofNoOne();
master.slaveof(slaveMeta.getIp(), slaveMeta.getPort());
sleep(1200);
int syncFull2 = Integer.parseInt(getInfoKey(slaveMeta, "stats", "sync_full"));
int syncPartialOk2 = Integer.parseInt(getInfoKey(slaveMeta, "stats", "sync_partial_ok"));
logger.info("{}, {}", syncFull2, syncPartialOk2);
Assert.assertEquals(syncFull1, syncFull2);
Assert.assertEquals(syncPartialOk1 + 1, syncPartialOk2);
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperSingleDcWipeOutData method testWipeOutSlaveDataAndRestart.
@Test
public void testWipeOutSlaveDataAndRestart() throws Exception {
sendMessageToMasterAndTestSlaveRedis(10000);
RedisKeeperServer slave = getRedisKeeperServer(backupKeeper);
// clean slave
slave.stop();
slave.dispose();
slave.destroy();
remove(slave);
//
startKeeper(backupKeeper);
setKeeperState(backupKeeper, KeeperState.BACKUP, activeKeeper.getIp(), activeKeeper.getPort());
RedisKeeperServer newSlave = getRedisKeeperServer(backupKeeper);
// wait for slave to synchronize with master
sleep(3000);
Assert.assertEquals(PARTIAL_STATE.FULL, newSlave.getRedisMaster().partialState());
setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
sleep(3000);
// should be partial
Assert.assertEquals(PARTIAL_STATE.PARTIAL, newSlave.getRedisMaster().partialState());
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class OneDcKeepers method killActive.
@Test
public void killActive() throws Exception {
RedisMeta redisMaster = getRedisMaster();
sendMessageToMasterAndTestSlaveRedis();
System.out.println("press any key to make back keeper active");
waitForAnyKey();
KeeperMeta backupKeeper = getKeepersBackup().get(0);
RedisKeeperServer redisKeeperServer = getRedisKeeperServer(backupKeeper);
Assert.assertEquals(PARTIAL_STATE.FULL, redisKeeperServer.getRedisMaster().partialState());
logger.info(remarkableMessage("make keeper active{}"), backupKeeper);
setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
waitForAnyKeyToExit();
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class AbstractIntegratedTest method startKeeper.
protected RedisKeeperServer startKeeper(KeeperMeta keeperMeta, KeeperConfig keeperConfig, MetaServerKeeperService metaService, LeaderElectorManager leaderElectorManager) throws Exception {
logger.info(remarkableMessage("[startKeeper]{}, {}"), keeperMeta);
File baseDir = new File(getTestFileDir() + "/replication_store_" + keeperMeta.getPort());
RedisKeeperServer redisKeeperServer = createRedisKeeperServer(keeperMeta, baseDir, keeperConfig, metaService, leaderElectorManager, new NoneKeepersMonitorManager());
add(redisKeeperServer);
return redisKeeperServer;
}
Aggregations