Search in sources :

Example 1 with MasterSlaveServersConfig

use of org.redisson.config.MasterSlaveServersConfig in project redisson by redisson.

the class MasterSlaveConnectionManager method create.

protected MasterSlaveServersConfig create(BaseMasterSlaveServersConfig<?> cfg) {
    MasterSlaveServersConfig c = new MasterSlaveServersConfig();
    c.setRetryInterval(cfg.getRetryInterval());
    c.setRetryAttempts(cfg.getRetryAttempts());
    c.setTimeout(cfg.getTimeout());
    c.setPingTimeout(cfg.getPingTimeout());
    c.setLoadBalancer(cfg.getLoadBalancer());
    c.setPassword(cfg.getPassword());
    c.setClientName(cfg.getClientName());
    c.setMasterConnectionPoolSize(cfg.getMasterConnectionPoolSize());
    c.setSlaveConnectionPoolSize(cfg.getSlaveConnectionPoolSize());
    c.setSubscriptionConnectionPoolSize(cfg.getSubscriptionConnectionPoolSize());
    c.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection());
    c.setConnectTimeout(cfg.getConnectTimeout());
    c.setIdleConnectionTimeout(cfg.getIdleConnectionTimeout());
    c.setFailedAttempts(cfg.getFailedAttempts());
    c.setReconnectionTimeout(cfg.getReconnectionTimeout());
    c.setMasterConnectionMinimumIdleSize(cfg.getMasterConnectionMinimumIdleSize());
    c.setSlaveConnectionMinimumIdleSize(cfg.getSlaveConnectionMinimumIdleSize());
    c.setSubscriptionConnectionMinimumIdleSize(cfg.getSubscriptionConnectionMinimumIdleSize());
    c.setReadMode(cfg.getReadMode());
    c.setSubscriptionMode(cfg.getSubscriptionMode());
    return c;
}
Also used : BaseMasterSlaveServersConfig(org.redisson.config.BaseMasterSlaveServersConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig)

Example 2 with MasterSlaveServersConfig

use of org.redisson.config.MasterSlaveServersConfig in project redisson by redisson.

the class ReplicatedConnectionManager method create.

@Override
protected MasterSlaveServersConfig create(BaseMasterSlaveServersConfig<?> cfg) {
    MasterSlaveServersConfig res = super.create(cfg);
    res.setDatabase(((ReplicatedServersConfig) cfg).getDatabase());
    return res;
}
Also used : MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) BaseMasterSlaveServersConfig(org.redisson.config.BaseMasterSlaveServersConfig)

Example 3 with MasterSlaveServersConfig

use of org.redisson.config.MasterSlaveServersConfig in project redisson by redisson.

the class SentinelConnectionManager method create.

@Override
protected MasterSlaveServersConfig create(BaseMasterSlaveServersConfig<?> cfg) {
    MasterSlaveServersConfig res = super.create(cfg);
    res.setDatabase(((SentinelServersConfig) cfg).getDatabase());
    return res;
}
Also used : BaseMasterSlaveServersConfig(org.redisson.config.BaseMasterSlaveServersConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig)

Example 4 with MasterSlaveServersConfig

use of org.redisson.config.MasterSlaveServersConfig in project redisson by redisson.

the class SingleConnectionManager method create.

private static MasterSlaveServersConfig create(SingleServerConfig cfg) {
    MasterSlaveServersConfig newconfig = new MasterSlaveServersConfig();
    String addr = cfg.getAddress().getHost() + ":" + cfg.getAddress().getPort();
    newconfig.setRetryAttempts(cfg.getRetryAttempts());
    newconfig.setRetryInterval(cfg.getRetryInterval());
    newconfig.setTimeout(cfg.getTimeout());
    newconfig.setPingTimeout(cfg.getPingTimeout());
    newconfig.setPassword(cfg.getPassword());
    newconfig.setDatabase(cfg.getDatabase());
    newconfig.setClientName(cfg.getClientName());
    newconfig.setMasterAddress(addr);
    newconfig.setMasterConnectionPoolSize(cfg.getConnectionPoolSize());
    newconfig.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection());
    newconfig.setSubscriptionConnectionPoolSize(cfg.getSubscriptionConnectionPoolSize());
    newconfig.setConnectTimeout(cfg.getConnectTimeout());
    newconfig.setIdleConnectionTimeout(cfg.getIdleConnectionTimeout());
    newconfig.setFailedAttempts(cfg.getFailedAttempts());
    newconfig.setReconnectionTimeout(cfg.getReconnectionTimeout());
    newconfig.setMasterConnectionMinimumIdleSize(cfg.getConnectionMinimumIdleSize());
    newconfig.setSubscriptionConnectionMinimumIdleSize(cfg.getSubscriptionConnectionMinimumIdleSize());
    newconfig.setReadMode(ReadMode.MASTER);
    newconfig.setSubscriptionMode(SubscriptionMode.MASTER);
    return newconfig;
}
Also used : MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig)

Example 5 with MasterSlaveServersConfig

use of org.redisson.config.MasterSlaveServersConfig in project redisson by redisson.

the class ClusterConnectionManager method addMasterEntry.

