2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2025-04-19 09:07:06 +00:00

Better handling of improperly-fetched Jedis resources.

This commit is contained in:
Tux 2014-11-26 17:26:51 -05:00
parent cb61d90d6c
commit e630116ff8
3 changed files with 53 additions and 56 deletions

View File

@ -68,6 +68,7 @@ public class DataManager implements Listener {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (tmpRsc != null)
plugin.getPool().returnBrokenResource(tmpRsc);
throw new RuntimeException("Unable to get server for " + uuid, e);
} finally {
@ -98,6 +99,7 @@ public class DataManager implements Listener {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (tmpRsc != null)
plugin.getPool().returnBrokenResource(tmpRsc);
throw new RuntimeException("Unable to get server for " + uuid, e);
} finally {
@ -132,6 +134,7 @@ public class DataManager implements Listener {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (tmpRsc != null)
plugin.getPool().returnBrokenResource(tmpRsc);
throw new RuntimeException("Unable to get server for " + uuid, e);
} catch (UnknownHostException e) {
@ -191,6 +194,7 @@ public class DataManager implements Listener {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
plugin.getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (tmpRsc != null)
plugin.getPool().returnBrokenResource(tmpRsc);
throw new RuntimeException("Unable to get server for " + uuid, e);
} finally {

View File

@ -106,6 +106,7 @@ public final class RedisBungee extends Plugin {
return servers.build();
} catch (JedisConnectionException e) {
getLogger().log(Level.SEVERE, "Unable to fetch all server IDs", e);
if (jedis != null)
pool.returnBrokenResource(jedis);
return Collections.singletonList(serverId);
} finally {
@ -135,6 +136,7 @@ public final class RedisBungee extends Plugin {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (rsc != null)
pool.returnBrokenResource(rsc);
throw new RuntimeException("Unable to get total player count", e);
} finally {
@ -181,6 +183,7 @@ public final class RedisBungee extends Plugin {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (rsc != null)
pool.returnBrokenResource(rsc);
throw new RuntimeException("Unable to get all players online", e);
} finally {
@ -197,17 +200,7 @@ public final class RedisBungee extends Plugin {
final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
checkArgument(getServerIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
Jedis jedis = pool.getResource();
try {
jedis.publish("redisbungee-" + proxyId, command);
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
pool.returnBrokenResource(jedis);
throw new RuntimeException("Unable to publish command", e);
} finally {
pool.returnResource(jedis);
}
sendChannelMessage("redisbungee-" + proxyId, command);
}
final void sendChannelMessage(String channel, String message) {
@ -217,6 +210,7 @@ public final class RedisBungee extends Plugin {
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
if (jedis != null)
pool.returnBrokenResource(jedis);
throw new RuntimeException("Unable to publish channel message", e);
} finally {

View File

@ -13,6 +13,7 @@ import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisException;
import java.util.Calendar;
@ -78,7 +79,6 @@ public final class UUIDTranslator {
// Let's try Redis.
Jedis jedis = plugin.getPool().getResource();
try {
try {
String stored = jedis.hget("uuid-cache", player.toLowerCase());
if (stored != null) {
@ -114,12 +114,11 @@ public final class UUIDTranslator {
}
} catch (JedisException e) {
plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e);
if (jedis != null)
plugin.getPool().returnBrokenResource(jedis);
// Go ahead and give them what we have.
return null;
}
} finally {
plugin.getPool().returnResource(jedis);
}
return null; // Nope, game over!
}