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

fix: ExtentTree use of invalidated iterator #4416

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/core/extent_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ExtentTree::Add(size_t start, size_t len) {
DCHECK_EQ(len_extents_.size(), extents_.size());

auto it = extents_.lower_bound(start);
optional<absl::btree_map<size_t, size_t>::iterator> prev_extent;
optional<size_t> prev_extent_key;

if (it != extents_.begin()) {
auto prev = it;
Expand All @@ -29,7 +29,7 @@ void ExtentTree::Add(size_t start, size_t len) {
prev->second += len;
start = prev->first;
len += prev_len;
prev_extent = prev;
prev_extent_key = prev->first;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

absl also issued a warning but the test did not fail. Maybe we should somehow be aware of these warnings (because they usually point to the root cause of the problem)

}
}

Expand All @@ -44,8 +44,9 @@ void ExtentTree::Add(size_t start, size_t len) {
}

len_extents_.emplace(len, start);
if (prev_extent) {
(*prev_extent)->second = start + len;
if (prev_extent_key) {
DCHECK(extents_.find(*prev_extent_key) != extents_.end());
extents_[*prev_extent_key] = start + len;
} else {
extents_.emplace(start, start + len);
}
Expand Down
Loading