Search in sources :

Example 1 with ReplicationStore

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

the class DefaultPsync method doWhenFullSyncToNonFreshReplicationStore.

@Override
protected void doWhenFullSyncToNonFreshReplicationStore(String replId) throws IOException {
    ReplicationStore oldStore = currentReplicationStore;
    if (oldStore != null) {
        try {
            logger.info("[doWhenFullSyncToNonFreshReplicationStore][full sync][replication store out of time, destroy]{}, {}", this, currentReplicationStore);
            oldStore.close();
        } catch (Exception e) {
            logger.error("[handleRedisReponse]" + oldStore, e);
        }
        notifyReFullSync();
    }
    logger.info("[doWhenFullSyncToNonFreshReplicationStore][set keepermeta]{}", replId);
    currentReplicationStore = createReplicationStore();
}
Also used : ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore) IOException(java.io.IOException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException)

Example 2 with ReplicationStore

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

the class DefaultReplicationStoreManagerTest method test.

@Test
public void test() throws Exception {
    String keeperRunid = randomKeeperRunid();
    File baseDir = new File(getTestFileDir());
    String clusterId = "cluster1";
    String shardId = "shard1";
    DefaultReplicationStoreManager mgr = (DefaultReplicationStoreManager) createReplicationStoreManager(clusterId, shardId, keeperRunid, baseDir);
    LifecycleHelper.initializeIfPossible(mgr);
    ReplicationStore currentStore = mgr.getCurrent();
    assertNull(currentStore);
    currentStore = mgr.create();
    assertEquals(clusterId, mgr.getClusterName());
    assertEquals(shardId, mgr.getShardName());
    assertEquals(currentStore, mgr.getCurrent());
    DefaultReplicationStore newCurrentStore = (DefaultReplicationStore) mgr.create();
    assertEquals(newCurrentStore, mgr.getCurrent());
    assertNotEquals(currentStore, mgr.getCurrent());
    MetaStore metaStore = newCurrentStore.getMetaStore();
    metaStore.setMasterAddress(new DefaultEndPoint("redis://127.0.0.1:6379"));
    newCurrentStore.beginRdb("masterRunid", 0, new LenEofType(100));
    ByteBuf cmdBuf = Unpooled.buffer();
    cmdBuf.writeByte(9);
    newCurrentStore.getCommandStore().appendCommands(cmdBuf);
    DefaultReplicationStoreManager mgr2 = (DefaultReplicationStoreManager) createReplicationStoreManager(clusterId, shardId, keeperRunid, baseDir);
    assertEquals(metaStore.getReplId(), mgr2.getCurrent().getMetaStore().getReplId());
    assertEquals(metaStore.beginOffset(), mgr2.getCurrent().getMetaStore().beginOffset());
    assertEquals(metaStore.getMasterAddress(), mgr2.getCurrent().getMetaStore().getMasterAddress());
    assertEquals(metaStore.beginOffset(), mgr2.getCurrent().getMetaStore().beginOffset());
}
Also used : MetaStore(com.ctrip.xpipe.redis.core.store.MetaStore) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) LenEofType(com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType) ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore) ByteBuf(io.netty.buffer.ByteBuf) File(java.io.File) Test(org.junit.Test) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)

Example 3 with ReplicationStore

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

the class DefaultRedisKeeperServer method initKeeperServerState.

private RedisKeeperServerState initKeeperServerState() {
    try {
        ReplicationStore replicationStore = replicationStoreManager.getCurrent();
        if (replicationStore == null) {
            return new RedisKeeperServerStateUnknown(this);
        }
        KeeperState keeperState = replicationStore.getMetaStore().dupReplicationStoreMeta().getKeeperState();
        if (keeperState == null) {
            logger.warn("[initKeeperServerState][keeperState null]");
            return new RedisKeeperServerStateUnknown(this);
        }
        RedisKeeperServerState redisKeeperServerState = null;
        switch(keeperState) {
            case ACTIVE:
                redisKeeperServerState = new RedisKeeperServerStatePreActive(this);
                break;
            case BACKUP:
                redisKeeperServerState = new RedisKeeperServerStatePreBackup(this);
                break;
            case UNKNOWN:
                redisKeeperServerState = new RedisKeeperServerStateUnknown(this);
                break;
            // wrong store state
            case PRE_ACTIVE:
            case PRE_BACKUP:
            default:
                logger.warn("[initKeeperServerState][error state]{}", keeperState);
                redisKeeperServerState = new RedisKeeperServerStateUnknown(this);
                break;
        }
        return redisKeeperServerState;
    } catch (Exception e) {
        logger.error("[initKeeperServerState]" + this, e);
    }
    return new RedisKeeperServerStateUnknown(this);
}
Also used : ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore) KeeperState(com.ctrip.xpipe.redis.core.meta.KeeperState) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException) IOException(java.io.IOException)

Example 4 with ReplicationStore

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

the class DefaultReplicationStoreManager method closeCurrentStore.

private void closeCurrentStore() {
    logger.info("[closeCurrentStore]{}", this);
    ReplicationStore replicationStore = currentStore.get();
    if (replicationStore != null) {
        try {
            replicationStore.close();
            currentStore.set(null);
        } catch (IOException e) {
            logger.info("[close]" + replicationStore, e);
        }
    }
}
Also used : ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore)

Example 5 with ReplicationStore

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

the class DefaultReplicationStoreManager method createIfNotExist.

@Override
public synchronized ReplicationStore createIfNotExist() throws IOException {
    ReplicationStore currentReplicationStore = null;
    try {
        currentReplicationStore = getCurrent();
    } catch (Exception e) {
        logger.error("[createIfNotExist]" + baseDir, e);
    }
    if (currentReplicationStore == null) {
        logger.info("[createIfNotExist]{}", baseDir);
        currentReplicationStore = create();
    }
    return currentReplicationStore;
}
Also used : ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore)

Aggregations

ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)15 IOException (java.io.IOException)4 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)2 MetaStore (com.ctrip.xpipe.redis.core.store.MetaStore)2 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)1 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)1 KeeperState (com.ctrip.xpipe.redis.core.meta.KeeperState)1 LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)1 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)1 RedisMaster (com.ctrip.xpipe.redis.keeper.RedisMaster)1 RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)1 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)1 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)1 ByteBuf (io.netty.buffer.ByteBuf)1 File (java.io.File)1 Date (java.util.Date)1