hemantk-12 commented on code in PR #8052:
URL: https://github.com/apache/ozone/pull/8052#discussion_r2023670665
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java:
##########
@@ -172,6 +210,59 @@ 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 void acquireLock(Resource resource, boolean isReadLock,
ReadWriteLock lock,
+ long startWaitingTimeNanos) {
Review Comment:
nit: alignment is off.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/MultiSnapshotLocks.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.snapshot;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
+import org.apache.hadoop.ozone.om.lock.OMLockDetails;
+import org.apache.hadoop.ozone.om.lock.OzoneManagerLock;
+
+/**
+ * Class to take multiple locks on multiple snapshots.
+ */
+public class MultiSnapshotLocks {
+ private final List<String[]> objectLocks;
+ private final IOzoneManagerLock lock;
+ private final OzoneManagerLock.Resource resource;
+ private final boolean writeLock;
+ private OMLockDetails lockDetails;
+
+ public MultiSnapshotLocks(IOzoneManagerLock lock, OzoneManagerLock.Resource
resource, boolean writeLock) {
+ this.writeLock = writeLock;
+ this.resource = resource;
+ this.lock = lock;
+ this.objectLocks = new ArrayList<>();
+ this.lockDetails = OMLockDetails.EMPTY_DETAILS_LOCK_NOT_ACQUIRED;
+ }
+
+ public synchronized OMLockDetails acquireLock(Collection<UUID> ids) throws
OMException {
+ if (this.lockDetails.isLockAcquired()) {
+ throw new OMException("More locks cannot be acquired when locks have
been already acquired. Locks acquired : ["
+ +
objectLocks.stream().map(Arrays::toString).collect(Collectors.joining(",")) +
"]",
Review Comment:
nit: use Collectors.joining() with `delimiter`, `prefix`, and `suffix`.
--
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]