Skip to content

feat: Add policy excluded intervals to the accumulated compaction status information for reporting - #19975

Open
capistrant wants to merge 1 commit into
apache:masterfrom
capistrant:compaction-progress-accounting-enrichement
Open

feat: Add policy excluded intervals to the accumulated compaction status information for reporting#19975
capistrant wants to merge 1 commit into
apache:masterfrom
capistrant:compaction-progress-accounting-enrichement

Conversation

@capistrant

@capistrant capistrant commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

#18802 added a compaction policy that prioritizes the most fragmented intervals for compaction. This policy also adds minimum fragmentation thresholds that allow an operator to willingly choose to skip compaction on intervals who do not have certain amounts of uncompacted volume (by uncompacted segment count and by aggregate uncompacted bytes).

These policy excluded intervals were not being reported in the compaction progress when using compaction supervisors, making it hard to understand overall compaction state for datasources when using this policy. This PR aims to close that gap by explicitly reporting on policy excluded intervals in the compaction stats reporting summary. That way datasource owners and/or cluster operators can see if compaction policy thresholds are preventing any of their data from reaching the configured compaction state for their interval.

New Metrics

|segment/policyExcluded/bytes|Total bytes of this datasource that do not match the auto compaction config but whose intervals were filtered out by the compaction candidate search policy. Relaxing the policy thresholds makes these intervals eligible for compaction again.|dataSource|Varies|
|segment/policyExcluded/count|Total number of segments of this datasource that do not match the auto compaction config but whose intervals were filtered out by the compaction candidate search policy.|dataSource|Varies|
|interval/policyExcluded/count|Total number of intervals of this datasource that need compaction but were filtered out by the compaction candidate search policy.|dataSource|Varies|

Updated web console visualization

These new statistics are folded into the web console reporting for compaction progress

Release note

Properly report statistics on intervals who require compaction to be compliant with their datasources configured compaction state, but are being excluded by the configured cluster compaction policy (for example, intervals with under 500 segments and require compaction but the most fragmented first policy is blocking compaction by having a threshold of 1000 uncompacted segments before executing a compaction run). This gives a true compaction progress report to cluster operators and datasource owners.

Key changed/added classes in this PR
  • CompactionStatus
  • CompactionConfigBasedJobTemplate

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 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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes, @capistrant !
While the change itself makes sense, I have suggested an alternative that allows capturing more info.

return state == State.SKIPPED;
}

public boolean isPolicyExcluded()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public boolean isPolicyExcluded()
public boolean isExcludedByPolicy()

* {@link CompactionCandidateSearchPolicy}. Unlike {@link #skipped}, such an
* interval becomes compactible again if the policy thresholds are relaxed.
*/
public static CompactionStatus policyExcluded(String reasonFormat, Object... args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static CompactionStatus policyExcluded(String reasonFormat, Object... args)
public static CompactionStatus excludedByPolicy(String reasonFormat, Object... args)

if (!eligibility.isEligible()) {
params.getSnapshotBuilder().addToPolicyExcluded(
candidate.withCurrentStatus(
CompactionStatus.policyExcluded("Rejected by search policy: %s", eligibility.getReason())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can omit the prefixed message Rejected by search policy since the state POLICY_EXCLUDED already implies that.

@JsonProperty
private final long segmentCountSkipped;
@JsonProperty
private final long segmentCountPolicyExcluded;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Might be nicer to have these fields and methods read as xyzExcludedByPolicy.

public enum State
{
COMPLETE, PENDING, RUNNING, SKIPPED
COMPLETE, PENDING, RUNNING, SKIPPED, POLICY_EXCLUDED

@kfaraz kfaraz Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I originally wanted SKIPPED to cover all skip reasons, and have the reason message itself be the distinguishing factor between things like excluded by policy, interval locked by another task, interval lies in skip offset.

Over time, we might want to be able to identify the interval/segment/byte counts against all of these reasons.

How do you feel about the following instead:

  • Do not add another value to the State enum
  • Have a new enum or maybe a bunch of constant Strings (aka error codes) which will serve as the skip reason
  • Have the compaction snapshot maintain counts for different skip reasons instead and just include that in the report.
  • Emit the skip reason as a dimension against the segment/skipCompact/bytes and other metrics

@capistrant

Copy link
Copy Markdown
Contributor Author

Thanks for the changes, @capistrant ! While the change itself makes sense, I have suggested an alternative that allows capturing more info.

thanks for the thoughts. I'm on board with keeping everything in skipped. Will prep the changes in the next day or so

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.

2 participants