[enhencement](lock) print table lock owner when failed to try lock (#16186)
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user