From 16a0ef0852f04930abb08f3d3cd69403f6b55216 Mon Sep 17 00:00:00 2001 From: deardeng Date: Wed, 2 Jul 2025 20:18:52 +0800 Subject: [PATCH] [fix](create table)Fixed table creation becomes slower as the number of tablets increases --- .../apache/doris/catalog/TabletInvertedIndex.java | 14 ++++++++++++++ .../org/apache/doris/system/SystemInfoService.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java index 0362205dbdef94..a1faada3fea669 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java @@ -718,6 +718,20 @@ public List getReplicasByTabletId(long tabletId) { } } + public Long getTabletSizeByBackendId(long backendId) { + Long ret = 0L; + long stamp = readLock(); + try { + Map replicaMetaWithBackend = backingReplicaMetaTable.row(backendId); + if (replicaMetaWithBackend != null) { + ret += replicaMetaWithBackend.size(); + } + } finally { + readUnlock(stamp); + } + return ret; + } + public List getTabletIdsByBackendId(long backendId) { List tabletIds = Lists.newArrayList(); long stamp = readLock(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java b/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java index 8df709c8ace14a..316a53b1ce0139 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java +++ b/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java @@ -482,7 +482,7 @@ public int getStartPosOfRoundRobin(Tag tag, TStorageMedium storageMedium, boolea long minBeTabletsNum = Long.MAX_VALUE; int minIndex = -1; for (int i = 0; i < beIds.size(); ++i) { - long tabletsNum = Env.getCurrentInvertedIndex().getTabletIdsByBackendId(beIds.get(i)).size(); + long tabletsNum = Env.getCurrentInvertedIndex().getTabletSizeByBackendId(beIds.get(i)); if (tabletsNum < minBeTabletsNum) { minBeTabletsNum = tabletsNum; minIndex = i;