Search in sources :

Example 6 with ReplicationStore

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

the class DefaultReplicationStoreManager method create.

@Override
public synchronized ReplicationStore create() throws IOException {
    if (!getLifecycleState().isInitialized()) {
        throw new ReplicationStoreManagerStateException("can not create", toString(), getLifecycleState().getPhaseName());
    }
    keeperMonitor.getReplicationStoreStats().increateReplicationStoreCreateCount();
    File storeBaseDir = new File(baseDir, UUID.randomUUID().toString());
    storeBaseDir.mkdirs();
    logger.info("[create]{}", storeBaseDir);
    recrodLatestStore(storeBaseDir.getName());
    ReplicationStore replicationStore = new DefaultReplicationStore(storeBaseDir, keeperConfig, keeperRunid, keeperMonitor);
    closeCurrentStore();
    currentStore.set(replicationStore);
    notifyObservers(new NodeAdded<ReplicationStore>(replicationStore));
    return currentStore.get();
}
Also used : ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore)

Example 7 with ReplicationStore

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

the class AbstractRedisKeeperServerState method doBecomeActive.

protected void doBecomeActive(InetSocketAddress masterAddress) {
    logger.info("[doBecomeActive]{}", this);
    try {
        ReplicationStore replicationStore = redisKeeperServer.getReplicationStore();
        replicationStore.getMetaStore().becomeActive();
    } catch (Exception e) {
        logger.error("[doBecomeActive]" + this + "," + masterAddress, e);
    }
    redisKeeperServer.setRedisKeeperServerState(new RedisKeeperServerStateActive(redisKeeperServer, masterAddress));
    reconnectMaster();
}
Also used : ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore) IOException(java.io.IOException)

Example 8 with ReplicationStore

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

the class PsyncHandler method waitForoffset.

protected void waitForoffset(final String[] args, final RedisSlave redisSlave, String replId, final Long offsetRequest) {
    try {
        ReplicationStore replicationStore = redisSlave.getRedisKeeperServer().getReplicationStore();
        logger.info("[waitForoffset][begin wait]{}", redisSlave);
        boolean result = replicationStore.awaitCommandsOffset(offsetRequest - replicationStore.beginOffsetWhenCreated() - 1, WAIT_OFFSET_TIME_MILLI);
        if (result) {
            logger.info("[waitForoffset][wait succeed]{}", redisSlave);
            redisSlave.getRedisKeeperServer().getKeeperMonitor().getKeeperStats().increaseWaitOffsetSucceed();
            doPartialSync(redisSlave, replId, offsetRequest);
            return;
        }
    } catch (InterruptedException e) {
        logger.error("[waitForoffset]" + redisSlave, e);
    } catch (Exception e) {
        logger.error("[waitForoffset][failed]", e);
        try {
            redisSlave.close();
        } catch (IOException e1) {
            logger.error("[waitForoffset][close slave]" + redisSlave, e);
        }
        return;
    }
    logger.info("[run][offset wait failed]{}", redisSlave);
    redisSlave.getRedisKeeperServer().getKeeperMonitor().getKeeperStats().increasWaitOffsetFail();
    redisSlave.getRedisKeeperServer().getKeeperMonitor().getKeeperStats().increatePartialSyncError();
    doFullSync(redisSlave);
}
Also used : IOException(java.io.IOException) ReplicationStore(com.ctrip.xpipe.redis.core.store.ReplicationStore) IOException(java.io.IOException)

Example 9 with ReplicationStore

use of com.ctrip.xpipe.redis.core.store.ReplicationStore 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 10 with ReplicationStore

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

the class DefaultReplicationStoreManager method getCurrent.

@Override
public synchronized ReplicationStore getCurrent() throws IOException {
    if (currentStore.get() == null) {
        Properties meta = currentMeta();
        if (meta != null) {
            if (meta.getProperty(LATEST_STORE_DIR) != null) {
                File latestStoreDir = new File(baseDir, meta.getProperty(LATEST_STORE_DIR));
                logger.info("[getCurrent][latest]{}", latestStoreDir);
                if (latestStoreDir.isDirectory()) {
                    currentStore.set(new DefaultReplicationStore(latestStoreDir, keeperConfig, keeperRunid, keeperMonitor));
                }
            }
        }
    }
    ReplicationStore replicationStore = currentStore.get();
    if (replicationStore != null && !replicationStore.checkOk()) {
        logger.info("[getCurrent][store not ok, return null]{}", replicationStore);
        return null;
    }
    return currentStore.get();
}
Also used : Properties(java.util.Properties) 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