Skip to content

MINOR: Prevent this leak while DefaultStatePersister construction.#22292

Merged
chia7712 merged 4 commits into
apache:trunkfrom
smjn:persister-init
May 18, 2026
Merged

MINOR: Prevent this leak while DefaultStatePersister construction.#22292
chia7712 merged 4 commits into
apache:trunkfrom
smjn:persister-init

Conversation

@smjn
Copy link
Copy Markdown
Collaborator

@smjn smjn commented May 15, 2026

  • Currently DefaultStatePersister instantiates PersisterStateManager
    in its constructor. This implies that the this creation is not yet
    complete and initializing another component.
  • To remedy this the public API constructor is replaced with static
    factory method.
  • Tests and BrokerServer code has been updated to reflect the change.

Reviewers: Chia-Ping Tsai chia7712@gmail.com

@github-actions github-actions Bot added triage PRs from the community core Kafka Broker small Small PRs labels May 15, 2026
@smjn smjn added ci-approved KIP-932 Queues for Kafka and removed triage PRs from the community labels May 15, 2026
@smjn smjn requested a review from AndrewJSchofield May 15, 2026 18:08
private static final Logger log = LoggerFactory.getLogger(DefaultStatePersister.class);

public DefaultStatePersister(PersisterStateManager stateManager) {
public static DefaultStatePersister instance(PersisterStateManager stateManager) {
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.

If we want DefaultStatePersister to manage the lifecycle of PersisterStateManager, should we let it instantiate the manager itself?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@chia7712 Thanks for the feedback.

Incorporated change. Left some default visibility methods for ease of testing.

}

// Visibility for tests
static DefaultStatePersister instance(PersisterStateManager stateManager) {
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.

It appears all the passed stateManager instances are mocked. Maybe we could remove this helper and have the tests use the package-private constructor instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@chia7712 Thanks for the suggestion, incorported.

shareGroupTimer
)
)
klass.getDeclaredMethod("instance", classOf[KafkaClient], classOf[ShareCoordinatorMetadataCacheHelper], classOf[Time], classOf[Timer])
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.

Out of curiosity, why use a dynamic call here if we already know it is a DefaultStatePersister

Copy link
Copy Markdown
Collaborator Author

@smjn smjn May 18, 2026

Choose a reason for hiding this comment

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

Hi,
initially the persister was planned to be a pluggable component and code was written in that way but it was subsequently decided to make it factory pluggable, hence the if condition. But yes with current state of code, this is unnecessary, will rectify

@smjn
Copy link
Copy Markdown
Collaborator Author

smjn commented May 18, 2026

@chia7712 Thanks for the comments, incorporated.

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

@chia7712 chia7712 merged commit 98ed67e into apache:trunk May 18, 2026
22 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.

2 participants