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

[RFC] include/interval_set: iterate until p->first < start #53063

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/include/interval_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,34 @@ class interval_set {
private:
auto find_inc(T start) const {
auto p = m.lower_bound(start); // p->first >= start
if (p != m.begin() &&
(p == m.end() || p->first > start)) {
--p; // might overlap?
if (p->first + p->second <= start)
++p; // it doesn't.
if (p != m.end()) {
while (p != m.begin()) {
if (p->first <= start) {
Copy link
Member

Choose a reason for hiding this comment

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

This is buggy. Old code will make sure that the p won't be .end(), but yours seems will crash ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so if we dont hit this if {} then it assume either p->first > start or p==m.end(), so in this case we decrement --p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i.e. it wont hit end() here either

Copy link
Member

Choose a reason for hiding this comment

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

Won't the m.lower_bound() return .end() if it couldn't find any item ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay so you're implying that we should just return directly in case we dont find anything in the map, right? you're correct, i need to handle this edge case. decrementing in case there is nothing would be disastrous

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the corner edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check now

Copy link
Member

Choose a reason for hiding this comment

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

In erase() it will check ceph_assert(p != m.end()); . Your above change could return .end().

break;
} else {
--p; // might overlap?
}
}
if (p->first + p->second <= start) {
++p; // it doesn't.
}
}
return p;
}

auto find_inc_m(T start) {
auto p = m.lower_bound(start);
lxbsz marked this conversation as resolved.
Show resolved Hide resolved
if (p != m.begin() &&
(p == m.end() || p->first > start)) {
--p; // might overlap?
if (p->first + p->second <= start)
++p; // it doesn't.
if (p != m.end()) {
while (p != m.begin()) {
if (p->first <= start) {
break;
} else {
--p; // might overlap?
}
}
if (p->first + p->second <= start) {
++p; // it doesn't.
}
}
return p;
}
Expand Down