Skip to content

KAFKA-19338: Error on read/write of uninitialized share part. #19861

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

Merged
merged 7 commits into from
Jun 3, 2025

Conversation

smjn
Copy link
Collaborator

@smjn smjn commented May 30, 2025

  • Currently, read and write share state requests were allowed on
    uninitialized share partitions (share partitions on which
    initializeState has NOT been called). This should not be the case.
  • This PR addresses the concern by adding error checks on read and
    write. Other requests are allowed (initialize, readSummary, alter).
  • Refactored ShareCoordinatorShardTest to reduce redundancy and added
    some new tests.
  • Some request/response classes have also been reformatted.

Reviewers: Andrew Schofield aschofield@confluent.io

@github-actions github-actions bot added triage PRs from the community KIP-932 Queues for Kafka clients labels May 30, 2025
@smjn smjn added ci-approved and removed triage PRs from the community labels May 30, 2025
@github-actions github-actions bot added the core Kafka Broker label May 30, 2025
Copy link
Member

@AndrewJSchofield AndrewJSchofield left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Looks good in general but one query to clear up please.

@@ -644,8 +632,7 @@ public CoordinatorResult<Void, CoordinatorRecord> maybeCleanupShareState(Set<Uui
/**
* Util method to generate a ShareSnapshot or ShareUpdate type record for a key, based on various conditions.
* <p>
* If no snapshot has been created for the key => create a new ShareSnapshot record
* else if number of ShareUpdate records for key >= max allowed per snapshot per key => create a new ShareSnapshot record
* Ff number of ShareUpdate records for key >= max allowed per snapshot per key or stateEpoch is highest seen => create a new ShareSnapshot record
Copy link
Member

Choose a reason for hiding this comment

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

nit: What's "Ff"?

.setWriteTimestamp(timestamp)
.build());
} else if (snapshotUpdateCount.getOrDefault(key, 0) >= updatesPerSnapshotLimit || partitionData.stateEpoch() > shareStateMap.get(key).stateEpoch()) {
if (snapshotUpdateCount.getOrDefault(key, 0) >= updatesPerSnapshotLimit || partitionData.stateEpoch() > shareStateMap.get(key).stateEpoch()) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe it's possible for shareStateMap not to contain the key.

Copy link
Collaborator Author

@smjn smjn Jun 3, 2025

Choose a reason for hiding this comment

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

Hi @AndrewJSchofield ,
Thanks for the review.
No, it is not possible since this method is called from ShareCoordinatorShard.writeState and ShareCoordinatorShard.readStateAndMaybeUpdateLeaderEpoch. But before calling it - both methods do error checking (maybeGetWriteStateError, maybeGetReadStateError) where they explicitly check that the shareStateMap is not empty and return "read/write on uninitialized share partition" error.

New tests testWriteFailsOnUninitializedPartition and testReadFailsOnUninitializedPartition add proof for the same.

Will add additional javadoc to clarify.

@smjn smjn requested a review from AndrewJSchofield June 3, 2025 07:44
@AndrewJSchofield AndrewJSchofield merged commit df93571 into apache:trunk Jun 3, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved clients core Kafka Broker KIP-932 Queues for Kafka
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants