Anurag-S1ngh commented on code in PR #41358:
URL: https://github.com/apache/beam/pull/41358#discussion_r4722282440


##########
sdks/python/apache_beam/runners/worker/statesampler.py:
##########
@@ -156,7 +156,9 @@ def scoped_state(
         step_name=name_context.metrics_name(),
         io_target=io_target)
     if counter_name in self._states_by_name:
-      return self._states_by_name[counter_name]
+      state = self._states_by_name[counter_name]
+      state.set_metrics_container(metrics_container)

Review Comment:
   The runner owns the container lifetime, so I moved the fix there.
   
   `TransformExecutor.call` created a new `MetricsContainer` for every bundle, 
but the sampler caches one `ScopedState` per step per worker thread and keeps 
using it. The runner now keeps one container per step per worker thread, 
matching the sampler's lifetime, and resets it for each bundle, so 
`commit_physical` still receives only that bundle's updates. `ScopedState` is 
untouched and `set_metrics_container` is gone from both samplers.
   
   Same test as before. It fails on master with `{'seen': 1}` and passes with 
the runner change on both the Cython and pure-Python sampler. 
`apache_beam/runners/direct/` and `statesampler_test.py` pass.
   
   I did not keep a single container per transform because 
`_ParallelEvaluationState` can run bundles of the same step on several threads, 
which would mix their counters.



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