Search in sources :

Example 1 with FullSyncListener

use of com.ctrip.xpipe.redis.core.store.FullSyncListener in project x-pipe by ctripcorp.

the class AbstractRdbDumper method tryFullSync.

@Override
public void tryFullSync(RedisSlave redisSlave) throws IOException {
    switch(rdbDumpState) {
        case DUMPING:
            FullSyncListener fullSyncListener = new DefaultFullSyncListener(redisSlave);
            if (!redisKeeperServer.getReplicationStore().fullSyncIfPossible(fullSyncListener)) {
                throw new IllegalStateException("[tryFullSync][rdb dumping, but can not full synn]");
            }
            break;
        case FAIL:
        case NORMAL:
            logger.warn("[tryFullSync]{}", redisSlave);
            redisKeeperServer.clearRdbDumper(this);
            redisKeeperServer.fullSyncToSlave(redisSlave);
            break;
        case WAIT_DUMPPING:
            logger.info("[tryFullSync][make slave waiting]{}", redisSlave);
            redisSlave.waitForRdbDumping();
            break;
    }
}
Also used : DefaultFullSyncListener(com.ctrip.xpipe.redis.keeper.store.DefaultFullSyncListener) FullSyncListener(com.ctrip.xpipe.redis.core.store.FullSyncListener) DefaultFullSyncListener(com.ctrip.xpipe.redis.keeper.store.DefaultFullSyncListener)

Example 2 with FullSyncListener

use of com.ctrip.xpipe.redis.core.store.FullSyncListener in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServer method fullSyncToSlave.

@Override
public void fullSyncToSlave(final RedisSlave redisSlave) throws IOException {
    logger.info("[fullSyncToSlave]{}, {}", redisSlave, rdbDumper.get());
    if (rdbDumper.get() == null) {
        logger.info("[fullSyncToSlave][dumper null]{}", redisSlave);
        FullSyncListener fullSyncListener = new DefaultFullSyncListener(redisSlave);
        if (!getCurrentReplicationStore().fullSyncIfPossible(fullSyncListener)) {
            // go dump rdb
            try {
                dumpNewRdb();
                redisSlave.waitForRdbDumping();
            } catch (AbstractRdbDumperException e) {
                logger.error("[fullSyncToSlave]", e);
                if (e.isCancelSlave()) {
                    logger.info("[fullSyncToSlave][cancel slave]");
                    redisSlave.close();
                }
            }
        }
    } else {
        rdbDumper.get().tryFullSync(redisSlave);
    }
}
Also used : FullSyncListener(com.ctrip.xpipe.redis.core.store.FullSyncListener) DefaultFullSyncListener(com.ctrip.xpipe.redis.keeper.store.DefaultFullSyncListener) DefaultFullSyncListener(com.ctrip.xpipe.redis.keeper.store.DefaultFullSyncListener)

Example 3 with FullSyncListener

use of com.ctrip.xpipe.redis.core.store.FullSyncListener in project x-pipe by ctripcorp.

the class DefaultReplicationStoreTest method testReadWhileDestroy.

@Test
public void testReadWhileDestroy() throws Exception {
    store = new DefaultReplicationStore(baseDir, new DefaultKeeperConfig(), randomKeeperRunid(), createkeeperMonitor());
    store.getMetaStore().becomeActive();
    int dataLen = 1000;
    RdbStore rdbStore = store.beginRdb(randomKeeperRunid(), -1, new LenEofType(dataLen));
    rdbStore.writeRdb(Unpooled.wrappedBuffer(randomString(dataLen).getBytes()));
    rdbStore.endRdb();
    CountDownLatch latch = new CountDownLatch(2);
    AtomicBoolean result = new AtomicBoolean(true);
    executors.execute(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            try {
                sleep(2);
                store.close();
                store.destroy();
            } finally {
                latch.countDown();
            }
        }
    });
    executors.execute(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            try {
                store.fullSyncIfPossible(new FullSyncListener() {

                    @Override
                    public ChannelFuture onCommand(ReferenceFileRegion referenceFileRegion) {
                        return null;
                    }

                    @Override
                    public void beforeCommand() {
                    }

                    @Override
                    public void setRdbFileInfo(EofType eofType, long rdbFileKeeperOffset) {
                    }

                    @Override
                    public void onFileData(ReferenceFileRegion referenceFileRegion) throws IOException {
                        sleep(10);
                    }

                    @Override
                    public boolean isOpen() {
                        return true;
                    }

                    @Override
                    public void exception(Exception e) {
                        logger.info("[exception][fail]" + e.getMessage());
                        result.set(false);
                    }

                    @Override
                    public void beforeFileData() {
                    }
                });
            } catch (Exception e) {
                logger.info("[exception][fail]" + e.getMessage());
                result.set(false);
            } finally {
                latch.countDown();
            }
        }
    });
    latch.await(100, TimeUnit.MILLISECONDS);
    Assert.assertFalse(result.get());
}
Also used : RdbStore(com.ctrip.xpipe.redis.core.store.RdbStore) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) EofType(com.ctrip.xpipe.redis.core.protocal.protocal.EofType) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) ReferenceFileRegion(com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FullSyncListener(com.ctrip.xpipe.redis.core.store.FullSyncListener) DefaultKeeperConfig(com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Test(org.junit.Test) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)

Aggregations

FullSyncListener (com.ctrip.xpipe.redis.core.store.FullSyncListener)3 DefaultFullSyncListener (com.ctrip.xpipe.redis.keeper.store.DefaultFullSyncListener)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 ReferenceFileRegion (com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion)1 EofType (com.ctrip.xpipe.redis.core.protocal.protocal.EofType)1 LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)1 RdbStore (com.ctrip.xpipe.redis.core.store.RdbStore)1 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)1 DefaultKeeperConfig (com.ctrip.xpipe.redis.keeper.config.DefaultKeeperConfig)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1