use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class ShardServiceImpl method createShardDeleteEvent.
@VisibleForTesting
protected ShardDeleteEvent createShardDeleteEvent(String clusterName, String shardName, ShardTbl shardTbl, Map<Long, SetinelTbl> sentinelTblMap) {
String monitorName = shardTbl.getSetinelMonitorName();
ShardDeleteEvent shardDeleteEvent = new ShardDeleteEvent(clusterName, shardName, executors);
shardDeleteEvent.setShardMonitorName(monitorName);
// Splicing sentinel address as "127.0.0.1:6379,127.0.0.2:6380"
StringBuffer sb = new StringBuffer();
for (SetinelTbl setinelTbl : sentinelTblMap.values()) {
sb.append(setinelTbl.getSetinelAddress()).append(",");
}
sb.deleteCharAt(sb.length() - 1);
shardDeleteEvent.setShardSentinels(sb.toString());
shardEventListeners.forEach(shardEventListener -> shardDeleteEvent.addObserver(shardEventListener));
return shardDeleteEvent;
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class HealthChecker method warmup.
@VisibleForTesting
protected void warmup() {
int period = 1000;
XpipeMeta xpipeMeta = null;
while (xpipeMeta == null) {
log.info("[warmup] waiting for metaCache initialized");
try {
Thread.sleep(period);
xpipeMeta = metaCache.getXpipeMeta();
Thread.sleep(period);
} catch (Exception e) {
log.error("[warmup]", e);
}
}
try {
List<DcMeta> dcsToCheck = new LinkedList<>(xpipeMeta.getDcs().values());
for (DcMeta dc : dcsToCheck) {
dc.accept(healthCheckVisitor);
}
} catch (Exception e) {
log.error("[warmup] error: {}", e);
}
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class DefaultRedisMasterCollector method isMaster.
@VisibleForTesting
protected boolean isMaster(String host, int port) {
try {
RedisSession redisSession = redisSessionManager.findOrCreateSession(host, port);
String role = redisSession.roleSync();
if (Server.SERVER_ROLE.MASTER.sameRole(role)) {
return true;
}
} catch (Exception e) {
logger.error(String.format("%s:%d", host, port), e);
}
return false;
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class DefaultBacklogActiveCollector method analysisInfoReplication.
@VisibleForTesting
void analysisInfoReplication(String infoReplication, String cluster, String shard, HostPort hostPort) {
boolean isBacklogActive = RedisInfoUtils.getReplBacklogActive(infoReplication);
String role = RedisInfoUtils.getRole(infoReplication);
if (!isBacklogActive && Server.SERVER_ROLE.SLAVE.sameRole(role)) {
// master last io seconds ago == server.master ? unix time - last ! -1
if (RedisInfoUtils.isMasterSyncInProgress(infoReplication) || RedisInfoUtils.getMasterLastIoSecondsAgo(infoReplication) == -1) {
logger.info("[analysisInfoReplication] master sync in progress, waiting for {}, {}, {}", cluster, shard, hostPort);
return;
}
RedisConf redisConf = redisConfManager.findOrCreateConfig(hostPort.getHost(), hostPort.getPort());
if ((!StringUtil.isEmpty(redisConf.getRedisVersion()) && StringUtil.compareVersion(redisConf.getRedisVersion(), "4.0.0") >= 0) || !StringUtil.isEmpty(redisConf.getXredisVersion())) {
String message = "Redis replication backlog not active";
alertManager.alert(cluster, shard, hostPort, ALERT_TYPE.REPL_BACKLOG_NOT_ACTIVE, message);
} else {
logger.warn("[analysisInfoReplication]Redis {}-{}-{} backlog_active is 0, " + "but redis is not xredis or with version greater than 4.0.0", cluster, shard, hostPort);
}
}
}
use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.
the class DefaultSentinelManager method getRealSentinels.
@VisibleForTesting
protected List<Sentinel> getRealSentinels(List<InetSocketAddress> sentinels, String sentinelMonitorName) {
List<Sentinel> realSentinels = null;
for (InetSocketAddress sentinelAddress : sentinels) {
SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
AbstractSentinelCommand.Sentinels sentinelsCommand = new AbstractSentinelCommand.Sentinels(clientPool, sentinelMonitorName, scheduled);
try {
realSentinels = sentinelsCommand.execute().get();
logger.info("[getRealSentinels]get sentinels from {} : {}", sentinelAddress, realSentinels);
if (realSentinels.size() > 0) {
realSentinels.add(new Sentinel(sentinelAddress.toString(), sentinelAddress.getHostString(), sentinelAddress.getPort()));
logger.info("[getRealSentinels]sentinels for monitor {}, list as: {}", sentinelMonitorName, realSentinels);
break;
}
} catch (Exception e) {
logger.warn("[getRealSentinels]get sentinels from " + sentinelAddress, e);
}
}
return realSentinels;
}
Aggregations