mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-10-31 18:48:01 +00:00
Tweaks, more pipelining.
This commit is contained in:
parent
511202044c
commit
688246b8fe
@ -332,8 +332,10 @@ public final class RedisBungee extends Plugin {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
rsc.hset("playerCounts", serverId, String.valueOf(getProxy().getOnlineCount()));
|
Pipeline pipeline = rsc.pipelined();
|
||||||
rsc.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis()));
|
pipeline.hset("playerCounts", serverId, String.valueOf(getProxy().getOnlineCount()));
|
||||||
|
pipeline.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis()));
|
||||||
|
pipeline.sync();
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to update proxy counts - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to update proxy counts - did your Redis server go away?", e);
|
||||||
@ -405,6 +407,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.hdel("playerCounts", serverId);
|
tmpRsc.hdel("playerCounts", serverId);
|
||||||
|
tmpRsc.hdel("heartbeats", serverId);
|
||||||
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
|
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
|
||||||
Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline");
|
Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline");
|
||||||
Pipeline pipeline = tmpRsc.pipelined();
|
Pipeline pipeline = tmpRsc.pipelined();
|
||||||
@ -413,7 +416,6 @@ public final class RedisBungee extends Plugin {
|
|||||||
|
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
}
|
}
|
||||||
tmpRsc.hdel("heartbeats", serverId);
|
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
@ -443,53 +445,51 @@ public final class RedisBungee extends Plugin {
|
|||||||
String redisPassword = configuration.getString("redis-password");
|
String redisPassword = configuration.getString("redis-password");
|
||||||
serverId = configuration.getString("server-id");
|
serverId = configuration.getString("server-id");
|
||||||
|
|
||||||
if (redisPassword != null && (redisPassword.equals("") || redisPassword.equals("none"))) {
|
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
||||||
redisPassword = null;
|
redisPassword = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration sanity checks.
|
// Configuration sanity checks.
|
||||||
if (serverId == null || serverId.equals("")) {
|
if (serverId == null || serverId.isEmpty()) {
|
||||||
throw new RuntimeException("server-id is not specified in the configuration or is empty");
|
throw new RuntimeException("server-id is not specified in the configuration or is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redisServer != null) {
|
if (redisServer != null && !redisServer.isEmpty()) {
|
||||||
if (!redisServer.equals("")) {
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
config.setMaxTotal(configuration.getInt("max-redis-connections", -1));
|
||||||
config.setMaxTotal(configuration.getInt("max-redis-connections", -1));
|
pool = new JedisPool(config, redisServer, redisPort, 0, redisPassword);
|
||||||
pool = new JedisPool(config, redisServer, redisPort, 0, redisPassword);
|
// Test the connection
|
||||||
// Test the connection
|
Jedis rsc = null;
|
||||||
Jedis rsc = null;
|
try {
|
||||||
try {
|
rsc = pool.getResource();
|
||||||
rsc = pool.getResource();
|
rsc.exists(String.valueOf(System.currentTimeMillis()));
|
||||||
rsc.exists(String.valueOf(System.currentTimeMillis()));
|
// If that worked, now we can check for an existing, alive Bungee:
|
||||||
// If that worked, now we can check for an existing, alive Bungee:
|
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
||||||
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
if (crashFile.exists())
|
||||||
if (crashFile.exists())
|
crashFile.delete();
|
||||||
crashFile.delete();
|
else if (rsc.hexists("heartbeats", serverId)) {
|
||||||
else if (rsc.hexists("heartbeats", serverId)) {
|
try {
|
||||||
try {
|
Long value = Long.valueOf(rsc.hget("heartbeats", serverId));
|
||||||
Long value = Long.valueOf(rsc.hget("heartbeats", serverId));
|
if (value != null && System.currentTimeMillis() < value + 20000) {
|
||||||
if (value != null && System.currentTimeMillis() < value + 20000) {
|
getLogger().severe("You have launched a possible imposter BungeeCord instance. Another instance is already running.");
|
||||||
getLogger().severe("You have launched a possible imposter BungeeCord instance. Another instance is already running.");
|
getLogger().severe("For data consistency reasons, RedisBungee will now disable itself.");
|
||||||
getLogger().severe("For data consistency reasons, RedisBungee will now disable itself.");
|
getLogger().severe("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check.");
|
||||||
getLogger().severe("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check.");
|
throw new RuntimeException("Possible imposter instance!");
|
||||||
throw new RuntimeException("Possible imposter instance!");
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException ignored) {
|
|
||||||
}
|
}
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
getLogger().log(Level.INFO, "Successfully connected to Redis.");
|
}
|
||||||
} catch (JedisConnectionException e) {
|
getLogger().log(Level.INFO, "Successfully connected to Redis.");
|
||||||
if (rsc != null)
|
} catch (JedisConnectionException e) {
|
||||||
pool.returnBrokenResource(rsc);
|
if (rsc != null)
|
||||||
pool.destroy();
|
pool.returnBrokenResource(rsc);
|
||||||
pool = null;
|
pool.destroy();
|
||||||
rsc = null;
|
pool = null;
|
||||||
throw e;
|
rsc = null;
|
||||||
} finally {
|
throw e;
|
||||||
if (rsc != null && pool != null) {
|
} finally {
|
||||||
pool.returnResource(rsc);
|
if (rsc != null && pool != null) {
|
||||||
}
|
pool.returnResource(rsc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user