mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-01 02:58:02 +00:00
[BREAKING] Use nanoTime() for heartbeat checks
This improves Windows and timezone-related support by using a time reference that is more-or-less fixed. You will need to update your network if you update.
This commit is contained in:
parent
c6c73cf731
commit
7c76b245d4
@ -101,10 +101,10 @@ public final class RedisBungee extends Plugin {
|
|||||||
for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
|
for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
|
||||||
try {
|
try {
|
||||||
long stamp = Long.parseLong(entry.getValue());
|
long stamp = Long.parseLong(entry.getValue());
|
||||||
if (System.currentTimeMillis() < stamp + 30000)
|
if (System.nanoTime() < stamp + TimeUnit.SECONDS.toNanos(30)) {
|
||||||
servers.add(entry.getKey());
|
servers.add(entry.getKey());
|
||||||
else if (nag <= 0) {
|
} else if (nag <= 0) {
|
||||||
getLogger().severe(entry.getKey() + " is " + (System.currentTimeMillis() - stamp) + "ms behind! (Time not synchronized or server down?)");
|
getLogger().severe(entry.getKey() + " is " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - stamp) + "ms behind! (Time not synchronized or server down?)");
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
rsc.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis()));
|
rsc.hset("heartbeats", serverId, String.valueOf(System.nanoTime()));
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user