Search in sources :

Example 6 with RedisURI

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;
    }
}
Also used : RedisURI(org.redisson.misc.RedisURI) UnknownHostException(java.net.UnknownHostException)

Example 7 with RedisURI

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);
}
Also used : UnknownHostException(java.net.UnknownHostException) RedisURI(org.redisson.misc.RedisURI) InetAddress(java.net.InetAddress)

Example 8 with RedisURI

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()));
        }
    }
}
Also used : RedisClient(org.redisson.client.RedisClient) NodeType(org.redisson.api.NodeType) RedisConnection(org.redisson.client.RedisConnection) org.redisson.config(org.redisson.config) Logger(org.slf4j.Logger) ScheduledFuture(io.netty.util.concurrent.ScheduledFuture) AsyncCountDownLatch(org.redisson.misc.AsyncCountDownLatch) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) RedisURI(org.redisson.misc.RedisURI) CompletableFuture(java.util.concurrent.CompletableFuture) RedisClient(org.redisson.client.RedisClient) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) RedisConnectionException(org.redisson.client.RedisConnectionException) RedisCommands(org.redisson.client.protocol.RedisCommands) RFuture(org.redisson.api.RFuture) TimeUnit(java.util.concurrent.TimeUnit) CompletionStage(java.util.concurrent.CompletionStage) FreezeReason(org.redisson.connection.ClientConnectionsEntry.FreezeReason) Map(java.util.Map) Collections(java.util.Collections) RedisURI(org.redisson.misc.RedisURI)

Example 9 with RedisURI

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);
    });
}
Also used : RedisURI(org.redisson.misc.RedisURI)

Example 10 with RedisURI

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();
    }
}
Also used : RedisURI(org.redisson.misc.RedisURI)

Aggregations

RedisURI (org.redisson.misc.RedisURI)25 InetSocketAddress (java.net.InetSocketAddress)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Collectors (java.util.stream.Collectors)7 NodeType (org.redisson.api.NodeType)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ScheduledFuture (io.netty.util.concurrent.ScheduledFuture)6 org.redisson.config (org.redisson.config)6 AddressResolver (io.netty.resolver.AddressResolver)5 Future (io.netty.util.concurrent.Future)5 java.util (java.util)5 java.util.concurrent (java.util.concurrent)5 RFuture (org.redisson.api.RFuture)5 RedisCommands (org.redisson.client.protocol.RedisCommands)5 FreezeReason (org.redisson.connection.ClientConnectionsEntry.FreezeReason)5 FutureListener (io.netty.util.concurrent.FutureListener)4 org.redisson.client (org.redisson.client)4 RedisStrictCommand (org.redisson.client.protocol.RedisStrictCommand)4 NetUtil (io.netty.util.NetUtil)3