Skip to content

KAFKA-19386: Correcting ExpirationReaper thread names from Purgatory#19918

Merged
apoorvmittal10 merged 2 commits into
apache:trunkfrom
apoorvmittal10:minor-threads
Jun 9, 2025
Merged

KAFKA-19386: Correcting ExpirationReaper thread names from Purgatory#19918
apoorvmittal10 merged 2 commits into
apache:trunkfrom
apoorvmittal10:minor-threads

Conversation

@apoorvmittal10

@apoorvmittal10 apoorvmittal10 commented Jun 7, 2025

Copy link
Copy Markdown
Contributor

The PR: #17636 migrated
DelayedOperationPurgatory from scala to java, and instatiated
expirationReaper at instance level where purgatoryName is still
null hence all expiration threads from different Purgatories has
incorrect names.

Screenshot 2025-06-07 at 01 28 58

The PR fixes the instatiation of ExpirationReaper, in constructor when
purgatoryName is defined.

Screenshot 2025-06-07 at 01 31 27

This issue affects 4.0 version as well, though minor.

Reviewers: Chia-Ping Tsai chia7712@gmail.com

@apoorvmittal10 apoorvmittal10 requested a review from mimaison June 7, 2025 00:42
@github-actions github-actions Bot added the triage PRs from the community label Jun 7, 2025
@apoorvmittal10 apoorvmittal10 requested review from chia7712 and junrao June 7, 2025 00:42
@github-actions github-actions Bot added core Kafka Broker small Small PRs labels Jun 7, 2025
@apoorvmittal10 apoorvmittal10 added ci-approved and removed triage PRs from the community labels Jun 7, 2025

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@apoorvmittal10 good catch!

this.purgeInterval = purgeInterval;
this.reaperEnabled = reaperEnabled;
this.timerEnabled = timerEnabled;
this.expirationReaper = new ExpiredOperationReaper();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that seems error-prone to me, since the issue is caused by an incorrect initialization order. Perhaps we should use anonymous class to ensure the initialization order. for example:

        this.expirationReaper = new ShutdownableThread("ExpirationReaper-" + brokerId + "-" + purgatoryName, false) {
            @Override
            public void doWork() {
                try {
                    advanceClock(200L);
                } catch (InterruptedException ie) {
                    throw new RuntimeException(ie);
                }
            }
        };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, is it really required as expirationReaper.start(); is post initialization of other objects?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologies for unclear comment. My point was that the expirationReaper initialization must happen after brokerId and purgatoryName are initialized. The dependency is implicit, which means we might inadvertently re-introduce a bug during future refactoring. Using an anonymous class could eliminate the happen-before constraint as it can directly reference the input arguments.

Alternatively, we could add comments to explicitly remind developers that expirationReaper must be initialized after brokerId and purgatoryName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Make sense. I have added the comment for now. Though the other suggestion was also valid.

@AndrewJSchofield AndrewJSchofield added the KIP-932 Queues for Kafka label Jun 7, 2025
@apoorvmittal10 apoorvmittal10 merged commit d07aa37 into apache:trunk Jun 9, 2025
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved core Kafka Broker KIP-932 Queues for Kafka small Small PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants