use of org.redisson.misc.RedisURI in project redisson by redisson.
the class MasterSlaveConnectionManager method initSingleEntry.
protected void initSingleEntry() {
try {
if (config.checkSkipSlavesInit()) {
masterSlaveEntry = new SingleEntry(this, config);
} else {
masterSlaveEntry = new MasterSlaveEntry(this, config);
}
CompletableFuture<RedisClient> masterFuture = masterSlaveEntry.setupMasterEntry(new RedisURI(config.getMasterAddress()));
masterFuture.join();
if (!config.checkSkipSlavesInit()) {
CompletableFuture<Void> fs = masterSlaveEntry.initSlaveBalancer(getDisconnectedNodes());
fs.join();
}
startDNSMonitoring(masterFuture.getNow(null));
} catch (Exception e) {
stopThreads();
if (e instanceof CompletionException) {
throw (RuntimeException) e.getCause();
}
throw e;
}
}
use of org.redisson.misc.RedisURI in project redisson by redisson.
the class MasterSlaveConnectionManager method toURI.
protected RedisURI toURI(String scheme, String host, String port) {
// convert IPv6 address to unified compressed format
if (NetUtil.isValidIpV6Address(host)) {
byte[] addr = NetUtil.createByteArrayFromIpAddressString(host);
try {
InetAddress ia = InetAddress.getByAddress(host, addr);
host = ia.getHostAddress();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
RedisURI uri = new RedisURI(scheme + "://" + host + ":" + port);
return applyNatMap(uri);
}
use of org.redisson.misc.RedisURI in project redisson by redisson.
the class ReplicatedConnectionManager method checkFailedSlaves.
private void checkFailedSlaves(Set<InetSocketAddress> slaveIPs) {
MasterSlaveEntry entry = getEntry(singleSlotRange.getStartSlot());
Set<RedisClient> failedSlaves = entry.getAllEntries().stream().filter(e -> e.getNodeType() == NodeType.SLAVE && !slaveIPs.contains(e.getClient().getAddr())).map(e -> e.getClient()).collect(Collectors.toSet());
for (RedisClient slave : failedSlaves) {
if (entry.slaveDown(slave.getAddr(), FreezeReason.MANAGER)) {
log.info("slave: {} is down", slave);
disconnectNode(new RedisURI(slave.getConfig().getAddress().getScheme(), slave.getAddr().getAddress().getHostAddress(), slave.getAddr().getPort()));
}
}
}
use of org.redisson.misc.RedisURI in project redisson by redisson.
the class ClusterConnectionManager method checkClusterState.
private void checkClusterState(ClusterServersConfig cfg, Iterator<RedisURI> iterator, AtomicReference<Throwable> lastException) {
if (!iterator.hasNext()) {
if (lastException.get() != null) {
log.error("Can't update cluster state", lastException.get());
}
scheduleClusterChangeCheck(cfg);
return;
}
if (!getShutdownLatch().acquire()) {
return;
}
RedisURI uri = iterator.next();
CompletionStage<RedisConnection> connectionFuture = connectToNode(cfg, uri, configEndpointHostName);
connectionFuture.whenComplete((connection, e) -> {
if (e != null) {
lastException.set(e);
getShutdownLatch().release();
checkClusterState(cfg, iterator, lastException);
return;
}
updateClusterState(cfg, connection, iterator, uri, lastException);
});
}
use of org.redisson.misc.RedisURI in project redisson by redisson.
the class ClusterConnectionManager method addCascadeSlaves.
private void addCascadeSlaves(Collection<ClusterPartition> partitions) {
Iterator<ClusterPartition> iter = partitions.iterator();
while (iter.hasNext()) {
ClusterPartition cp = iter.next();
if (cp.getType() != Type.SLAVE) {
continue;
}
if (cp.getParent() != null && cp.getParent().getType() == Type.MASTER) {
ClusterPartition parent = cp.getParent();
for (RedisURI addr : cp.getSlaveAddresses()) {
parent.addSlaveAddress(addr);
}
for (RedisURI addr : cp.getFailedSlaveAddresses()) {
parent.addFailedSlaveAddress(addr);
}
}
iter.remove();
}
}
Aggregations