From 0e888e6c604dea568e67273db033a590803a8a54 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 5 Nov 2023 00:12:00 +0300 Subject: [PATCH] Prevent spamming etcd with last_clean_pgs update requests --- mon/mon.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mon/mon.js b/mon/mon.js index 87dc83b7..8ecc23ce 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -693,8 +693,27 @@ class Mon }); } + // Schedule save_last_clean() to to run after a small timeout (1s) (to not spam etcd) + schedule_save_last_clean() + { + if (!this.save_last_clean_timer) + { + this.save_last_clean_timer = setTimeout(() => + { + this.save_last_clean_timer = null; + this.save_last_clean().catch(this.die); + }, this.config.mon_change_timeout || 1000); + } + } + async save_last_clean() { + if (this.save_last_clean_running) + { + this.schedule_save_last_clean(); + return; + } + this.save_last_clean_running = true; // last_clean_pgs is used to avoid extra data move when observing a series of changes in the cluster const new_clean_pgs = { items: {} }; next_pool: @@ -731,6 +750,7 @@ class Mon value: b64(JSON.stringify(this.state.history.last_clean_pgs)) } } ], }, this.etcd_start_timeout, 0); + this.save_last_clean_running = false; } get_mon_state()