-
Notifications
You must be signed in to change notification settings - Fork 14.5k
KAFKA-19441: encapsulate MetadataImage in GroupCoordinator/ShareCoordinator #20061
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
Open
zzbennett
wants to merge
14
commits into
apache:trunk
Choose a base branch
from
zzbennett:lbennett-kafka-19441
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,609
−918
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c582944
KAFKA-19441: encapsulate MetadataImage in GroupCoordinator/ShareCoord…
zzbennett 0fefdb3
minor cleanup
zzbennett d089ed0
fix linting
zzbennett 12aa519
Merge branch 'trunk' of github.com:apache/kafka into lbennett-kafka-1…
zzbennett 12d593b
fix linting
zzbennett e66548e
PR feedback
zzbennett 5bd417f
remove the partitionSet() function from TopicMetadata interface
zzbennett adc7ce1
fix linting
zzbennett 0d05da2
cleanup from PR review
zzbennett e9bd51e
Merge branch 'trunk' of github.com:apache/kafka into lbennett-kafka-1…
zzbennett 621be71
Merge branch 'trunk' of github.com:apache/kafka into lbennett-kafka-1…
zzbennett 27a2df9
remove redundant TopicsDelta interface
zzbennett 36055d8
slightly enhance metadata delta tests
zzbennett a2f563e
add a javadoc
zzbennett 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
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
67 changes: 67 additions & 0 deletions
67
...n/src/main/java/org/apache/kafka/coordinator/common/runtime/CoordinatorMetadataDelta.java
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.coordinator.common.runtime; | ||
|
||
import org.apache.kafka.common.Uuid; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
/** | ||
* Provides metadata deltas to Coordinators (GroupCoordinator, ShareCoordinator, etc) such as changed topics and deleted topics | ||
* Implementations should be immutable. | ||
*/ | ||
public interface CoordinatorMetadataDelta { | ||
|
||
CoordinatorMetadataDelta EMPTY = emptyDelta(); | ||
|
||
Collection<Uuid> createdTopicIds(); | ||
|
||
Collection<Uuid> changedTopicIds(); | ||
|
||
Set<Uuid> deletedTopicIds(); | ||
|
||
/** | ||
* Returns the previous image of the coordinator metadata. | ||
* This image is a snapshot of the metadata before the delta occurred. | ||
*/ | ||
CoordinatorMetadataImage image(); | ||
|
||
private static CoordinatorMetadataDelta emptyDelta() { | ||
return new CoordinatorMetadataDelta() { | ||
@Override | ||
public Collection<Uuid> createdTopicIds() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Collection<Uuid> changedTopicIds() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Set<Uuid> deletedTopicIds() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public CoordinatorMetadataImage image() { | ||
return CoordinatorMetadataImage.EMPTY; | ||
} | ||
}; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
...n/src/main/java/org/apache/kafka/coordinator/common/runtime/CoordinatorMetadataImage.java
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.coordinator.common.runtime; | ||
|
||
import org.apache.kafka.common.Uuid; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
/** | ||
* Provides metadata to Coordinators (GroupCoordinator, ShareCoordinator, etc) such as topics, partitions, and their configurations. | ||
* Implementations should be thread-safe and immutable. | ||
*/ | ||
public interface CoordinatorMetadataImage { | ||
CoordinatorMetadataImage EMPTY = emptyImage(); | ||
|
||
Optional<String> topicName(Uuid id); | ||
|
||
Optional<Uuid> topicId(String topicName); | ||
|
||
default Optional<Integer> partitionCount(Uuid topicId) { | ||
var topicName = topicName(topicId); | ||
return topicName.isEmpty() ? Optional.empty() : partitionCount(topicName.get()); | ||
} | ||
|
||
Optional<Integer> partitionCount(String topicName); | ||
|
||
Set<Uuid> topicIds(); | ||
|
||
Set<String> topicNames(); | ||
|
||
Optional<TopicMetadata> topicMetadata(String topicName); | ||
|
||
default Optional<TopicMetadata> topicMetadata(Uuid topicId) { | ||
var topicName = topicName(topicId); | ||
return topicName.isEmpty() ? Optional.empty() : topicMetadata(topicName.get()); | ||
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. This impl is fine, but you could do Is there a reason why we made topicMetadata(Uuid topicId) the default impl rather than |
||
} | ||
|
||
CoordinatorMetadataDelta emptyDelta(); | ||
|
||
long version(); | ||
|
||
boolean isEmpty(); | ||
|
||
/** | ||
* Metadata about a particular topic | ||
*/ | ||
interface TopicMetadata { | ||
String name(); | ||
|
||
Uuid id(); | ||
|
||
int partitionCount(); | ||
|
||
List<String> partitionRacks(int partitionId); | ||
} | ||
|
||
private static CoordinatorMetadataImage emptyImage() { | ||
|
||
return new CoordinatorMetadataImage() { | ||
@Override | ||
public Optional<String> topicName(Uuid id) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Uuid> topicId(String topicName) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> partitionCount(String topicName) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Set<Uuid> topicIds() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Set<String> topicNames() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Optional<TopicMetadata> topicMetadata(String topicName) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<TopicMetadata> topicMetadata(Uuid topicId) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public CoordinatorMetadataDelta emptyDelta() { | ||
return CoordinatorMetadataDelta.EMPTY; | ||
} | ||
|
||
@Override | ||
public long version() { | ||
return 0L; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
} |
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
82 changes: 82 additions & 0 deletions
82
.../main/java/org/apache/kafka/coordinator/common/runtime/KRaftCoordinatorMetadataDelta.java
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.coordinator.common.runtime; | ||
|
||
import org.apache.kafka.common.Uuid; | ||
import org.apache.kafka.image.MetadataDelta; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
/** | ||
* An implementation of {@link CoordinatorMetadataDelta} that wraps the KRaft MetadataDelta. | ||
*/ | ||
public class KRaftCoordinatorMetadataDelta implements CoordinatorMetadataDelta { | ||
|
||
final MetadataDelta metadataDelta; | ||
|
||
public KRaftCoordinatorMetadataDelta(MetadataDelta metadataDelta) { | ||
this.metadataDelta = metadataDelta; | ||
} | ||
|
||
@Override | ||
public Collection<Uuid> createdTopicIds() { | ||
if (metadataDelta == null || metadataDelta.topicsDelta() == null) { | ||
return Set.of(); | ||
} | ||
return metadataDelta.topicsDelta().createdTopicIds(); | ||
} | ||
|
||
@Override | ||
public Collection<Uuid> changedTopicIds() { | ||
if (metadataDelta == null || metadataDelta.topicsDelta() == null) { | ||
return Set.of(); | ||
} | ||
return metadataDelta.topicsDelta().changedTopics().keySet(); | ||
} | ||
|
||
@Override | ||
public Set<Uuid> deletedTopicIds() { | ||
if (metadataDelta == null || metadataDelta.topicsDelta() == null) { | ||
return Set.of(); | ||
} | ||
return metadataDelta.topicsDelta().deletedTopicIds(); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return metadataDelta.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || !o.getClass().equals(this.getClass())) return false; | ||
KRaftCoordinatorMetadataDelta other = (KRaftCoordinatorMetadataDelta) o; | ||
return metadataDelta.equals(other.metadataDelta); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return metadataDelta.hashCode(); | ||
} | ||
|
||
@Override | ||
public CoordinatorMetadataImage image() { | ||
return new KRaftCoordinatorMetadataImage(metadataDelta.image()); | ||
} | ||
} |
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.
Could be static variable?