-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Feature] support event scheduler (part 1) #54260
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba1ebda
[Feature] support phased scheduler
stdpain cc8f32d
save pipeline driver
stdpain 142ea2a
add case
stdpain 59315fa
fix unstable UT
stdpain 7791a7d
tmp save
stdpain 8d6abcf
add more case
stdpain 19f5211
save
stdpain 8312196
fix ut
stdpain 2fb8a1e
add case
stdpain 2428618
fix comments
stdpain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// https://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 | ||
|
||
#define TRACE_SCHEDULE_LOG VLOG(10) | ||
|
||
#define SCHEDULE_CHECK CHECK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// https://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. | ||
|
||
#include "exec/pipeline/schedule/event_scheduler.h" | ||
|
||
#include "exec/pipeline/pipeline_driver.h" | ||
#include "exec/pipeline/pipeline_driver_queue.h" | ||
#include "exec/pipeline/pipeline_fwd.h" | ||
#include "exec/pipeline/schedule/common.h" | ||
#include "exec/pipeline/schedule/utils.h" | ||
|
||
namespace starrocks::pipeline { | ||
|
||
void EventScheduler::add_blocked_driver(const DriverRawPtr driver) { | ||
// Capture query-context is needed before calling reschedule to avoid UAF | ||
auto query_ctx = driver->fragment_ctx()->runtime_state()->query_ctx()->shared_from_this(); | ||
SCHEDULE_CHECK(!driver->is_in_block_queue()); | ||
driver->set_in_block_queue(true); | ||
TRACE_SCHEDULE_LOG << "TRACE add to block queue:" << driver << "," << driver->to_readable_string(); | ||
auto token = driver->acquire_schedule_token(); | ||
// The driver is ready put to block queue. but is_in_block_queue is false, but the driver is active. | ||
// set this flag to make the block queue should check the driver is active | ||
if (!token.acquired() || driver->need_check_reschedule()) { | ||
driver->observer()->cancel_update(); | ||
} | ||
} | ||
|
||
// For a single driver try_schedule has no concurrency. | ||
void EventScheduler::try_schedule(const DriverRawPtr driver) { | ||
SCHEDULE_CHECK(driver->is_in_block_queue()); | ||
bool add_to_ready_queue = false; | ||
RACE_DETECT(driver->schedule); | ||
|
||
// The logic in the pipeline poller is basically the same. | ||
auto fragment_ctx = driver->fragment_ctx(); | ||
if (fragment_ctx->is_canceled()) { | ||
add_to_ready_queue = on_cancel(driver); | ||
} else if (driver->need_report_exec_state()) { | ||
add_to_ready_queue = true; | ||
} else if (driver->pending_finish()) { | ||
if (!driver->is_still_pending_finish()) { | ||
driver->set_driver_state(fragment_ctx->is_canceled() ? DriverState::CANCELED : DriverState::FINISH); | ||
add_to_ready_queue = true; | ||
} | ||
} else if (driver->is_finished()) { | ||
add_to_ready_queue = true; | ||
} else { | ||
auto status_or_is_not_blocked = driver->is_not_blocked(); | ||
if (!status_or_is_not_blocked.ok()) { | ||
fragment_ctx->cancel(status_or_is_not_blocked.status()); | ||
add_to_ready_queue = on_cancel(driver); | ||
} else if (status_or_is_not_blocked.value()) { | ||
driver->set_driver_state(DriverState::READY); | ||
add_to_ready_queue = true; | ||
} | ||
} | ||
|
||
if (add_to_ready_queue) { | ||
TRACE_SCHEDULE_LOG << "TRACE schedule driver:" << driver << " to ready queue"; | ||
driver->set_need_check_reschedule(false); | ||
driver->set_in_block_queue(false); | ||
stdpain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_driver_queue->put_back(driver); | ||
} | ||
} | ||
|
||
bool EventScheduler::on_cancel(DriverRawPtr driver) { | ||
driver->cancel_operators(driver->fragment_ctx()->runtime_state()); | ||
if (driver->is_still_pending_finish()) { | ||
driver->set_driver_state(DriverState::PENDING_FINISH); | ||
return false; | ||
} else { | ||
driver->set_driver_state(DriverState::CANCELED); | ||
return true; | ||
} | ||
} | ||
} // namespace starrocks::pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// https://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 "exec/pipeline/pipeline_fwd.h" | ||
#include "gutil/macros.h" | ||
|
||
namespace starrocks::pipeline { | ||
class DriverQueue; | ||
class EventScheduler { | ||
public: | ||
EventScheduler() = default; | ||
DISALLOW_COPY(EventScheduler); | ||
|
||
void add_blocked_driver(const DriverRawPtr driver); | ||
|
||
void try_schedule(const DriverRawPtr driver); | ||
|
||
bool on_cancel(DriverRawPtr driver); | ||
|
||
void attach_queue(DriverQueue* queue) { | ||
if (_driver_queue == nullptr) { | ||
_driver_queue = queue; | ||
} | ||
} | ||
|
||
private: | ||
DriverQueue* _driver_queue = nullptr; | ||
}; | ||
} // namespace starrocks::pipeline |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: shall it be
event_scheduler_enabled
?enable_event_scheduler
reads like to perform an action, turn on the event_scheduler, not query the on/off status.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.
our session variables style is enable_xxx_feature