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

[v24.2.x] Fixed race condition between appends and prefix truncation #24329

Conversation

vbotbuildovich
Copy link
Collaborator

Backport of PR #24306

Adding a stress fiber to the test executing appends and concurrently
prefix truncation allows to easily trigger any race condition bugs.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
(cherry picked from commit 73fdfe1)
The race condition between prefix truncation and appends was leading to
an issue in which the same offset might have been assigned twiice to
batches that were appended to log. This invalidates the invariant and
may lead to inconsistencies.

The fix has two parts. The first part fixes calculation of next offset
for the newly created log appender. Previously the check incorrectly
validated if the log is empty. The condition was simplified and it is
now based on an invariant that if the `start_offset > dirty_offset` the
log is empty (there is one exception to it when the log is empty and
first initialized, but then the next offset is derived as usual by
incrementing the dirty offset).

The second part of the fix is an addition of check if the segment is
still removable after the segment write lock was acquired for its
removal. It is perfectly viable scenario that when the prefix truncation
fiber is waiting for the lock the segment is written to. In this case
the segment should not be removed as it contains valid data.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
(cherry picked from commit 3709f81)
@vbotbuildovich vbotbuildovich added this to the v24.2.x-next milestone Nov 26, 2024
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label Nov 26, 2024
@piyushredpanda piyushredpanda merged commit cb0cb27 into redpanda-data:v24.2.x Nov 27, 2024
17 checks passed
@BenPope BenPope modified the milestones: v24.2.x-next, v24.2.13 Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redpanda kind/backport PRs targeting a stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants