This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 ef9ebfae7a8 HDDS-16695. Preserve shared RDBMetrics when closing
RDBStore (#12091)
ef9ebfae7a8 is described below
commit ef9ebfae7a838bfdda5e44f519d4f675283379fa
Author: Andy Huang <[email protected]>
AuthorDate: Sun Nov 22 20:29:39 2026 +0800
HDDS-16695. Preserve shared RDBMetrics when closing RDBStore (#12091)
---
.../apache/hadoop/hdds/utils/db/RDBMetrics.java | 8 +-----
.../org/apache/hadoop/hdds/utils/db/RDBStore.java | 1 -
.../apache/hadoop/hdds/utils/db/TestRDBStore.java | 30 ++++++++++++++++++++
.../hadoop/hdds/utils/db/TestRDBTableStore.java | 33 ++++++++++++++--------
.../hadoop/ozone/TestMetricsLeakAssertion.java | 2 +-
.../apache/hadoop/ozone/MetricsLeakAssertion.java | 1 +
6 files changed, 55 insertions(+), 20 deletions(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBMetrics.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBMetrics.java
index 624d1bb761c..b1e78df8761 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBMetrics.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBMetrics.java
@@ -24,7 +24,7 @@
import org.apache.hadoop.metrics2.lib.MutableCounterLong;
/**
- * Class to hold RocksDB metrics.
+ * RocksDB metrics shared by all RDBStores for the lifetime of the JVM.
*/
public class RDBMetrics {
@@ -123,10 +123,4 @@ public long getWalUpdateSequenceCount() {
return walUpdateSequenceCount.value();
}
- public static synchronized void unRegister() {
- instance = null;
- MetricsSystem ms = DefaultMetricsSystem.instance();
- ms.unregisterSource(SOURCE_NAME);
- }
-
}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
index efccdf31aef..a6a6ae61bd7 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/RDBStore.java
@@ -245,7 +245,6 @@ public void close() {
metrics = null;
}
- RDBMetrics.unRegister();
IOUtils.close(LOG, checkPointManager);
if (rocksDBCheckpointDiffer != null) {
RocksDBCheckpointDifferHolder
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java
index 8fda20ab41a..3aec9e8a337 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java
@@ -18,11 +18,14 @@
package org.apache.hadoop.hdds.utils.db;
import static org.apache.hadoop.ozone.OzoneConsts.ROCKSDB_SST_SUFFIX;
+import static org.apache.ozone.test.MetricsAsserts.assertCounter;
+import static org.apache.ozone.test.MetricsAsserts.getMetrics;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -32,6 +35,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -45,9 +49,11 @@
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.hdds.StringUtils;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.utils.db.managed.ManagedColumnFamilyOptions;
import org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions;
import org.apache.hadoop.hdds.utils.db.managed.ManagedWriteOptions;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -120,6 +126,30 @@ public void tearDown() throws Exception {
CodecBuffer.assertNoLeaks();
}
+ @Test
+ void testMetricsRemainRegisteredAfterStoreClose(@TempDir Path tempDir)
throws Exception {
+ RDBMetrics metrics = rdbStore.getMetrics();
+ long keyGets = metrics.getNumDBKeyGets();
+
+ try (RDBStore otherStore = DBStoreBuilder.newBuilder(new
OzoneConfiguration())
+ .setPath(tempDir).setName("other.db").build()) {
+ assertSame(metrics, otherStore.getMetrics());
+ }
+
+ assertNotNull(DefaultMetricsSystem.instance().getSource("RDBMetrics"));
+ assertSame(metrics, rdbStore.getMetrics());
+ metrics.incNumDBKeyGets();
+ assertCounter("NumDBKeyGets", keyGets + 1, getMetrics("RDBMetrics"));
+ rdbStore.close();
+
+ try (RDBStore reopenedStore = DBStoreBuilder.newBuilder(new
OzoneConfiguration())
+ .setPath(tempDir).setName("other.db").build()) {
+ assertSame(metrics, reopenedStore.getMetrics());
+ assertNotNull(DefaultMetricsSystem.instance().getSource("RDBMetrics"));
+ assertCounter("NumDBKeyGets", keyGets + 1, getMetrics("RDBMetrics"));
+ }
+ }
+
public void insertRandomData(RDBStore dbStore, int familyIndex)
throws IOException {
Table<byte[], byte[]> firstTable =
dbStore.getTable(families.get(familyIndex));
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
index c38277e7917..aafffe808d8 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
@@ -448,6 +448,11 @@ public void testIsExist() throws Exception {
Table<byte[], byte[]> testTable = rdbStore.getTable(tableName);
testTable.put(key, value);
+ RDBMetrics rdbMetrics = rdbStore.getMetrics();
+ long mayExistChecks = rdbMetrics.getNumDBKeyMayExistChecks();
+ long mayExistMisses = rdbMetrics.getNumDBKeyMayExistMisses();
+ long keyGets = rdbMetrics.getNumDBKeyGets();
+
// Test if isExist returns true for a key that definitely exists.
assertTrue(testTable.isExist(key));
@@ -465,16 +470,18 @@ public void testIsExist() throws Exception {
// Test if isExist returns false for a key that is definitely not present.
assertFalse(testTable.isExist(invalidKey));
- RDBMetrics rdbMetrics = rdbStore.getMetrics();
- assertEquals(3, rdbMetrics.getNumDBKeyMayExistChecks());
- assertEquals(0, rdbMetrics.getNumDBKeyMayExistMisses());
- assertEquals(2, rdbMetrics.getNumDBKeyGets());
+ assertEquals(mayExistChecks + 3, rdbMetrics.getNumDBKeyMayExistChecks());
+ assertEquals(mayExistMisses, rdbMetrics.getNumDBKeyMayExistMisses());
+ assertEquals(keyGets + 2, rdbMetrics.getNumDBKeyGets());
// Reinsert key for further testing.
testTable.put(key, value);
rdbStore.close();
setUp();
+ mayExistChecks = rdbMetrics.getNumDBKeyMayExistChecks();
+ mayExistMisses = rdbMetrics.getNumDBKeyMayExistMisses();
+ keyGets = rdbMetrics.getNumDBKeyGets();
Table<byte[], byte[]> testTable2 = rdbStore.getTable(tableName);
// Verify isExist works with key not in block cache.
assertTrue(testTable2.isExist(key));
@@ -482,9 +489,9 @@ public void testIsExist() throws Exception {
assertTrue(testTable2.isExist(zeroSizeKey));
RDBMetrics rdbMetrics2 = rdbStore.getMetrics();
- assertEquals(2, rdbMetrics2.getNumDBKeyMayExistChecks());
- assertEquals(0, rdbMetrics2.getNumDBKeyMayExistMisses());
- assertEquals(2, rdbMetrics2.getNumDBKeyGets());
+ assertEquals(mayExistChecks + 2, rdbMetrics2.getNumDBKeyMayExistChecks());
+ assertEquals(mayExistMisses, rdbMetrics2.getNumDBKeyMayExistMisses());
+ assertEquals(keyGets + 2, rdbMetrics2.getNumDBKeyGets());
}
@Test
@@ -521,6 +528,11 @@ public void testGetIfExist() throws Exception {
Table<byte[], byte[]> testTable = rdbStore.getTable(tableName);
testTable.put(key, value);
+ RDBMetrics rdbMetrics = rdbStore.getMetrics();
+ long checks = rdbMetrics.getNumDBKeyGetIfExistChecks();
+ long misses = rdbMetrics.getNumDBKeyGetIfExistMisses();
+ long gets = rdbMetrics.getNumDBKeyGetIfExistGets();
+
// Test if isExist returns value for a key that definitely exists.
assertNotNull(testTable.getIfExist(key));
@@ -533,12 +545,11 @@ public void testGetIfExist() throws Exception {
// Test if isExist returns null for a key that is definitely not present.
assertNull(testTable.getIfExist(invalidKey));
- RDBMetrics rdbMetrics = rdbStore.getMetrics();
- assertEquals(3, rdbMetrics.getNumDBKeyGetIfExistChecks());
+ assertEquals(checks + 3, rdbMetrics.getNumDBKeyGetIfExistChecks());
- assertEquals(0, rdbMetrics.getNumDBKeyGetIfExistMisses());
+ assertEquals(misses, rdbMetrics.getNumDBKeyGetIfExistMisses());
- assertEquals(0, rdbMetrics.getNumDBKeyGetIfExistGets());
+ assertEquals(gets, rdbMetrics.getNumDBKeyGetIfExistGets());
// Reinsert key for further testing.
testTable.put(key, value);
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMetricsLeakAssertion.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMetricsLeakAssertion.java
index 531a28f14fa..836fd89eb94 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMetricsLeakAssertion.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMetricsLeakAssertion.java
@@ -82,7 +82,7 @@ void testUnexpectedSourceFails(String sourceName) {
@ParameterizedTest
@ValueSource(strings = {"ContainerCacheMetrics", "ContainerCacheMetrics-1",
"ContainerCacheMetrics-123",
"JvmMetricsOM", "RpcActivityForPort15000", "VolumeIOStats-/data/volume",
"keyTableCache", "keyTableCache-1",
- "XceiverClientMetrics", "XceiverClientMetrics-1"})
+ "XceiverClientMetrics", "XceiverClientMetrics-1", "RDBMetrics",
"RDBMetrics-1"})
void testAllowedSourcePasses(String sourceName) {
registerSource(sourceName);
diff --git
a/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java
b/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java
index 04ed659c3b9..f0ad5a3e7b5 100644
---
a/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java
+++
b/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java
@@ -53,6 +53,7 @@ public final class MetricsLeakAssertion {
"JvmMetrics*", // per service, via HddsServerUtil.initializeMetrics
"UgiMetrics", // Hadoop security UGI metrics
"ManagedRocksObjectMetrics",
+ "RDBMetrics", // shared by all RDBStores for the lifetime of the JVM
"XceiverClientMetrics", // shared by all XceiverClientManagers for the
lifetime of the JVM
"ContainerCacheMetrics" // ContainerCache singleton, created once per JVM
);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]