swamirishi commented on code in PR #8052: URL: https://github.com/apache/ozone/pull/8052#discussion_r2023529659
########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java: ########## @@ -172,6 +204,54 @@ public OMLockDetails acquireWriteLock(Resource resource, String... keys) { return acquireLock(resource, false, keys); } + /** + * Acquire write locks on a list of resources. + * + * 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 keys - A list of 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 + public OMLockDetails acquireWriteLocks(Resource resource, Collection<String[]> keys) { + return acquireLocks(resource, false, keys); + } + + private OMLockDetails acquireLocks(Resource resource, boolean isReadLock, + Collection<String[]> keys) { + omLockDetails.get().clear(); + if (!resource.canLock(lockSet.get())) { + String errorMessage = getErrorMessage(resource); + LOG.error(errorMessage); + throw new RuntimeException(errorMessage); + } + + long startWaitingTimeNanos = Time.monotonicNowNanos(); + + for (ReadWriteLock lock : bulkGetLock(resource, keys)) { + if (isReadLock) { + lock.readLock().lock(); + updateReadLockMetrics(resource, (ReentrantReadWriteLock) lock, startWaitingTimeNanos); + } else { + lock.writeLock().lock(); + updateWriteLockMetrics(resource, (ReentrantReadWriteLock) lock, startWaitingTimeNanos); + } Review Comment: done ########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java: ########## @@ -122,6 +126,12 @@ private Striped<ReadWriteLock> createStripeLock(Resource r, return SimpleStriped.readWriteLock(size, fair); } + private Iterable<ReadWriteLock> bulkGetLock(Resource resource, Collection<String[]> keys) { + Striped<ReadWriteLock> striped = stripedLockByResource.get(resource); + return striped.bulkGet(keys.stream().filter(Objects::nonNull) 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-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org