Search in sources :

Example 1 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class AbstractFakeRedisTest method sendInmemoryPsync.

protected InMemoryPsync sendInmemoryPsync(String ip, int port, String runid, long offset) throws Exception {
    SequenceCommandChain chain = new SequenceCommandChain(false);
    SimpleObjectPool<NettyClient> pool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(ip, port));
    NettyClient nettyClient = null;
    try {
        nettyClient = pool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        chain.add(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString()));
        InMemoryPsync psync = new InMemoryPsync(clientPool, runid, offset, scheduled);
        chain.add(psync);
        psync.addPsyncObserver(new PsyncObserver() {

            private long masterRdbOffset = 0;

            @Override
            public void reFullSync() {
            }

            @Override
            public void onFullSync() {
            }

            @Override
            public void onContinue(String requestReplId, String responseReplId) {
            }

            @Override
            public void endWriteRdb() {
                new Replconf(clientPool, ReplConfType.ACK, scheduled, String.valueOf(masterRdbOffset)).execute();
            }

            @Override
            public void beginWriteRdb(EofType eofType, long masterRdbOffset) throws IOException {
                this.masterRdbOffset = masterRdbOffset;
            }
        });
        chain.execute();
        return psync;
    } finally {
        if (nettyClient != null) {
            pool.returnObject(nettyClient);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) EofType(com.ctrip.xpipe.redis.core.protocal.protocal.EofType) IOException(java.io.IOException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) PsyncObserver(com.ctrip.xpipe.redis.core.protocal.PsyncObserver)

Example 2 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class ReplconfTest method test.

@Test
public void test() throws Exception {
    for (int i = 0; i < 100; i++) {
        FixedObjectPool<NettyClient> clientPool = null;
        try {
            clientPool = createClientPool(host, port);
            Replconf replconf = new Replconf(clientPool, ReplConfType.LISTENING_PORT, scheduled, String.valueOf(1234));
            replconf.execute().addListener(new CommandFutureListener<Object>() {

                @Override
                public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
                    logger.info("{}", commandFuture.get());
                }
            });
            Psync psync = new InMemoryPsync(clientPool, "?", -1L, scheduled);
            try {
                psync.execute().get(100, TimeUnit.MILLISECONDS);
                Assert.fail();
            } catch (TimeoutException e) {
            }
        } finally {
            if (clientPool != null) {
                clientPool.getObject().channel().close();
            }
        }
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) Psync(com.ctrip.xpipe.redis.core.protocal.Psync) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 3 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServerConnectToFakeRedisTest method startKeeperServerAndTestReFullSync.

private void startKeeperServerAndTestReFullSync(int fileToKeep, int maxTransferCommnadsSize) throws Exception {
    RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis(fileToKeep, maxTransferCommnadsSize, 1000);
    int keeperPort = redisKeeperServer.getListeningPort();
    sleep(2000);
    logger.info(remarkableMessage("send psync to redump rdb"));
    int rdbDumpCount1 = ((DefaultReplicationStore) redisKeeperServer.getReplicationStore()).getRdbUpdateCount();
    InMemoryPsync psync = sendInmemoryPsync("localhost", keeperPort);
    sleep(3000);
    int rdbDumpCount2 = ((DefaultReplicationStore) redisKeeperServer.getReplicationStore()).getRdbUpdateCount();
    Assert.assertEquals(rdbDumpCount1 + 1, rdbDumpCount2);
    assertPsyncResultEquals(psync);
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) DefaultReplicationStore(com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)

Example 4 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServerConnectToFakeRedisTest method testDumpWhileWaitForRdb.

@Test
public void testDumpWhileWaitForRdb() throws Exception {
    int sleepBeforeSendRdb = 2000;
    fakeRedisServer.setSleepBeforeSendRdb(sleepBeforeSendRdb);
    RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis(100, allCommandsSize);
    sleep(sleepBeforeSendRdb / 4);
    int rdbDumpCount1 = ((DefaultRedisKeeperServer) redisKeeperServer).getRdbDumpTryCount();
    Assert.assertEquals(1, rdbDumpCount1);
    int keeperPort = redisKeeperServer.getListeningPort();
    logger.info(remarkableMessage("send psync to keeper port:{}"), keeperPort);
    InMemoryPsync psync = sendInmemoryPsync("localhost", keeperPort, "?", -1L);
    sleep(1000);
    int rdbDumpCount2 = ((DefaultRedisKeeperServer) redisKeeperServer).getRdbDumpTryCount();
    Assert.assertEquals(1, rdbDumpCount2);
    sleep(sleepBeforeSendRdb);
    assertPsyncResultEquals(psync);
}
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) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) Test(org.junit.Test)

Example 5 with InMemoryPsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync in project x-pipe by ctripcorp.

the class FakeRedisHalfRdbServerFail method redisFailKeeperRestartDumpNewRdb.

@Test
public void redisFailKeeperRestartDumpNewRdb() throws Exception {
    sleep(sleepBeforeSendFullSyncInfo + 1000);
    redisKeeperServer.stop();
    redisKeeperServer.dispose();
    redisKeeperServer.initialize();
    redisKeeperServer.start();
    connectToFakeRedis(redisKeeperServer);
    waitUntilRedisMasterConnected(redisKeeperServer);
    sleep(1000);
    InMemoryPsync inMemoryPsync = sendInmemoryPsync("localhost", redisKeeperServer.getListeningPort());
    sleep(1500);
    assertPsyncResultEquals(inMemoryPsync);
    Assert.assertEquals(1, redisKeeperServer.getKeeperMonitor().getReplicationStoreStats().getReplicationStoreCreateCount());
}
Also used : InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) Test(org.junit.Test)

Aggregations

InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)7 Test (org.junit.Test)5 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)3 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)3 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)2 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)1 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)1 Psync (com.ctrip.xpipe.redis.core.protocal.Psync)1 PsyncObserver (com.ctrip.xpipe.redis.core.protocal.PsyncObserver)1 EofType (com.ctrip.xpipe.redis.core.protocal.protocal.EofType)1 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 TimeoutException (java.util.concurrent.TimeoutException)1