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


##########
fe/fe-core/src/main/java/org/apache/doris/common/profile/Profile.java:
##########
@@ -599,6 +599,44 @@ public boolean profileHasBeenStored() {
         return !Strings.isNullOrEmpty(profileStoragePath);
     }
 
+    public String getProfileCompletionState() {
+        if (profileHasBeenStored()) {
+            String storedState = 
summaryProfile.getSummary().getInfoString(SummaryProfile.PROFILE_COMPLETION_STATE);
+            if (!Strings.isNullOrEmpty(storedState)) {
+                return storedState;
+            }
+            return SummaryProfile.PROFILE_COMPLETION_STATE_UNKNOWN;
+        }
+
+        if (!isQueryFinished) {
+            return SummaryProfile.PROFILE_COMPLETION_STATE_RUNNING;
+        }
+
+        for (ExecutionProfile executionProfile : executionProfiles) {
+            if (!executionProfile.isCompleted()) {
+                return SummaryProfile.PROFILE_COMPLETION_STATE_COLLECTING;
+            }
+        }
+        return SummaryProfile.PROFILE_COMPLETION_STATE_COMPLETE;
+    }
+
+    private String getProfileCompletionStateForStorage() {
+        if (!isQueryFinished) {
+            return SummaryProfile.PROFILE_COMPLETION_STATE_RUNNING;
+        }
+
+        for (ExecutionProfile executionProfile : executionProfiles) {
+            if (!executionProfile.isCompleted()) {
+                return SummaryProfile.PROFILE_COMPLETION_STATE_INCOMPLETE;
+            }
+        }
+        return SummaryProfile.PROFILE_COMPLETION_STATE_COMPLETE;
+    }

Review Comment:
   `getProfileCompletionState()` / `getProfileCompletionStateForStorage()` 
iterate `executionProfiles` using the enhanced-for iterator. 
`executionProfiles` is a plain `ArrayList` and can be appended to concurrently 
(e.g. load tasks calling `addExecutionProfile()` while the profile list 
endpoint is being served), which can throw `ConcurrentModificationException` 
and break `/rest/v1/query_profile` once the new "Profile Completion State" 
column is requested. Use an index-based loop (or a snapshot copy) to avoid 
fail-fast iteration here.



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