-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
fix issue in composite file #1456
Conversation
The file offsets were recorded incorrectly in some cases, e.g. when the recording looked like this [(Field 1, Index 0, Offset 0), (Field 1, Index 1, Offset 14), (Field 0, Index 0, Offset 14)]. The last file is offset 14 to end of file for field 0. But the data was converted to a vec and sorted, which changes the last file to Field 1.
a49c4fe
to
471fab2
Compare
Codecov Report
@@ Coverage Diff @@
## main #1456 +/- ##
==========================================
- Coverage 94.19% 94.18% -0.02%
==========================================
Files 237 237
Lines 44406 44443 +37
==========================================
+ Hits 41830 41860 +30
- Misses 2576 2583 +7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -106,6 +98,14 @@ pub struct CompositeFile { | |||
offsets_index: HashMap<FileAddr, Range<usize>>, | |||
} | |||
|
|||
impl std::fmt::Debug for CompositeFile { | |||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
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.
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
What an horrible bug. Thanks for spotting! |
@@ -60,8 +60,8 @@ impl<W: TerminatingWrite + Write> CompositeWrite<W> { | |||
pub fn for_field_with_idx(&mut self, field: Field, idx: usize) -> &mut CountingWriter<W> { | |||
let offset = self.write.written_bytes(); | |||
let file_addr = FileAddr::new(field, idx); | |||
assert!(!self.offsets.contains_key(&file_addr)); | |||
self.offsets.insert(file_addr, offset); | |||
assert!(!self.offsets.iter().any(|el| el.0 == file_addr)); |
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.
Should this really be an assert
instead of a debug_assert
, i.e. is it necessary for memory safety? This does have linear instead of amortized constant runtime in the number of offsets now, so avoiding the check in release builds would be nice if possible IMHO.
The file offsets were recorded incorrectly in some cases, e.g. when the recording looked like this [(Field 1, Index 0, Offset 0), (Field 1, Index 1, Offset 14), (Field 0, Index 0, Offset 14)]. The last file is offset 14 to end of file for field 0. But the data was converted to a vec and sorted, which changes the last file to Field 1.