duongkame commented on code in PR #4885:
URL: https://github.com/apache/ozone/pull/4885#discussion_r1235646808


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java:
##########
@@ -95,34 +97,35 @@ public class OzoneManagerLock implements IOzoneManagerLock {
    * @param conf Configuration object
    */
   public OzoneManagerLock(ConfigurationSource conf) {
-    boolean fair = conf.getBoolean(OZONE_MANAGER_FAIR_LOCK,
-        OZONE_MANAGER_FAIR_LOCK_DEFAULT);
-    manager = new LockManager<>(conf, fair);
     omLockMetrics = OMLockMetrics.create();
+
+    // TODO: for now, guava Striped doesn't allow create a striped
+    //  ReadWriteLock with fair-lock yet.
+    //  https://github.com/google/guava/issues/2514.
+    //  We may have to consider implement our own striped locks.
+    //boolean fair = conf.getBoolean(OZONE_MANAGER_FAIR_LOCK,
+    //    OZONE_MANAGER_FAIR_LOCK_DEFAULT);
+
+    Map<Resource, Striped<ReadWriteLock>> stripedLockMap = new HashMap<>();
+    for (Resource r : Resource.values()) {
+      stripedLockMap.put(r, createStripeLock(r, conf));
+    }
+    this.stripedLockByResource = Collections.unmodifiableMap(stripedLockMap);
   }
 
-  /**
-   * Acquire lock on resource.
-   *
-   * For S3_BUCKET_LOCK, VOLUME_LOCK, BUCKET_LOCK type resource, same
-   * thread acquiring lock again is allowed.
-   *
-   * For USER_LOCK, PREFIX_LOCK, S3_SECRET_LOCK type resource, same thread
-   * acquiring lock again is not allowed.
-   *
-   * Special Note for USER_LOCK: Single thread can acquire single user lock/
-   * multi user lock. But not both at the same time.
-   * @param resource - Type of the resource.
-   * @param resources - Resource names on which user want to acquire lock.
-   * For Resource type BUCKET_LOCK, first param should be volume, second param
-   * should be bucket name. For remaining all resource only one param should
-   * be passed.
-   */
-  @Override
-  @Deprecated
-  public boolean acquireLock(Resource resource, String... resources) {
-    String resourceName = generateResourceName(resource, resources);
-    return lock(resource, resourceName, manager::writeLock, WRITE_LOCK);
+  private Striped<ReadWriteLock> createStripeLock(Resource r,
+      ConfigurationSource conf) {
+    String stripeSizeKey = OZONE_MANAGER_STRIPED_LOCK_SIZE_PREFIX +
+        r.name().toLowerCase();
+    int size = conf.getInt(stripeSizeKey,
+        OZONE_MANAGER_STRIPED_LOCK_SIZE_DEFAULT);
+    return Striped.readWriteLock(size);
+  }
+
+  private ReentrantReadWriteLock getLock(Resource resource, String... keys) {
+    Object key = keys.length == 1 ? keys[0] : combineKeys(keys);

Review Comment:
   Good one, thanks.



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