You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by fe...@apache.org on 2022/07/13 02:16:18 UTC

[ozone] branch master updated: HDDS-6981. Add metrics for BlockDeletingService on Datanode (#3580)

This is an automated email from the ASF dual-hosted git repository.

ferhui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new aa3bbf9932 HDDS-6981. Add metrics for BlockDeletingService on Datanode (#3580)
aa3bbf9932 is described below

commit aa3bbf993271a58d3bcecdaa63caa080604cd4b0
Author: Symious <yi...@foxmail.com>
AuthorDate: Wed Jul 13 10:16:13 2022 +0800

    HDDS-6981. Add metrics for BlockDeletingService on Datanode (#3580)
---
 .../helpers/BlockDeletingServiceMetrics.java       | 102 +++++++++++++++++++++
 .../background/BlockDeletingService.java           |  14 +++
 .../container/common/TestBlockDeletingService.java |  10 ++
 3 files changed, 126 insertions(+)

diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockDeletingServiceMetrics.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockDeletingServiceMetrics.java
new file mode 100644
index 0000000000..d6d36a3534
--- /dev/null
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockDeletingServiceMetrics.java
@@ -0,0 +1,102 @@
+/**
+ * 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.common.helpers;
+
+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.MutableCounterLong;
+import org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService;
+
+/**
+ * Metrics related to Block Deleting Service running on Datanode.
+ */
+@Metrics(name = "BlockDeletingService Metrics", about = "Metrics related to "
+    + "background block deleting service on Datanode", context = "dfs")
+public final class BlockDeletingServiceMetrics {
+
+  private static BlockDeletingServiceMetrics instance;
+  public static final String SOURCE_NAME =
+      BlockDeletingService.class.getSimpleName();
+
+  @Metric(about = "The number of successful delete blocks")
+  private MutableCounterLong successCount;
+
+  @Metric(about = "The total bytes for blocks successfully deleted.")
+  private MutableCounterLong successBytes;
+
+  @Metric(about = "The number of failed delete blocks.")
+  private MutableCounterLong failureCount;
+
+  private BlockDeletingServiceMetrics() {
+  }
+
+  public static BlockDeletingServiceMetrics create() {
+    if (instance == null) {
+      MetricsSystem ms = DefaultMetricsSystem.instance();
+      instance = ms.register(SOURCE_NAME, "BlockDeletingService",
+          new BlockDeletingServiceMetrics());
+    }
+
+    return instance;
+  }
+
+  /**
+   * Unregister the metrics instance.
+   */
+  public static void unRegister() {
+    instance = null;
+    MetricsSystem ms = DefaultMetricsSystem.instance();
+    ms.unregisterSource(SOURCE_NAME);
+  }
+
+  public void incrSuccessCount(long count) {
+    this.successCount.incr(count);
+  }
+
+  public void incrSuccessBytes(long bytes) {
+    this.successBytes.incr(bytes);
+  }
+
+  public void incrFailureCount() {
+    this.failureCount.incr();
+  }
+
+  public long getSuccessCount() {
+    return successCount.value();
+  }
+
+  public long getSuccessBytes() {
+    return successBytes.value();
+  }
+
+  public long getFailureCount() {
+    return failureCount.value();
+  }
+
+  @Override
+  public String toString() {
+    StringBuffer buffer = new StringBuffer();
+    buffer.append("successCount = " + successCount.value()).append("\t")
+        .append("successBytes = " + successBytes.value()).append("\t")
+        .append("failureCount = " + failureCount.value()).append("\t");
+    return buffer.toString();
+  }
+}
\ No newline at end of file
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/statemachine/background/BlockDeletingService.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/statemachine/background/BlockDeletingService.java
index 084493daeb..ebe8b590e1 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/statemachine/background/BlockDeletingService.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/statemachine/background/BlockDeletingService.java
@@ -43,6 +43,7 @@ import org.apache.hadoop.hdds.utils.MetadataKeyFilters.KeyPrefixFilter;
 import org.apache.hadoop.hdds.utils.db.Table;
 import org.apache.hadoop.hdds.utils.db.TableIterator;
 import org.apache.hadoop.ozone.container.common.helpers.BlockData;
+import org.apache.hadoop.ozone.container.common.helpers.BlockDeletingServiceMetrics;
 import org.apache.hadoop.ozone.container.common.impl.ContainerData;
 import org.apache.hadoop.ozone.container.common.impl.TopNOrderedContainerDeletionChoosingPolicy;
 import org.apache.hadoop.ozone.container.common.interfaces.Container;
@@ -86,6 +87,8 @@ public class BlockDeletingService extends BackgroundService {
 
   private final int blockLimitPerInterval;
 
+  private final BlockDeletingServiceMetrics metrics;
+
   // Task priority is useful when a to-delete block has weight.
   private static final int TASK_PRIORITY_DEFAULT = 1;
 
@@ -107,6 +110,7 @@ public class BlockDeletingService extends BackgroundService {
     this.conf = conf;
     DatanodeConfiguration dnConf = conf.getObject(DatanodeConfiguration.class);
     this.blockLimitPerInterval = dnConf.getBlockDeletionLimit();
+    metrics = BlockDeletingServiceMetrics.create();
   }
 
   /**
@@ -380,6 +384,8 @@ public class BlockDeletingService extends BackgroundService {
           containerData.decrBlockCount(deletedBlocksCount);
           containerData.decrBytesUsed(releasedBytes);
           containerData.getVolume().decrementUsedSpace(releasedBytes);
+          metrics.incrSuccessCount(deletedBlocksCount);
+          metrics.incrSuccessBytes(releasedBytes);
         }
 
         if (!succeedBlocks.isEmpty()) {
@@ -393,6 +399,7 @@ public class BlockDeletingService extends BackgroundService {
       } catch (IOException exception) {
         LOG.warn("Deletion operation was not successful for container: " +
             container.getContainerData().getContainerID(), exception);
+        metrics.incrFailureCount();
         throw exception;
       }
     }
@@ -495,6 +502,8 @@ public class BlockDeletingService extends BackgroundService {
           containerData.decrBlockCount(deletedBlocksCount);
           containerData.decrBytesUsed(releasedBytes);
           containerData.getVolume().decrementUsedSpace(releasedBytes);
+          metrics.incrSuccessCount(deletedBlocksCount);
+          metrics.incrSuccessBytes(releasedBytes);
         }
 
         LOG.debug("Container: {}, deleted blocks: {}, space reclaimed: {}, " +
@@ -505,6 +514,7 @@ public class BlockDeletingService extends BackgroundService {
       } catch (IOException exception) {
         LOG.warn("Deletion operation was not successful for container: " +
             container.getContainerData().getContainerID(), exception);
+        metrics.incrFailureCount();
         throw exception;
       }
     }
@@ -554,4 +564,8 @@ public class BlockDeletingService extends BackgroundService {
     void apply(Table<?, DeletedBlocksTransaction> deleteTxnsTable,
         BatchOperation batch, long txnID) throws IOException;
   }
+
+  public BlockDeletingServiceMetrics getMetrics() {
+    return metrics;
+  }
 }
diff --git a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestBlockDeletingService.java b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestBlockDeletingService.java
index 91d06f4aa4..8888151511 100644
--- a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestBlockDeletingService.java
+++ b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestBlockDeletingService.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.ozone.common.Checksum;
 import org.apache.hadoop.ozone.common.ChunkBuffer;
 import org.apache.hadoop.ozone.container.ContainerTestHelper;
 import org.apache.hadoop.ozone.container.common.helpers.BlockData;
+import org.apache.hadoop.ozone.container.common.helpers.BlockDeletingServiceMetrics;
 import org.apache.hadoop.ozone.container.common.helpers.ChunkInfo;
 import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics;
 import org.apache.hadoop.ozone.container.common.impl.ContainerLayoutVersion;
@@ -422,6 +423,7 @@ public class TestBlockDeletingService {
     BlockDeletingServiceTestImpl svc =
         getBlockDeletingService(containerSet, conf, keyValueHandler);
     svc.start();
+    BlockDeletingServiceMetrics deletingServiceMetrics = svc.getMetrics();
     GenericTestUtils.waitFor(svc::isStarted, 100, 3000);
 
     // Ensure 1 container was created
@@ -443,6 +445,8 @@ public class TestBlockDeletingService {
       // Number of deleted blocks in container should be equal to 0 before
       // block delete
 
+      long deleteSuccessCount =
+          deletingServiceMetrics.getSuccessCount();
       Assert.assertEquals(0, transactionId);
 
       // Ensure there are 3 blocks under deletion and 0 deleted blocks
@@ -464,6 +468,9 @@ public class TestBlockDeletingService {
       // used by the container should be less than the space used by the
       // container initially(before running deletion services).
       Assert.assertTrue(containerData.get(0).getBytesUsed() < containerSpace);
+      Assert.assertEquals(2,
+          deletingServiceMetrics.getSuccessCount()
+              - deleteSuccessCount);
 
       deleteAndWait(svc, 2);
 
@@ -479,6 +486,9 @@ public class TestBlockDeletingService {
       Assert.assertEquals(0,
           meta.getStore().getMetadataTable().get(data.blockCountKey())
               .longValue());
+      Assert.assertEquals(3,
+          deletingServiceMetrics.getSuccessCount()
+              - deleteSuccessCount);
     }
 
     svc.shutdown();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org