You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Grant Overby (groverby)" <gr...@cisco.com> on 2015/03/26 23:07:51 UTC

Thread Safety in KafkaServer.scala

KafkaServer.scala is using 3 AtomicBooleans (startupComplete, isShuttingDown, isStartingUp) as locks around the broker lifecycle. This strategy doesn’t appear to be thread safe, which I assume is the goal.

Consider two threads, A and B, calling startup() and execution occurring as:

Thread A progresses to the first line inside the if (canStartup) block.
Thread B progresses past if(startupComplete.get), but does not progress to setting canStartup.
Thread A completes startup()
Thread B resumes from previous location and sets canStartup to true.

Similar situations allow concurrent execution of startup() and shutdown().

It seems none of this is likely to happen.

Given the infrequency of calls to startup() and shutdown(), could a simple lock work in place of the three AtomicBooleans?



Fair warning: Take this with a grain of salt. Today is my first read through Kafka source and my scala fu is weak.


[http://www.cisco.com/web/europe/images/email/signature/est2014/logo_06.png?ct=1398192119726]

Grant Overby
Software Engineer
Cisco.com<http://www.cisco.com/>
groverby@cisco.com<ma...@cisco.com>
Mobile: 865 724 4910






[http://www.cisco.com/assets/swa/img/thinkbeforeyouprint.gif] Think before you print.

This email may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message.

Please click here<http://www.cisco.com/web/about/doing_business/legal/cri/index.html> for Company Registration Information.