-
Notifications
You must be signed in to change notification settings - Fork 14
prevent absent unused segment from overwriting existing segments #103
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b64cde
prevent absent unused segment from overwriting existing segments
generall 77c0217
Add debug assert, any open segment cannot have same/newer ID than unused
timvisee 83b8b9a
Assert in test that open-3 does not exists, ensure test correctness
timvisee 1c91957
Move debug assertion to the top
timvisee 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
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
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
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,80 @@ | ||
| use crate::test_utils::EntryGenerator; | ||
| use crate::{Wal, WalOptions}; | ||
| use std::num::NonZeroUsize; | ||
| use tempfile::Builder; | ||
|
|
||
| #[test] | ||
| fn test_handling_missing_empty_segment() { | ||
| let entry_count = 5; | ||
|
|
||
| let dir = Builder::new().prefix("wal").tempdir().unwrap(); | ||
| let options = WalOptions { | ||
| segment_capacity: 1024, | ||
| segment_queue_len: 0, | ||
| retain_closed: NonZeroUsize::new(1).unwrap(), | ||
| }; | ||
|
|
||
| let mut wal = Wal::with_options(dir.path(), &options).unwrap(); | ||
| let entries = EntryGenerator::new().take(entry_count).collect::<Vec<_>>(); | ||
|
|
||
| for entry in &entries { | ||
| wal.append(entry).unwrap(); | ||
| } | ||
|
|
||
| wal.flush_open_segment().unwrap(); | ||
|
|
||
| drop(wal); | ||
|
|
||
| eprintln!("------------ first WAL created ------------"); | ||
|
|
||
| let wal = Wal::open(dir.path()).unwrap(); | ||
|
|
||
| let num = wal.num_entries(); | ||
|
|
||
| assert_eq!(num, entry_count as u64); | ||
|
|
||
| drop(wal); | ||
|
|
||
| eprintln!("------------ WAL opened and closed ------------"); | ||
|
|
||
| // List directory contents | ||
|
|
||
| let entries: Vec<_> = std::fs::read_dir(dir.path()) | ||
| .unwrap() | ||
| .map(|res| res.map(|e| e.file_name())) | ||
| .collect::<Result<_, std::io::Error>>() | ||
| .unwrap(); | ||
|
|
||
| for entry in &entries { | ||
| eprintln!("{:?}", entry); | ||
| } | ||
|
|
||
| // Remove the last segment file (which is empty) | ||
| assert!( | ||
| !dir.path().join("open-3").exists(), | ||
| "open-3 should not exist", | ||
| ); | ||
| let last_segment_file = dir.path().join("open-2"); | ||
| std::fs::remove_file(last_segment_file).unwrap(); | ||
|
|
||
| eprintln!("------------ removed last segment ------------"); | ||
|
|
||
| let wal = Wal::open(dir.path()).unwrap(); | ||
|
|
||
| let num = wal.num_entries(); | ||
|
|
||
| assert_eq!(num, entry_count as u64); | ||
|
|
||
| // sleep, to account for background process creating more segments | ||
| std::thread::sleep(std::time::Duration::from_millis(100)); | ||
|
|
||
| drop(wal); | ||
|
|
||
| eprintln!("------------ WAL opened and closed again ------------"); | ||
|
|
||
| let wal = Wal::open(dir.path()).unwrap(); | ||
|
|
||
| let num = wal.num_entries(); | ||
|
|
||
| assert_eq!(num, entry_count as u64); | ||
| } |
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.
I've added a debug assertion to ensure any
open_segmenthas a lower ID than allunused_segments.