You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "swamirishi (via GitHub)" <gi...@apache.org> on 2025/11/22 14:46:34 UTC
[PR] HDDS-13984. Move ResourceLockTracker outside of OzoneManagerLock class and also reuse it for HierarchicalResourceLockManager interface [ozone]
swamirishi opened a new pull request, #9352:
URL: https://github.com/apache/ozone/pull/9352
## What changes were proposed in this pull request?
Currently ResourceLockTracker is only present in the OzoneManagerLock which is responsible for tracking all the locks held by a thread and enforce order of lock acquisition by a thread. We would need this also for PoolBasedHierarchicalResourceLock to enforce lock ordering there.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-13984
## How was this patch tested?
Added unit tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi merged PR #9352:
URL: https://github.com/apache/ozone/pull/9352
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "jojochuang (via GitHub)" <gi...@apache.org>.
jojochuang commented on code in PR #9352:
URL: https://github.com/apache/ozone/pull/9352#discussion_r2560959850
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java:
##########
@@ -581,151 +577,6 @@ public OMLockMetrics getOMLockMetrics() {
return omLockMetrics;
}
- private abstract static class ResourceLockManager<T extends Resource> {
Review Comment:
Basically, rename ResourceLockManager to ResourceLockTracker, and move it out to its own class file, so that it can be used by HierarchicalResourceLockManager.
Similarly, DAGResourceLockManager renamed and moved to DAGResourceLockTracker.java
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/DAGResourceLockTracker.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.lock;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import java.util.stream.Stream;
+
+final class DAGResourceLockTracker extends ResourceLockTracker<DAGLeveledResource> {
Review Comment:
Please add a javadoc:
track lock usage and enforce a locking rule based on a DAG (directed acyclic graph) of resources: a resource should not be locked while any of its dependent resources (children or descendants in the DAG) are currently locked.
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/DAGResourceLockTracker.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.lock;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import java.util.stream.Stream;
+
+final class DAGResourceLockTracker extends ResourceLockTracker<DAGLeveledResource> {
+
+ private final EnumMap<DAGLeveledResource, ThreadLocal<Integer>> acquiredLocksMap =
+ new EnumMap<>(DAGLeveledResource.class);
+ private final Map<DAGLeveledResource, Set<DAGLeveledResource>> lockDependentAdjacencySet =
+ new EnumMap<>(DAGLeveledResource.class);
+
+ private static volatile DAGResourceLockTracker instance = null;
+
+ public static DAGResourceLockTracker get() {
+ if (instance == null) {
+ synchronized (DAGResourceLockTracker.class) {
+ if (instance == null) {
+ instance = new DAGResourceLockTracker();
+ }
+ }
+ }
+ return instance;
+ }
+
Review Comment:
/**
* Performs a depth-first traversal (DFS) on the directed acyclic graph (DAG)
* of {@link DAGLeveledResource} objects, processing dependencies and updating
* the lock-dependent adjacency set with resource relationships.
*
* @param resource the DAGLeveledResource instance to start the traversal from
* @param stack a stack to manage the DFS traversal state
* @param visited a set to keep track of resources that have already been visited
* during the traversal
*/
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestPoolBasedHierarchicalResourceLockManager.java:
##########
@@ -580,4 +572,39 @@ public void testIOExceptionPropagation() {
assertNotNull(e.getMessage());
}
}
+
+ @ParameterizedTest
+ @EnumSource
+ public void testDAGLockOrderAcquisition(DAGLeveledResource dagLeveledResource) throws IOException {
+ Map<DAGLeveledResource, Set<IOzoneManagerLock.Resource>> forbiddenLockOrdering =
+ ImmutableMap.of(SNAPSHOT_DB_CONTENT_LOCK, ImmutableSet.of(SNAPSHOT_DB_LOCK, SNAPSHOT_LOCAL_DATA_LOCK),
+ BOOTSTRAP_LOCK, ImmutableSet.of(SNAPSHOT_GC_LOCK, SNAPSHOT_DB_LOCK, SNAPSHOT_DB_CONTENT_LOCK,
+ SNAPSHOT_LOCAL_DATA_LOCK));
+ List<DAGLeveledResource> resources = Arrays.stream(DAGLeveledResource.values()).collect(Collectors.toList());
+ for (DAGLeveledResource otherResource : resources) {
+ String otherResourceName1 = otherResource.getName() + "key";
+ String otherResourceName2 = otherResource.getName() + "key";
+ String flatResourceName = dagLeveledResource.getName() + "key";
+ try (HierarchicalResourceLock lock1 = lockManager.acquireWriteLock(otherResource, otherResourceName1);
+ HierarchicalResourceLock lock2 = lockManager.acquireWriteLock(otherResource, otherResourceName2)) {
Review Comment:
is this to ensure a lock is reentrant? because otherResourceName1 and otherResourceName2 would be the same.
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestPoolBasedHierarchicalResourceLockManager.java:
##########
@@ -580,4 +572,39 @@ public void testIOExceptionPropagation() {
assertNotNull(e.getMessage());
}
}
+
+ @ParameterizedTest
+ @EnumSource
+ public void testDAGLockOrderAcquisition(DAGLeveledResource dagLeveledResource) throws IOException {
+ Map<DAGLeveledResource, Set<IOzoneManagerLock.Resource>> forbiddenLockOrdering =
+ ImmutableMap.of(SNAPSHOT_DB_CONTENT_LOCK, ImmutableSet.of(SNAPSHOT_DB_LOCK, SNAPSHOT_LOCAL_DATA_LOCK),
+ BOOTSTRAP_LOCK, ImmutableSet.of(SNAPSHOT_GC_LOCK, SNAPSHOT_DB_LOCK, SNAPSHOT_DB_CONTENT_LOCK,
+ SNAPSHOT_LOCAL_DATA_LOCK));
+ List<DAGLeveledResource> resources = Arrays.stream(DAGLeveledResource.values()).collect(Collectors.toList());
+ for (DAGLeveledResource otherResource : resources) {
+ String otherResourceName1 = otherResource.getName() + "key";
+ String otherResourceName2 = otherResource.getName() + "key";
+ String flatResourceName = dagLeveledResource.getName() + "key";
Review Comment:
String dagResourceName = dagLeveledResource.getName() + "key";
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #9352:
URL: https://github.com/apache/ozone/pull/9352#discussion_r2561081572
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestPoolBasedHierarchicalResourceLockManager.java:
##########
@@ -580,4 +572,39 @@ public void testIOExceptionPropagation() {
assertNotNull(e.getMessage());
}
}
+
+ @ParameterizedTest
+ @EnumSource
+ public void testDAGLockOrderAcquisition(DAGLeveledResource dagLeveledResource) throws IOException {
+ Map<DAGLeveledResource, Set<IOzoneManagerLock.Resource>> forbiddenLockOrdering =
+ ImmutableMap.of(SNAPSHOT_DB_CONTENT_LOCK, ImmutableSet.of(SNAPSHOT_DB_LOCK, SNAPSHOT_LOCAL_DATA_LOCK),
+ BOOTSTRAP_LOCK, ImmutableSet.of(SNAPSHOT_GC_LOCK, SNAPSHOT_DB_LOCK, SNAPSHOT_DB_CONTENT_LOCK,
+ SNAPSHOT_LOCAL_DATA_LOCK));
+ List<DAGLeveledResource> resources = Arrays.stream(DAGLeveledResource.values()).collect(Collectors.toList());
+ for (DAGLeveledResource otherResource : resources) {
+ String otherResourceName1 = otherResource.getName() + "key";
+ String otherResourceName2 = otherResource.getName() + "key";
+ String flatResourceName = dagLeveledResource.getName() + "key";
+ try (HierarchicalResourceLock lock1 = lockManager.acquireWriteLock(otherResource, otherResourceName1);
+ HierarchicalResourceLock lock2 = lockManager.acquireWriteLock(otherResource, otherResourceName2)) {
Review Comment:
I am closing lock1 while still holding lock2. I would want to still forbid lock retention based on the number of locks held
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on PR #9352:
URL: https://github.com/apache/ozone/pull/9352#issuecomment-3577979530
Compile had succeeded in fork
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #9352:
URL: https://github.com/apache/ozone/pull/9352#discussion_r2561096775
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/DAGResourceLockTracker.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.lock;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import java.util.stream.Stream;
+
+final class DAGResourceLockTracker extends ResourceLockTracker<DAGLeveledResource> {
Review Comment:
done
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/DAGResourceLockTracker.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.lock;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+import java.util.stream.Stream;
+
+final class DAGResourceLockTracker extends ResourceLockTracker<DAGLeveledResource> {
+
+ private final EnumMap<DAGLeveledResource, ThreadLocal<Integer>> acquiredLocksMap =
+ new EnumMap<>(DAGLeveledResource.class);
+ private final Map<DAGLeveledResource, Set<DAGLeveledResource>> lockDependentAdjacencySet =
+ new EnumMap<>(DAGLeveledResource.class);
+
+ private static volatile DAGResourceLockTracker instance = null;
+
+ public static DAGResourceLockTracker get() {
+ if (instance == null) {
+ synchronized (DAGResourceLockTracker.class) {
+ if (instance == null) {
+ instance = new DAGResourceLockTracker();
+ }
+ }
+ }
+ return instance;
+ }
+
Review Comment:
done
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestPoolBasedHierarchicalResourceLockManager.java:
##########
@@ -580,4 +572,39 @@ public void testIOExceptionPropagation() {
assertNotNull(e.getMessage());
}
}
+
+ @ParameterizedTest
+ @EnumSource
+ public void testDAGLockOrderAcquisition(DAGLeveledResource dagLeveledResource) throws IOException {
+ Map<DAGLeveledResource, Set<IOzoneManagerLock.Resource>> forbiddenLockOrdering =
+ ImmutableMap.of(SNAPSHOT_DB_CONTENT_LOCK, ImmutableSet.of(SNAPSHOT_DB_LOCK, SNAPSHOT_LOCAL_DATA_LOCK),
+ BOOTSTRAP_LOCK, ImmutableSet.of(SNAPSHOT_GC_LOCK, SNAPSHOT_DB_LOCK, SNAPSHOT_DB_CONTENT_LOCK,
+ SNAPSHOT_LOCAL_DATA_LOCK));
+ List<DAGLeveledResource> resources = Arrays.stream(DAGLeveledResource.values()).collect(Collectors.toList());
+ for (DAGLeveledResource otherResource : resources) {
+ String otherResourceName1 = otherResource.getName() + "key";
+ String otherResourceName2 = otherResource.getName() + "key";
+ String flatResourceName = dagLeveledResource.getName() + "key";
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #9352:
URL: https://github.com/apache/ozone/pull/9352#discussion_r2561072904
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestPoolBasedHierarchicalResourceLockManager.java:
##########
@@ -580,4 +572,39 @@ public void testIOExceptionPropagation() {
assertNotNull(e.getMessage());
}
}
+
+ @ParameterizedTest
+ @EnumSource
+ public void testDAGLockOrderAcquisition(DAGLeveledResource dagLeveledResource) throws IOException {
+ Map<DAGLeveledResource, Set<IOzoneManagerLock.Resource>> forbiddenLockOrdering =
+ ImmutableMap.of(SNAPSHOT_DB_CONTENT_LOCK, ImmutableSet.of(SNAPSHOT_DB_LOCK, SNAPSHOT_LOCAL_DATA_LOCK),
+ BOOTSTRAP_LOCK, ImmutableSet.of(SNAPSHOT_GC_LOCK, SNAPSHOT_DB_LOCK, SNAPSHOT_DB_CONTENT_LOCK,
+ SNAPSHOT_LOCAL_DATA_LOCK));
+ List<DAGLeveledResource> resources = Arrays.stream(DAGLeveledResource.values()).collect(Collectors.toList());
+ for (DAGLeveledResource otherResource : resources) {
+ String otherResourceName1 = otherResource.getName() + "key";
+ String otherResourceName2 = otherResource.getName() + "key";
+ String flatResourceName = dagLeveledResource.getName() + "key";
+ try (HierarchicalResourceLock lock1 = lockManager.acquireWriteLock(otherResource, otherResourceName1);
+ HierarchicalResourceLock lock2 = lockManager.acquireWriteLock(otherResource, otherResourceName2)) {
Review Comment:
yeah
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-13984. Reuse ResourceLockTracker for HierarchicalResourceLockManager [ozone]
Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on PR #9352:
URL: https://github.com/apache/ozone/pull/9352#issuecomment-3577980987
Thank you @jojochuang for reviewing the patch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org