mumrah commented on a change in pull request #10008:
URL: https://github.com/apache/kafka/pull/10008#discussion_r568149064



##########
File path: 
core/src/main/scala/kafka/coordinator/group/GroupMetadataManager.scala
##########
@@ -78,7 +78,20 @@ class GroupMetadataManager(brokerId: Int,
   private val shuttingDown = new AtomicBoolean(false)
 
   /* number of partitions for the consumer metadata topic */
-  private val groupMetadataTopicPartitionCount = 
getGroupMetadataTopicPartitionCount
+  private var _groupMetadataTopicPartitionCount: Option[Int] = Option.empty // 
lazy, once-only evaluation
+  private def groupMetadataTopicPartitionCount: Int = {
+    _groupMetadataTopicPartitionCount match {
+      case Some(partitionCount) => partitionCount
+      case None => synchronized { // make sure we only invoke the function once
+        _groupMetadataTopicPartitionCount match {
+          case Some(partitionCount) => partitionCount // another thread beat 
us to it
+          case None =>
+            _groupMetadataTopicPartitionCount = 
Some(offsetsTopicPartitionCountFunc())

Review comment:
       It's worth noting that if our underlying function throws an error, this 
will throw as well for any usages of `groupMetadataTopicPartitionCount` (e.g., 
`GroupMetadataManager#partitionFor`). That wasn't possible in the ZK world 
(since this value was cached on startup), so we should probably make sure the 
callers can all tolerate an exception.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to