use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class RoleCommandHandler method doHandle.
@Override
protected void doHandle(String[] args, RedisClient redisClient) {
RedisKeeperServer redisKeeperServer = redisClient.getRedisKeeperServer();
ReplicationStore replicationStore = redisKeeperServer.getReplicationStore();
RedisMaster redisMaster = redisKeeperServer.getRedisMaster();
Endpoint masterEndPoint = null;
if (redisMaster != null) {
masterEndPoint = redisMaster.masterEndPoint();
}
Object[] result = new Object[5];
result[0] = redisKeeperServer.role().toString();
result[1] = masterEndPoint == null ? "0.0.0.0" : masterEndPoint.getHost();
result[2] = masterEndPoint == null ? "0" : masterEndPoint.getPort();
result[3] = redisMaster == null ? MASTER_STATE.REDIS_REPL_NONE.getDesc() : redisMaster.getMasterState().getDesc();
result[4] = replicationStore == null ? -1L : replicationStore.getEndOffset();
redisClient.sendMessage(ParserManager.parse(result));
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperContainerService method createRedisKeeperServer.
private RedisKeeperServer createRedisKeeperServer(KeeperMeta keeper, File baseDir, MetaServerKeeperService metaService) throws Exception {
RedisKeeperServer redisKeeperServer = new DefaultRedisKeeperServer(keeper, keeperConfig, baseDir, metaService, leaderElectorManager, keepersMonitorManager);
register(redisKeeperServer);
return redisKeeperServer;
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperContainerService method start.
public void start(String clusterId, String shardId) {
String keeperServerKey = assembleKeeperServerKey(clusterId, shardId);
RedisKeeperServer keeperServer = redisKeeperServers.get(keeperServerKey);
if (keeperServer == null) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_NOT_EXIST, String.format("Start keeper for cluster %s shard %s failed since keeper doesn't exist", clusterId, shardId)), null);
}
if (keeperServer.getLifecycleState().isStarted()) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_STARTED, String.format("Keeper for cluster %s shard %s already started", clusterId, shardId)), null);
}
try {
keeperServer.start();
} catch (Throwable ex) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Start keeper failed for cluster %s shard %s", clusterId, shardId)), ex);
}
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.
the class KeeperContainerService method add.
public RedisKeeperServer add(KeeperTransMeta keeperTransMeta) {
KeeperMeta keeperMeta = keeperTransMeta.getKeeperMeta();
enrichKeeperMetaFromKeeperTransMeta(keeperMeta, keeperTransMeta);
String keeperServerKey = assembleKeeperServerKey(keeperTransMeta);
if (!redisKeeperServers.containsKey(keeperServerKey)) {
synchronized (this) {
if (!redisKeeperServers.containsKey(keeperServerKey)) {
if (runningPorts.contains(keeperMeta.getPort())) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Add keeper for cluster %s shard %s failed since port %d is already used", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId(), keeperMeta.getPort())), null);
}
try {
RedisKeeperServer redisKeeperServer = doAdd(keeperTransMeta, keeperMeta);
cacheKeeper(keeperServerKey, redisKeeperServer);
return redisKeeperServer;
} catch (Throwable ex) {
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Add keeper for cluster %s shard %s failed", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), ex);
}
}
}
}
throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Keeper already exists for cluster %s shard %s", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), null);
}
use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer 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);
}
}
Aggregations