Skip to content

Commit

Permalink
Fix handling of end of user records
Browse files Browse the repository at this point in the history
Summary: This addresses some broken logic that didn't need to exist. For all files, if the index record is before user records, or after, and we can always trust that it if after, then it marks the end of user records data.

Reviewed By: hanghu

Differential Revision: D64150620

fbshipit-source-id: 61b40ed6e5b72fc538b6eccf9a84ade23c3dfd8e
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Oct 10, 2024
1 parent ec70069 commit 524211f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
17 changes: 3 additions & 14 deletions vrs/FileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,9 @@ void FileHeader::enableFrontIndexRecordSupport() {

int64_t FileHeader::getEndOfUserRecordsOffset(int64_t fileSize) const {
if (looksLikeAVRSFile()) {
switch (fileFormatVersion.get()) {
case kOriginalFileFormatVersion:
// index record always in the back, firstUserRecordOffset is 0
if (indexRecordOffset.get() > 0) {
return min<int64_t>(fileSize, indexRecordOffset.get());
}
break;
case kFrontIndexFileFormatVersion:
case kZstdFormatVersion:
// index maybe before or after the user records, and firstUserRecordOffset should be valid.
if (indexRecordOffset.get() > 0 && indexRecordOffset.get() > firstUserRecordOffset.get()) {
return min<int64_t>(fileSize, indexRecordOffset.get());
}
break;
// index maybe before or after the user records
if (indexRecordOffset.get() > firstUserRecordOffset.get()) {
return min<int64_t>(fileSize, indexRecordOffset.get());
}
}
return fileSize;
Expand Down
6 changes: 2 additions & 4 deletions vrs/RecordFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,8 @@ const vector<int64_t>& RecordFileReader::getRecordBoundaries() const {
}
lastOffset = r.fileOffset;
}
int64_t fileSize = file_->getTotalSize();
recordBoundaries_.emplace_back(
endOfUserRecordsOffset_ < fileSize ? endOfUserRecordsOffset_ : fileSize);
if (sortNeeded || recordBoundaries_.back() < lastOffset) {
recordBoundaries_.emplace_back(endOfUserRecordsOffset_);
if (sortNeeded) {
sort(recordBoundaries_.begin(), recordBoundaries_.end());
}
}
Expand Down

0 comments on commit 524211f

Please sign in to comment.