This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new 0f2fb4c8974 branch-4.1: [improvement](catalog) narrow 
MaterializedIndex addTablet sync scope #64478 (#64859)
0f2fb4c8974 is described below

commit 0f2fb4c897400199e019149dec775227d91a9768
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Jun 29 11:44:35 2026 +0800

    branch-4.1: [improvement](catalog) narrow MaterializedIndex addTablet sync 
scope #64478 (#64859)
    
    Cherry-picked from #64478
    
    Co-authored-by: yaoxiao <[email protected]>
---
 .../apache/doris/catalog/MaterializedIndex.java    | 29 ++++++++--------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
index 81d9e1f7dd0..82520e93cc8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.java
@@ -126,37 +126,28 @@ public class MaterializedIndex extends MetaObject 
implements GsonPostProcessable
         idToTablets = new HashMap<>();
     }
 
-    public synchronized void addTablet(Tablet tablet, TabletMeta tabletMeta) {
+    public void addTablet(Tablet tablet, TabletMeta tabletMeta) {
         addTablet(tablet, tabletMeta, false);
     }
 
-    // Writers are synchronized on this index to prevent concurrent 
lost-update:
-    // some callers (e.g. InternalCatalog.createTablets) do NOT hold the 
OlapTable
-    // write lock when adding tablets.
-    // Copy-on-write keeps readers CME-safe without locking; for bulk creation 
use
-    // appendTablets(...) so the per-index tablets list is copied once per 
batch
-    // instead of once per tablet.
-    public synchronized void addTablet(Tablet tablet, TabletMeta tabletMeta, 
boolean isRestore) {
+    // For bulk creation, prefer appendTablets() so the per-index list is 
copied
+    // once per batch instead of once per tablet.
+    public void addTablet(Tablet tablet, TabletMeta tabletMeta, boolean 
isRestore) {
         appendTabletsInternal(Collections.singletonList(tablet));
         if (!isRestore) {
             Env.getCurrentInvertedIndex().addTablet(tablet.getId(), 
tabletMeta);
         }
     }
 
-    // Bulk-publish: append the given tablets to this index's tablets list in a
-    // single copy-on-write (O(existing + batch) instead of O(n^2) over n
-    // single-tablet adds inside a synchronized block).
-    //
-    // Does NOT touch TabletInvertedIndex. Bulk-creation callers register 
tablets
-    // in TabletInvertedIndex eagerly inside their per-tablet loop because
-    // Tablet.addReplica(...) (non-restore) requires the tablet to already be
-    // present in the inverted index; only the per-index list copy is expensive
-    // enough to be worth batching.
-    public synchronized void appendTablets(Collection<Tablet> newTablets) {
+    // Bulk-publish path. Does NOT register tablets in TabletInvertedIndex —
+    // callers do that per tablet (needed before Tablet.addReplica in 
non-restore paths).
+    public void appendTablets(Collection<Tablet> newTablets) {
         appendTabletsInternal(newTablets);
     }
 
-    private void appendTabletsInternal(Collection<Tablet> newTablets) {
+    // Synchronized to prevent concurrent lost-update on the per-index 
list/map snapshots;
+    // some callers (e.g. InternalCatalog.createTablets) do not hold the 
OlapTable write lock.
+    private synchronized void appendTabletsInternal(Collection<Tablet> 
newTablets) {
         if (newTablets.isEmpty()) {
             return;
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to