This is an automated email from the ASF dual-hosted git repository.

caiconghui pushed a commit to branch writeLock
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit 467c078e891a02bb3014e58450fa9ce8b43962f4
Author: caiconghui <caiconghui2...@163.com>
AuthorDate: Sun Sep 12 22:42:41 2021 +0800

    add isDropped mark
---
 .../java/org/apache/doris/catalog/Database.java    |  1 +
 .../main/java/org/apache/doris/catalog/Table.java  | 56 ++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
index 0f15ff9..621703f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
@@ -475,6 +475,7 @@ public class Database extends MetaObject implements 
Writable {
     public Table getTableOrMetaException(long tableId) throws 
MetaNotFoundException {
         return getTableOrException(tableId, t -> new 
MetaNotFoundException("unknown table, tableId=" + t));
     }
+
     @SuppressWarnings("unchecked")
     public <T extends Table> T getTableOrMetaException(String tableName, 
TableType tableType) throws MetaNotFoundException {
         Table table = getTableOrMetaException(tableName);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
index ecf1e1e..c2b349f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
@@ -18,7 +18,10 @@
 package org.apache.doris.catalog;
 
 import org.apache.doris.analysis.CreateTableStmt;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
 import org.apache.doris.common.FeMetaVersion;
+import org.apache.doris.common.MetaNotFoundException;
 import org.apache.doris.common.io.Text;
 import org.apache.doris.common.io.Writable;
 import org.apache.doris.common.util.SqlUtils;
@@ -54,6 +57,8 @@ public class Table extends MetaObject implements Writable {
     // assume that the time a lock is held by thread is less then 100ms
     public static final long TRY_LOCK_TIMEOUT_MS = 100L;
 
+    public volatile boolean isDropped = false;
+
     public enum TableType {
         MYSQL,
         ODBC,
@@ -155,6 +160,14 @@ public class Table extends MetaObject implements Writable {
         this.rwLock.writeLock().lock();
     }
 
+    public boolean writeLockIfExist() {
+        if (!isDropped) {
+            this.rwLock.writeLock().lock();
+            return true;
+        }
+        return false;
+    }
+
     public boolean tryWriteLock(long timeout, TimeUnit unit) {
         try {
            return this.rwLock.writeLock().tryLock(timeout, unit);
@@ -172,6 +185,49 @@ public class Table extends MetaObject implements Writable {
         return this.rwLock.writeLock().isHeldByCurrentThread();
     }
 
+    public <E extends Exception> void writeLockOrException(E e) throws E {
+        writeLock();
+        if (isDropped) {
+            writeUnlock();
+            throw e;
+        }
+    }
+
+    public void writeLockOrDdlException() throws DdlException {
+        writeLockOrException(new DdlException("unknown table, tableName=" + 
name));
+    }
+
+    public void writeLockOrMetaException() throws MetaNotFoundException {
+        writeLockOrException(new MetaNotFoundException("unknown table, 
tableName=" + name));
+    }
+
+    public void writeLockOrAnalysisException() throws AnalysisException {
+        writeLockOrException(new AnalysisException("unknown table, tableName=" 
+ name));
+    }
+
+    public boolean tryWriteLockOrDdlException(long timeout, TimeUnit unit) 
throws DdlException {
+        return tryWriteLockOrException(timeout, unit, new 
DdlException("unknown table, tableName=" + name));
+    }
+
+    public boolean tryWriteLockOrMetaException(long timeout, TimeUnit unit) 
throws MetaNotFoundException {
+        return tryWriteLockOrException(timeout, unit, new 
MetaNotFoundException("unknown table, tableName=" + name));
+    }
+
+    public boolean tryWriteLockOrAnalysisException(long timeout, TimeUnit 
unit) throws AnalysisException {
+        return tryWriteLockOrException(timeout, unit, new 
AnalysisException("unknown table, tableName=" + name));
+    }
+
+    public <E extends Exception> boolean tryWriteLockOrException(long timeout, 
TimeUnit unit, E e) throws E {
+        if (tryWriteLock(timeout, unit)) {
+            if (isDropped) {
+                writeUnlock();
+                throw e;
+            }
+            return true;
+        }
+        return false;
+    }
+
     public boolean isTypeRead() {
         return isTypeRead;
     }

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

Reply via email to