bfd: actually insert peers into persistent db - #884
Open
taspelund wants to merge 2 commits into
Open
Conversation
BFD peers were not being inserted into the sled db, which means they weren't recoverable on daemon restart/crash. This moves all of the BFD API handlers' core logic into methods of BfdContext, and makes BfdContext.daemon private. With BfdContext being the sole owner of its inner state, all locking invariants can be upheld without requiring any participation from its callers. API operations now lock the daemon slightly earlier, ensuring updates to both the DB and the runtime state happen during the critical section of the mutex. This prevents concurrent API Add/Del requests from partially trampling over each other by enforcing serialization. Peer add requests now implement a rollback function upon runtime errors. e.g. 1) Add peer to DB (success) 2) Add peer to daemon (failure) 3) Rollback DB entry Rollback failures return a 500 error. before: ``` treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) › ./target/debug/mgadm bfd add-peer 100.64.0.0 0.0.0.0 1000 3 single-hop treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) › ./target/debug/mgadm bfd get-peers Peer Listen Required Rx Detection Threshold Mode Status 100.64.0.0 0.0.0.0 1000 3 SingleHop Down treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) › pkill mgd pkill: signalling pid 33096: Operation not permitted treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕ › sudo !! treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕ › sudo pkill mgd treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) › pkill mgd pkill: signalling pid 35931: Operation not permitted treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕ › ./target/debug/mgadm bfd get-peers Peer Listen Required Rx Detection Threshold Mode Status treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) › ``` after: ``` treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9 › ./target/debug/mgadm bfd get-peers Peer Listen Required Rx Detection Threshold Mode Status treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9 › ./target/debug/mgadm bfd add-peer 100.64.0.0 0.0.0.0 1000 3 single-hop treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9 › pgrep mgd 42931 treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9 › sudo pkill mgd treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9 › pgrep mgd 43407 treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9 › ./target/debug/mgadm bfd get-peers Peer Listen Required Rx Detection Threshold Mode Status 100.64.0.0 0.0.0.0 1000 3 SingleHop Down ``` Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
taspelund
requested review from
cfzimmerman,
jgallagher,
nicolaskagami and
rcgoodfellow
August 20, 2026 02:22
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.
BFD peers were not being inserted into the sled db, which means they
weren't recoverable on daemon restart/crash.
This moves all of the BFD API handlers' core logic into methods of
BfdContext, and makes BfdContext.daemon private. With BfdContext being
the sole owner of its inner state, all locking invariants can be upheld
without requiring any participation from its callers.
API operations now lock the daemon slightly earlier, ensuring updates to
both the DB and the runtime state happen during the critical section of
the mutex. This prevents concurrent API Add/Del requests from partially
trampling over each other by enforcing serialization.
Peer add requests now implement a rollback function upon runtime errors.
e.g.
Rollback failures return a 500 error.
before:
after:
Signed-off-by: Trey Aspelund trey@oxidecomputer.com