This is an automated email from the ASF dual-hosted git repository.
siyao pushed a commit to branch HDDS-6517-Snapshot
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/HDDS-6517-Snapshot by this
push:
new 01762a385d HDDS-7506. [Snapshot] Expose more snapshot metrics under
OMMetrics (#4164)
01762a385d is described below
commit 01762a385d073231d0c4614ec7a98a6a0cdf2f2c
Author: Christos Bisias <[email protected]>
AuthorDate: Sat Jan 21 00:19:47 2023 +0200
HDDS-7506. [Snapshot] Expose more snapshot metrics under OMMetrics (#4164)
---
.../org/apache/hadoop/ozone/om/TestOmMetrics.java | 61 ++++++++++++++++++++++
.../java/org/apache/hadoop/ozone/om/OMMetrics.java | 54 +++++++++++++++++++
.../org/apache/hadoop/ozone/om/OzoneManager.java | 42 +++++++++++++++
.../request/snapshot/OMSnapshotCreateRequest.java | 1 +
4 files changed, 158 insertions(+)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
index b0a32512ab..8bd09f543a 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
@@ -384,6 +384,67 @@ public class TestOmMetrics {
}
+ @Test
+ public void testSnapshotOps() throws Exception {
+ // This tests needs enough datanodes to allocate the
+ // blocks for the keys.
+ clusterBuilder.setNumDatanodes(3);
+ startCluster();
+
+ OmBucketInfo omBucketInfo = createBucketInfo(false);
+
+ String volumeName = omBucketInfo.getVolumeName();
+ String bucketName = omBucketInfo.getBucketName();
+ String snapshot1 = "snap1";
+ String snapshot2 = "snap2";
+
+ writeClient.createBucket(omBucketInfo);
+
+ // Create first key
+ OmKeyArgs keyArgs1 = createKeyArgs(volumeName, bucketName,
+
RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE));
+ OpenKeySession keySession = writeClient.openKey(keyArgs1);
+ writeClient.commitKey(keyArgs1, keySession.getId());
+
+ // Create first snapshot
+ writeClient.createSnapshot(volumeName, bucketName, snapshot1);
+
+ MetricsRecordBuilder omMetrics = getMetrics("OMMetrics");
+
+ assertCounter("NumSnapshotCreateFails", 0L, omMetrics);
+ assertCounter("NumSnapshotCreates", 1L, omMetrics);
+ assertCounter("NumSnapshotListFails", 0L, omMetrics);
+ assertCounter("NumSnapshotLists", 0L, omMetrics);
+
+ assertCounter("NumSnapshotActive", 1L, omMetrics);
+ assertCounter("NumSnapshotDeleted", 0L, omMetrics);
+ assertCounter("NumSnapshotReclaimed", 0L, omMetrics);
+
+ // Create second key
+ OmKeyArgs keyArgs2 = createKeyArgs(volumeName, bucketName,
+
RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE));
+ OpenKeySession keySession2 = writeClient.openKey(keyArgs2);
+ writeClient.commitKey(keyArgs2, keySession2.getId());
+
+ // Create second snapshot
+ writeClient.createSnapshot(volumeName, bucketName, snapshot2);
+
+ // List snapshots
+ writeClient.listSnapshot(volumeName, bucketName);
+
+ omMetrics = getMetrics("OMMetrics");
+ assertCounter("NumSnapshotActive", 2L, omMetrics);
+ assertCounter("NumSnapshotCreates", 2L, omMetrics);
+ assertCounter("NumSnapshotLists", 1L, omMetrics);
+
+ // restart OM
+ cluster.restartOzoneManager();
+
+ // Check number of active snapshots in the snapshot table
+ // is the same after OM restart
+ assertCounter("NumSnapshotActive", 2L, omMetrics);
+ }
+
private <T> void mockWritePathExceptions(Class<T>klass) throws Exception {
String tableName;
if (klass == OmBucketInfo.class) {
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
index 23183446c0..e85a033d18 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
@@ -120,6 +120,9 @@ public class OMMetrics implements OmMetadataReaderMetrics {
private @Metric MutableCounterLong numOpenKeyDeleteRequestFails;
private @Metric MutableCounterLong numSnapshotCreateFails;
private @Metric MutableCounterLong numSnapshotListFails;
+ private @Metric MutableCounterLong numSnapshotActive;
+ private @Metric MutableCounterLong numSnapshotDeleted;
+ private @Metric MutableCounterLong numSnapshotReclaimed;
// Number of tenant operations attempted
private @Metric MutableCounterLong numTenantOps;
@@ -448,6 +451,45 @@ public class OMMetrics implements OmMetadataReaderMetrics {
numSnapshotListFails.incr();
}
+ public void setNumSnapshotActive(long num) {
+ long currVal = numSnapshotActive.value();
+ numSnapshotActive.incr(num - currVal);
+ }
+
+ public void incNumSnapshotActive() {
+ numSnapshotActive.incr();
+ }
+
+ public void decNumSnapshotActive() {
+ numSnapshotActive.incr(-1);
+ }
+
+ public void setNumSnapshotDeleted(long num) {
+ long currVal = numSnapshotDeleted.value();
+ numSnapshotDeleted.incr(num - currVal);
+ }
+
+ public void incNumSnapshotDeleted() {
+ numSnapshotDeleted.incr();
+ }
+
+ public void decNumSnapshotDeleted() {
+ numSnapshotDeleted.incr(-1);
+ }
+
+ public void setNumSnapshotReclaimed(long num) {
+ long currVal = numSnapshotReclaimed.value();
+ numSnapshotReclaimed.incr(num - currVal);
+ }
+
+ public void incNumSnapshotReclaimed() {
+ numSnapshotReclaimed.incr();
+ }
+
+ public void decNumSnapshotReclaimed() {
+ numSnapshotReclaimed.incr(-1);
+ }
+
public void incNumCompleteMultipartUploadFails() {
numCompleteMultipartUploadFails.incr();
}
@@ -1143,6 +1185,18 @@ public class OMMetrics implements
OmMetadataReaderMetrics {
return numSnapshotListFails.value();
}
+ public long getNumSnapshotActive() {
+ return numSnapshotActive.value();
+ }
+
+ public long getNumSnapshotDeleted() {
+ return numSnapshotDeleted.value();
+ }
+
+ public long getNumSnapshotReclaimed() {
+ return numSnapshotReclaimed.value();
+ }
+
public void incNumTrashRenames() {
numTrashRenames.incr();
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index 92a7fb9778..8eef324523 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -727,6 +727,9 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
this, LOG, AUDIT, metrics);
omSnapshotManager = new OmSnapshotManager(this);
+ // Snapshot metrics
+ updateActiveSnapshotMetrics();
+
if (withNewSnapshot) {
Integer layoutVersionInDB = getLayoutVersionInDB();
if (layoutVersionInDB != null &&
@@ -1622,6 +1625,45 @@ public final class OzoneManager extends
ServiceRuntimeInfoImpl
omState = State.RUNNING;
}
+ /**
+ * Iterate the Snapshot table, check the status
+ * for every snapshot and update OMMetrics.
+ */
+ private void updateActiveSnapshotMetrics()
+ throws IOException {
+
+ long activeGauge = 0;
+ long deletedGauge = 0;
+ long reclaimedGauge = 0;
+
+ try (TableIterator<String, ? extends
+ KeyValue<String, SnapshotInfo>> keyIter =
+ metadataManager.getSnapshotInfoTable().iterator()) {
+
+ while (keyIter.hasNext()) {
+ SnapshotInfo info = keyIter.next().getValue();
+
+ SnapshotInfo.SnapshotStatus snapshotStatus =
+ info.getSnapshotStatus();
+
+ if (snapshotStatus.equals(SnapshotInfo
+ .SnapshotStatus.SNAPSHOT_ACTIVE)) {
+ activeGauge++;
+ } else if (snapshotStatus.equals(SnapshotInfo
+ .SnapshotStatus.SNAPSHOT_DELETED)) {
+ deletedGauge++;
+ } else if (snapshotStatus.equals(SnapshotInfo
+ .SnapshotStatus.SNAPSHOT_RECLAIMED)) {
+ reclaimedGauge++;
+ }
+ }
+ }
+
+ metrics.setNumSnapshotActive(activeGauge);
+ metrics.setNumSnapshotDeleted(deletedGauge);
+ metrics.setNumSnapshotReclaimed(reclaimedGauge);
+ }
+
private void checkConfigBeforeBootstrap() throws IOException {
List<OMNodeDetails> omsWihtoutNewConfig = new ArrayList<>();
for (Map.Entry<String, OMNodeDetails> entry : peerNodesMap.entrySet()) {
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotCreateRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotCreateRequest.java
index 4b9f636811..3f1af514c1 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotCreateRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotCreateRequest.java
@@ -109,6 +109,7 @@ public class OMSnapshotCreateRequest extends
OMClientRequest {
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumSnapshotCreates();
+ omMetrics.incNumSnapshotActive();
boolean acquiredBucketLock = false, acquiredSnapshotLock = false;
IOException exception = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]