-
Notifications
You must be signed in to change notification settings - Fork 14.9k
KAFKA-20012: Move NodeToControllerChannelManagerImpl to server module #21261
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
Conversation
chia7712
left a comment
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.
@joshua2519 thanks for this patch!
| /** | ||
| * Discovers the active controller node and provides connection details for communicating with it. | ||
| */ | ||
| public interface ControllerNodeProvider { |
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 we use Supplier<ControllerInformation> instead?
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.
Done. ControllerNodeProvider now extends Supplier for better idiomatic Java usage.
| * | ||
| * @param reconfigurable the component to register for configuration updates | ||
| */ | ||
| public void addReconfigurable(Reconfigurable reconfigurable) { |
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.
why we don't set it as abstract method?
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.
Agreed and changed. Since all current implementations (KafkaConfig) already provide concrete implementations, making them abstract clarifies the contract and ensures future subclasses don't accidentally rely on no-op behavior.
| * | ||
| * @param reconfigurable the component to unregister | ||
| */ | ||
| public void removeReconfigurable(Reconfigurable reconfigurable) { |
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.
ditto
| private final ApiVersions apiVersions = new ApiVersions(); | ||
| private final NodeToControllerRequestThread requestThread; | ||
|
|
||
| @SuppressWarnings("this-escape") |
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.
Would you mind inlining newRequestThread to get rid of this warning?
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.
Done.
| } else if (response.wasDisconnected()) { | ||
| updateControllerAddress(null); | ||
| try { | ||
| requestQueue.putFirst(queueItem); |
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.
We can substitute addFirst for putFirst, since requestQueue is an unbounded LinkedBlockingDeque
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.
Agreed. Since requestQueue is unbounded (LinkedBlockingDeque with no capacity limit), putFirst() will never block and the InterruptedException handling is unnecessary. Changed to addFirst() for simplicity.
| /** | ||
| * Discovers the active controller node and provides connection details for communicating with it. | ||
| */ | ||
| public interface ControllerNodeProvider extends Supplier<ControllerInformation> { |
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 meant that the standard Supplier<ControllerInformation> interface could simply replace ControllerNodeProvider
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.
Done. Replaced ControllerNodeProvider with Supplier throughout the codebase since there's only one production implementation.
| } | ||
|
|
||
| @Override | ||
| public void shutdown() { |
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.
We should throw an exception here to align with the Scala implementation
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.
Done. Updated shutdown() to declare throws InterruptedException allowing the exception to propagate instead of being swallowed.
| Optional<Node> controllerAddress = activeControllerAddress(); | ||
| if (controllerAddress.isPresent()) { | ||
| requestIter.remove(); | ||
| return Collections.singletonList(new RequestAndCompletionHandler( |
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.
List.of
| } | ||
| } | ||
|
|
||
| return Collections.emptyList(); |
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.
List.of
| activeControllerAddress().map(Node::idString).orElse("null")); | ||
| maybeDisconnectAndUpdateController(); | ||
| try { | ||
| requestQueue.putFirst(queueItem); |
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.
addFirst?
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.
Done
| } | ||
|
|
||
| @SuppressWarnings("resource") // RaftClient lifecycle managed by RaftManager | ||
| private Optional<Node> idToNode(int id) { |
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 we really need this private method? Having two @SuppressWarnings seems to double the noise
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.
Agreed, I have inlined to get().
Migrates
NodeToControllerChannelManagerand related classes from Scala(core module) to Java (server module).
New Java Classes (server module) include
ControllerInformation,RaftControllerNodeProvider,NodeToControllerChannelManagerImpl,NodeToControllerRequestThreadandNodeToControllerQueueItem.In
AbstractKafkaConfig, addedaddReconfigurable()/removeReconfigurable()abstract methods tosupport migration. In
KafkaConfig, addedoverridekeywords forreconfigurable methods. Updated imports and usages across core module
classes and tests. Replace
ControllerNodeProviderbySupplier<ControllerInformation>.Reviewers: Chia-Ping Tsai [email protected]