[ 
https://issues.apache.org/jira/browse/BEAM-6233?focusedWorklogId=191417&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-191417
 ]

ASF GitHub Bot logged work on BEAM-6233:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Jan/19 04:59
            Start Date: 29/Jan/19 04:59
    Worklog Time Spent: 10m 
      Work Description: kennknowles commented on pull request #7330: 
[BEAM-6233]: Add initial user timer support in Dataflow for batch pipelines
URL: https://github.com/apache/beam/pull/7330#discussion_r251691288
 
 

 ##########
 File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/fn/control/ProcessRemoteBundleOperation.java
 ##########
 @@ -100,6 +218,80 @@ public void finish() throws Exception {
       } catch (Exception e) {
         throw new RuntimeException("Failed to finish remote bundle", e);
       }
+
+      try {
+        // In Batch, the input watermark advances from -inf to +inf once all 
elements are processed.
+        // For timers, this means we only fire them at the end of the bundle.
+        fireTimers();
+      } catch (Exception e) {
+        throw new RuntimeException("Failed to finish remote bundle", e);
+      }
+    }
+  }
+
+  // Recursively fires all scheduled timers from the SDK Harness.
+  private void fireTimers() throws Exception {
+    DataflowExecutionContext.DataflowStepContext stepContext =
+        executionContext.getStepContext((DataflowOperationContext) 
this.context).namespacedToUser();
+
+    TimerInternals.TimerData timerData = 
stepContext.getNextFiredTimer(GlobalWindow.Coder.INSTANCE);
+    while (timerData != null) {
+      StateNamespaces.WindowNamespace windowNamespace =
+          (StateNamespaces.WindowNamespace) timerData.getNamespace();
+      BoundedWindow window = windowNamespace.getWindow();
+
+      WindowedValue<KV<Object, Timer>> timerValue =
+          WindowedValue.of(
+              KV.of(
+                  timerIdToKey.get(timerData.getTimerId()),
+                  Timer.of(timerData.getTimestamp(), 
timerIdToPayload.get(timerData.getTimerId()))),
+              timerData.getTimestamp(),
+              Collections.singleton(window),
+              PaneInfo.NO_FIRING);
+
+      String timerInputPCollection =
+          
timerIdToTimerSpecMap.get(timerData.getTimerId()).inputCollectionId();
+
+      // TODO(BEAM-6274): check this for performance considerations.
+      // Timers are allowed to A) fire other timers, and B) fire themselves. 
To implement this,
+      // we send the timer to the SDK Harness, wait for any elements, then 
check if any additional
+      // timers were fired.
+      RemoteBundle timerRemoteBundle =
+          stageBundleFactory.getBundle(receiverFactory, stateRequestHandler, 
progressHandler);
+      
timerRemoteBundle.getInputReceivers().get(timerInputPCollection).accept(timerValue);
+      timerRemoteBundle.close();
 
 Review comment:
   Is this blocking? I'm not super familiar with the portability framework at 
this point.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 191417)
    Time Spent: 3h 50m  (was: 3h 40m)

> Make bundle execution with ExecutableStage support timer/states
> ---------------------------------------------------------------
>
>                 Key: BEAM-6233
>                 URL: https://issues.apache.org/jira/browse/BEAM-6233
>             Project: Beam
>          Issue Type: Task
>          Components: runner-dataflow
>            Reporter: Boyuan Zhang
>            Assignee: Sam Rohde
>            Priority: Major
>          Time Spent: 3h 50m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to