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 7294fc2da18 HDDS-17355. Datanode stop aborts halfway if a schema V1/V2
container DB is still in use (#11706)
7294fc2da18 is described below
commit 7294fc2da180254d7430a3e61ae5f1af80581cb1
Author: Siyao Meng <[email protected]>
AuthorDate: Mon Nov 2 12:05:15 2026 -0800
HDDS-17355. Datanode stop aborts halfway if a schema V1/V2 container DB is
still in use (#11706)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../container/common/utils/ContainerCache.java | 18 +++++++---
.../ozone/container/common/TestContainerCache.java | 39 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/utils/ContainerCache.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/utils/ContainerCache.java
index ea0c9cc1e3a..642575cc77d 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/utils/ContainerCache.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/utils/ContainerCache.java
@@ -21,6 +21,8 @@
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Striped;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.collections4.MapIterator;
@@ -81,9 +83,10 @@ public static synchronized ContainerCache getInstance(
}
/**
- * Closes all the db instances and resets the cache.
+ * Closes and removes all the db instances that are not in use.
*/
public void shutdownCache() {
+ List<String> inUse = new ArrayList<>();
lock.lock();
try {
// iterate the cache and close each db
@@ -91,14 +94,19 @@ public void shutdownCache() {
while (iterator.hasNext()) {
iterator.next();
ReferenceCountedDB db = (ReferenceCountedDB) iterator.getValue();
- Preconditions.checkArgument(cleanupDb(db), "refCount: %s",
- db.getReferenceCount());
+ if (cleanupDb(db)) {
+ iterator.remove();
+ } else {
+ // Still referenced: leave it open for its user; it is closed once
released and evicted or removed.
+ inUse.add(db.getContainerDBPath() + " refCount=" +
db.getReferenceCount());
+ }
}
- // reset the cache
- cache.clear();
} finally {
lock.unlock();
}
+ if (!inUse.isEmpty()) {
+ LOG.warn("Not closing {} container DB(s) still in use: {}",
inUse.size(), inUse);
+ }
}
/**
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestContainerCache.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestContainerCache.java
index f8ae2f3bdcd..44b9796595d 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestContainerCache.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestContainerCache.java
@@ -17,6 +17,7 @@
package org.apache.hadoop.ozone.container.common;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -186,6 +187,44 @@ void testConcurrentDBGet() throws Exception {
FileUtils.deleteDirectory(root);
}
+ @Test
+ void testShutdownCacheKeepsDBInUseOpen() throws Exception {
+ File root = new File(testRoot);
+ assertTrue(root.mkdirs());
+
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setInt(OzoneConfigKeys.OZONE_CONTAINER_CACHE_SIZE, 2);
+ ContainerCache cache = ContainerCache.getInstance(conf);
+ cache.clear();
+ File containerDir1 = new File(root, "cont1");
+ File containerDir2 = new File(root, "cont2");
+ createContainerDB(conf, containerDir1);
+ createContainerDB(conf, containerDir2);
+ String schemaVersion =
VersionedDatanodeFeatures.SchemaV2.chooseSchemaVersion();
+
+ try {
+ // A DB still in use comes first in the cache, followed by an idle one.
+ ReferenceCountedDB inUse = cache.getDB(1, "RocksDB",
containerDir1.getPath(), schemaVersion, conf);
+ ReferenceCountedDB idle = cache.getDB(2, "RocksDB",
containerDir2.getPath(), schemaVersion, conf);
+ idle.close();
+
+ cache.shutdownCache();
+ assertThat(idle.isClosed()).isTrue();
+ assertThat(inUse.isClosed()).isFalse();
+ assertThat(cache).containsOnlyKeys(containerDir1.getPath());
+
+ // Once released, the next shutdown closes it.
+ inUse.close();
+ cache.shutdownCache();
+ assertThat(inUse.isClosed()).isTrue();
+ assertThat(cache).isEmpty();
+ } finally {
+ cache.values().forEach(db -> ((ReferenceCountedDB)
db).getStore().stop());
+ cache.clear();
+ FileUtils.deleteDirectory(root);
+ }
+ }
+
@Test
public void testUnderlyingDBzIsClosed() throws Exception {
File root = new File(testRoot);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]