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


##########
fe/fe-core/src/main/java/org/apache/doris/cloud/backup/CloudRestoreJob.java:
##########
@@ -459,6 +491,13 @@ private void handleOlapTableMeta(MetaSeriviceOperation 
operation, OlapTable olap
                 partitions.forEach(partition -> {
                     visibleVersions.add(partition.getCachedVisibleVersion());
                     partitionIds.add(partition.getId());
+                    if (partition instanceof CloudPartition) {
+                        ((CloudPartition) 
partition).setCachedVisibleVersion(partition.getVisibleVersion(),
+                                System.currentTimeMillis());
+                        LOG.info("set cloud partition: {}, version: {}, 
versionTime: {}",
+                                partition.getId(), 
partition.getCachedVisibleVersion(),
+                                partition.getVisibleVersionTime());

Review Comment:
   In PREPARE, `visibleVersions` is populated from 
`partition.getCachedVisibleVersion()` before the new CloudPartition cache is 
refreshed. For CloudPartition the initial cached version is typically `-1`, so 
this can send invalid versions to `preparePartitions(...)`. Refresh/fetch the 
correct version first (e.g., call `partition.getVisibleVersion()` for 
CloudPartition or move the cache update ahead of `visibleVersions.add(...)`) 
and then add that value to `visibleVersions`.
   ```suggestion
                       partitionIds.add(partition.getId());
                       if (partition instanceof CloudPartition) {
                           long visibleVersion = partition.getVisibleVersion();
                           ((CloudPartition) 
partition).setCachedVisibleVersion(visibleVersion,
                                   System.currentTimeMillis());
                           visibleVersions.add(visibleVersion);
                           LOG.info("set cloud partition: {}, version: {}, 
versionTime: {}",
                                   partition.getId(), 
partition.getCachedVisibleVersion(),
                                   partition.getVisibleVersionTime());
                       } else {
                           
visibleVersions.add(partition.getCachedVisibleVersion());
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/backup/CloudRestoreJob.java:
##########
@@ -157,6 +159,36 @@ public synchronized void run() {
         }
     }
 
+    @Override
+    protected void updateOlapTablesVersion(Database db, boolean isReplay) {
+        super.updateOlapTablesVersion(db, isReplay);
+        if (isReplay) {
+            return;
+        }
+        for (String tableName : jobInfo.backupOlapTableObjects.keySet()) {
+            Table tbl = 
db.getTableNullable(jobInfo.getAliasByOriginNameIfSet(tableName));
+            if (tbl == null || tbl.getType() != TableType.OLAP) {
+                continue;
+            }
+            OlapTable olapTable = (OlapTable) tbl;
+
+            // sync version
+            Map<CloudPartition, Pair<Long, Long>> partitionVersionMap = new 
HashMap<>(olapTable.getPartitions().size());
+            for (Partition partition : olapTable.getPartitions()) {
+                CloudPartition cloudPartition = (CloudPartition) partition;
+                long version = cloudPartition.getCachedVisibleVersion();
+                partitionVersionMap.put(cloudPartition, Pair.of(version, 
partition.getVisibleVersionTime()));
+            }
+            List<Pair<OlapTable, Long>> tableVersionMap = Lists.newArrayList(
+                    Pair.of(olapTable, olapTable.getCachedTableVersion()));
+            ((CloudEnv) env).getCloudFEVersionSynchronizer()
+                    .pushVersionAsync(dbId, tableVersionMap, 
partitionVersionMap);

Review Comment:
   `pushVersionAsync` is fed from `getCachedTableVersion()` / 
`getCachedVisibleVersion()` without validating that those caches have been 
initialized. In cloud mode these defaults are `-1`; pushing `-1` will cause 
other FEs to cache an invalid version and potentially stop fetching real 
versions (since `setCachedTableVersion(-1)` updates the cache timestamp). 
Consider skipping entries with non-positive versions or forcing a fetch (e.g., 
`olapTable.getVisibleVersion()` / `partition.getVisibleVersion()`) before 
pushing.
   ```suggestion
                   if (version <= 0) {
                       version = partition.getVisibleVersion();
                   }
                   if (version > 0) {
                       partitionVersionMap.put(cloudPartition, Pair.of(version, 
partition.getVisibleVersionTime()));
                   }
               }
               long tableVersion = olapTable.getCachedTableVersion();
               if (tableVersion <= 0) {
                   tableVersion = olapTable.getVisibleVersion();
               }
               List<Pair<OlapTable, Long>> tableVersionMap = 
Lists.newArrayList();
               if (tableVersion > 0) {
                   tableVersionMap.add(Pair.of(olapTable, tableVersion));
               }
               if (!tableVersionMap.isEmpty() || 
!partitionVersionMap.isEmpty()) {
                   ((CloudEnv) env).getCloudFEVersionSynchronizer()
                           .pushVersionAsync(dbId, tableVersionMap, 
partitionVersionMap);
               }
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/backup/CloudRestoreJob.java:
##########
@@ -157,6 +159,36 @@ public synchronized void run() {
         }
     }
 
+    @Override
+    protected void updateOlapTablesVersion(Database db, boolean isReplay) {
+        super.updateOlapTablesVersion(db, isReplay);
+        if (isReplay) {
+            return;
+        }
+        for (String tableName : jobInfo.backupOlapTableObjects.keySet()) {
+            Table tbl = 
db.getTableNullable(jobInfo.getAliasByOriginNameIfSet(tableName));
+            if (tbl == null || tbl.getType() != TableType.OLAP) {
+                continue;
+            }
+            OlapTable olapTable = (OlapTable) tbl;
+
+            // sync version
+            Map<CloudPartition, Pair<Long, Long>> partitionVersionMap = new 
HashMap<>(olapTable.getPartitions().size());
+            for (Partition partition : olapTable.getPartitions()) {
+                CloudPartition cloudPartition = (CloudPartition) partition;
+                long version = cloudPartition.getCachedVisibleVersion();
+                partitionVersionMap.put(cloudPartition, Pair.of(version, 
partition.getVisibleVersionTime()));
+            }
+            List<Pair<OlapTable, Long>> tableVersionMap = Lists.newArrayList(
+                    Pair.of(olapTable, olapTable.getCachedTableVersion()));
+            ((CloudEnv) env).getCloudFEVersionSynchronizer()
+                    .pushVersionAsync(dbId, tableVersionMap, 
partitionVersionMap);
+
+            // add active tablets to get stats
+            
CloudTabletStatMgr.getInstance().addActiveTablets(olapTable.getAllTabletIds());
+        }

Review Comment:
   New behavior in `updateOlapTablesVersion` (version push + 
`addActiveTablets`) isn’t covered by existing `CloudRestoreJobTest`. Please add 
a unit test asserting the version synchronizer is called with the expected 
table/partition versions and that `CloudTabletStatMgr.addActiveTablets(...)` is 
invoked (can be done with mocks/spies on `cloudEnv`/stat mgr).



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/backup/CloudRestoreJob.java:
##########
@@ -157,6 +159,36 @@ public synchronized void run() {
         }
     }
 
+    @Override
+    protected void updateOlapTablesVersion(Database db, boolean isReplay) {
+        super.updateOlapTablesVersion(db, isReplay);
+        if (isReplay) {
+            return;
+        }
+        for (String tableName : jobInfo.backupOlapTableObjects.keySet()) {
+            Table tbl = 
db.getTableNullable(jobInfo.getAliasByOriginNameIfSet(tableName));
+            if (tbl == null || tbl.getType() != TableType.OLAP) {
+                continue;
+            }
+            OlapTable olapTable = (OlapTable) tbl;
+
+            // sync version
+            Map<CloudPartition, Pair<Long, Long>> partitionVersionMap = new 
HashMap<>(olapTable.getPartitions().size());
+            for (Partition partition : olapTable.getPartitions()) {

Review Comment:
   This loop unconditionally casts `Partition` to `CloudPartition`. In the same 
file you guard with `partition instanceof CloudPartition` (PREPARE path), which 
suggests non-cloud partitions are possible here as well; this cast can then 
throw `ClassCastException` and fail the restore. Filter/guard with `instanceof` 
(and decide how to handle non-cloud partitions) before adding to 
`partitionVersionMap`.
   ```suggestion
               for (Partition partition : olapTable.getPartitions()) {
                   if (!(partition instanceof CloudPartition)) {
                       continue;
                   }
   ```



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