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