github-actions[bot] commented on code in PR #41541:
URL: https://github.com/apache/beam/pull/41541#discussion_r4647542133


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/DataflowOperationContext.java:
##########
@@ -106,6 +109,29 @@ public class DataflowOperationContext implements 
OperationContext {
     processTimersState = 
newExecutionState(ExecutionStateTracker.PROCESS_TIMERS_STATE_NAME);
     finishState = newExecutionState(ExecutionStateTracker.FINISH_STATE_NAME);
     abortState = newExecutionState(ExecutionStateTracker.ABORT_STATE_NAME);
+
+    ProcessScope resolvedScope = null;
+    if (executionStateTracker.getClass() == 
DataflowExecutionStateTracker.class) {
+      DataflowExecutionStateTracker dfTracker =
+          (DataflowExecutionStateTracker) executionStateTracker;
+      if (dfTracker.supportsFastProcessElementTransition()) {
+        if (dfTracker.isStreaming()
+            && processElementState.isProcessElementState
+            && processElementState instanceof DataflowExecutionState) {
+          NameContext stepName = ((DataflowExecutionState) 
processElementState).getStepName();
+          String userName = stepName != null ? stepName.userName() : null;
+          if (userName != null) {
+            resolvedScope =
+                new StreamingProcessScope(dfTracker, 
dfTracker.getOrCreateStepStats(userName));
+          }
+        } else {

Review Comment:
   **🟡 Medium**: When `dfTracker.isStreaming()` is `true` and 
`processElementState` is a `DataflowExecutionState`, if `userName` is `null`, 
`resolvedScope` remains `null` instead of falling back to `new 
DirectProcessScope()`. More importantly, if an outer step (with a non-null 
`userName`) calls into a nested step whose `userName` is `null`, 
`enterProcess()` falls back to `dfTracker.enterState(processElementState)`. 
While `enterState` does not overwrite `localActiveStepStats` when `userName == 
null`, closing the returned `Closeable` will unconditionally record and clear 
the outer step's `localActiveStepStats` upon exiting the inner `userName == 
null` step. Using `DirectProcessScope` when `userName == null` (or capturing 
whether `setActiveMessage` was actually invoked in `enterState`) avoids 
prematurely ending the outer step's active message tracking and keeps the 
zero-allocation fast path for unnamed steps.
   
   ```suggestion
             } else {
               resolvedScope = new DirectProcessScope();
             }
   ```



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

Reply via email to