refactor(core): move heartbeat/liveness logic into core behind remote-adapter feature - #768
refactor(core): move heartbeat/liveness logic into core behind remote-adapter feature#768LiamCarPer wants to merge 1 commit into
Conversation
…-adapter feature Moves the duplicated heartbeat/liveness logic from the postgres and mongodb adapters into socketioxide-core behind the existing remote-adapter feature flag. - HeartbeatTracker: wraps nodes_liveness + hb_timeout; on_heartbeat (update-or-push, returns whether an InitHeartbeat reply is due), server_count (prune dead nodes + self), is_alive - HeartbeatSender trait: uid, send_req, with default emit_heartbeat, emit_init_heartbeat and recv_heartbeat implementations - heartbeat_loop helper Postgres and mongodb now keep only a thin HeartbeatSender impl. No behavior or wire-format change. Closes Totodore#767
|
Totodore I wanted to say Thanks for the patience, really appreciate you letting me take on this refactor. Happy to iterate on any feedback. |
Totodore
left a comment
There was a problem hiding this comment.
Hey, thanks for this initiative. With this work, there is one emerging issue that needs to be adressed before continuing.
Adapters are created per-namespace from an adapter constructor/adapter state.
Currently the heartbeat mechanism is bound to an adapter (per-namespace) wheras it does not rely on any per-namespace feature, it only uses the uid which is a global server id.
For this purpose it would be better to bind the heartbeat mechanism to the constructor/adapter state to avoid duplicating all this logic between every namespace.
Each adapter could then take an instance of HeartbeatTracker to access specific shared infos (like server count).
refactor(core): move heartbeat/liveness logic into core behind remote-adapter feature
Motivation
The postgres and mongodb adapters independently implement the same
heartbeat/liveness logic: the same
nodes_liveness: Mutex<Vec<(Uid, Instant)>>field, the same interval-based heartbeat job, the same
emit_heartbeat/emit_init_heartbeathelpers, the samerecv_heartbeathandler (~130 LOC duplicated verbatim, only the error type differs) and the
same
server_countdead-node pruning. This duplication makes maintenanceharder and is contrary to the goal of #727 (share more code between adapters).
Solution
Move the heartbeat/liveness logic into
socketioxide-corebehind the existingremote-adapterfeature flag:HeartbeatTracker: wrapsnodes_liveness+hb_timeout;on_heartbeat(update-or-push, returns whether an
InitHeartbeatreply is due),server_count(prune dead nodes + self),is_alive.HeartbeatSendertrait:uid,send_req, with defaultemit_heartbeat,emit_init_heartbeatandrecv_heartbeatimplementations.heartbeat_loophelper.Postgres and mongodb now keep only a thin
HeartbeatSenderimpl (theiradapter-specific
send_req+uid) plus aHeartbeatTrackerfield.No behavior or wire-format change. Redis is unaffected: it has no heartbeat
(liveness is pub/sub subscriber counting via
num_serv).Closes #767