sumitagrawl commented on code in PR #7647:
URL: https://github.com/apache/ozone/pull/7647#discussion_r1925053459


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/lock/OmLockOpr.java:
##########
@@ -0,0 +1,268 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import org.apache.hadoop.util.Time;
+import org.jheaps.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * key locking.
+ */
+public class OmLockOpr {
+  private static final Logger LOG = LoggerFactory.getLogger(OmLockOpr.class);
+  private static final long MONITOR_DELAY = 10 * 60 * 1000;
+  private static final long MONITOR_LOCK_THRESHOLD_NS = 10 * 60 * 
1000_000_000L;
+  private final KeyLock keyLocking;
+  private final KeyLock bucketLocking;
+  private final KeyLock volumeLocking;
+  private final String threadNamePrefix;
+  private ScheduledExecutorService executorService;
+  private final Map<OmLockInfo, OmLockInfo> lockMonitorMap = new 
ConcurrentHashMap<>();
+
+  public OmLockOpr(String threadNamePrefix) {
+    this.threadNamePrefix = threadNamePrefix;
+    keyLocking = new KeyLock(102400);
+    bucketLocking = new KeyLock(1024);
+    volumeLocking = new KeyLock(1024);
+  }
+
+  public void start() {
+    ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true)
+        .setNameFormat(threadNamePrefix + "OmLockOpr-Monitor-%d").build();
+    executorService = Executors.newScheduledThreadPool(1, threadFactory);
+    executorService.scheduleWithFixedDelay(this::monitor, 0, MONITOR_DELAY, 
TimeUnit.MILLISECONDS);
+  }
+
+  public void stop() {
+    executorService.shutdown();
+  }
+
+  public OmLockInfo volumeReadLock(String volumeName) throws IOException {

Review Comment:
   Will add to the doc,
   
   We have different lock group for volume, bucket and key, as they can 
conflict with each other.
   
   As API surface,
   For volume handling, we have, volume read and write lock
   For bucket handling, we have bucket read and write lock
   For OBS key handling, its obsLock
   
   So had these set of API, will update design doc further.



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