You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/01/31 15:39:16 UTC
[doris] 18/20: [enhencement](lock) print table lock owner when failed to try lock (#16186)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
commit f1539758e3bdc614acc512c0d0a05436fe8c65c7
Author: Mingyu Chen <mo...@163.com>
AuthorDate: Tue Jan 31 18:21:18 2023 +0800
[enhencement](lock) print table lock owner when failed to try lock (#16186)
---
.../main/java/org/apache/doris/catalog/Table.java | 22 ++++++++----
.../util/QueryableReentrantReadWriteLock.java | 41 ++++++++++++++++++++++
2 files changed, 57 insertions(+), 6 deletions(-)
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 f3c306a88c..5c8454fa0a 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
@@ -23,6 +23,7 @@ import org.apache.doris.common.DdlException;
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.QueryableReentrantReadWriteLock;
import org.apache.doris.common.util.SqlUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.external.hudi.HudiTable;
@@ -49,7 +50,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
/**
@@ -70,7 +70,7 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
protected volatile String qualifiedDbName;
protected TableType type;
protected long createTime;
- protected ReentrantReadWriteLock rwLock;
+ protected QueryableReentrantReadWriteLock rwLock;
/*
* fullSchema and nameToColumn should contains all columns, both visible and shadow.
@@ -110,7 +110,7 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
this.type = type;
this.fullSchema = Lists.newArrayList();
this.nameToColumn = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
- this.rwLock = new ReentrantReadWriteLock(true);
+ this.rwLock = new QueryableReentrantReadWriteLock(true);
}
public Table(long id, String tableName, TableType type, List<Column> fullSchema) {
@@ -130,7 +130,7 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
// Only view in with-clause have null base
Preconditions.checkArgument(type == TableType.VIEW, "Table has no columns");
}
- this.rwLock = new ReentrantReadWriteLock();
+ this.rwLock = new QueryableReentrantReadWriteLock(true);
this.createTime = Instant.now().getEpochSecond();
}
@@ -148,7 +148,12 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
public boolean tryReadLock(long timeout, TimeUnit unit) {
try {
- return this.rwLock.readLock().tryLock(timeout, unit);
+ boolean res = this.rwLock.readLock().tryLock(timeout, unit);
+ if (!res && unit.toSeconds(timeout) >= 1) {
+ LOG.warn("Failed to try table {}'s read lock. timeout {} {}. Current owner: {}",
+ name, timeout, unit.name(), rwLock.getOwner());
+ }
+ return res;
} catch (InterruptedException e) {
LOG.warn("failed to try read lock at table[" + name + "]", e);
return false;
@@ -174,7 +179,12 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
public boolean tryWriteLock(long timeout, TimeUnit unit) {
try {
- return this.rwLock.writeLock().tryLock(timeout, unit);
+ boolean res = this.rwLock.writeLock().tryLock(timeout, unit);
+ if (!res && unit.toSeconds(timeout) >= 1) {
+ LOG.warn("Failed to try table {}'s write lock. timeout {} {}. Current owner: {}",
+ name, timeout, unit.name(), rwLock.getOwner());
+ }
+ return res;
} catch (InterruptedException e) {
LOG.warn("failed to try write lock at table[" + name + "]", e);
return false;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/QueryableReentrantReadWriteLock.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/QueryableReentrantReadWriteLock.java
new file mode 100644
index 0000000000..3f55b54229
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/QueryableReentrantReadWriteLock.java
@@ -0,0 +1,41 @@
+// 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 java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/*
+ * This Lock is for exposing the getOwner() method,
+ * which is a protected method of ReentrantLock
+ */
+public class QueryableReentrantReadWriteLock extends ReentrantReadWriteLock {
+ private static final long serialVersionUID = 1L;
+
+ public QueryableReentrantReadWriteLock() {
+ super();
+ }
+
+ public QueryableReentrantReadWriteLock(boolean fair) {
+ super(fair);
+ }
+
+ @Override
+ public Thread getOwner() {
+ return super.getOwner();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org