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(exex): write ahead log #10995

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft

feat(exex): write ahead log #10995

wants to merge 29 commits into from

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Sep 18, 2024

Towards #10489.

Implements the write-ahead log for ExEx notifications but doesn't integrate it yet.

/// WAL is a write-ahead log (WAL) that stores the notifications sent to a particular ExEx.
///
/// WAL is backed by a binary file represented by [`Storage`] and a block cache represented by
/// [`BlockCache`].
///
/// The expected mode of operation is as follows:
/// 1. On every new canonical chain notification, call [`Wal::commit`].
/// 2. When ExEx is on a wrong fork, rollback the WAL using [`Wal::rollback`]. The caller is
/// expected to create reverts from the removed notifications and backfill the blocks between the
/// returned block and the given rollback block. After that, commit new notifications as usual
/// with [`Wal::commit`].
/// 3. When the chain is finalized, call [`Wal::finalize`] to prevent the infinite growth of the
/// WAL.

@shekhirin shekhirin added C-enhancement New feature or request A-exex Execution Extensions labels Sep 18, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

unsure I fully understood how the file and cache is kept in sync.

/// Clears the block cache and fills it with the notifications from the [`Storage`], up to the
/// given offset in bytes, not inclusive.
#[instrument(target = "exex::wal", skip(self))]
fn fill_block_cache(&mut self, to_offset: u64) -> eyre::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is basically initialization?

Comment on lines +10 to +18
/// The underlying WAL storage backed by a file.
///
/// Each notification is written without any delimiters and structured as follows:
/// ```text
/// +--------------------------+----------------------------------+
/// | little endian u32 length | MessagePack-encoded notification |
/// +--------------------------+----------------------------------+
/// ```
/// The length is the length of the MessagePack-encoded notification in bytes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

not obvious to me what the order is here,
are new notifications appended?

Comment on lines 44 to 53
/// Truncates the underlying file from the given byte offset (inclusive) to the end of the file.
///
/// 1. Creates a new file and copies all notifications starting from the offset (inclusive) to
/// the end of the original file.
/// 2. Renames the new file to the original file.
///
/// # Returns
///
/// The old and new underlying file sizes in bytes
pub(super) fn truncate_from_offset(&mut self, offset: u64) -> eyre::Result<(u64, u64)> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

so finalizing a block means we must copy and reinitialize the entire file?
with > 64 blocks (more with reorged blocks) this isn't very cheap I suppose

what happens to the offsets that the cache tracks?

@shekhirin shekhirin marked this pull request as draft September 20, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exex Execution Extensions C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants