From f1f4b64a15ea9b2bbde2126a9a4a5fcff0c76cc2 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 8 Feb 2024 18:25:31 +0800 Subject: [PATCH 1/3] Add ckb-channel as dependency for ckb-indexer --- Cargo.lock | 1 + util/indexer/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1f913ffcf9..bf42e1e1e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -907,6 +907,7 @@ version = "0.114.0-pre" dependencies = [ "ckb-app-config", "ckb-async-runtime", + "ckb-channel", "ckb-db-schema", "ckb-jsonrpc-types", "ckb-logger", diff --git a/util/indexer/Cargo.toml b/util/indexer/Cargo.toml index ea01bb6ffe..294921a99b 100644 --- a/util/indexer/Cargo.toml +++ b/util/indexer/Cargo.toml @@ -22,6 +22,7 @@ ckb-notify = { path = "../../notify", version = "= 0.114.0-pre" } ckb-store = { path = "../../store", version = "= 0.114.0-pre" } ckb-stop-handler = { path = "../stop-handler", version = "= 0.114.0-pre" } ckb-async-runtime = { path = "../runtime", version = "= 0.114.0-pre" } +ckb-channel = { path = "../channel", version = "= 0.114.0-pre" } rhai = { version = "1.10.0", features = ["no_function", "no_float", "no_module", "sync"]} serde_json = "1.0" numext-fixed-uint = "0.1" From 27488553a0ab09789d2b6bf4a4e1e6eecbcf551b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 8 Feb 2024 18:26:28 +0800 Subject: [PATCH 2/3] `apply_init_tip` should stop after received exit signal --- util/indexer/src/service.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/util/indexer/src/service.rs b/util/indexer/src/service.rs index fc3aed3c83..6a8d059162 100644 --- a/util/indexer/src/service.rs +++ b/util/indexer/src/service.rs @@ -18,7 +18,7 @@ use ckb_jsonrpc_types::{ }; use ckb_logger::{error, info}; use ckb_notify::NotifyController; -use ckb_stop_handler::{new_tokio_exit_rx, CancellationToken}; +use ckb_stop_handler::{new_crossbeam_exit_rx, new_tokio_exit_rx, CancellationToken}; use ckb_store::ChainStore; use ckb_types::{ core::{self, BlockNumber}, @@ -153,7 +153,16 @@ impl IndexerService { } } } + let stop_rx = new_crossbeam_exit_rx(); loop { + ckb_channel::select! { + recv(stop_rx) -> _ =>{ + info!("apply_init_tip received exit signal, exit now"); + break; + }, + default() => {}, + } + if let Err(e) = self.secondary_db.try_catch_up_with_primary() { error!("secondary_db try_catch_up_with_primary error {}", e); } @@ -228,6 +237,16 @@ impl IndexerService { let poll_service = self.clone(); self.async_handle.spawn(async move { let _initial_finished = initial_syncing.await; + info!("initial_syncing finished"); + + tokio::select! { + _ = stop.cancelled() => { + info!("Indexer received exit signal, cancel new_block_watcher task, exit now"); + return; + }, + else => {}, + } + let mut new_block_watcher = notify_controller .watch_new_block(SUBSCRIBER_NAME.to_string()) .await; From 058fe68ba4fc91edfdfeff6e936721a79e6175ae Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 8 Feb 2024 19:08:57 +0800 Subject: [PATCH 3/3] Fix graceful_shutdown bats test --- util/app-config/src/tests/graceful_shutdown.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/app-config/src/tests/graceful_shutdown.bats b/util/app-config/src/tests/graceful_shutdown.bats index 17ac2661b3..6d6aa5e82e 100644 --- a/util/app-config/src/tests/graceful_shutdown.bats +++ b/util/app-config/src/tests/graceful_shutdown.bats @@ -26,7 +26,7 @@ function ckb_graceful_shutdown { #@test assert_output --regexp "INFO ckb_tx_pool::chunk_process TxPool chunk_command service received exit signal, exit now" assert_output --regexp "INFO ckb_tx_pool::service TxPool is saving, please wait..." assert_output --regexp "INFO ckb_tx_pool::service TxPool reorg process service received exit signal, exit now" - assert_output --regexp "INFO ckb_indexer::service Indexer received exit signal, exit now" + assert_output --regexp "INFO ckb_indexer::service Indexer received exit signal, cancel new_block_watcher task, exit now" assert_output --regexp "INFO ckb_notify NotifyService received exit signal, exit now" assert_output --regexp "INFO ckb_block_filter::filter BlockFilter received exit signal, exit now" assert_output --regexp "INFO ckb_sync::types::header_map HeaderMap limit_memory received exit signal, exit now"