jojochuang commented on code in PR #9328:
URL: https://github.com/apache/ozone/pull/9328#discussion_r2558125435
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java:
##########
@@ -601,36 +604,97 @@ OMLockDetails lockResource(T resource) {
}
}
- private static final class FlatResourceLockManager extends
ResourceLockManager<FlatResource> {
+ private static final class DAGResourceLockManager extends
ResourceLockManager<DAGLeveledResource> {
- private EnumMap<FlatResource, ThreadLocal<Boolean>> acquiredLocksMap = new
EnumMap<>(FlatResource.class);
+ private final EnumMap<DAGLeveledResource, ThreadLocal<Boolean>>
acquiredLocksMap =
+ new EnumMap<>(DAGLeveledResource.class);
+ private final Map<DAGLeveledResource, Set<DAGLeveledResource>>
lockDependentAdjacencySet =
+ new EnumMap<>(DAGLeveledResource.class);
- private FlatResourceLockManager() {
- for (FlatResource flatResource : FlatResource.values()) {
- acquiredLocksMap.put(flatResource, ThreadLocal.withInitial(() ->
Boolean.FALSE));
+ /**
+ * 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.
Review Comment:
After executing this method, lockDependentAdjacencySet is populated with the
transitive set of dependent child resources of a given resource type.
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/DAGLeveledResource.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock.Resource;
+
+/**
+ * The {@code DAGLeveledResource} enum represents a set of resources that are
associated with
+ * specific locks in the Ozone Manager Lock mechanism. These resources allow
fine-grained
+ * locking at various levels, ensuring consistent access and management of
system data.
+ * Each resource can optionally define child resources, forming a directed
acyclic graph (DAG)
+ * structure for hierarchical locking.
+ *
+ * The enum implements the {@code Resource} interface, providing a name for
identification and
+ * an associated {@link IOzoneManagerLock.ResourceManager} to manage its
locking behavior.
+ */
Review Comment:
A little more explanation will be nice.
Add: DAGLeveledResource defines the order in which resources can be locked.
Attempting to lock the resources out of order will throw a RuntimeException.
For instance, acquiring SNAPSHOT_DB_CONTENT_LOCK followed by SNAPSHOT_DB_LOCK
is allowed; acquiring SNAPSHOT_LOCAL_DATA_LOCK followed by
SNAPSHOT_DB_CONTENT_LOCK is not permitted.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]