Copilot commented on code in PR #59683:
URL: https://github.com/apache/doris/pull/59683#discussion_r2671915346


##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletInvertedIndex.java:
##########
@@ -0,0 +1,125 @@
+// 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.cloud.catalog;
+
+import org.apache.doris.catalog.Replica;
+import org.apache.doris.catalog.TabletInvertedIndex;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+
+public class CloudTabletInvertedIndex extends TabletInvertedIndex {
+    private static final Logger LOG = 
LogManager.getLogger(CloudTabletInvertedIndex.class);
+
+    // tablet id -> replica
+    // for cloud mode, no need to know the replica's backend
+    private Map<Long, Replica> replicaMetaTable = Maps.newHashMap();
+
+    public CloudTabletInvertedIndex() {
+        super();
+    }
+
+    @Override
+    public List<Replica> getReplicas(Long tabletId) {
+        long stamp = readLock();
+        try {
+            if (replicaMetaTable.containsKey(tabletId)) {
+                return Lists.newArrayList(replicaMetaTable.get(tabletId));
+            }
+            return Lists.newArrayList();
+        } finally {
+            readUnlock(stamp);
+        }
+    }
+
+    @Override
+    protected void innerDeleteTablet(long tabletId) {
+        replicaMetaTable.remove(tabletId);
+    }
+
+    @Override
+    public void addReplica(long tabletId, Replica replica) {
+        long stamp = writeLock();
+        try {
+            Preconditions.checkState(tabletMetaMap.containsKey(tabletId),
+                    "tablet " + tabletId + " not exists, replica " + 
replica.getId());
+            replicaMetaTable.put(tabletId, replica);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("add replica {} of tablet {}", replica.getId(), 
tabletId);
+            }
+        } finally {
+            writeUnlock(stamp);
+        }
+    }
+
+    @Override
+    public void deleteReplica(long tabletId, long backendId) {
+        long stamp = writeLock();
+        try {
+            Preconditions.checkState(tabletMetaMap.containsKey(tabletId), 
"tablet " + tabletId + " not exists");
+            if (replicaMetaTable.containsKey(tabletId)) {
+                Replica replica = replicaMetaTable.remove(tabletId);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("delete replica {} of tablet {}", 
replica.getId(), tabletId);
+                }
+            } else {
+                // this may happen when fe restart after tablet is empty(bug 
cause)
+                // add log instead of assertion to observe
+                LOG.error("tablet[{}] contains no replica in inverted index", 
tabletId);
+            }
+        } finally {
+            writeUnlock(stamp);
+        }
+    }
+

Review Comment:
   The CloudTabletInvertedIndex.getReplica method ignores the backendId 
