use of com.ctrip.xpipe.redis.core.protocal.pojo.SlaveInfo 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;
}
Aggregations