Skip to content

[improve][broker] Enhance compaction triggering with message check to avoid unnecessary operations #24449

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

coderzc
Copy link
Member

@coderzc coderzc commented Jun 24, 2025

Motivation

If no more message need to compact, then we should skip compaction task

Modifications

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jun 24, 2025
@coderzc coderzc changed the title [improve][compaction] Enhance compaction triggering with message check to avoid unnecessary operations [improve][broker] Enhance compaction triggering with message check to avoid unnecessary operations Jun 24, 2025
public synchronized CompletableFuture<Void> triggerCompactionWithCheckHasMoreMessages() {
return getLastDispatchablePosition().thenCombine(topicCompactionService.getLastCompactedPosition(),
(lastDispatchablePosition, lastCompactedPosition) -> {
return lastCompactedPosition == null || lastDispatchablePosition.compareTo(lastCompactedPosition) > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think lastDispatchablePosition might be null, so need to add null check to prevent NPE

Copy link
Member Author

Choose a reason for hiding this comment

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

fix

@3pacccccc
Copy link
Contributor

I'm wondering does lastDispatchablePosition.compareTo(lastCompactedPosition) > 0 really means need to triggering compaction? For example, I publish a message with no key present after last compaction, there's actually no need to triggering compaction as well.

@coderzc
Copy link
Member Author

coderzc commented Jun 24, 2025

I'm wondering does lastDispatchablePosition.compareTo(lastCompactedPosition) > 0 really means need to triggering compaction? For example, I publish a message with no key present after last compaction, there's actually no need to triggering compaction as well.

if topicCompactionRetainNullKey=false, then a message with no key may be deleted during compaction, so trigger compaction task is meaningful

@3pacccccc
Copy link
Contributor

I'm wondering does lastDispatchablePosition.compareTo(lastCompactedPosition) > 0 really means need to triggering compaction? For example, I publish a message with no key present after last compaction, there's actually no need to triggering compaction as well.

if topicCompactionRetainNullKey=false, then a message with no key may be deleted during compaction, so trigger compaction task is meaningful

OK, I get it, thank you, now LGTM

@codelipenghui codelipenghui added this to the 4.1.0 milestone Jun 28, 2025
@codelipenghui codelipenghui added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Jun 28, 2025
@coderzc coderzc assigned coderzc and unassigned 3pacccccc Jun 30, 2025
@coderzc coderzc closed this Jun 30, 2025
@coderzc coderzc reopened this Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker doc-not-needed Your PR changes do not impact docs type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants