From bc1ddebe5526aa5e0cee66ccad1f8d15cab63b2f Mon Sep 17 00:00:00 2001 From: jeremyhi Date: Wed, 25 Sep 2024 14:43:49 +0800 Subject: [PATCH] fix: atomic refresh --- .../main/java/io/greptime/RouterClient.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/ingester-protocol/src/main/java/io/greptime/RouterClient.java b/ingester-protocol/src/main/java/io/greptime/RouterClient.java index a569513..c65f0c0 100644 --- a/ingester-protocol/src/main/java/io/greptime/RouterClient.java +++ b/ingester-protocol/src/main/java/io/greptime/RouterClient.java @@ -78,24 +78,26 @@ public boolean init(RouterOptions opts) { return; } - // I don't want to worry about the overflow issue with long anymore, - // because assuming one increment per second, it will take 292 years - // to overflow. I think that's sufficient. - if (thisOrder < order.get()) { - LOG.warn("Skip outdated health check result, order: {}", thisOrder); - return; - } + synchronized (this) { + // I don't want to worry about the overflow issue with long anymore, + // because assuming one increment per second, it will take 292 years + // to overflow. I think that's sufficient. + if (thisOrder < order.get()) { + LOG.warn("Skip outdated health check result, order: {}", thisOrder); + return; + } - List activities = new ArrayList<>(); - List inactivities = new ArrayList<>(); - for (Map.Entry entry : r.entrySet()) { - if (entry.getValue()) { - activities.add(entry.getKey()); - } else { - inactivities.add(entry.getKey()); + List activities = new ArrayList<>(); + List inactivities = new ArrayList<>(); + for (Map.Entry entry : r.entrySet()) { + if (entry.getValue()) { + activities.add(entry.getKey()); + } else { + inactivities.add(entry.getKey()); + } } + this.router.onRefresh(activities, inactivities); } - this.router.onRefresh(activities, inactivities); }); }, Util.randomInitialDelay(180),