Search in sources :

Example 11 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperContainerService method addOrStart.

public RedisKeeperServer addOrStart(KeeperTransMeta keeperTransMeta) {
    String keeperServerKey = assembleKeeperServerKey(keeperTransMeta);
    RedisKeeperServer keeperServer = redisKeeperServers.get(keeperServerKey);
    if (keeperServer == null) {
        return add(keeperTransMeta);
    }
    start(keeperTransMeta.getClusterId(), keeperTransMeta.getShardId());
    return keeperServer;
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer)

Example 12 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class KeeperContainerService method remove.

public void remove(String clusterId, String shardId) {
    String keeperServerKey = assembleKeeperServerKey(clusterId, shardId);
    RedisKeeperServer keeperServer = redisKeeperServers.get(keeperServerKey);
    if (keeperServer == null) {
        return;
    }
    try {
        // 1. stop and dispose keeper server
        deRegister(keeperServer);
        // 2. remove keeper
        removeKeeperCache(keeperServerKey);
        // 3. clean external resources, such as replication stores
        keeperServer.destroy();
    } catch (Throwable ex) {
        throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Remove 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 13 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class AbstractFakeRedisTest method startRedisKeeperServerAndConnectToFakeRedis.

protected RedisKeeperServer startRedisKeeperServerAndConnectToFakeRedis(int replicationStoreCommandFileNumToKeep, int replicationStoreMaxCommandsToTransferBeforeCreateRdb, int minTimeMilliToGcAfterCreate) throws Exception {
    RedisKeeperServer redisKeeperServer = startRedisKeeperServer(replicationStoreCommandFileNumToKeep, replicationStoreMaxCommandsToTransferBeforeCreateRdb, 1000);
    connectToFakeRedis(redisKeeperServer);
    return redisKeeperServer;
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer)

Example 14 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class FakeRedisExceptionTest method testRdbFileError.

@Test
public void testRdbFileError() throws Exception {
    RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis();
    countDownLatch.await(10, TimeUnit.SECONDS);
    RdbStore rdbStore = ((DefaultReplicationStore) redisKeeperServer.getReplicationStore()).getRdbStore();
    Assert.assertFalse(rdbStore.checkOk());
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RdbStore(com.ctrip.xpipe.redis.core.store.RdbStore) DefaultReplicationStore(com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore) Test(org.junit.Test)

Example 15 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer in project x-pipe by ctripcorp.

the class FakeRedisRdbDumpLong method testRedisNoLf.

@Test
public void testRedisNoLf() throws Exception {
    int sleepBeforeSendRdb = replicationTimeoutMilli * 3;
    fakeRedisServer.setSleepBeforeSendRdb(sleepBeforeSendRdb);
    fakeRedisServer.setSendLFBeforeSendRdb(false);
    RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis();
    sleep(replicationTimeoutMilli * 3);
    Assert.assertEquals(MASTER_STATE.REDIS_REPL_HANDSHAKE, redisKeeperServer.getRedisMaster().getMasterState());
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) 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