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

cloud_storage: fix segment materialisation race #13796

Merged

Conversation

VladLazar
Copy link
Contributor

In order to create a new materialised segment, one needs to grab units
from materialized_resources first. This is an async operation. By the
time units are acquired, said segment might have already been via a
different code path, resulting in the assertion in
remote_partition::materialize_segment triggering.
remote_partition::aborted_transactions was particularly susceptible to
this.

This patch fixes the issue by checking for the existence of the segment
and creating a segment (if needed) in the same scheduling task.
Functionally, for the read path, nothing should change.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.2.x
  • v23.1.x
  • v22.3.x

Release Notes

Bug Fixes

  • Fix race leading to assertion on materialisation of cloud storage segments

abhijat
abhijat previously approved these changes Sep 29, 2023
abhijat
abhijat previously approved these changes Sep 29, 2023
@vbotbuildovich
Copy link
Collaborator

@vbotbuildovich
Copy link
Collaborator

In order to create a new materialised segment, one needs to grab units
from `materialized_resources` first. This is an async operation. By the
time units are acquired, said segment might have already been via a
different code path, resulting in the assertion in
`remote_partition::materialize_segment` triggering.
`remote_partition::aborted_transactions` was particularly susceptible to
this.

This patch fixes the issue by checking for the existence of the segment
and creating a segment (if needed) in the same scheduling task.
Functionally, for the read path, nothing should change.
Copy link
Contributor

@Lazin Lazin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@andrwng andrwng left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but might be nice to avoid changes to the non-transactional path if we can avoid it

@@ -163,7 +180,7 @@ remote_partition::borrow_result_t remote_partition::borrow_next_segment_reader(
}
if (iter == _segments.end()) {
auto path = manifest.generate_segment_path(*mit);
iter = materialize_segment(path, *mit, std::move(segment_unit));
iter = get_or_materialize_segment(path, *mit, std::move(segment_unit));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should have a separate call that expects callers to have made the segment check in the same task. Or maybe we can tweak the above find() to use get_or_materialize_segment()?

Just noting that this is seeking twice for the same offset with no scheduling points in between.

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 think the offloading logic above should move in get_or_materialize_segment, but I chose not to do it in this PR to keep the change less intrusive.

@vbotbuildovich
Copy link
Collaborator

@vbotbuildovich
Copy link
Collaborator

@vbotbuildovich
Copy link
Collaborator

@VladLazar
Copy link
Contributor Author

Will trigger another run to see if the instability is caused by this change or if we go unlucky.

@VladLazar
Copy link
Contributor Author

/ci-repeat

@piyushredpanda piyushredpanda merged commit ed38970 into redpanda-data:dev Sep 29, 2023
9 checks passed
@vbotbuildovich
Copy link
Collaborator

/backport v23.2.x

@vbotbuildovich
Copy link
Collaborator

@vbotbuildovich
Copy link
Collaborator

@vbotbuildovich
Copy link
Collaborator

Copy link
Member

@dotnwat dotnwat left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants