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 b31401d04c1 HDDS-17015. Make DbVolume#hddsDbStorePathMap thread-safe
(#12111)
b31401d04c1 is described below
commit b31401d04c191e8d032d1dacc6a1e09110943380
Author: Navink <[email protected]>
AuthorDate: Sun Nov 22 01:14:45 2026 +0530
HDDS-17015. Make DbVolume#hddsDbStorePathMap thread-safe (#12111)
---
.../ozone/container/common/volume/DbVolume.java | 6 ++-
.../container/common/volume/TestDbVolume.java | 55 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/DbVolume.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/DbVolume.java
index a1f13998b85..6897c9b41c6 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/DbVolume.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/DbVolume.java
@@ -21,9 +21,9 @@
import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.hadoop.ozone.container.common.utils.DatanodeStoreCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,13 +48,15 @@ public class DbVolume extends StorageVolume {
/**
* Records all HddsVolumes that put its db instance under this DbVolume.
* Map: HddsVolume.StorageID -> DBStorePath
+ * Must be thread-safe, because HddsVolume.createDbStore can add entries
+ * while failVolume or shutdown iterate over them without a common lock.
*/
private final Map<String, String> hddsDbStorePathMap;
protected DbVolume(Builder b) throws IOException {
super(b);
- this.hddsDbStorePathMap = new HashMap<>();
+ this.hddsDbStorePathMap = new ConcurrentHashMap<>();
if (!b.getFailedVolume()) {
initialize();
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestDbVolume.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestDbVolume.java
index 280f8597d71..a932da5ced4 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestDbVolume.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestDbVolume.java
@@ -21,7 +21,10 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import java.io.File;
@@ -29,17 +32,21 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import java.util.UUID;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.fs.MockSpaceUsageCheckFactory;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.container.common.ContainerTestUtils;
import org.apache.hadoop.ozone.container.common.utils.DatanodeStoreCache;
import org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.mockito.MockedStatic;
/**
* Unit tests for {@link DbVolume}.
@@ -157,6 +164,54 @@ public void testDbStoreClosedOnBadDbVolume() throws
IOException {
assertEquals(0, DatanodeStoreCache.getInstance().size());
}
+ @Test
+ public void testFailVolumeWhileDbStorePathIsAdded() throws IOException {
+ // Use a separate conf to keep the shared CONF unchanged for other tests.
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.HDDS_DATANODE_CONTAINER_DB_DIR,
+ Files.createDirectory(folder.resolve("dbDir")).toString());
+ MutableVolumeSet dbVolumeSet = new MutableVolumeSet(DATANODE_UUID,
+ CLUSTER_ID, conf, null, StorageVolume.VolumeType.DB_VOLUME, null);
+ DbVolume dbVolume = (DbVolume) dbVolumeSet.getVolumesList().get(0);
+ // The db stores are closed only if the clusterID dir exists.
+ dbVolume.format(CLUSTER_ID);
+ dbVolume.createWorkingDir(CLUSTER_ID, null);
+
+ // More than one path, so that iteration continues after the new path is
added.
+ Set<String> dbPaths = new HashSet<>();
+ for (int i = 0; i < 3; i++) {
+ String dbPath = "db" + i;
+ dbVolume.addHddsDbStorePath(UUID.randomUUID().toString(), dbPath);
+ dbPaths.add(dbPath);
+ }
+
+ // Register one more db store path when the first db is closed,
+ // while closing the first DB, add a new path as HddsVolume#createDbStore
does during SchemaV3
+ // finalization while holding a different lock.
+ Set<String> closedDbPaths = new HashSet<>();
+ DatanodeStoreCache cache = mock(DatanodeStoreCache.class);
+ doAnswer(invocation -> {
+ if (closedDbPaths.isEmpty()) {
+ dbVolume.addHddsDbStorePath(UUID.randomUUID().toString(), "newDb");
+ }
+ closedDbPaths.add(invocation.getArgument(0));
+ return null;
+ }).when(cache).removeDB(anyString());
+
+ // Fail the volume the way the disk checker does
+ try (MockedStatic<DatanodeStoreCache> mockedCache =
mockStatic(DatanodeStoreCache.class)) {
+ mockedCache.when(DatanodeStoreCache::getInstance).thenReturn(cache);
+ dbVolumeSet.failVolume(dbVolume.getStorageDir().getPath());
+ }
+
+ assertEquals(HddsVolume.VolumeState.FAILED, dbVolume.getStorageState());
+ // The newly added path may or may not be visited by the iteration.
+ assertTrue(closedDbPaths.containsAll(dbPaths));
+ // The failed volume must be moved out of the active volumes.
+ assertFalse(dbVolumeSet.getVolumesList().contains(dbVolume));
+ assertEquals(Collections.singletonList(dbVolume),
dbVolumeSet.getFailedVolumesList());
+ }
+
private MutableVolumeSet createHddsVolumeSet(int volumeNum)
throws IOException {
File[] hddsVolumeDirs = new File[volumeNum];
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]