Enforce directional controlled-flow replication config on live connections#506
Merged
Conversation
Member
Author
|
Companion PRs: schema validation HarperFast/harper#1529, docs HarperFast/documentation#555. |
There was a problem hiding this comment.
Code Review
This pull request implements controlled-flow (directional) replication via config routes, ensuring that directionality gates (sends/receives) configured locally are respected and enforced on live connections. It introduces helper functions to check route authorization and updates both subscription and sending logic to prioritize local configuration over hdb_nodes. Feedback is provided regarding a potential runtime TypeError in the new routeEntriesIncludePeer helper if it encounters non-array or null/non-object values in the entries list.
This comment has been minimized.
This comment has been minimized.
… live connections Directional config (replication.routes[].replicates.sends/receives) was stored and round-tripped but not honored at runtime: the direction gates read replicates only from the hdb_nodes record (default true), so traffic flowed bidirectionally regardless of the route config (harper-pro#498). Honor the config route's direction in four gates, only for the directional object form so boolean/subscriptions-only routes keep their existing behavior: - receive (shouldReplicateFromNode): prefer route receives/receivesFrom, carried on a distinct configRouteReplicates payload field so it is never confused with an hdb_nodes sends/sendsTo object (which would regress the add_node path). - send-authorization: honor the local route's sends/sendsTo (resolved from options.routes, which the server-side worker has). - send-side excludeTables: prefer the config route's sendsTo. - connection establishment (onNodeUpdate): the gate that decides whether to open a socket listed sends/sendsTo/receivesFrom but not the receives boolean, so a receive-only edge never connected and upstream flow died. Adds an integration test (directed edge->core topology: upstream flows, reverse and lateral flow blocked) and a unit test for the routeEntriesIncludePeer matcher. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
b9f7698 to
a69b371
Compare
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.
Summary
Makes
replication.routes[].replicates.sends/receives(controlled flow) actually constrain live traffic. Today the fields are stored and round-trip throughget_configuration, but the runtime direction gates readreplicatesonly from thehdb_nodesrecord (defaulttrue), so traffic flows fully bidirectionally regardless of the route config (harper-pro#498).Four gates now honor the config route's direction, only for the directional object form (
{ sends, receives, … }) — boolean and subscriptions-only routes keep their existing behavior:shouldReplicateFromNode): prefer the route'sreceives/receivesFrom, carried on a distinctconfigRouteReplicatespayload field so it is never confused with an hdb_nodessends/sendsToobject (which would regress theadd_nodecontrolled-flow path).replicationConnection): honor the local route'ssends/sendsTo, resolved fromoptions.routes(the server-side worker has the route list even though it has no subscription payload).excludeTables: prefer the config route'ssendsTo(was reading hdb_nodes only).onNodeUpdate): the "should I open a socket" check listedsends/sendsTo/receivesFrombut not thereceivesboolean — so a receive-only edge never connected and upstream flow died. This is the load-bearing piece that makes a one-way edge work.Purpose
Restore the documented controlled-flow behavior (
reference/replication/overview.md→ "Controlling Replication Flow"). Directed multi-tier topologies (edge → aggregation → core) currently leak reverse and lateral traffic.Where to look
subscriptionManager.onNodeUpdate(thereceives-boolean connection gate) and theconfigRouteReplicatesvsrouteReplicatesdistinction inknownNodes.shouldReplicateFromNode— the latter is the subtle correctness point (the two encodings are not interchangeable; mixing them would breakadd_nodedirectional flow).route.name === remoteNodeName; this matches the existingroutes.find(r => r.name === node.name)convention (node name = hostname).Validation
directionalFlowReplication.test.mjs: directed edge→core — upstream flows, the core write never reaches the edge (reverse/lateral blocked). Passes.excludeTablesReplicationandreplicationTopology(add_node, 9/9) pass — no regression.routeEntriesIncludePeermatcher test).Notes
allowUnknown.host:→hostname:reconcile: HarperFast/documentation companion PR (linked below once open).Generated by an LLM (Claude Opus 4.8).
🤖 Generated with Claude Code