refactor(core): move heartbeat/liveness logic into core behind remote… - #768
Open
LiamCarPer wants to merge 1 commit into
Open
refactor(core): move heartbeat/liveness logic into core behind remote…#768LiamCarPer wants to merge 1 commit into
LiamCarPer 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
Contributor
Author
|
Totodore I wanted to say Thanks for the patience, really appreciate you letting me take on this refactor. Happy to iterate on any feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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