Fix unbounded growth of Broker.set_stat cluster master list (#322)

Prune stale entries from the master list on new cluster registration
and only write the list when membership changes (with timeout=None).

Before this fix, set_stat was append-only — dead cluster keys accumulated
forever because the only cleanup path (get_stats) runs only from the
monitor UIs. On DatabaseCache backends this rewrote the growing pickled
list to Postgres on every heartbeat, producing measurable egress.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Yuan
2026-04-14 00:24:43 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 1abdc5b653
commit fab97463c2
2 changed files with 57 additions and 1 deletions
+6 -1
View File
@@ -106,8 +106,13 @@ class Broker:
return
key_list = self.cache.get(Conf.Q_STAT, [])
if key not in key_list:
# Prune stale entries whose per-stat value has expired, so the
# master list cannot grow without bound across cluster restarts.
key_list = [k for k in key_list if self.cache.get(k) is not None]
key_list.append(key)
self.cache.set(Conf.Q_STAT, key_list)
# timeout=None: master list lifetime is managed by membership
# changes, not by TTL refresh on every heartbeat.
self.cache.set(Conf.Q_STAT, key_list, None)
return self.cache.set(key, value, timeout)
def get_stat(self, key: str):