I understand that watermarks are concurrently advanced, and that they are estimates and not precise. but I’m not sure this is relevant in this case. In this repro code we are in processElement() and the watermark HAS advanced but the timer has not been called even though we asked the runtime to do that. In this case we are in a per-key stateful operating mode and our timer should not be shared with any other runners (is that correct?) so it seems to me that we should be able to operate in a manner that is locally consistent from the point of view of the DoFn we are writing. That is to say, _before_ we enter processElement we check any local timers first. I would argue that this would be far more sensible from the authors perspective.
From: Reuven Lax <[email protected]> Reply-To: "[email protected]" <[email protected]> Date: Thursday, August 6, 2020 at 11:57 PM To: dev <[email protected]> Subject: Re: Stateful Pardo Question Notice: This email is from an external sender. On Tue, Aug 4, 2020 at 1:08 PM [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>> wrote: So, after some additional digging, it appears that Beam does not consistently check for timer expiry before calling process. The result is that it may be the case that the watermark has moved beyond your timer expiry, and if youre counting on the timer callback happening at the time you set it for, that simply may NOT have happened when you are in DoFn.process(). You can “fix” the behavior by simply checking the watermark manually in process() and doing what you would normally do for timestamp exipry before proceeding. See my latest updated code reproducing the issue and showing the fix at https://github.com/randomsamples/pardo_repro. I would argue that users of this API will naturally expect that timer callback semantics will guarantee that when they are in process(), if the current watermark is past a timers expiry that the timer callback in question will have been called. Is there any reason why this isn’t happening? Am I misunderstanding something? Timers do not expire synchronously with the watermark advancing. So if you have a timer set for 12pm and the watermark advances past 12pm, that timer is now eligible to fire, but might not fire immediately. Some other elements may process before that timer fires. There are multiple reasons for this, but one is that Beam does not guarantee that watermark advancement is synchronous with element processing. The watermark might advance suddenly while in the middle processing an element, or at any other time. This makes it impossible (or at least, exceedingly difficult) to really provide the guarantee you expected. Reuven From: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Date: Monday, August 3, 2020 at 10:51 AM To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Subject: Re: Stateful Pardo Question Notice: This email is from an external sender. Yeah, unless I am misunderstanding something. The output from my repro code shows event timestamp and the context timestamp every time we process an event. Receiving event at: 2000-01-01T00:00:00.000Z Resetting timer to : 2000-01-01T00:15:00.000Z Receiving event at: 2000-01-01T00:05:00.000Z Resetting timer to : 2000-01-01T00:20:00.000Z <-- Shouldn’t the timer have fired before we processed the next event? Receiving event at: 2000-01-01T00:40:00.000Z Why didnt the timer fire? Resetting timer to : 2000-01-01T00:55:00.000Z Receiving event at: 2000-01-01T00:45:00.000Z Resetting timer to : 2000-01-01T01:00:00.000Z Receiving event at: 2000-01-01T00:50:00.000Z Resetting timer to : 2000-01-01T01:05:00.000Z Timer firing at: 2000-01-01T01:05:00.000Z From: Reuven Lax <[email protected]<mailto:[email protected]>> Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Date: Monday, August 3, 2020 at 10:02 AM To: dev <[email protected]<mailto:[email protected]>> Subject: Re: Stateful Pardo Question Notice: This email is from an external sender. Are you sure that there is a 15 minute gap in your data? On Mon, Aug 3, 2020 at 6:20 AM [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>> wrote: I am confused about the behavior of timers on a simple stateful pardo. I have put together a little repro here: https://github.com/randomsamples/pardo_repro I basically want to build something like a session window, accumulating events until quiescence of the stream for a given key and gap time, then output results. But it appears that the timer is not firing when the watermark is passed it expiration time, so the event stream is not being split as I would have expected. Would love some help getting this work, the behavior is for a project I’m working on.
