Skip to content
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

fix: Ensure Historical Stream is cleared before pushing new messages #375

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions indexer/queryapi_coordinator/src/historical_block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const MAX_UNINDEXED_BLOCKS_TO_PROCESS: u64 = 7200; // two hours of blocks ta
pub const MAX_RPC_BLOCKS_TO_PROCESS: u8 = 20;

pub struct Task {
handle: JoinHandle<anyhow::Result<()>>,
handle: JoinHandle<()>,
cancellation_token: tokio_util::sync::CancellationToken,
}

Expand Down Expand Up @@ -51,11 +51,11 @@ impl Streamer {
let handle = tokio::spawn(async move {
tokio::select! {
_ = cancellation_token_clone.cancelled() => {
storage::del(
&redis_connection_manager,
storage::generate_historical_stream_key(&indexer.get_full_name()),
)
.await
tracing::info!(
target: crate::INDEXER,
"Cancelling existing historical backfill for indexer: {:?}",
indexer.get_full_name(),
);
},
_ = process_historical_messages_or_handle_error(
current_block_height,
Expand All @@ -64,9 +64,7 @@ impl Streamer {
&s3_client,
&chain_id,
&json_rpc_client,
) => {
Ok(())
}
) => { }
}
});

Expand All @@ -81,7 +79,7 @@ impl Streamer {
pub async fn cancel(&mut self) -> anyhow::Result<()> {
if let Some(task) = self.task.take() {
task.cancellation_token.cancel();
task.handle.await??;
task.handle.await?;

return Ok(());
}
Expand Down Expand Up @@ -185,6 +183,11 @@ pub(crate) async fn process_historical_messages(
blocks_from_index.append(&mut blocks_between_indexed_and_current_block);

if !blocks_from_index.is_empty() {
storage::del(
redis_connection_manager,
storage::generate_historical_stream_key(&indexer_function.get_full_name()),
)
.await?;
storage::sadd(
redis_connection_manager,
storage::STREAMS_SET_KEY,
Expand Down
Loading