Repository navigation
MINOR: Make share group state partition metadata unmodifiable #23888
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
squah-confluent
merged 5 commits into
apache:trunk
from
confluentinc:squah-immutable-initmapvalue-and-refactor
Oct 21, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf331b2
MINOR: Make InitMapValue's partitions immutable
squah-confluent 096acb8
fixup: Wrap InitMapValue's partitions in an unmodifiable set instead …
squah-confluent 1189796
MINOR: Make ShareGroupStatePartitionMetadataInfo's collections unmodi…
squah-confluent 674eb42
fixup: Take a Set in InitMapValue's withAddedPartitions and withRemov…
squah-confluent e9c0c9d
fixup: Test InitMapValue's withAddedPartitions and withRemovedPartitions
squah-confluent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ | |
| import org.apache.kafka.timeline.SnapshotRegistry; | ||
| import org.apache.kafka.timeline.TimelineObject; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
|
|
@@ -82,6 +84,11 @@ public record ShareGroupStatePartitionMetadataInfo( | |
| Map<Uuid, InitMapValue> initializedTopics, | ||
| Set<Uuid> deletingTopics | ||
| ) { | ||
| public ShareGroupStatePartitionMetadataInfo { | ||
| initializingTopics = Collections.unmodifiableMap(initializingTopics); | ||
| initializedTopics = Collections.unmodifiableMap(initializedTopics); | ||
| deletingTopics = Collections.unmodifiableSet(deletingTopics); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -97,6 +104,29 @@ public record InitMapValue( | |
| Set<Integer> partitions, | ||
| long timestamp | ||
| ) { | ||
| public InitMapValue { | ||
| partitions = Collections.unmodifiableSet(partitions); | ||
| } | ||
|
|
||
| /** | ||
| * @param added The partitions to add. | ||
| * @return A copy of this value with the partitions added. | ||
| */ | ||
| public InitMapValue withAddedPartitions(Set<Integer> added) { | ||
| Set<Integer> newPartitions = new HashSet<>(partitions); | ||
| newPartitions.addAll(added); | ||
| return new InitMapValue(name, newPartitions, timestamp); | ||
| } | ||
|
|
||
| /** | ||
| * @param removed The partitions to remove. | ||
| * @return A copy of this value with the partitions removed. | ||
| */ | ||
| public InitMapValue withRemovedPartitions(Set<Integer> removed) { | ||
| Set<Integer> newPartitions = new HashSet<>(partitions); | ||
| newPartitions.removeAll(removed); | ||
| return new InitMapValue(name, newPartitions, timestamp); | ||
|
Comment on lines
+126
to
+128
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a tad wasteful to allocate an HashSet here to then copy it in InitMapValue. Have you considered using unmodifiableSet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean replacing
Set.copyOfwithCollections.unmodifiableSetin the constructor or passing anunmodifiableSetwrapper in to the existing constructor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is fine. I don't really have a preference and I don't think that we have established a pattern (yet).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer
copyOfin the constructor since it's truly immutable and it's not possible to misuse by holding on to the original collection and modifying it. But it does end up with more copies overall.I think our original convention was to use
Collections.unmodifiableMap/Setin constructors, so I'll go with that. Though the streams code is pulling a different way and going withcopyOflately...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version of the PR uses
unmodifiableMap/Set.