You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/12/03 11:19:34 UTC

[GitHub] [incubator-doris] wangbo commented on a change in pull request #3775: Support read and write lock in table level to reduce lock competition

wangbo commented on a change in pull request #3775:
URL: https://github.com/apache/incubator-doris/pull/3775#discussion_r535123440



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/util/MetaLockUtils.java
##########
@@ -0,0 +1,76 @@
+// 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.doris.common.util;
+
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public class MetaLockUtils {
+
+    public static void readLockDatabases(List<Database> databaseList) {
+        for (Database database : databaseList) {
+            database.readLock();
+        }
+    }
+
+    public static void readUnlockDatabases(List<Database> databaseList) {
+        for (int i = databaseList.size() - 1; i >= 0; i--) {
+            databaseList.get(i).readUnlock();
+        }
+    }
+
+    public static void readLockTables(List<Table> tableList) {
+        for (Table table : tableList) {
+            table.readLock();
+        }
+    }
+
+    public static void readUnlockTables(List<Table> tableList) {
+        for (int i = tableList.size() - 1; i >= 0; i--) {
+            tableList.get(i).readUnlock();
+        }
+    }
+
+    public static void writeLockTables(List<Table> tableList) {

Review comment:
       I find a corner case as below:
   There are three threads wants to get table lock:
   T1(thread 1) try lock(TableA,TableB)
   T2(thread 2) try lock(TableB,TableC)
   T3(thread 3) try lock(TableC,TableA)
   
   If T1 get TableA's lock  and T2 get TableB's lock and T3 get TableC's lock at the same time ,
   Then three threads try get next table's lock ,dead lock happends.
   T1 try lock TableB, but TableB is held by T2.
   T2 try lock TableC,but TableC is held by T3.
   T3 try lock TableA,but TableA is held by T1.
   Can the current implementation solve this case?
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org