-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Implement idle source handling for WatermarkStatus #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gluten-0530
Are you sure you want to change the base?
Changes from all commits
33c9f34
2da2e8f
68e45f5
69e7c09
154a48e
4b7d8a6
2ae6d4c
0fae470
6cf098c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <atomic> | ||
| #include <cstdint> | ||
| #include <functional> | ||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| #include "velox/experimental/stateful/ProcessingTimeScheduler.h" | ||
|
|
||
| namespace facebook::velox::stateful { | ||
|
|
||
| // Shared one-shot idle timer helper for watermark-generating operators. It | ||
| // owns the background scheduler, prevents duplicate timer registrations, skips | ||
| // scheduling after the owner is already idle, and clamps past idle deadlines to | ||
| // the current time. | ||
| class IdleTimerManager { | ||
| public: | ||
| using TimerCallback = std::function<void(int64_t)>; | ||
|
|
||
| explicit IdleTimerManager( | ||
| std::unique_ptr<ProcessingTimeScheduler> scheduler = nullptr) | ||
| : scheduler_(std::move(scheduler)) {} | ||
|
|
||
| ~IdleTimerManager() { | ||
| shutdown(); | ||
| } | ||
|
|
||
| void schedule( | ||
| int64_t now, | ||
| bool enabled, | ||
| bool idle, | ||
| int64_t idleDeadline, | ||
| TimerCallback callback) { | ||
| if (!enabled || idle || timerPending_.exchange(true)) { | ||
| return; | ||
| } | ||
| if (!scheduler_) { | ||
| scheduler_ = std::make_unique<SystemProcessingTimeScheduler>(); | ||
| } | ||
| const int64_t fireAt = idleDeadline < now ? now : idleDeadline; | ||
| scheduler_->registerTimer( | ||
| fireAt, | ||
| ProcessingTimerTask( | ||
| fireAt, | ||
| [this, callback = std::move(callback)](int64_t timestamp) mutable { | ||
| timerPending_ = false; | ||
| callback(timestamp); | ||
| })); | ||
| } | ||
|
|
||
| void shutdown() { | ||
| if (scheduler_) { | ||
| scheduler_->close(); | ||
| scheduler_.reset(); | ||
| } | ||
| timerPending_ = false; | ||
| } | ||
|
|
||
| private: | ||
| std::unique_ptr<ProcessingTimeScheduler> scheduler_; | ||
| std::atomic<bool> timerPending_{false}; | ||
| }; | ||
|
|
||
| } // namespace facebook::velox::stateful |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Blocker 2] Timer scheduled from int64_t fireAt = now + idleTimeout_;
Suggestion: expose last-record (or remaining) from fireAt = lastRecordWallTime + idleTimeout; // clamp to now if already due[Blocker 3] Keep scheduling idle timers after already IDLE
Suggestion: skip [Suggestion] Calling ~WatermarkAssigner() {
WatermarkAssigner::close();
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Blocker 1] Blocked path drops already-emitted
WatermarkStatusThe empty-output path below correctly re-checks
pendings_and falls through topopOutput(). The blocked path does not.Typical failure: timer wakes mailbox →
next()→ source still blocked → IDLE is computed this round but returned asnullptr.Suggestion:
Please treat this as a merge blocker and add a regression test that covers blocked + idle emission in the same
next()call.