Skip to content

Conversation

@kfaraz
Copy link
Contributor

@kfaraz kfaraz commented Jul 8, 2025

Bug

Concurrent append uses lock of type APPEND which always uses a lock version of epoch 1970-01-01.

This can cause data loss in a flow as follows:

  • Ingest data using an APPEND task to an empty interval
  • Mark all the segments as unused
  • Re-run the APPEND task
  • Data is not visible since old segment IDs (now unused) are allocated again

Fix

In segment allocation, do not reuse an old segment ID, used or unused.
This fix was already done for some cases back in #16380 .

An embedded test for this has been included in #18207 EmbeddedConcurrentAppendReplaceTest


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@kfaraz kfaraz added the Bug label Jul 8, 2025
@kfaraz kfaraz added this to the 34.0.0 milestone Jul 8, 2025
Copy link
Contributor

@jtuglu1 jtuglu1 left a comment

Choose a reason for hiding this comment

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

LGTM

@kfaraz kfaraz merged commit acd3b29 into apache:master Jul 8, 2025
76 checks passed
@kfaraz kfaraz deleted the fix_car branch July 8, 2025 17:13
@imply-cheddar
Copy link
Contributor

This code change will append the new segment to the old set of segments. If that old set of segments had a non-zero core partition numbers, then the appended segment will carry the same set of core partitions (non-zero) and will publish the new appended segment with the extra appended partition num.

This new segment will never actually be used in queries because the core partitions will never be fully loaded by the system as it is not a complete partition of data (the semantics of the system are that the core partitions must all exist for the segments in that time range to be considered complete, extra partitions can exist, but do not have to). This means that even in the case where this showed up (a segment was dropped and then new data came in), the newly created segment won't actually be queried.

The correct fix for this is to generate a net-new version that is "better" than the previous version, adding more partitions to the unused segments is weird. IIRC, we used the static 1970 version just as a short-circuit because we weren't sure what the best version to use was in the case where nothing exists yet. At this point, we now understand why it's important to use a better version and the version of the lock should be "better" than the unused segments. Please revert this change and adjust to use a better version.

kfaraz added a commit that referenced this pull request Jul 11, 2025
This is a better approach to the fix in #18216

Changes:
- When allocating the first segment in an interval which already contains an unused segment,
use a fresh version rather than reusing the old version (now unused)
capistrant pushed a commit to capistrant/incubator-druid that referenced this pull request Jul 17, 2025
This is a better approach to the fix in apache#18216

Changes:
- When allocating the first segment in an interval which already contains an unused segment,
use a fresh version rather than reusing the old version (now unused)
capistrant added a commit that referenced this pull request Jul 17, 2025
This is a better approach to the fix in #18216

Changes:
- When allocating the first segment in an interval which already contains an unused segment,
use a fresh version rather than reusing the old version (now unused)

Co-authored-by: Kashif Faraz <[email protected]>
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.

3 participants