This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new e0793c97b60 [opt](fe) Use `table.readLock` in `TabletStatMgr` for
updating statistics (#39612)
e0793c97b60 is described below
commit e0793c97b60e9d187ebdb156f87fb39ce17becb0
Author: Lei Zhang <[email protected]>
AuthorDate: Fri Aug 23 12:20:40 2024 +0800
[opt](fe) Use `table.readLock` in `TabletStatMgr` for updating statistics
(#39612)
---
.../java/org/apache/doris/catalog/CloudTabletStatMgr.java | 5 +++--
fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java | 9 +++++++++
.../main/java/org/apache/doris/catalog/TabletStatMgr.java | 12 +++---------
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
index 8bd05213e0f..ff01f736081 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.java
@@ -156,7 +156,7 @@ public class CloudTabletStatMgr extends MasterDaemon {
Long tableRowsetCount = 0L;
Long tableSegmentCount = 0L;
- if (!table.writeLockIfExist()) {
+ if (!table.readLockIfExist()) {
continue;
}
try {
@@ -203,13 +203,14 @@ public class CloudTabletStatMgr extends MasterDaemon {
} // end for indices
} // end for partitions
+ // this is only one thread to update table statistics,
readLock is enough
olapTable.setStatistics(new
OlapTable.Statistics(db.getName(),
table.getName(), tableDataSize,
tableTotalReplicaDataSize, 0L,
tableReplicaCount, tableRowCount,
tableRowsetCount, tableSegmentCount));
LOG.debug("finished to set row num for table: {} in
database: {}",
table.getName(), db.getFullName());
} finally {
- table.writeUnlock();
+ table.readUnlock();
}
newCloudTableStatsMap.put(Pair.of(dbId, table.getId()), new
OlapTable.Statistics(db.getName(),
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 0665b128bfd..c3b2f01448b 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
@@ -183,6 +183,15 @@ public abstract class Table extends MetaObject implements
Writable, TableIf, Gso
}
}
+ public boolean readLockIfExist() {
+ readLock();
+ if (isDropped) {
+ readUnlock();
+ return false;
+ }
+ return true;
+ }
+
public boolean tryReadLock(long timeout, TimeUnit unit) {
try {
boolean res = this.rwLock.readLock().tryLock(timeout, unit);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
index 030dc4d7a0e..1206c6b2f82 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.java
@@ -35,7 +35,6 @@ import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.TimeUnit;
/*
* TabletStatMgr is for collecting tablet(replica) statistics from backends.
@@ -121,13 +120,7 @@ public class TabletStatMgr extends MasterDaemon {
Long tableRowCount = 0L;
- // Use try write lock to avoid such cases
- // Time1: Thread1 hold read lock for 5min
- // Time2: Thread2 want to add write lock, then it will be
the first element in lock queue
- // Time3: Thread3 want to add read lock, but it will not,
because thread 2 want to add write lock
- // In this case, thread 3 has to wait more than 5min, because
it has to wait thread 2 to add
- // write lock and release write lock and thread 2 has to wait
thread 1 to release read lock
- if (!table.tryWriteLockIfExist(3000, TimeUnit.MILLISECONDS)) {
+ if (!table.readLockIfExist()) {
continue;
}
try {
@@ -169,6 +162,7 @@ public class TabletStatMgr extends MasterDaemon {
} // end for indices
} // end for partitions
+ // this is only one thread to update table statistics,
readLock is enough
olapTable.setStatistics(new
OlapTable.Statistics(db.getName(), table.getName(),
tableDataSize, tableTotalReplicaDataSize,
tableRemoteDataSize, tableReplicaCount,
tableRowCount, 0L, 0L));
@@ -178,7 +172,7 @@ public class TabletStatMgr extends MasterDaemon {
table.getName(), db.getFullName());
}
} finally {
- table.writeUnlock();
+ table.readUnlock();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]