Search in sources :

Example 26 with RedisKeeperServer

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));
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Endpoint(com.ctrip.xpipe.api.endpoint.Endpoint) ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore) RedisMaster(com.ctrip.xpipe.redis.keeper.RedisMaster)

Example 27 with RedisKeeperServer

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;
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer)

Example 28 with 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);
    }
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) ErrorMessage(com.ctrip.xpipe.exception.ErrorMessage)

Example 29 with RedisKeeperServer

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);
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) ErrorMessage(com.ctrip.xpipe.exception.ErrorMessage) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 30 with RedisKeeperServer

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);
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)44 Test (org.junit.Test)23 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)13 RedisSlave (com.ctrip.xpipe.redis.keeper.RedisSlave)6 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)5 ErrorMessage (com.ctrip.xpipe.exception.ErrorMessage)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)4 RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)4 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)4 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)3 RedisErrorParser (com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)3 LinkedList (java.util.LinkedList)3 ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)2 XSlaveofJob (com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob)2 IOException (java.io.IOException)2 Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)1 PARTIAL_STATE (com.ctrip.xpipe.api.server.PARTIAL_STATE)1 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 NoMasterlinkRedisError (com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)1