parameter but doesn't document this behavior. In cloud mode, the backendId is 
not used since there's only one replica per tablet, but this should be 
documented to avoid confusion for callers expecting backend-specific replica 
retrieval.
   ```suggestion
   
       /**
        * Returns the replica for the given tablet in cloud mode.
        * <p>
        * In cloud deployments there is at most one replica per tablet and the 
backend
        * location is not tracked in this index. Therefore, the {@code 
backendId}
        * parameter is ignored and is only present to satisfy the {@link 
TabletInvertedIndex}
        * interface. Callers should not rely on {@code backendId} to select a 
specific
        * replica when using {@code CloudTabletInvertedIndex}.
        */
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletInvertedIndex.java:
##########
@@ -0,0 +1,125 @@
+// 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.cloud.catalog;
+
+import org.apache.doris.catalog.Replica;
+import org.apache.doris.catalog.TabletInvertedIndex;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+
+public class CloudTabletInvertedIndex extends TabletInvertedIndex {
+    private static final Logger LOG = 
LogManager.getLogger(CloudTabletInvertedIndex.class);
+
+    // tablet id -> replica
+    // for cloud mode, no need to know the replica's backend
+    private Map<Long, Replica> replicaMetaTable = Maps.newHashMap();
+
+    public CloudTabletInvertedIndex() {
+        super();
+    }
+
+    @Override
+    public List<Replica> getReplicas(Long tabletId) {
+        long stamp = readLock();
+        try {
+            if (replicaMetaTable.containsKey(tabletId)) {
+                return Lists.newArrayList(replicaMetaTable.get(tabletId));
+            }
+            return Lists.newArrayList();
+        } finally {
+            readUnlock(stamp);
+        }
+    }
+
+    @Override
+    protected void innerDeleteTablet(long tabletId) {
+        replicaMetaTable.remove(tabletId);
+    }
+
+    @Override
+    public void addReplica(long tabletId, Replica replica) {
+        long stamp = writeLock();
+        try {
+            Preconditions.checkState(tabletMetaMap.containsKey(tabletId),
+                    "tablet " + tabletId + " not exists, replica " + 
replica.getId());
+            replicaMetaTable.put(tabletId, replica);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("add replica {} of tablet {}", replica.getId(), 
tabletId);
+            }
+        } finally {
+            writeUnlock(stamp);
+        }
+    }
+
+    @Override
+    public void deleteReplica(long tabletId, long backendId) {

Review Comment:
   The CloudTabletInvertedIndex.deleteReplica method ignores the backendId 
parameter but doesn't document this behavior. In cloud mode, the backendId is 
not used, but callers may still pass a specific backendId expecting it to be 
used. Consider adding documentation or a parameter validation to make this 
behavior explicit.



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/LocalTabletInvertedIndex.java:
##########
@@ -0,0 +1,1039 @@
+// 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.catalog;
+
+import org.apache.doris.catalog.Replica.ReplicaState;
+import org.apache.doris.clone.PartitionRebalancer.TabletMove;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.Pair;
+import org.apache.doris.cooldown.CooldownConf;
+import org.apache.doris.master.PartitionInfoCollector.PartitionCollectInfo;
+import org.apache.doris.task.PublishVersionTask;
+import org.apache.doris.thrift.TPartitionVersionInfo;
+import org.apache.doris.thrift.TStorageMedium;
+import org.apache.doris.thrift.TTablet;
+import org.apache.doris.thrift.TTabletInfo;
+import org.apache.doris.thrift.TTabletMetaInfo;
+import org.apache.doris.transaction.GlobalTransactionMgrIface;
+import org.apache.doris.transaction.PartitionCommitInfo;
+import org.apache.doris.transaction.TableCommitInfo;
+import org.apache.doris.transaction.TransactionState;
+import org.apache.doris.transaction.TransactionStatus;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Ordering;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
+import com.google.common.collect.TreeMultimap;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class LocalTabletInvertedIndex extends TabletInvertedIndex {
+    private static final Logger LOG = 
LogManager.getLogger(LocalTabletInvertedIndex.class);
+
+    // tablet id -> (backend id -> replica)
+    // for cloud mode, no need to known the replica's backend, so use backend 
id = -1 in cloud mode.
+    private Table<Long, Long, Replica> replicaMetaTable = 
HashBasedTable.create();
+
+    // backing replica table, for visiting backend replicas faster.
+    // backend id -> (tablet id -> replica)
+    private Table<Long, Long, Replica> backingReplicaMetaTable = 
HashBasedTable.create();
+
+    // partition id -> partition info.
+    // notice partition info update every 
Config.partition_info_update_interval_secs seconds,
+    // so it may be stale.
+    // Notice only none-cloud use it for be reporting tablets. This map is 
empty in cloud mode.

Review Comment:
   The comment on line 80 says "Notice only none-cloud use it for be reporting 
tablets. This map is empty in cloud mode." This is incorrect context since this 
is LocalTabletInvertedIndex (non-cloud). The comment should be simplified to 
just describe that this map is used for BE reporting tablets and may be stale, 
without mentioning cloud mode.
   ```suggestion
       // This map is used for BE reporting tablets and may be stale.
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/LocalTabletInvertedIndex.java:
##########
@@ -0,0 +1,1039 @@
+// 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.catalog;
+
+import org.apache.doris.catalog.Replica.ReplicaState;
+import org.apache.doris.clone.PartitionRebalancer.TabletMove;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.Pair;
+import org.apache.doris.cooldown.CooldownConf;
+import org.apache.doris.master.PartitionInfoCollector.PartitionCollectInfo;
+import org.apache.doris.task.PublishVersionTask;
+import org.apache.doris.thrift.TPartitionVersionInfo;
+import org.apache.doris.thrift.TStorageMedium;
+import org.apache.doris.thrift.TTablet;
+import org.apache.doris.thrift.TTabletInfo;
+import org.apache.doris.thrift.TTabletMetaInfo;
+import org.apache.doris.transaction.GlobalTransactionMgrIface;
+import org.apache.doris.transaction.PartitionCommitInfo;
+import org.apache.doris.transaction.TableCommitInfo;
+import org.apache.doris.transaction.TransactionState;
+import org.apache.doris.transaction.TransactionStatus;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Ordering;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
+import com.google.common.collect.TreeMultimap;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class LocalTabletInvertedIndex extends TabletInvertedIndex {
+    private static final Logger LOG = 
LogManager.getLogger(LocalTabletInvertedIndex.class);
+
+    // tablet id -> (backend id -> replica)
+    // for cloud mode, no need to known the replica's backend, so use backend 
id = -1 in cloud mode.

Review Comment:
   The comment on line 70 mentions "for cloud mode" but this is now 
LocalTabletInvertedIndex which is specifically for non-cloud mode. This 
outdated comment should be removed as it's no longer applicable to this class.
   ```suggestion
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to