use of com.ctrip.xpipe.redis.core.meta.KeeperState 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.meta.KeeperState in project x-pipe by ctripcorp.
the class KeeperCommandHandler method doHandle.
@Override
protected void doHandle(String[] args, RedisClient redisClient) {
if (args.length >= 1) {
if (args[0].equalsIgnoreCase(AbstractKeeperCommand.GET_STATE)) {
KeeperState keeperState = redisClient.getRedisKeeperServer().getRedisKeeperServerState().keeperState();
redisClient.sendMessage(new SimpleStringParser(keeperState.toString()).format());
} else if (args[0].equalsIgnoreCase(AbstractKeeperCommand.SET_STATE)) {
if (args.length >= 4) {
KeeperState keeperState = KeeperState.valueOf(args[1]);
InetSocketAddress masterAddress = new InetSocketAddress(args[2], Integer.parseInt(args[3]));
doSetKeeperState(redisClient, keeperState, masterAddress);
} else {
throw new IllegalArgumentException("setstate argument error:" + StringUtil.join(" ", args));
}
} else {
throw new IllegalStateException("unknown command:" + args[0]);
}
}
}
use of com.ctrip.xpipe.redis.core.meta.KeeperState in project x-pipe by ctripcorp.
the class DefaultRedisKeeperServer method initReplicationStore.
public synchronized void initReplicationStore(ReplicationStore replicationStore) {
logger.info("[initReplicationStore]{}", replicationStore);
RedisKeeperServerState redisKeeperServerState = getRedisKeeperServerState();
if (redisKeeperServerState != null) {
KeeperState keeperState = redisKeeperServerState.keeperState();
try {
if (keeperState.isActive()) {
replicationStore.getMetaStore().becomeActive();
} else if (keeperState.isBackup()) {
replicationStore.getMetaStore().becomeBackup();
} else {
logger.warn("[initReplicationStore][not active and not backup]{}, {}", keeperState, replicationStore);
}
} catch (IOException e) {
logger.error("[initReplicationStore]" + replicationStore, e);
}
}
}
Aggregations