Skip to content

ControllerEventThread

ControllerEventThread is a ShutdownableThread that ControllerEventManager uses to process QueuedEvents (asynchronously on a separate thread).

ControllerEventThread is Started Alongside ControllerEventManager

Review Me

ControllerEventThread is a ShutdownableThread that is <> for <> (with the <> being controller-event-thread).

// jstack [brokerPid]
"controller-event-thread" #42 prio=5 os_prio=31 cpu=387,10ms elapsed=82679,68s tid=0x00007f920e489800 nid=0x14703 waiting on condition  [0x000070000fcea000]
   java.lang.Thread.State: WAITING (parking)
    at jdk.internal.misc.Unsafe.park(java.base@12.0.2/Native Method)
    - parking to wait for  <0x00000007c07f0298> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(java.base@12.0.2/LockSupport.java:194)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(java.base@12.0.2/AbstractQueuedSynchronizer.java:2081)
    at java.util.concurrent.LinkedBlockingQueue.take(java.base@12.0.2/LinkedBlockingQueue.java:433)
    at kafka.controller.ControllerEventManager$ControllerEventThread.doWork(ControllerEventManager.scala:127)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:89)

ControllerEventThread is <> with <>.

[[creating-instance]][[name]] ControllerEventThread takes the name of the thread to be created.

[[logIdent]] ControllerEventThread uses [ControllerEventThread controllerId=[controllerId]] as the logging prefix (aka logIdent).

=== [[doWork]] Processing Controller Events -- doWork Method

[source, scala]

doWork(): Unit

doWork takes (and removes) a <> from the head of the <> (waiting for a QueuedEvent to be available if the queue is empty).

NOTE: The very first event in the event queue is Startup that KafkaController puts when it is link:kafka-controller-KafkaController.adoc#startup[started].

doWork sets <> (of ControllerEventManager) to be the <> of the controller event.

doWork requests the <> to update (with the time between the current time and the <>).

doWork finds the KafkaTimer for the current controller state (in <> lookup table) to measure and record the time to requests the event to <> using the <>.

In the end, doWork sets the <> (of ControllerEventManager) as Idle.

In case of any error (Throwable), doWork simply prints out the following ERROR message to the logs:

Uncaught error processing event [controllerEvent]