Copilot commented on code in PR #9160:
URL: https://github.com/apache/ozone/pull/9160#discussion_r2434712037


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/ReadOnlyHierarchicalResourceLockManager.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.io.IOException;
+
+/**
+ * A read only lock manager that does not acquire any lock.
+ */
+public class ReadOnlyHierarchicalResourceLockManager implements 
HierachicalResourceLockManager {
+
+  private static final HierarchicalResourceLock EMPTY_LOCK_ACQUIRED = new 
HierarchicalResourceLock() {
+    @Override
+    public boolean isLockAcquired() {
+      return true;
+    }
+
+    @Override
+    public void close() {
+
+    }
+  };
+
+  private static final HierarchicalResourceLock EMPTY_LOCK_NOT_ACQUIRED = new 
HierarchicalResourceLock() {
+    @Override
+    public boolean isLockAcquired() {
+      return true;

Review Comment:
   The `EMPTY_LOCK_NOT_ACQUIRED` constant incorrectly returns `true` for 
`isLockAcquired()`. This should return `false` to indicate the lock was not 
acquired, which is consistent with its name and usage context for write locks 
in read-only scenarios.
   ```suggestion
         return false;
   ```



##########
hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java:
##########
@@ -90,6 +91,11 @@ public interface OMMetadataManager extends DBStoreHAManager, 
AutoCloseable {
    */
   IOzoneManagerLock getLock();
 
+  /**
+   * Returns the Hierarchical ResourceLock used on Metadata DB.
+   */
+  HierachicalResourceLockManager getHierarchicalLockManager();

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -133,6 +136,7 @@ public class OmMetadataManagerImpl implements 
OMMetadataManager,
   private DBStore store;
 
   private final IOzoneManagerLock lock;
+  private final HierachicalResourceLockManager hierarchicalLockManager;

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."



##########
hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java:
##########
@@ -51,6 +51,7 @@
 import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
 import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
 import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.ozone.om.lock.HierachicalResourceLockManager;

Review Comment:
   Corrected spelling of 'Hierachical' to 'Hierarchical'."



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -644,6 +652,11 @@ public IOzoneManagerLock getLock() {
     return lock;
   }
 
+  @Override
+  public HierachicalResourceLockManager getHierarchicalLockManager() {

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/PoolBasedHierarchicalResourceLockManager.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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 static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_HARD_LIMIT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_HARD_LIMIT_DEFAULT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_SOFT_LIMIT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_SOFT_LIMIT_DEFAULT;
+
+import com.google.common.base.Preconditions;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Consumer;
+import org.apache.commons.pool2.BasePooledObjectFactory;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+
+/**
+ * A lock manager implementation that manages hierarchical resource locks
+ * using a pool of reusable {@link ReadWriteLock} instances. The implementation
+ * ensures deterministic lock ordering for resources, avoiding cyclic
+ * lock dependencies, and is typically useful for structures like
+ * DAGs (e.g., File System trees or snapshot chains).
+ */
+public class PoolBasedHierarchicalResourceLockManager implements 
HierachicalResourceLockManager {

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."
   ```suggestion
   public class PoolBasedHierarchicalResourceLockManager implements 
HierarchicalResourceLockManager {
   ```



##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestPoolBasedHierarchicalResourceLockManager.java:
##########
@@ -0,0 +1,577 @@
+/*
+ * 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 static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_HARD_LIMIT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_HARD_LIMIT_DEFAULT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_SOFT_LIMIT;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HIERARCHICAL_RESOURCE_LOCKS_SOFT_LIMIT_DEFAULT;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import 
org.apache.hadoop.ozone.om.lock.HierachicalResourceLockManager.HierarchicalResourceLock;

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."
   ```suggestion
   import 
org.apache.hadoop.ozone.om.lock.HierarchicalResourceLockManager.HierarchicalResourceLock;
   ```



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/ReadOnlyHierarchicalResourceLockManager.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.io.IOException;
+
+/**
+ * A read only lock manager that does not acquire any lock.
+ */
+public class ReadOnlyHierarchicalResourceLockManager implements 
HierachicalResourceLockManager {

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."
   ```suggestion
   public class ReadOnlyHierarchicalResourceLockManager implements 
HierarchicalResourceLockManager {
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java:
##########
@@ -103,9 +103,12 @@
 import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
 import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
 import org.apache.hadoop.ozone.om.helpers.WithMetadata;
+import org.apache.hadoop.ozone.om.lock.HierachicalResourceLockManager;

Review Comment:
   Corrected spelling of 'HierachicalResourceLockManager' to 
'HierarchicalResourceLockManager'."



-- 
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]

Reply via email to