use of org.redisson.client.RedisTimeoutException in project redisson by redisson.
the class RedisClientEntry method pingAsync.
@Override
public RFuture<Boolean> pingAsync(long timeout, TimeUnit timeUnit) {
RFuture<Boolean> f = commandExecutor.readAsync(client, null, RedisCommands.PING_BOOL);
CompletableFuture<Boolean> s = f.toCompletableFuture().handle((res, e) -> {
if (e != null) {
return false;
}
return res;
});
commandExecutor.getConnectionManager().newTimeout(t -> {
RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for command: PING, Redis client: " + client);
s.completeExceptionally(ex);
}, timeout, timeUnit);
return new CompletableFutureWrapper<>(s);
}
use of org.redisson.client.RedisTimeoutException in project redisson by redisson.
the class RedisNode method pingAsync.
@Override
public RFuture<Boolean> pingAsync(long timeout, TimeUnit timeUnit) {
RFuture<Boolean> f = commandExecutor.readAsync(client, null, RedisCommands.PING_BOOL);
CompletionStage<Boolean> s = f.exceptionally(e -> false);
commandExecutor.getConnectionManager().newTimeout(t -> {
RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout (" + timeUnit.toMillis(timeout) + "ms) for command: PING, Redis client: " + client);
s.toCompletableFuture().completeExceptionally(ex);
}, timeout, timeUnit);
return new CompletableFutureWrapper<>(s);
}
use of org.redisson.client.RedisTimeoutException in project redisson by redisson.
the class PublishSubscribe method subscribe.
public CompletableFuture<E> subscribe(String entryName, String channelName) {
AsyncSemaphore semaphore = service.getSemaphore(new ChannelName(channelName));
CompletableFuture<E> newPromise = new CompletableFuture<>();
int timeout = service.getConnectionManager().getConfig().getTimeout();
Timeout lockTimeout = service.getConnectionManager().newTimeout(t -> {
newPromise.completeExceptionally(new RedisTimeoutException("Unable to acquire subscription lock after " + timeout + "ms. " + "Increase 'subscriptionsPerConnection' and/or 'subscriptionConnectionPoolSize' parameters."));
}, timeout, TimeUnit.MILLISECONDS);
semaphore.acquire(() -> {
if (!lockTimeout.cancel()) {
semaphore.release();
return;
}
E entry = entries.get(entryName);
if (entry != null) {
entry.acquire();
semaphore.release();
entry.getPromise().whenComplete((r, e) -> {
if (e != null) {
newPromise.completeExceptionally(e);
return;
}
newPromise.complete(r);
});
return;
}
E value = createEntry(newPromise);
value.acquire();
E oldValue = entries.putIfAbsent(entryName, value);
if (oldValue != null) {
oldValue.acquire();
semaphore.release();
oldValue.getPromise().whenComplete((r, e) -> {
if (e != null) {
newPromise.completeExceptionally(e);
return;
}
newPromise.complete(r);
});
return;
}
RedisPubSubListener<Object> listener = createListener(channelName, value);
CompletableFuture<PubSubConnectionEntry> s = service.subscribe(LongCodec.INSTANCE, channelName, semaphore, listener);
s.whenComplete((r, e) -> {
if (e != null) {
value.getPromise().completeExceptionally(e);
return;
}
value.getPromise().complete(value);
});
});
return newPromise;
}
use of org.redisson.client.RedisTimeoutException in project redisson by redisson.
the class RedissonTopicTest method testResubscriptionAfterFailover.
@Test
public void testResubscriptionAfterFailover() throws Exception {
RedisRunner.RedisProcess master = new RedisRunner().nosave().randomDir().port(6400).run();
RedisRunner.RedisProcess slave1 = new RedisRunner().port(6380).nosave().randomDir().slaveof("127.0.0.1", 6400).run();
RedisRunner.RedisProcess sentinel1 = new RedisRunner().nosave().randomDir().port(26379).sentinel().sentinelMonitor("myMaster", "127.0.0.1", 6400, 2).sentinelDownAfterMilliseconds("myMaster", 750).sentinelFailoverTimeout("myMaster", 1250).run();
RedisRunner.RedisProcess sentinel2 = new RedisRunner().nosave().randomDir().port(26380).sentinel().sentinelMonitor("myMaster", "127.0.0.1", 6400, 2).sentinelDownAfterMilliseconds("myMaster", 750).sentinelFailoverTimeout("myMaster", 1250).run();
RedisRunner.RedisProcess sentinel3 = new RedisRunner().nosave().randomDir().port(26381).sentinel().sentinelMonitor("myMaster", "127.0.0.1", 6400, 2).sentinelDownAfterMilliseconds("myMaster", 750).sentinelFailoverTimeout("myMaster", 1250).run();
Thread.sleep(1000);
Config config = new Config();
config.useSentinelServers().addSentinelAddress(sentinel3.getRedisServerAddressAndPort()).setMasterName("myMaster").setSubscriptionsPerConnection(20).setSubscriptionConnectionPoolSize(200);
RedissonClient redisson = Redisson.create(config);
ScheduledExecutorService executor1 = Executors.newScheduledThreadPool(5);
AtomicBoolean exceptionDetected = new AtomicBoolean(false);
Deque<String> status = new ConcurrentLinkedDeque<>();
Runnable rLockPayload = () -> {
try {
Integer randomLock = ThreadLocalRandom.current().nextInt(100);
RLock lock = redisson.getLock(randomLock.toString());
lock.lock(10, TimeUnit.SECONDS);
lock.unlock();
status.add("ok");
} catch (Exception e) {
status.add("failed");
if (e.getCause().getMessage().contains("slaves were synced")) {
return;
}
e.printStackTrace();
exceptionDetected.set(true);
}
};
executor1.scheduleAtFixedRate(rLockPayload, 100, 50, TimeUnit.MILLISECONDS);
executor1.scheduleAtFixedRate(rLockPayload, 100, 50, TimeUnit.MILLISECONDS);
executor1.scheduleAtFixedRate(rLockPayload, 100, 50, TimeUnit.MILLISECONDS);
executor1.scheduleAtFixedRate(rLockPayload, 100, 50, TimeUnit.MILLISECONDS);
executor1.scheduleAtFixedRate(rLockPayload, 100, 50, TimeUnit.MILLISECONDS);
Thread.sleep(java.time.Duration.ofSeconds(10).toMillis());
RedisClientConfig masterConfig = new RedisClientConfig().setAddress(master.getRedisServerAddressAndPort());
// Failover from master to slave
try {
RedisClient.create(masterConfig).connect().sync(new RedisStrictCommand<Void>("DEBUG", "SEGFAULT"));
} catch (RedisTimeoutException e) {
// node goes down, so this command times out waiting for the response
}
// Re-introduce master as slave like kubernetes would do
RedisRunner.RedisProcess slave2 = new RedisRunner().port(6381).nosave().randomDir().slaveof("127.0.0.1", 6380).run();
System.out.println("Failover Finished, start to see Subscribe timeouts now. Can't recover this without a refresh of redison client ");
Thread.sleep(java.time.Duration.ofSeconds(10).toMillis());
assertThat(exceptionDetected.get()).isFalse();
assertThat(status.peekLast()).isEqualTo("ok");
executor1.shutdown();
redisson.shutdown();
sentinel1.stop();
sentinel2.stop();
sentinel3.stop();
master.stop();
slave1.stop();
slave2.stop();
}
use of org.redisson.client.RedisTimeoutException in project redisson by redisson.
the class RedissonTopicTest method failover.
private void failover(ClusterProcesses processes, RedisRunner master, RedisRunner slave) throws InterruptedException {
final RedisClient masterClient = connect(processes, master);
try {
masterClient.connect().sync(new RedisStrictCommand<Void>("DEBUG", "SEGFAULT"));
} catch (RedisTimeoutException e) {
// node goes down, so this command times out waiting for the response
}
Thread.sleep(java.time.Duration.ofSeconds(25).toMillis());
final RedisClient slaveClient = connect(processes, slave);
slaveClient.connect().sync(new RedisStrictCommand<Void>("CLUSTER", "FAILOVER"), "TAKEOVER");
Thread.sleep(java.time.Duration.ofSeconds(25).toMillis());
}
Aggregations