-
Notifications
You must be signed in to change notification settings - Fork 185
Better shutdown. #867
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
Merged
Merged
Better shutdown. #867
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f103986
waits more
ZanCorDX 38bcc3e
Update crates/rbuilder/src/live_builder/mod.rs
ZanCorDX 86329a1
removed sleep
ZanCorDX 845b32b
V3 wait handle
ZanCorDX 4211920
lint
ZanCorDX 92fb077
removed warning
ZanCorDX ffed962
comment, renames
ZanCorDX 72f789b
rename
ZanCorDX b4beb75
log text
ZanCorDX 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ use ::serde::{Deserialize, Serialize}; | |
| use clickhouse::Client; | ||
| use reth_tasks::TaskExecutor; | ||
| use tokio::sync::mpsc; | ||
| use tokio::task::JoinHandle; | ||
|
|
||
| use crate::clickhouse::{ | ||
| backup::{ | ||
|
|
@@ -59,6 +60,7 @@ impl From<Quantities> for clickhouse::inserter::Quantities { | |
| const BACKUP_INPUT_CHANNEL_BUFFER_SIZE: usize = 128; | ||
|
|
||
| /// Main func to spawn the clickhouse inserter and backup tasks. | ||
| /// Returns a JoinHandle that resolves when both tasks have completed. | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub fn spawn_clickhouse_inserter_and_backup< | ||
| DataType: ClickhouseIndexableData + Send + Sync + 'static, | ||
|
|
@@ -75,7 +77,8 @@ pub fn spawn_clickhouse_inserter_and_backup< | |
| send_timeout: Duration, | ||
| end_timeout: Duration, | ||
| tracing_target: &'static str, | ||
| ) where | ||
| ) -> JoinHandle<()> | ||
| where | ||
| for<'a> <DataType::ClickhouseRowType as clickhouse::Row>::Value<'a>: Sync, | ||
| { | ||
| let backup_table_name = RowType::TABLE_NAME.to_string(); | ||
|
|
@@ -93,6 +96,13 @@ pub fn spawn_clickhouse_inserter_and_backup< | |
| disk_backup_db, | ||
| ) | ||
| .with_memory_backup_config(MemoryBackupConfig::new(memory_max_size_bytes)); | ||
| inserter_runner.spawn(task_executor, backup_table_name.clone(), tracing_target); | ||
| backup.spawn(task_executor, backup_table_name, tracing_target); | ||
|
|
||
| let inserter_handle = | ||
| inserter_runner.spawn(task_executor, backup_table_name.clone(), tracing_target); | ||
| let backup_handle = backup.spawn(task_executor, backup_table_name, tracing_target); | ||
|
|
||
| // Spawn a wrapper task that waits for both to complete | ||
| tokio::spawn(async move { | ||
|
Contributor
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. Good pattern: Wrapping both handles in a single task that waits for both to complete is a clean solution. This ensures the returned |
||
| let _ = tokio::join!(inserter_handle, backup_handle); | ||
| }) | ||
| } | ||
This file contains hidden or 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
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.
Good design pattern: This task forwards the abort signal to the task_manager, which is cleaner than the previous approach that used a hardcoded sleep. However, ensure that
task_manager.graceful_shutdown()properly signals all child tasks to complete their cleanup work before theclickhouse_shutdown_handlecompletes.