Skip to content

KAFKA-9265: Fix kafka.log.Log instance leak on log deletion#7773

Merged
ijuma merged 5 commits into
apache:trunkfrom
soondenana:LogLeakFix
Dec 4, 2019
Merged

KAFKA-9265: Fix kafka.log.Log instance leak on log deletion#7773
ijuma merged 5 commits into
apache:trunkfrom
soondenana:LogLeakFix

Conversation

@soondenana

Copy link
Copy Markdown
Contributor

KAFKA-8448 fixes problem with similar leak. The Log objects are being
held in ScheduledExecutor PeriodicProducerExpirationCheck callback. The
fix in KAFKA-8448 was to change the policy of ScheduledExecutor to
remove the scheduled task when it gets canceled (by calling
setRemoveOnCancelPolicy(true)).

This works when a log is closed using close() method. But when a log is
deleted either when the topic gets deleted or when the rebalancing
operation moves the replica away from broker, the delete() operation is
invoked. Log.delete() doesn't close the pending scheduled task and that
leaks Log instance.

Fix is to close the scheduled task in the Log.delete() method too.

Tested with and without this fix and Log instances are no longer leaked
and scheduled tasks are gone once log is deleted.

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

KAFKA-8448 fixes problem with similar leak. The Log objects are being
held in ScheduledExecutor PeriodicProducerExpirationCheck callback. The
fix in KAFKA-8448 was to change the policy of ScheduledExecutor to
remove the scheduled task when it gets canceled (by calling
setRemoveOnCancelPolicy(true)).

This works when a log is closed using close() method. But when a log is
deleted either when the topic gets deleted or when the rebalancing
operation moves the replica away from broker, the delete() operation is
invoked. Log.delete() doesn't close the pending scheduled task and that
leaks Log instance.

Fix is to close the scheduled task in the Log.delete() method too.

Tested with and without this fix and Log instances are no longer leaked
and scheduled tasks are gone once log is deleted.
Comment thread core/src/main/scala/kafka/log/Log.scala
This change updates delete to call close so that the functionality gets
reused. Otherwise both close and delete were doing different things and
missing on what one or other does. This change consolidates that logic.

@hachikuji hachikuji 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 updates. Left a few small suggestions.

Comment thread core/src/main/scala/kafka/log/AbstractIndex.scala Outdated
Comment thread core/src/main/scala/kafka/log/Log.scala Outdated
Comment thread core/src/main/scala/kafka/log/Log.scala Outdated
This makes both delete and close have same cleanup steps and remove both
users (metrics and PeriodicProducerExpirationCheck callback) of the Log
once log is either closed or deleted.

@hachikuji hachikuji 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.

LGTM. Thanks for the fix!

@ijuma ijuma 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.

LGTM

@ijuma

ijuma commented Dec 4, 2019

Copy link
Copy Markdown
Member

retest this please

@ijuma

ijuma commented Dec 4, 2019

Copy link
Copy Markdown
Member

1 job passed and 2 failed with known flakes:

kafka.api.SaslOAuthBearerSslEndToEndAuthorizationTest > testNoDescribeProduceOrConsumeWithoutTopicDescribeAcl
kafka.api.CustomQuotaCallbackTest > testCustomQuotaCallback
kafka.network.DynamicConnectionQuotaTest > testDynamicConnectionQuota

@ijuma ijuma merged commit 2accf14 into apache:trunk Dec 4, 2019
ijuma pushed a commit that referenced this pull request Dec 4, 2019
KAFKA-8448 fixes problem with similar leak. The Log objects are being
held in ScheduledExecutor PeriodicProducerExpirationCheck callback. The
fix in KAFKA-8448 was to change the policy of ScheduledExecutor to
remove the scheduled task when it gets canceled (by calling
setRemoveOnCancelPolicy(true)).

This works when a log is closed using close() method. But when a log is
deleted either when the topic gets deleted or when the rebalancing
operation moves the replica away from broker, the delete() operation is
invoked. Log.delete() doesn't close the pending scheduled task and that
leaks Log instance.

Fix is to close the scheduled task in the Log.delete() method too.

Reviewers: Jason Gustafson <jason@confluent.io>, Ismael Juma <ismael@juma.me.uk>
ijuma pushed a commit that referenced this pull request Dec 4, 2019
KAFKA-8448 fixes problem with similar leak. The Log objects are being
held in ScheduledExecutor PeriodicProducerExpirationCheck callback. The
fix in KAFKA-8448 was to change the policy of ScheduledExecutor to
remove the scheduled task when it gets canceled (by calling
setRemoveOnCancelPolicy(true)).

This works when a log is closed using close() method. But when a log is
deleted either when the topic gets deleted or when the rebalancing
operation moves the replica away from broker, the delete() operation is
invoked. Log.delete() doesn't close the pending scheduled task and that
leaks Log instance.

Fix is to close the scheduled task in the Log.delete() method too.

Reviewers: Jason Gustafson <jason@confluent.io>, Ismael Juma <ismael@juma.me.uk>
@ijuma

ijuma commented Dec 4, 2019

Copy link
Copy Markdown
Member

Merged to trunk and cherry-picked to 2.4 and 2.3 branches.

@soondenana soondenana deleted the LogLeakFix branch December 4, 2019 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants