showuon commented on code in PR #12347:
URL: https://github.com/apache/kafka/pull/12347#discussion_r917645850


##########
core/src/main/scala/kafka/log/LogManager.scala:
##########
@@ -410,12 +442,34 @@ class LogManager(logDirs: Seq[File],
         error(s"There was an error in one of the threads during logs loading: 
${e.getCause}")
         throw e.getCause
     } finally {
+      removeLogRecoveryMetrics(curNumRecoveryThreadsPerDataDir)
       threadPools.foreach(_.shutdown())
     }
 
     info(s"Loaded $numTotalLogs logs in ${time.hiResClockMs() - startMs}ms.")
   }
 
+  private[log] def addLogRecoveryMetrics(curNumRecoveryThreadsPerDataDir: 
Int): Unit = {
+    for (dir <- logDirs) {
+      newGauge("remainingLogsToRecover", () => 
numRemainingLogs.get(dir.getAbsolutePath),
+        Map("dir" -> dir.getAbsolutePath))
+      for (i <- 0 until curNumRecoveryThreadsPerDataDir) {
+        val threadName = logRecoveryThreadName(dir.getAbsolutePath, i)
+        newGauge("remainingSegmentsToRecover", () => 
numRemainingSegments.get(threadName),
+          Map("dir" -> dir.getAbsolutePath, "threadNum" -> i.toString))
+      }
+    }
+  }
+
+  private[log] def removeLogRecoveryMetrics(curNumRecoveryThreadsPerDataDir: 
Int): Unit = {
+    for (dir <- logDirs) {
+      removeMetric("remainingLogsToRecover", Map("dir" -> dir.getAbsolutePath))
+      for (i <- 0 until curNumRecoveryThreadsPerDataDir) {
+        removeMetric("remainingSegmentsToRecover", Map("dir" -> 
dir.getAbsolutePath, "threadNum" -> i.toString))

Review Comment:
   pass the `curNumRecoveryThreadsPerDataDir` in so that it won't be affected 
by the dynamically numRecoveryThreads change.



-- 
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.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

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

Reply via email to