Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(outbox): implement outbox queue on transaction #548

Merged
merged 1 commit into from
Sep 5, 2024
Merged

Conversation

zcabter
Copy link
Collaborator

@zcabter zcabter commented Aug 21, 2024

Context

This PR omplements the lower level transactional outbox queue api

Part of JSTZ-27

Description

Why

The kernel is only allowed to write 100 messages per level. Luckily, the kernel sdk to expose an OutboxQueue which decouples enqueuing outbox messages and writing to the outbox, allowing a much high upper limit of outbox messages to be persisted as long as they are flushed (ideally, every level). However, the OutboxQueue is eager to write to persistent storage on message enqueue which makes it difficult to rollback and doesn't fit our transaction model.

What

Instead, we define an outbox queue for each snapshot that adheres to the transaction rules. Furthermore, an api is added to transaction to enqueue messages to the latest snapshot and to flush messages (on commit).
Here are high level details:

  • Each snapshot in the transaction carries its own outbox queue.
  • On enqueue, the outbox message is appended to the latest snapshot
  • On commit:
    • The current snapshot queue is merged with its parent, respecting the enqueue order of messages.
    • If the snapshot is at the bottom of the stack, the snapshot queue will be flushed instead.
  • On flush, the rollup outbox queue is flushed (written to outbox) first then the snapshot outbox queue until 100 messages have been flushed . The remaining messages in the snapshot outbox queue will be pushed into the rollup outbox queue. The next time flush is called, these remaining messages will be written out first followed by the snapshot and so on.

Manually testing the PR

cargo test -p jstz_core kv

@zcabter zcabter changed the title feat(outbox): implement outbox on transaction [WIP] feat(outbox): implement outbox on transaction Aug 21, 2024
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 86.90476% with 66 lines in your changes missing coverage. Please review.

Project coverage is 29.69%. Comparing base (c8fcaed) to head (0492b3c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/jstz_core/src/kv/outbox.rs 89.15% 12 Missing and 24 partials ⚠️
crates/jstz_core/src/kv/transaction.rs 84.02% 22 Missing and 5 partials ⚠️
crates/jstz_core/src/error.rs 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
crates/jstz_core/src/kv/mod.rs 39.13% <ø> (ø)
crates/jstz_core/src/error.rs 0.00% <0.00%> (ø)
crates/jstz_core/src/kv/transaction.rs 69.69% <84.02%> (+7.78%) ⬆️
crates/jstz_core/src/kv/outbox.rs 89.15% <89.15%> (ø)

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8fcaed...0492b3c. Read the comment docs.

@zcabter zcabter force-pushed the ryan@outbox branch 2 times, most recently from 59bcf1d to 72460ad Compare August 22, 2024 13:30
@zcabter zcabter changed the title [WIP] feat(outbox): implement outbox on transaction feat(outbox): implement outbox on transaction Aug 22, 2024
@zcabter zcabter changed the title feat(outbox): implement outbox on transaction feat(outbox): implement outbox queue on transaction Aug 22, 2024
@zcabter zcabter requested a review from johnyob August 22, 2024 13:48
@zcabter zcabter force-pushed the ryan@outbox branch 2 times, most recently from ae53270 to 995a24b Compare August 22, 2024 18:31
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
/// next flush.
pub fn flush(
&mut self,
host: &mut impl Runtime,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
host: &mut impl Runtime,
rt: &mut impl Runtime,

crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
let max = u16::MAX as u32;
let mut outbox_queue = OutboxQueue {
meta: OutboxQueueMeta {
queue_len: 120,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Incorrect setup? Initial queue length is 60


outbox_queue.flush(&mut host, outbox_queue_snapshot);

assert_eq!(20, outbox_queue.queue_len());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Incorrect calculation: 120 - 60 (flushed) - 40 (written) = 20
Should be: 60 - 60 (flushed) + 20 (queued) = 20

crates/jstz_core/src/kv/transaction.rs Outdated Show resolved Hide resolved
@johnyob johnyob assigned zcabter and unassigned johnyob Aug 28, 2024
@zcabter zcabter force-pushed the ryan@outbox branch 5 times, most recently from bdbd15d to 10d45f0 Compare August 28, 2024 18:33
@zcabter zcabter assigned johnyob and unassigned zcabter Aug 28, 2024
crates/jstz_core/src/kv/transaction.rs Outdated Show resolved Hide resolved
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
crates/jstz_core/src/kv/outbox.rs Outdated Show resolved Hide resolved
@johnyob johnyob assigned zcabter and unassigned johnyob Aug 29, 2024
@zcabter zcabter force-pushed the ryan@outbox branch 2 times, most recently from 617b2ff to e4ad642 Compare September 2, 2024 15:37
@zcabter zcabter assigned johnyob and unassigned zcabter Sep 2, 2024
Copy link
Collaborator

@johnyob johnyob left a comment

Choose a reason for hiding this comment

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

lgtm 🚀

@johnyob johnyob removed their assignment Sep 5, 2024
feat(outbox): move outbox snapshots into outbox queue
@zcabter zcabter merged commit c7b6c30 into main Sep 5, 2024
3 checks passed
@zcabter zcabter deleted the ryan@outbox branch September 5, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants