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

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

                Author: ASF GitHub Bot
            Created on: 08/Mar/22 04:38
            Start Date: 08/Mar/22 04:38
    Worklog Time Spent: 10m 
      Work Description: youngoli commented on a change in pull request #16980:
URL: https://github.com/apache/beam/pull/16980#discussion_r821314562



##########
File path: sdks/go/pkg/beam/core/runtime/exec/fn.go
##########
@@ -39,23 +40,47 @@ type MainInput struct {
        RTracker sdf.RTracker
 }
 
+type bundleFinalizationCallback struct {
+       callback   func() error
+       validUntil time.Time
+}
+
+// bundleFinalizer holds all the user defined callbacks to be run on bundle 
finalization.
+// Implements typex.BundleFinalization
+type bundleFinalizer struct {
+       callbacks         []bundleFinalizationCallback
+       lastValidCallback time.Time // Used to track when we can safely gc the 
bundleFinalizer
+}
+
+// RegisterCallback is used to register callbacks during DoFn execution.
+func (bf *bundleFinalizer) RegisterCallback(t time.Duration, cb func() error) {
+       callback := bundleFinalizationCallback{
+               callback:   cb,
+               validUntil: time.Now().Add(t),
+       }
+       bf.callbacks = append(bf.callbacks, callback)
+       if bf.lastValidCallback.Before(callback.validUntil) {
+               bf.lastValidCallback = callback.validUntil
+       }
+}
+
 // Invoke invokes the fn with the given values. The extra values must match 
the non-main
 // side input and emitters. It returns the direct output, if any.
-func Invoke(ctx context.Context, pn typex.PaneInfo, ws []typex.Window, ts 
typex.EventTime, fn *funcx.Fn, opt *MainInput, extra ...interface{}) 
(*FullValue, error) {
+func Invoke(ctx context.Context, pn typex.PaneInfo, ws []typex.Window, ts 
typex.EventTime, fn *funcx.Fn, opt *MainInput, bf *bundleFinalizer, extra 
...interface{}) (*FullValue, error) {

Review comment:
       I'm in agreement that this is further from being a MainInput than 
RTracker was. In that case, the intention wasn't just that RTracker modified 
how the input is accessed, but also that it is the interface for accessing the 
restriction, which is considered to _be part of_ the input elements. The same 
way that attaching a key to a value turns them into a single MainInput.
   
   Like for a practical example, say we have an SDF that takes filename strings 
as elements and byte ranges as the restriction. If we had inputs "foo.txt" [0, 
10] and "foo.txt" [10, 20], those are considered separate input elements 
despite the string portion being the same because they represent different byte 
ranges due to the restriction. That's why I considered the RTracker (or more 
specifically, the restriction itself) to be part of the MainInput.




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


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

    Worklog Id:     (was: 737950)
    Time Spent: 5.5h  (was: 5h 20m)

> Enable Bundle Finalization in Go SDK
> ------------------------------------
>
>                 Key: BEAM-10976
>                 URL: https://issues.apache.org/jira/browse/BEAM-10976
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-go
>            Reporter: Robert Burke
>            Assignee: Danny McCormick
>            Priority: P3
>          Time Spent: 5.5h
>  Remaining Estimate: 0h
>
> Eg. to support acking pubsub/kafka messages as processed after the results 
> have been properly committed by the runner.
> Note, that due to BEAM-10959 that when implementing this, an instruction must 
> remain "active" until it's finalization occurs as well. Specifically, we 
> should probably keep another map around for "to be finalized" process bundle 
> instructions so we can return the appropriate "empty" response and not 
> accidently evict them from the nearly equivalent inactive state until after 
> finalization.
> [https://s.apache.org/beam-finalizing-bundles]
>  
> (To be updated once [https://github.com/apache/beam/pull/13160] is merged and 
> the programming guide updated with SDF content.)
> See also Java and Python approaches
> https://beam.apache.org/documentation/programming-guide/#bundle-finalization



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to