use of com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo in project x-pipe by ctripcorp.
the class DefaultOffsetwaiter method doWait.
private boolean doWait(String masterReplId, Long masterOffset, HostPort hostPort, ExecutionLog executionLog) {
int waitMilli = metaServerConfig.getWaitforOffsetMilli();
long endTime = System.currentTimeMillis() + waitMilli;
String slaveReplId = null;
Long slaveOffset = null;
executionLog.info(String.format("wait timeout config:%d ms", waitMilli));
while (true) {
InfoReplicationComplementCommand command = new InfoReplicationComplementCommand(keyedObjectPool.getKeyPool(new InetSocketAddress(hostPort.getHost(), hostPort.getPort())), scheduled);
try {
RedisInfo redisInfo = command.execute().get(waitMilli, TimeUnit.MILLISECONDS);
if ((redisInfo instanceof MasterInfo) || !(redisInfo instanceof SlaveInfo)) {
executionLog.info("target role:" + (redisInfo == null ? "null" : redisInfo.getClass().getSimpleName()));
break;
}
SlaveInfo slaveInfo = (SlaveInfo) redisInfo;
slaveReplId = slaveInfo.getMasterReplId();
slaveOffset = slaveInfo.getSlaveReplOffset();
if (!StringUtil.isEmpty(slaveReplId) && !StringUtil.isEmpty(masterReplId)) {
if (!slaveReplId.equalsIgnoreCase(masterReplId)) {
executionLog.info(String.format("master replid not equal with slave replid, break. %s %s", masterReplId, slaveReplId));
break;
}
}
if (slaveOffset >= masterOffset) {
executionLog.info(String.format("wait succeed:%d >= %d", slaveOffset, masterOffset));
return true;
}
} catch (Exception e) {
executionLog.error(e.getMessage());
logger.error("[waitfor]" + hostPort, e);
}
long current = System.currentTimeMillis();
if (current >= endTime) {
executionLog.error("wait time out, exit");
break;
}
sleep(1);
}
if (slaveOffset != null) {
executionLog.info(String.format("master offset:%s, slave offset:%d, sub:%d", masterOffset, slaveOffset, masterOffset - slaveOffset));
}
return false;
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo in project x-pipe by ctripcorp.
the class DefaultPrimaryDcPrepareToChange method prepare.
@Override
public MetaServerConsoleService.PreviousPrimaryDcMessage prepare(String clusterId, String shardId) {
logger.info("[prepare]{}, {}", clusterId, shardId);
MetaServerConsoleService.PreviousPrimaryDcMessage message = new MetaServerConsoleService.PreviousPrimaryDcMessage();
ExecutionLog executionLog = new ExecutionLog(String.format("meta server:%s", currentClusterServer.getClusterInfo()));
Pair<String, Integer> keeperMaster = currentMetaManager.getKeeperMaster(clusterId, shardId);
message.setMasterAddr(new HostPort(keeperMaster.getKey(), keeperMaster.getValue()));
executionLog.info("[prepare]" + keeperMaster);
RedisInfo redisInfo = getInfoReplication(keeperMaster, executionLog);
MasterInfo masterInfo = convert(redisInfo, executionLog);
message.setMasterInfo(masterInfo);
logger.info("[prepare]{}, {}, {}", keeperMaster, redisInfo, masterInfo);
makeMasterReadOnly(clusterId, shardId, keeperMaster, true, executionLog);
removeSentinel(clusterId, shardId, executionLog);
message.setMessage(executionLog.getLog());
return message;
}
use of com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo in project x-pipe by ctripcorp.
the class DefaultPrimaryDcPrepareToChange method getInfoReplication.
public RedisInfo getInfoReplication(Pair<String, Integer> redisMaster, ExecutionLog executionLog) {
InfoReplicationComplementCommand command = new InfoReplicationComplementCommand(keyedObjectPool.getKeyPool(new InetSocketAddress(redisMaster.getKey(), redisMaster.getValue())), scheduled);
try {
executionLog.info("[getInfoReplication]" + redisMaster);
RedisInfo redisInfo = command.execute().get(waitForMasterInfoMilli, TimeUnit.MILLISECONDS);
executionLog.info("[getInfoReplication]" + redisInfo);
return redisInfo;
} catch (InterruptedException e) {
logger.error("[getInfoReplication]" + redisMaster, e);
executionLog.error(e.getMessage());
} catch (ExecutionException e) {
logger.error("[getInfoReplication]" + redisMaster, e);
executionLog.error(e.getMessage());
} catch (TimeoutException e) {
logger.error("[getInfoReplication]" + redisMaster, e);
executionLog.error(e.getMessage());
}
return null;
}
Aggregations