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 2df6bbeec7a HDDS-17655. Prevent FULL_CACHE tables in snapshot and 
checkpoint DBs (#11896)
2df6bbeec7a is described below

commit 2df6bbeec7aa043f36486ea7499238cb344a952e
Author: Siyao Meng <[email protected]>
AuthorDate: Fri Nov 6 05:33:33 2026 -0800

    HDDS-17655. Prevent FULL_CACHE tables in snapshot and checkpoint DBs 
(#11896)
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../hadoop/ozone/om/OmMetadataManagerImpl.java     | 20 ++++++----
 .../hadoop/ozone/om/TestOmMetadataManager.java     | 45 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 7 deletions(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
index deb358f534f..eca1287e160 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
@@ -494,12 +494,12 @@ private static DBStoreBuilder 
newDBStoreBuilder(OzoneConfiguration conf, String
   protected void initializeOmTables(CacheType cacheType,
                                     boolean addCacheMetrics)
       throws IOException {
-    final TableInitializer initializer = new TableInitializer(addCacheMetrics);
+    final TableInitializer initializer = new TableInitializer(cacheType, 
addCacheMetrics);
 
     userTable = initializer.get(OMDBDefinition.USER_TABLE_DEF);
 
-    volumeTable = initializer.get(OMDBDefinition.VOLUME_TABLE_DEF, cacheType);
-    bucketTable = initializer.get(OMDBDefinition.BUCKET_TABLE_DEF, cacheType);
+    volumeTable = initializer.getWithDbCache(OMDBDefinition.VOLUME_TABLE_DEF);
+    bucketTable = initializer.getWithDbCache(OMDBDefinition.BUCKET_TABLE_DEF);
     keyTable = initializer.get(OMDBDefinition.KEY_TABLE_DEF);
 
     openKeyTable = initializer.get(OMDBDefinition.OPEN_KEY_TABLE_DEF);
@@ -542,8 +542,7 @@ protected void initializeOmTables(CacheType cacheType,
 
     // originalAccessKeyId -> revocationTimeMillis
     // FULL_CACHE keeps revocations in memory as there are not expected to be 
many
-    s3RevokedStsTokenTable = initializer.get(
-        OMDBDefinition.S3_REVOKED_STS_TOKEN_TABLE_DEF, cacheType);
+    s3RevokedStsTokenTable = 
initializer.getWithDbCache(OMDBDefinition.S3_REVOKED_STS_TOKEN_TABLE_DEF);
 
     lifecycleConfigurationTable = 
initializer.get(OMDBDefinition.LIFECYCLE_CONFIGURATION_TABLE_DEF);
     lifecycleScanStateTable = 
initializer.get(OMDBDefinition.LIFECYCLE_SCAN_STATE_TABLE_DEF);
@@ -2150,9 +2149,11 @@ public void deleteWithBatch(AutoCloseable batchOperator, 
String id)
   }
 
   private class TableInitializer {
+    private final CacheType cacheType;
     private final boolean addCacheMetrics;
 
-    TableInitializer(boolean addCacheMetrics) {
+    TableInitializer(CacheType cacheType, boolean addCacheMetrics) {
+      this.cacheType = cacheType;
       this.addCacheMetrics = addCacheMetrics;
     }
 
@@ -2161,7 +2162,12 @@ <KEY, VALUE> Table<KEY, VALUE> 
get(DBColumnFamilyDefinition<KEY, VALUE> definiti
       return get(definition.getTable(store));
     }
 
-    <KEY, VALUE> Table<KEY, VALUE> get(DBColumnFamilyDefinition<KEY, VALUE> 
definition, CacheType cacheType)
+    /**
+     * Get a table with the cache type the DB was opened with. There is 
deliberately no way to pass a cache type
+     * here: a FULL_CACHE table loads the whole table and starts a cleanup 
thread on every open, so snapshot and
+     * checkpoint DBs, which are opened with PARTIAL_CACHE again and again, 
must never get one.
+     */
+    <KEY, VALUE> Table<KEY, VALUE> 
getWithDbCache(DBColumnFamilyDefinition<KEY, VALUE> definition)
         throws IOException {
       return get(definition.getTable(store, cacheType));
     }
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
index c203a1e56b0..842c741ad81 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
@@ -24,6 +24,7 @@
 import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_MPU_EXPIRE_THRESHOLD_DEFAULT;
 import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_OPEN_KEY_EXPIRE_THRESHOLD;
 import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_OPEN_KEY_EXPIRE_THRESHOLD_DEFAULT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SNAPSHOT_DB_MAX_OPEN_FILES_DEFAULT;
 import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.BUCKET_TABLE;
 import static 
org.apache.hadoop.ozone.om.codec.OMDBDefinition.COMPACTION_LOG_TABLE;
 import static 
org.apache.hadoop.ozone.om.codec.OMDBDefinition.DELEGATION_TOKEN_TABLE;
@@ -85,6 +86,8 @@
 import org.apache.hadoop.hdds.protocol.StorageType;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
 import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
+import org.apache.hadoop.hdds.utils.db.RDBStore;
 import org.apache.hadoop.hdds.utils.db.TypedTable;
 import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
 import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
@@ -1412,6 +1415,48 @@ public void 
testAllTablesAreProperInOMMetadataManagerImpl() {
     assertEquals(tablesByDefinition, tablesInManager);
   }
 
+  /**
+   * Snapshot and checkpoint DBs are opened and closed repeatedly, so opening 
one must not create a FULL_CACHE table,
+   * and opening and closing one must not leave any thread behind.
+   */
+  @Test
+  public void testSnapshotDbOpenLeaksNoThread() throws Exception {
+    final String snapshotDirName = 
SnapshotInfo.getCheckpointDirName(UUID.randomUUID(), 0);
+    ((RDBStore) omMetadataManager.getStore()).getSnapshot(snapshotDirName);
+    final DBCheckpoint checkpoint = 
omMetadataManager.getStore().getCheckpoint(true);
+    final int iterations = 10;
+    // The active DB has FULL_CACHE tables, so the thread name used below is 
right.
+    assertThat(countFullTableCacheThreads()).isPositive();
+
+    // Warm up, so that threads started once on first use are not counted.
+    openAndCloseSnapshotDbs(snapshotDirName, checkpoint);
+    final Set<Thread> before = Thread.getAllStackTraces().keySet();
+    for (int i = 0; i < iterations; i++) {
+      openAndCloseSnapshotDbs(snapshotDirName, checkpoint);
+    }
+
+    final Set<Thread> leaked = new 
HashSet<>(Thread.getAllStackTraces().keySet());
+    leaked.removeAll(before);
+    // Tolerate a few transient threads; a per-open leak adds at least one per 
iteration.
+    assertThat(leaked).hasSizeLessThan(iterations);
+  }
+
+  private void openAndCloseSnapshotDbs(String snapshotDirName, DBCheckpoint 
checkpoint) throws Exception {
+    final long fullTableCacheThreads = countFullTableCacheThreads();
+    try (OmMetadataManagerImpl snapshotManager = new 
OmMetadataManagerImpl(ozoneConfiguration, snapshotDirName,
+            OZONE_OM_SNAPSHOT_DB_MAX_OPEN_FILES_DEFAULT);
+        OmMetadataManagerImpl checkpointManager =
+            
OmMetadataManagerImpl.createCheckpointMetadataManager(ozoneConfiguration, 
checkpoint)) {
+      assertEquals(fullTableCacheThreads, countFullTableCacheThreads());
+    }
+  }
+
+  private static long countFullTableCacheThreads() {
+    return Thread.getAllStackTraces().keySet().stream()
+        .filter(t -> t.getName().contains("FullTableCache-Cleanup"))
+        .count();
+  }
+
   @Test
   public void testListSnapshot() throws Exception {
     String vol1 = "vol1";


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

Reply via email to