Fixed - org.redisson.spring.data.connection.RedissonConnectionFactory.getSentinelConnection() method throws error on the first offline sentinel #5817

pull/5884/head
Nikita Koksharov 9 months ago
parent 6bfd7c978d
commit 4a849af9b3

@ -107,22 +107,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory, Initia
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
}

@ -119,22 +119,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory, Initia
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
}

@ -126,22 +126,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
}

@ -125,22 +125,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager());
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -125,22 +125,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = ((SentinelConnectionManager)((RedissonKeys)redisson.getKeys()).getConnectionManager());
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -134,19 +134,22 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

@ -131,22 +131,25 @@ public class RedissonConnectionFactory implements RedisConnectionFactory,
if (!redisson.getConfig().isSentinelConfig()) {
throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode");
}
SentinelConnectionManager manager = (SentinelConnectionManager)(((Redisson)redisson).getConnectionManager());
for (RedisClient client : manager.getSentinels()) {
org.redisson.client.RedisConnection connection = client.connect();
org.redisson.client.RedisConnection connection = null;
try {
connection = client.connect();
String res = connection.sync(RedisCommands.PING);
if ("pong".equalsIgnoreCase(res)) {
return new RedissonSentinelConnection(connection);
}
} catch (Exception e) {
log.warn("Can't connect to " + client, e);
connection.closeAsync();
if (connection != null) {
connection.closeAsync();
}
}
}
throw new InvalidDataAccessResourceUsageException("Sentinels are not found");
throw new InvalidDataAccessResourceUsageException("Sentinels are offline");
}
@Override

Loading…
Cancel
Save