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]


Reply via email to