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();
}
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();
}
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);
}
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));
}
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();
}
Aggregations