-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(buffers): recover disk_v2 from durable checkpoints #25845
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
Open
graphcareful
wants to merge
3
commits into
vectordotdev:master
Choose a base branch
from
graphcareful:fix/disk-v2-checkpoint-window-recovery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fixed a `disk_v2` buffer accounting bug where the unread-bytes counter (`total_buffer_size`) could underflow on restart. Previously the buffer seeded the counter from the sum of on-disk data file sizes and then had the reader decrement it record-by-record while seeking to its persisted read position. Those two inputs were captured at different moments — the data files on disk versus the read position in the ledger, which are flushed on independent schedules — so a crash between their flushes could make the decrements exceed the seeded total. Because the counter is unsigned, the subtraction wrapped to a near-maximum value, making the buffer appear permanently full and wedging the writer (no further writes accepted, and recovery could stall). The reader now recomputes the unread total authoritatively at the end of its startup seek, from a single consistent snapshot — the total size of the data files still on disk minus the bytes it consumed reaching the resume position — so the counter can no longer underflow across a restart. | ||
|
|
||
| authors: graphcareful | ||
1,324 changes: 1,324 additions & 0 deletions
1,324
lib/vector-buffers/src/variants/disk_v2/checkpoint_recovery.rs
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ pub const MINIMUM_MAX_RECORD_SIZE: usize = align16(RECORD_HEADER_LEN + 1); | |
| // have it configured. | ||
| pub const DEFAULT_FLUSH_INTERVAL: Duration = Duration::from_millis(500); | ||
|
|
||
| pub const DEFAULT_DATA_FILE_CLEANUP_INTERVAL: Duration = Duration::from_secs(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment on this in the manner of the other DEFAULT_ constants would be swell. |
||
|
|
||
| // Using 256KB as it aligns nicely with the I/O size exposed by major cloud providers. This may not | ||
| // be the underlying block size used by the OS, but it still aligns well with what will happen on | ||
| // the "backend" for cloud providers, which is simply a useful default for when we want to look at | ||
|
|
@@ -44,6 +46,29 @@ pub const MAX_FILE_ID: u16 = u16::MAX; | |
| #[cfg(test)] | ||
| pub const MAX_FILE_ID: u16 = 6; | ||
|
|
||
| pub(crate) fn data_file_id_in_range(file_id: u16, start: u16, end: u16) -> bool { | ||
| if start <= end { | ||
| (start..=end).contains(&file_id) | ||
| } else { | ||
| file_id >= start || file_id <= end | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn data_file_name(file_id: u16) -> String { | ||
| format!("buffer-data-{file_id}.dat") | ||
| } | ||
|
|
||
| pub(crate) fn parse_data_file_id(path: &Path) -> Option<u16> { | ||
| let file_name = path.file_name()?.to_str()?; | ||
| let id = file_name | ||
| .strip_prefix("buffer-data-")? | ||
| .strip_suffix(".dat")? | ||
| .parse() | ||
| .ok()?; | ||
|
|
||
| (id < MAX_FILE_ID).then_some(id) | ||
| } | ||
|
|
||
| // The alignment used by the record serializer. | ||
| const SERIALIZER_ALIGNMENT: usize = 16; | ||
| const MAX_ALIGNABLE_AMOUNT: usize = usize::MAX - SERIALIZER_ALIGNMENT; | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little much for a changelog note. I think the first sentence may be all we need here, though including the rest in the PR description or some other documentation would be valuable.