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


##########
fe/fe-core/src/main/java/org/apache/doris/cloud/datasource/CloudInternalCatalog.java:
##########
@@ -879,7 +878,11 @@ public void 
erasePartitionDropBackendReplicas(List<Partition> partitions) {
             for (MaterializedIndex index : 
partition.getMaterializedIndices(IndexExtState.ALL)) {
                 indexIds.add(index.getId());
                 if (tableId == -1) {
-                    tableId = ((CloudTablet) 
index.getTablets().get(0)).getCloudReplica().getTableId();
+                    long firstTabletId = index.getTablets().get(0).getId();
+                    TabletMeta meta = 
Env.getCurrentInvertedIndex().getTabletMeta(firstTabletId);
+                    if (meta != null) {
+                        tableId = meta.getTableId();
+                    }
                 }

Review Comment:
   `erasePartitionDropBackendReplicas()` now derives `tableId` via 
`Env.getCurrentInvertedIndex().getTabletMeta(firstTabletId)`, but 
`Env.onErasePartition()` deletes all tablets from the inverted index *before* 
calling this method. As a result `meta` will commonly be null and `tableId` 
will remain `-1`, leading to `dropCloudPartition()` sending an invalid tableId 
to MetaService.
   
   Instead of relying on TabletMeta here, use a source that is still available 
after inverted-index cleanup (e.g. `((CloudPartition) 
partitions.get(0)).getTableId()`), or capture the tableId before 
`deleteTablet()` is invoked.



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java:
##########
@@ -104,23 +102,38 @@ public CloudReplica() {
 
     public CloudReplica(ReplicaContext context) {
         this(context.replicaId, context.backendId, context.state, 
context.version,
-                context.schemaHash, context.dbId, context.tableId, 
context.partitionId,
-                context.indexId,
+                context.schemaHash, context.dbId, context.indexId,
                 context.originReplica != null ? ((CloudReplica) 
context.originReplica).getIdx() : -1);
     }
 
     public CloudReplica(long replicaId, Long backendId, ReplicaState state, 
long version, int schemaHash,
-            long dbId, long tableId, long partitionId, long indexId, long idx) 
{
+            long dbId, long indexId, long idx) {
         super(replicaId, -1, state, version, schemaHash);
         this.dbId = dbId;
-        this.tableId = tableId;
-        this.partitionId = partitionId;
         this.indexId = indexId;
         this.idx = idx;
     }
 
+    public void setTabletId(long tabletId) {
+        this.tabletId = tabletId;
+    }
+
+    private TabletMeta getTabletMeta() {

Review Comment:
   `tabletId` is written after construction via `setTabletId()` and then read 
from multiple methods to look up `TabletMeta`. Because it is not `volatile` 
(and there is no other guaranteed happens-before for readers that may access a 
replica through the tablet/table structures), there is a risk that other 
threads observe the default `-1` value or a stale value, causing incorrect meta 
lookups (and potentially NPEs downstream when colocate logic expects a valid 
tableId).
   
   Make `tabletId` `volatile` (or otherwise ensure safe publication), and 
consider setting it as early as possible when the replica is attached to a 
tablet.
   ```suggestion
       public synchronized void setTabletId(long tabletId) {
           this.tabletId = tabletId;
       }
   
       private synchronized TabletMeta getTabletMeta() {
   ```



-- 
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