Skip to content

wal-protocol: store UpsertRuleBookCommand as opaque bilrost bytes in v1#4722

Merged
muhamadazmy merged 1 commit into
mainfrom
pr4722
May 12, 2026
Merged

wal-protocol: store UpsertRuleBookCommand as opaque bilrost bytes in v1#4722
muhamadazmy merged 1 commit into
mainfrom
pr4722

Conversation

@muhamadazmy
Copy link
Copy Markdown
Contributor

@muhamadazmy muhamadazmy commented May 12, 2026

wal-protocol: store UpsertRuleBookCommand as opaque bilrost bytes in v1

Summary

  • Convert UpsertRuleBookCommand to a bilrost::Message carrying
    Arc<RuleBook> directly, instead of a serde struct wrapping an
    already-bilrost-encoded Bytes. Eliminates the previous double encoding
    (serde-around-bilrost) on the proposal path.
  • In v1, Command::UpsertRuleBook now wraps an opaque Bytes payload (the
    bilrost-encoded UpsertRuleBookCommand) rather than the typed struct.
    Because UpsertRuleBook is *Since v1.7.0 and still unreleased, this
    payload change is backward compatible.
  • v1→v2 compatibility no longer decodes/re-encodes the rule book; it
    forwards the bilrost payload via Envelope::from_bytes_unchecked,
    matching the existing pattern used for VQueues* / VQSchedulerDecisions.
  • record_keys() for the v1 variant falls back to Keys::Single(self.partition_key())
    since the partition_key_range is no longer reachable without decoding.
  • Leader proposer encodes the command into the shared arena buffer before
    proposing, avoiding an extra allocation.
  • State machine now ignores UpsertRuleBook messages whose
    partition_key_range does not overlap the local partition's range,
    mirroring how other range-targeted commands are filtered.

Stack created with Sapling. Best reviewed with ReviewStack.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5cbbba9959

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/wal-protocol/src/v1.rs Outdated
// log per partition `Keys::Single` is enough for routing
// (`Keys::None` would also work); v2 decodes the typed command and
// uses the full range.
Command::UpsertRuleBook(_) => Keys::Single(self.partition_key()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep rule-book records visible to overlapping readers

When a v1 UpsertRuleBook is replayed by a partition whose key range overlaps the encoded command but does not contain the envelope destination key, this Keys::Single makes Bifrost filter the record out before the new overlap check can run: partition processors create readers with KeyFilter::Within(partition_store.partition_key_range()) (crates/worker/src/partition/mod.rs:561-564), and Keys::Single only matches if that exact key is inside the reader range (crates/types/src/logs/mod.rs:214-215). Since the payload still carries the full partition_key_range, use Keys::None or preserve range keys; otherwise overlapping successors/readers can miss a rule-book update entirely.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

Test Results

  8 files  ±0    8 suites  ±0   4m 44s ⏱️ -8s
 50 tests ±0   50 ✅ ±0  0 💤 ±0  0 ❌ ±0 
218 runs  ±0  218 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 95164d7. ± Comparison against base commit cf62e91.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me. Just a small nit to explain to readers that the wrapper is meant to be a v1-only stop-gap measure.

Comment thread crates/wal-protocol/src/control.rs Outdated
Comment on lines +275 to +281
/// A temporary wrapper for [`UpsertRuleBookCommand`]
/// to only supply the partition_key_range
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UpsertRuleBookCommandWrapper {
pub partition_key_range: KeyRange,
pub rule_book: Bytes,
/// Bytes are bilrost encoded [`UpsertRuleBookCommand`]
pub command: Bytes,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave a comment indicating that this is a v1-only wrapper? Or perhaps move to v1/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it's a good idea indeed to move it to v1.

## Summary
- Convert `UpsertRuleBookCommand` to a `bilrost::Message` carrying
  `Arc<RuleBook>` directly, instead of a serde struct wrapping an
  already-bilrost-encoded `Bytes`. Eliminates the previous double encoding
  (serde-around-bilrost) on the proposal path.
- In v1, `Command::UpsertRuleBook` now wraps an opaque `Bytes` payload (the
  bilrost-encoded `UpsertRuleBookCommand`) rather than the typed struct.
  Because `UpsertRuleBook` is `*Since v1.7.0` and still unreleased, this
  payload change is backward compatible.
- v1→v2 compatibility no longer decodes/re-encodes the rule book; it
  forwards the bilrost payload via `Envelope::from_bytes_unchecked`,
  matching the existing pattern used for `VQueues*` / `VQSchedulerDecisions`.
- `record_keys()` for the v1 variant falls back to `Keys::Single(self.partition_key())`
  since the `partition_key_range` is no longer reachable without decoding.
- Leader proposer encodes the command into the shared arena buffer before
  proposing, avoiding an extra allocation.
- State machine now ignores `UpsertRuleBook` messages whose
  `partition_key_range` does not overlap the local partition's range,
  mirroring how other range-targeted commands are filtered.
@muhamadazmy muhamadazmy merged commit 1d5bbab into main May 12, 2026
58 of 59 checks passed
@muhamadazmy muhamadazmy deleted the pr4722 branch May 12, 2026 16:17
@github-actions github-actions Bot locked and limited conversation to collaborators May 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants