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

span: Re-initialize iterator when forwarding #115509

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

miretskiy
Copy link
Contributor

@miretskiy miretskiy commented Dec 3, 2023

Re-initialize iterator when forwarding span
frontier timestamp. The underlying btree may be
mutated (by merge operation) invalidating previously
constructed iterator.

Btree implementation is also hardened against mis-use
when mutating span frontier while iterating.

Fixes #115411
Fixes #115528
Fixes #115512
Fixes #115490
Fixes #115488
Fixes #115487
Fixes #115483

Release notes: None

@miretskiy miretskiy requested review from stevendanna and a team December 3, 2023 02:07
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Use concurrent frontier in TestRangeFeedMetricsManagement.

Fixes cockroachdb#115407

Release note: None
Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

I left some questions but I think I'm going to need to read the implementation more completely to understand this bug fix.

Comment on lines 129 to 135
if err := collectOverlaps(span, startAt, f, &sg); err != nil {
return err
}

if err := collectOverlaps(span, startAt, f, &sg); err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we do this twice? If required, it could definitely use a comment.

If unintentional, perhaps collectOverlaps could construct the SpanGroup and return it rather than taking it as an out param?

Comment on lines 820 to 822
// collectOverlaps collects all spans overlapping s, and including s, into span
// group. Any overlapping spans with timestamp less than startAt are forwarded.
func collectOverlaps(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we could give this a name that makes it more clear it will mutate the given frontier.

Copy link
Contributor Author

@miretskiy miretskiy left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna)


pkg/util/span/frontier.go line 822 at r2 (raw file):

Previously, stevendanna (Steven Danna) wrote…

I wonder if we could give this a name that makes it more clear it will mutate the given frontier.

Got better name; and simplified this function and the call sites.
This function, now called spanDifference simply computes a set difference
between the span and the frontier, and returns that diff.


pkg/util/span/llrb_frontier.go line 135 at r2 (raw file):

Previously, stevendanna (Steven Danna) wrote…

Why do we do this twice? If required, it could definitely use a comment.

If unintentional, perhaps collectOverlaps could construct the SpanGroup and return it rather than taking it as an out param?

Total copy pasta.

Re-initialize iterator when forwarding span
frontier timestamp.  The underlying btree may be
mutated (by merge operation) invalidating previously
constructed iterator.

Fixes cockroachdb#115411

Release notes: None
Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Thanks for hunting this down!

@miretskiy
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 4, 2023

Build succeeded:

@craig craig bot merged commit cac8b23 into cockroachdb:master Dec 4, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment