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

Fix used segment retrieval in Kill tasks #15306

Conversation

AmatyaAvadhanula
Copy link
Contributor

@AmatyaAvadhanula AmatyaAvadhanula commented Nov 2, 2023

Fixes a bug introduced because of #15107.
If the batch size is large and there are more than 120 intervals in the used segment fetch query, it may fail with the following error:
java.sql.SQLSyntaxErrorException: Statement too complex.

Since a KillTask operates with an EXCLUSIVE lock, the set of used segments cannot change in between the task unless there is a revokal.

Changes in this PR:

  1. Fetch the used segment set exactly once before processing any of the batches because of the above assumption.
  2. Fetch all non-revoked locks of the task before each batch to ensure that none of them were revoked in between batch processing. This ensures that we kill only those segments which are currently locked by the kill task.

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.

@AmatyaAvadhanula AmatyaAvadhanula marked this pull request as ready for review November 2, 2023 06:29
Copy link
Contributor

@abhishekrb19 abhishekrb19 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 the fix! If it's not too much effort, it'd also be nice to have a test that would otherwise fail without this patch.

@@ -196,21 +195,40 @@ public TaskStatus runTask(TaskToolbox toolbox) throws Exception
limit,
numTotalBatches != null ? StringUtils.format(" in [%d] batches.", numTotalBatches) : "."
);

RetrieveUsedSegmentsAction retrieveUsedSegmentsAction = new RetrieveUsedSegmentsAction(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could be final

Suggested change
RetrieveUsedSegmentsAction retrieveUsedSegmentsAction = new RetrieveUsedSegmentsAction(
final RetrieveUsedSegmentsAction retrieveUsedSegmentsAction = new RetrieveUsedSegmentsAction(

ImmutableList.of(getInterval()),
Segments.INCLUDING_OVERSHADOWED
);
// Fetch the load specs of all segments overlapping with the unused segment intervals
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong:

  1. The interval check is only done below from L246-249, so maybe this comment here is a bit confusing?
  2. Segments may/may not be marked as unused here depending on the deprecated markAsUnused flag, so there's no guarantee that the segments will be marked as unused in the kill tasks' interval if markAsUnused=false
Suggested change
// Fetch the load specs of all segments overlapping with the unused segment intervals
// Fetch the load specs of all used segments in the kill task's interval

@AmatyaAvadhanula
Copy link
Contributor Author

@abhishekrb19 I'll address your feedback in a follow-up PR.

@AmatyaAvadhanula AmatyaAvadhanula merged commit dc3213b into apache:master Nov 2, 2023
82 checks passed
AmatyaAvadhanula added a commit to AmatyaAvadhanula/druid that referenced this pull request Nov 2, 2023
Fix used segment retrieval in Kill tasks
@kfaraz kfaraz deleted the killTask_usedSegmentRetrieval branch November 2, 2023 14:56
AmatyaAvadhanula added a commit that referenced this pull request Nov 2, 2023
Fix used segment retrieval in Kill tasks
CaseyPan pushed a commit to CaseyPan/druid that referenced this pull request Nov 17, 2023
Fix used segment retrieval in Kill tasks
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