Commit Graph
14 Commits
Author SHA1 Message Date
lukaszraczylo b6ddf3d7c8 refactor(shared-state): drop the unused local arm of sharedBreaker
Every caller keeps its own local breaker and reads only sharedOpen, so the
local arm in sharedBreaker (isOpen, recordFailureLocal, breakerLocal) was
reached only by tests.
A per-id failure count since the last success replaces it, because
recordSuccess still needs it to decide whether a fleet reset write is due.
Tests now read sharedOpen. A failover test pins that the caller's local
breaker still opens while the store is down.
2026-11-26 07:48:05 +00:00
lukaszraczylo beaefa3cf6 perf(shared-state): cache primitive key lists
The breaker key list depends only on its ids, so the constructor builds it once.
The in-flight key list depends on ids and the epoch, so it rebuilds only when the epoch changes.
Under Yaegi, keys() drops from about 0.5 ms to 0.013 ms per refresh.
Callers must not modify the returned slices.
2026-11-26 07:27:08 +00:00
lukaszraczylo cbc3471279 style(shared-state): gofmt shared_state.go
Align the const block as gofmt expects. No behaviour change.
2026-11-26 07:07:42 +00:00
lukaszraczylo ebe38e7527 fix(shared-state): count discovery failures per instance
With redis.sharedState on, every route instance added each failed
discovery refresh to one fleet count. One failed round across the
fleet could then open the discovery breaker.

Each instance now counts its own consecutive failures. Only the
instance whose own count reaches breaker.failureThreshold shares a
trip, and the fleet breaker opens on the first trip.
2026-11-26 06:21:10 +00:00
lukaszraczylo 0753a8cb4c fix(shared-state): read calibrator counters without the limiter latch
The shared calibration refresh read through the limiter. A Redis error
there latched the chat route's limiter store for five seconds. The
refresh now reads the store directly, as the shared-state loop does.
2026-11-26 04:13:36 +00:00
lukaszraczylo 383d477778 fix(shared-state): rate-limit the loop's store error logs
A Redis outage logged one line per refresh and per failed write. The
loop now logs at most one store error per 30 seconds, the interval the
limiter already uses.
2026-11-26 04:11:17 +00:00
lukaszraczylo a9468f5d51 fix(shared-state): drop breaker deltas older than the fail window
During a Redis outage the queued failure deltas kept a replaced
gateway's loop alive for ever. A queued failure older than the fail
window cannot change the fleet count, so the breaker now drops it.
2026-11-26 04:10:29 +00:00
lukaszraczylo 5cb01e2c4b fix(shared-state): restart the loop when an in-flight request ends
A request that outlived the idle window ended after the loop had
stopped. Its finish delta then stayed queued with no loop to send it.
The end function now touches the loop.
2026-11-26 04:09:07 +00:00
lukaszraczylo 6438a95a76 fix(shared-state): resend an ambiguous in-flight batch at most once
A flush whose reply timed out may have landed in Redis. The flusher
kept the batch and resent it every tick, which counted it many times.
A batch that never reached the wire is still kept. A batch that may
have landed is resent once and then dropped.
2026-11-26 04:07:43 +00:00
lukaszraczylo 648848e23a fix(shared-state): trip the breaker after a lost incr reply
A flush whose INCR Redis applied but whose reply failed was resent.
The resend never crossed the threshold, so the fleet never tripped.
The flush now trips when the count is at or above the threshold and the
last refresh shows the breaker closed. A short reply is now an error.
2026-11-26 04:05:30 +00:00
lukaszraczylo 3833997221 fix(shared-state): reset breaker backoff when a request succeeds
The open count only grew, so each trip after a recovery waited longer
than the last. The breaker now reads the open count on every refresh.
A success sets the count to zero when the last refresh showed it above
zero. The next trip then opens for the base duration.
2026-11-26 04:04:21 +00:00
lukaszraczylo a46058694b feat(failover): share the request breaker through Redis
The request breaker now also reads and writes the fleet breaker when redis.sharedState is on. A pod that sees enough failures opens the breaker for every pod after one refresh. A success on any pod closes it again. With the switch off, the tracker runs its local code only and makes no store call.
2026-11-26 03:26:39 +00:00
lukaszraczylo 807cc6ee75 fix(redis): flush in-flight counts from the refresh loop
begin and end now add to a local accumulator. The refresh loop sends
all deltas in one incrMulti before each read, so a request starts no
goroutine and makes no store call. A failed flush keeps the deltas.
Deltas for epochs outside the read window are discarded.

Breaker failures use the same path. The instance whose flush takes a
count from below the threshold to at or above it opens the breaker.
The loop does not idle-stop with pending deltas and flushes on Close.
2026-11-26 03:22:50 +00:00
lukaszraczylo 590a23750b feat(redis): shared breaker and in-flight primitives
Add sharedStateLoop, sharedBreaker and sharedInflight. One loop per
gateway refreshes every primitive from the store once per second, so
request paths read local copies only. A store error keeps the last
values, and three failed refreshes make shared values absent.

Add the redis.sharedState switch. It defaults off, and it needs
redis.address. With it off, no shared keys are read or written.
2026-11-26 03:15:12 +00:00