adoroszlai commented on code in PR #3727:
URL: https://github.com/apache/ozone/pull/3727#discussion_r965023673


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/AbstractContainerScanner.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.hadoop.ozone.container.ozoneimpl;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Base class for scheduled scanners on a Datanode.
+ */
+public abstract class AbstractContainerScanner extends Thread {
+  public static final Logger LOG =
+      LoggerFactory.getLogger(AbstractContainerScanner.class);
+
+  private final AbstractContainerScannerMetric metrics;
+  private final long dataScanInterval;
+
+  /**
+   * True if the thread is stopping.<p/>
+   * Protected by this object's lock.
+   */
+  private volatile boolean stopping = false;
+
+  public AbstractContainerScanner(String name, long dataScanInterval,
+                                  AbstractContainerScannerMetric metrics) {
+    this.dataScanInterval = dataScanInterval;
+    this.metrics = metrics;
+    setName(name);
+    setDaemon(true);
+  }
+
+  @Override
+  public final void run() {
+    try {
+      while (!stopping) {
+        runIteration();
+        metrics.resetNumContainersScanned();
+        metrics.resetNumUnhealthyContainers();
+      }
+      LOG.info("{} exiting.", this);
+    } catch (Exception e) {
+      LOG.error("{} exiting because of exception ", this, e);
+    } finally {
+      if (metrics != null) {
+        metrics.unregister();
+      }
+    }
+  }
+
+  @VisibleForTesting
+  public final void runIteration() {
+    long startTime = System.nanoTime();
+    scanContainers();
+    long totalDuration = System.nanoTime() - startTime;
+    if (stopping) {
+      return;
+    }
+    metrics.incNumScanIterations();
+    LOG.info("Completed an iteration of " + this.getClass().toString() +
+            " in {} minutes." +

Review Comment:
   Actual output:
   
   ```
   datanode_1  | 2022-09-07 15:48:00,816 
[ContainerDataScanner(/data/hdds/hdds)] INFO 
ozoneimpl.AbstractContainerScanner: Completed an iteration of class 
org.apache.hadoop.ozone.container.ozoneimpl.ContainerDataScanner in 0 minutes. 
Number of iterations (since the data-node restart) : 13, Number of containers 
scanned in this iteration : 0, Number of unhealthy containers found in this 
iteration : 0
   datanode_1  | 2022-09-07 15:48:00,831 [ContainerMetadataScanner] INFO 
ozoneimpl.AbstractContainerScanner: Completed an iteration of class 
org.apache.hadoop.ozone.container.ozoneimpl.ContainerMetadataScanner in 0 
minutes. Number of iterations (since the data-node restart) : 25, Number of 
containers scanned in this iteration : 1, Number of unhealthy containers found 
in this iteration : 0
   ```
   
   The part `class 
org.apache.hadoop.ozone.container.ozoneimpl.ContainerDataScanner` looks a bit 
odd in the message.  I think instance name would be better than class name.  
And since it is already included due to thread name pattern, we might omit it.
   
   ```suggestion
       LOG.info("Completed an iteration in {} minutes" +
   ```



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerDataScanner.java:
##########
@@ -163,23 +102,17 @@ private static void logScanCompleted(
     }
   }
 
+  @Override
   public synchronized void shutdown() {
-    this.stopping = true;
     this.canceler.cancel(
         String.format(NAME_FORMAT, volume) + " is shutting down");
-    this.interrupt();
-    try {
-      this.join();
-    } catch (InterruptedException ex) {
-      LOG.warn("Unexpected exception while stopping data scanner for volume "
-          + volume, ex);
-      Thread.currentThread().interrupt();
-    }
+    super.shutdown();
   }
 
   @VisibleForTesting
-  public ContainerDataScrubberMetrics getMetrics() {
-    return metrics;
+  @Override
+  public ContainerDataScannerMetrics getMetrics() {
+    return this.metrics;

Review Comment:
   Currently `metrics` is stored in both parent and subclasses.  We could 
eliminate the former by making `getMetrics()` abstract, and using it instead of 
`metrics` variable.  It would also allow getting rid of the cast in subclass 
constructors.



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/AbstractContainerScannerMetric.java:
##########
@@ -7,31 +7,31 @@
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
  */
 package org.apache.hadoop.ozone.container.ozoneimpl;
 
 import org.apache.hadoop.hdds.annotation.InterfaceAudience;
 import org.apache.hadoop.metrics2.MetricsSystem;
 import org.apache.hadoop.metrics2.annotation.Metric;
 import org.apache.hadoop.metrics2.annotation.Metrics;
-import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 import org.apache.hadoop.metrics2.lib.MutableCounterInt;
 import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
 
 /**
- * This class captures the container meta-data scrubber metrics on the
- * data-node.
- **/
+ * Base class for container scanner metrics.
+ */
 @InterfaceAudience.Private
-@Metrics(about = "DataNode container data scrubber metrics", context = "dfs")
-public final class ContainerMetadataScrubberMetrics {
+@Metrics(about = "Datanode container scanner metrics", context = "dfs")
+public abstract class AbstractContainerScannerMetric {

Review Comment:
   Nit: this is a collection of metrics, should be plural: 
`AbstractContainerScannerMetrics`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to