use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class AddKeeperCommandTest method beforeAddKeeperCommandTest.
@Before
public void beforeAddKeeperCommandTest() {
KeeperMeta keeperMeta = new KeeperMeta();
keeperMeta.setPort(keeperPort);
keeperMeta.setIp("localhost");
keeperTransMeta = new KeeperTransMeta("clusterId", "shardId", keeperMeta);
addKeeperCommand = new AddKeeperCommand(keeperContainerService, keeperTransMeta, scheduled, timeoutMilli, checkInterval);
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class DemoStarter method startKeepers.
private void startKeepers(String dc, String clusterId, String shardId, Integer index) throws Exception {
DcMeta dcMeta = getDcMeta(dc);
MetaServerKeeperService metaService = createMetaService(dcMeta.getMetaServers());
LeaderElectorManager leaderElectorManager = createLeaderElectorManager(dcMeta);
int count = 0;
for (KeeperMeta keeperMeta : getDcKeepers(dc, clusterId, shardId)) {
if (index == null || index == count) {
startKeeper(keeperMeta, metaService, leaderElectorManager);
}
count++;
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class KeeperPsync2 method testKeeperPsync2.
@Test
public void testKeeperPsync2() throws Exception {
// init
initKeepers();
sleep(2000);
assertSyncCount(redisKeeperServers);
for (int i = 0; i < testRound; i++) {
logger.info(remarkableMessage("[testRound]{}"), i);
KeeperMeta lastKeeper = new KeeperMeta().setIp(redisMaster.getIp()).setPort(redisMaster.getPort());
List<RedisKeeperServer> currentKeepers = new LinkedList<>();
for (int j = 0; j < totalKeepers; j++) {
int current = randomInt(0, redisKeeperServers.size() - 1);
RedisKeeperServer currentRedisKeeperServer = redisKeeperServers.get(current);
setKeeperState(currentRedisKeeperServer.getCurrentKeeperMeta(), KeeperState.ACTIVE, lastKeeper.getIp(), lastKeeper.getPort());
redisKeeperServers.remove(currentRedisKeeperServer);
logger.info("[testKeeperPsync2][slaveof]{}:{} slaveof {}:{}", currentRedisKeeperServer.getCurrentKeeperMeta().getIp(), currentRedisKeeperServer.getCurrentKeeperMeta().getPort(), lastKeeper.getIp(), lastKeeper.getPort());
lastKeeper = currentRedisKeeperServer.getCurrentKeeperMeta();
currentKeepers.add(currentRedisKeeperServer);
}
sendMessageToMaster(redisMaster, 10);
redisKeeperServers = currentKeepers;
sleep(2000);
assertSyncCount(redisKeeperServers);
assertCommandsEquals(redisKeeperServers);
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class KeeperPsync2 method initKeepers.
private void initKeepers() throws Exception {
redisKeeperServers.add(getRedisKeeperServer(activeKeeper));
redisKeeperServers.add(getRedisKeeperServer(backupKeeper));
setKeeperState(backupKeeper, KeeperState.ACTIVE, activeKeeper.getIp(), activeKeeper.getPort());
KeeperMeta lastKeeper = backupKeeper;
List<KeeperMeta> keeperMetas = new LinkedList<>();
int portStart = Math.max(activeKeeper.getPort(), backupKeeper.getPort());
for (int i = 0; i < totalKeepers - redisKeeperServers.size(); i++) {
KeeperMeta keeperMeta = new KeeperMeta().setIp("localhost").setPort(++portStart);
keeperMeta.setParent(activeKeeper.parent());
keeperMetas.add(keeperMeta);
}
for (KeeperMeta keeperMeta : keeperMetas) {
RedisKeeperServer redisKeeperServer = startKeeper(keeperMeta);
setKeeperState(keeperMeta, KeeperState.ACTIVE, lastKeeper.getIp(), lastKeeper.getPort());
logger.info("[initKeepers][slaveof]{}:{} slaveof {}:{}", keeperMeta.getIp(), keeperMeta.getPort(), lastKeeper.getIp(), lastKeeper.getPort());
redisKeeperServers.add(redisKeeperServer);
lastKeeper = keeperMeta;
}
}
use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.
the class KeeperSingleDc method testBackupActiveChangeManyTimes.
@Test
public void testBackupActiveChangeManyTimes() throws Exception {
for (int i = 0; i < 3; i++) {
logger.info(remarkableMessage("------{}-------"), i);
// exchange role
// make backup active
logger.info(remarkableMessage("make keeper active {}:{}"), backupKeeper.getIp(), backupKeeper.getPort());
setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
// make active backup
logger.info(remarkableMessage("make keeper backup {}:{}"), activeKeeper.getIp(), activeKeeper.getPort());
setKeeperState(activeKeeper, KeeperState.BACKUP, backupKeeper.getIp(), backupKeeper.getPort());
sleep(2000);
Assert.assertEquals(KeeperState.ACTIVE, getKeeperState(backupKeeper));
Assert.assertEquals(KeeperState.BACKUP, getKeeperState(activeKeeper));
KeeperMeta tmp = backupKeeper;
backupKeeper = activeKeeper;
activeKeeper = tmp;
}
}
Aggregations