private RFuture<Collection<RFuture<Void>>> addMasterEntry(final ClusterPartition partition, final ClusterServersConfig cfg) {
    if (partition.isMasterFail()) {
        RedisException e = new RedisException("Failed to add master: " + partition.getMasterAddress() + " for slot ranges: " + partition.getSlotRanges() + ". Reason - server has FAIL flag");
        if (partition.getSlotRanges().isEmpty()) {
            e = new RedisException("Failed to add master: " + partition.getMasterAddress() + ". Reason - server has FAIL flag");
        }
        return newFailedFuture(e);
    }
    final RPromise<Collection<RFuture<Void>>> result = newPromise();
    RFuture<RedisConnection> connectionFuture = connect(cfg, partition.getMasterAddress());
    connectionFuture.addListener(new FutureListener<RedisConnection>() {

        @Override
        public void operationComplete(Future<RedisConnection> future) throws Exception {
            if (!future.isSuccess()) {
                log.error("Can't connect to master: {} with slot ranges: {}", partition.getMasterAddress(), partition.getSlotRanges());
                result.tryFailure(future.cause());
                return;
            }
            final RedisConnection connection = future.getNow();
            RFuture<Map<String, String>> clusterFuture = connection.async(RedisCommands.CLUSTER_INFO);
            clusterFuture.addListener(new FutureListener<Map<String, String>>() {

                @Override
                public void operationComplete(Future<Map<String, String>> future) throws Exception {
                    if (!future.isSuccess()) {
                        log.error("Can't execute CLUSTER_INFO for " + connection.getRedisClient().getAddr(), future.cause());
                        result.tryFailure(future.cause());
                        return;
                    }
                    Map<String, String> params = future.getNow();
                    if ("fail".equals(params.get("cluster_state"))) {
                        RedisException e = new RedisException("Failed to add master: " + partition.getMasterAddress() + " for slot ranges: " + partition.getSlotRanges() + ". Reason - cluster_state:fail");
                        log.error("cluster_state:fail for " + connection.getRedisClient().getAddr());
                        result.tryFailure(e);
                        return;
                    }
                    MasterSlaveServersConfig config = create(cfg);
                    config.setMasterAddress(partition.getMasterAddress());
                    final MasterSlaveEntry e;
                    List<RFuture<Void>> futures = new ArrayList<RFuture<Void>>();
                    if (config.getReadMode() == ReadMode.MASTER) {
                        e = new SingleEntry(partition.getSlotRanges(), ClusterConnectionManager.this, config);
                    } else {
                        config.setSlaveAddresses(partition.getSlaveAddresses());
                        e = new MasterSlaveEntry(partition.getSlotRanges(), ClusterConnectionManager.this, config);
                        List<RFuture<Void>> fs = e.initSlaveBalancer(partition.getFailedSlaveAddresses());
                        futures.addAll(fs);
                        if (!partition.getSlaveAddresses().isEmpty()) {
                            log.info("slaves: {} added for slot ranges: {}", partition.getSlaveAddresses(), partition.getSlotRanges());
                            if (!partition.getFailedSlaveAddresses().isEmpty()) {
                                log.warn("slaves: {} is down for slot ranges: {}", partition.getFailedSlaveAddresses(), partition.getSlotRanges());
                            }
                        }
                    }
                    RFuture<Void> f = e.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
                    final RPromise<Void> initFuture = newPromise();
                    futures.add(initFuture);
                    f.addListener(new FutureListener<Void>() {

                        @Override
                        public void operationComplete(Future<Void> future) throws Exception {
                            if (!future.isSuccess()) {
                                log.error("Can't add master: {} for slot ranges: {}", partition.getMasterAddress(), partition.getSlotRanges());
                                initFuture.tryFailure(future.cause());
                                return;
                            }
                            for (Integer slot : partition.getSlots()) {
                                addEntry(slot, e);
                                lastPartitions.put(slot, partition);
                            }
                            log.info("master: {} added for slot ranges: {}", partition.getMasterAddress(), partition.getSlotRanges());
                            if (!initFuture.trySuccess(null)) {
                                throw new IllegalStateException();
                            }
                        }
                    });
                    if (!result.trySuccess(futures)) {
                        throw new IllegalStateException();
                    }
                }
            });
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) RedisException(org.redisson.client.RedisException) FutureListener(io.netty.util.concurrent.FutureListener) SingleEntry(org.redisson.connection.SingleEntry) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) RFuture(org.redisson.api.RFuture) RedisException(org.redisson.client.RedisException) RedisConnectionException(org.redisson.client.RedisConnectionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) ScheduledFuture(io.netty.util.concurrent.ScheduledFuture) RFuture(org.redisson.api.RFuture) Future(io.netty.util.concurrent.Future) RedisConnection(org.redisson.client.RedisConnection)

Aggregations

MasterSlaveServersConfig (org.redisson.config.MasterSlaveServersConfig)6 BaseMasterSlaveServersConfig (org.redisson.config.BaseMasterSlaveServersConfig)3 Future (io.netty.util.concurrent.Future)1 FutureListener (io.netty.util.concurrent.FutureListener)1 ScheduledFuture (io.netty.util.concurrent.ScheduledFuture)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RFuture (org.redisson.api.RFuture)1 RedisConnection (org.redisson.client.RedisConnection)1 RedisConnectionException (org.redisson.client.RedisConnectionException)1 RedisException (org.redisson.client.RedisException)1 RedisTimeoutException (org.redisson.client.RedisTimeoutException)1 MasterSlaveEntry (org.redisson.connection.MasterSlaveEntry)1 SingleEntry (org.redisson.connection.SingleEntry)1