[ 
https://issues.apache.org/jira/browse/KAFKA-20286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18143219#comment-18143219
 ] 

Kamil Karczmarzyk commented on KAFKA-20286:
-------------------------------------------

Looked into this on current trunk and I think it has already been addressed by 
two later changes:
 
1. KAFKA-20247 (commit 32c0e1c4d0, released in 4.3.0) changed 
\{{RegistrationResponseHandler}} so that \{{onComplete}} and \{{onTimeout}} no 
longer modify the manager's state on the \{{NodeToControllerRequestThread}}. 
They now append a \{{RequestCompleteEvent}} or \{{RequestTimeoutEvent}} to the 
manager's event queue, and \{{pendingRpc}} is reset inside those events. That 
commit also fixed \{{onTimeout}} not resetting \{{pendingRpc}} at all.
 
2. KAFKA-20348 (commit a3fae9cbfa, released in 4.4.0) moved the class to Java, 
as \{{org.apache.kafka.server.controller.ControllerRegistrationManager}} in the 
server module, which covers the "rewrite to Java" idea in the description.
 
On trunk, every read and write of the mutable fields (\{{pendingRpc}}, 
\{{registeredInLog}}, \{{metadataVersion}}, \{{channelManager}}, 
\{{successfulRpcs}}, \{{failedRpcs}}) happens on the event handler thread: 
inside an event, a deferred task, the \{{start()}} lambda, or the 
\{{ShutdownEvent}} cleanup. The test-only getters are read through 
\{{eventQueue.append}} in \{{ControllerRegistrationManagerTest}} as well.

Is there anything else you had in mind for this ticket? If not, could it be 
closed as fixed by KAFKA-20247?

> Refactor ControllerRegistrationManager
> --------------------------------------
>
>                 Key: KAFKA-20286
>                 URL: https://issues.apache.org/jira/browse/KAFKA-20286
>             Project: Kafka
>          Issue Type: Improvement
>            Reporter: Jonah Hooper
>            Priority: Minor
>
> It may be possible to simplify the ControllerRegistrationManager class. It 
> currently has a slight problem where it is not clear that modifications of 
> the classes internal state happens in multiple threads. 
> For example:
> [pendingRpc=false]([https://github.com/confluentinc/ce-kafka/blob/c53057794ea2af07ad88d98c98db84134faf73b4/core/src/main/scala/kafka/server/ControllerRegistrationManager.scala#L241|https://github.com/apache/kafka/blob/4ea29da3ca1776f6870905eed015ef5751e4866c/core/src/main/scala/kafka/server/ControllerRegistrationManager.scala#L241])
>  will always be run in `eventQueue`.  
> But 
> [onTimeout](https://github.com/apache/kafka/blob/4ea29da3ca1776f6870905eed015ef5751e4866c/core/src/main/scala/kafka/server/ControllerRegistrationManager.scala#L236)
>  is called in NodeToControllerRequestThread. 
> While the synchronization is unlikely to actually cause problems it does make 
> the code a lot harder to reason about which could lead to future subtle bugs. 
> Ideally we would refactor this class to make it clear in which state thread 
> is modified. This could be part of a rewrite to Java. 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to