Skip to content

Commit

Permalink
fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs committed Aug 8, 2024
1 parent 9a7d28c commit b11ac6a
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,7 @@ public static int metaServiceRpcRetryTimes() {
"Deadlock detection interval time, unit minute"})
public static long deadlock_detection_interval_minute = 5;

@ConfField(description = {"表示最大锁持有时间,超过该时间会打印告警日志,单位秒",
@ConfField(mutable = true, description = {"表示最大锁持有时间,超过该时间会打印告警日志,单位秒",
"Maximum lock hold time; logs a warning if exceeded"})
public static long max_lock_hold_threshold_seconds = 30;
public static long max_lock_hold_threshold_seconds = 10;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.lock.MonitoredReentrantReadWriteLock;
import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.common.util.QueryableReentrantReadWriteLock;
import org.apache.doris.common.util.Util;
import org.apache.doris.datasource.CatalogIf;
import org.apache.doris.persist.CreateTableInfo;
Expand Down Expand Up @@ -87,7 +87,7 @@ public class Database extends MetaObject implements Writable, DatabaseIf<Table>,
@SerializedName(value = "fullQualifiedName")
private volatile String fullQualifiedName;

private QueryableReentrantReadWriteLock rwLock;
private MonitoredReentrantReadWriteLock rwLock;

// table family group map
private final Map<Long, Table> idToTable;
Expand Down Expand Up @@ -138,7 +138,7 @@ public Database(long id, String name) {
if (this.fullQualifiedName == null) {
this.fullQualifiedName = "";
}
this.rwLock = new QueryableReentrantReadWriteLock(true);
this.rwLock = new MonitoredReentrantReadWriteLock(true);
this.idToTable = Maps.newConcurrentMap();
this.nameToTable = Maps.newConcurrentMap();
this.lowerCaseToTableName = Maps.newConcurrentMap();
Expand Down
6 changes: 3 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.CountingDataOutputStream;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.lock.MonitoredReentrantLock;
import org.apache.doris.common.publish.TopicPublisher;
import org.apache.doris.common.publish.TopicPublisherThread;
import org.apache.doris.common.publish.WorkloadGroupPublisher;
Expand All @@ -122,7 +123,6 @@
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.common.util.QueryableReentrantLock;
import org.apache.doris.common.util.SmallFileMgr;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.common.util.Util;
Expand Down Expand Up @@ -362,7 +362,7 @@ public class Env {
// We use fair ReentrantLock to avoid starvation. Do not use this lock in critical code pass
// because fair lock has poor performance.
// Using QueryableReentrantLock to print owner thread in debug mode.
private QueryableReentrantLock lock;
private MonitoredReentrantLock lock;

private CatalogMgr catalogMgr;
private GlobalFunctionMgr globalFunctionMgr;
Expand Down Expand Up @@ -680,7 +680,7 @@ public Env(boolean isCheckpointCatalog) {
this.syncJobManager = new SyncJobManager();
this.alter = new Alter();
this.consistencyChecker = new ConsistencyChecker();
this.lock = new QueryableReentrantLock(true);
this.lock = new MonitoredReentrantLock(true);
this.backupHandler = new BackupHandler(this);
this.metaDir = Config.meta_dir;
this.publishVersionDaemon = new PublishVersionDaemon();
Expand Down
8 changes: 4 additions & 4 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.lock.MonitoredReentrantLock;
import org.apache.doris.common.util.QueryableReentrantReadWriteLock;
import org.apache.doris.common.lock.MonitoredReentrantReadWriteLock;
import org.apache.doris.common.util.SqlUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.persist.gson.GsonPostProcessable;
Expand Down Expand Up @@ -84,7 +84,7 @@ public abstract class Table extends MetaObject implements Writable, TableIf, Gso
protected TableType type;
@SerializedName(value = "createTime")
protected long createTime;
protected QueryableReentrantReadWriteLock rwLock;
protected MonitoredReentrantReadWriteLock rwLock;
// Used for queuing commit transactifon tasks to avoid fdb transaction conflicts,
// especially to reduce conflicts when obtaining delete bitmap update locks for
// MoW table
Expand Down Expand Up @@ -134,7 +134,7 @@ public Table(TableType type) {
this.type = type;
this.fullSchema = Lists.newArrayList();
this.nameToColumn = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
this.rwLock = new QueryableReentrantReadWriteLock(true);
this.rwLock = new MonitoredReentrantReadWriteLock(true);
if (Config.check_table_lock_leaky) {
this.readLockThreads = Maps.newConcurrentMap();
}
Expand All @@ -158,7 +158,7 @@ public Table(long id, String tableName, TableType type, List<Column> fullSchema)
// Only view in with-clause have null base
Preconditions.checkArgument(type == TableType.VIEW, "Table has no columns");
}
this.rwLock = new QueryableReentrantReadWriteLock(true);
this.rwLock = new MonitoredReentrantReadWriteLock(true);
this.createTime = Instant.now().getEpochSecond();
if (Config.check_table_lock_leaky) {
this.readLockThreads = Maps.newConcurrentMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public abstract class AbstractMonitoredLock {
// Lock hold timeout in milliseconds
protected static final long HOLD_TIMEOUT = Config.max_lock_hold_threshold_seconds * 1;
protected static final long HOLD_TIMEOUT = Config.max_lock_hold_threshold_seconds * 1000;
private static final Logger LOG = LoggerFactory.getLogger(AbstractMonitoredLock.class);

// Thread-local variable to store the lock start time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException
lockMonitor.afterTryLock(acquired, start); // Log result and elapsed time
return acquired;
}

@Override
public Thread getOwner() {
return super.getOwner();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
* monitoring capabilities for read and write locks.
*/
public class MonitoredReentrantReadWriteLock extends ReentrantReadWriteLock {
private final AbstractMonitoredLock readLockMonitor = new AbstractMonitoredLock() {
};
private final AbstractMonitoredLock writeLockMonitor = new AbstractMonitoredLock() {
};
// Monitored read and write lock instances
private final ReadLock readLock = new ReadLock(this);
private final WriteLock writeLock = new WriteLock(this);

// Constructor for creating a monitored lock with fairness option
public MonitoredReentrantReadWriteLock(boolean fair) {
Expand All @@ -42,6 +41,7 @@ public MonitoredReentrantReadWriteLock() {
*/
public class ReadLock extends ReentrantReadWriteLock.ReadLock {
private static final long serialVersionUID = 1L;
private final AbstractMonitoredLock monitor = new AbstractMonitoredLock() {};

/**
* Constructs a new ReadLock instance.
Expand All @@ -59,7 +59,7 @@ protected ReadLock(ReentrantReadWriteLock lock) {
@Override
public void lock() {
super.lock();
readLockMonitor.afterLock();
monitor.afterLock();
}

/**
Expand All @@ -68,7 +68,7 @@ public void lock() {
*/
@Override
public void unlock() {
readLockMonitor.afterUnlock();
monitor.afterUnlock();
super.unlock();
}
}
Expand All @@ -78,6 +78,7 @@ public void unlock() {
*/
public class WriteLock extends ReentrantReadWriteLock.WriteLock {
private static final long serialVersionUID = 1L;
private final AbstractMonitoredLock monitor = new AbstractMonitoredLock() {};

/**
* Constructs a new WriteLock instance.
Expand All @@ -95,7 +96,7 @@ protected WriteLock(ReentrantReadWriteLock lock) {
@Override
public void lock() {
super.lock();
writeLockMonitor.afterLock();
monitor.afterLock();
}

/**
Expand All @@ -104,7 +105,7 @@ public void lock() {
*/
@Override
public void unlock() {
writeLockMonitor.afterUnlock();
monitor.afterUnlock();
super.unlock();
}
}
Expand All @@ -116,7 +117,7 @@ public void unlock() {
*/
@Override
public ReadLock readLock() {
return new ReadLock(this);
return readLock;
}

/**
Expand All @@ -126,6 +127,11 @@ public ReadLock readLock() {
*/
@Override
public WriteLock writeLock() {
return new WriteLock(this);
return writeLock;
}

@Override
public Thread getOwner() {
return super.getOwner();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@
import org.apache.doris.common.Pair;
import org.apache.doris.common.UserException;
import org.apache.doris.common.io.CountingDataOutputStream;
import org.apache.doris.common.lock.MonitoredReentrantLock;
import org.apache.doris.common.util.DbUtil;
import org.apache.doris.common.util.DebugPointUtil;
import org.apache.doris.common.util.DynamicPartitionUtil;
import org.apache.doris.common.util.IdGeneratorUtil;
import org.apache.doris.common.util.MetaLockUtils;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.common.util.QueryableReentrantLock;
import org.apache.doris.common.util.SqlParserUtils;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.common.util.Util;
Expand Down Expand Up @@ -216,7 +216,7 @@ public class InternalCatalog implements CatalogIf<Database> {

private static final Logger LOG = LogManager.getLogger(InternalCatalog.class);

private QueryableReentrantLock lock = new QueryableReentrantLock(true);
private MonitoredReentrantLock lock = new MonitoredReentrantLock(true);
private transient ConcurrentHashMap<Long, Database> idToDb = new ConcurrentHashMap<>();
private transient ConcurrentHashMap<String, Database> fullNameToDb = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.doris.common.PatternMatcherException;
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.lock.MonitoredReentrantReadWriteLock;
import org.apache.doris.mysql.MysqlPassword;
import org.apache.doris.persist.gson.GsonPostProcessable;
import org.apache.doris.persist.gson.GsonUtils;
Expand Down Expand Up @@ -60,7 +60,7 @@ public class UserManager implements Writable, GsonPostProcessable {
public static final String ANY_HOST = "%";
private static final Logger LOG = LogManager.getLogger(UserManager.class);

private static final QueryableReentrantReadWriteLock rwLock = new QueryableReentrantReadWriteLock(false);
private static final MonitoredReentrantReadWriteLock rwLock = new MonitoredReentrantReadWriteLock(false);
private static final Lock rlock = rwLock.readLock();
private static final Lock wlock = rwLock.writeLock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package org.apache.doris.common.util;

import org.apache.doris.common.lock.MonitoredReentrantLock;

import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

public class QueryableReentrantLockTest {

private QueryableReentrantLock lock = new QueryableReentrantLock(true);
private MonitoredReentrantLock lock = new MonitoredReentrantLock(true);

@Test
public void test() throws InterruptedException {
Expand Down

0 comments on commit b11ac6a

Please sign in to comment.