Skip to content

Commit

Permalink
chore: restrict for how long the backward syncer can block (#3918)
Browse files Browse the repository at this point in the history
### Description

<!--
What's included in this PR?
-->

### Drive-by changes

<!--
Are there any minor or drive-by changes also included?
-->

### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

<!--
What kind of testing have these changes undergone?

None/Manual/Unit Tests
-->
  • Loading branch information
daniel-savu authored Jun 6, 2024
1 parent 8693ca3 commit 4261df7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ use hyperlane_core::{
HyperlaneSequenceAwareIndexerStoreReader, IndexMode, Indexed, LogMeta, SequenceIndexed,
};
use itertools::Itertools;
use tokio::time::sleep;
use tracing::{debug, instrument, warn};

use super::{LastIndexedSnapshot, TargetSnapshot};

const MAX_BACKWARD_SYNC_BLOCKING_TIME: Duration = Duration::from_secs(5);

/// A sequence-aware cursor that syncs backward until there are no earlier logs to index.
pub(crate) struct BackwardSequenceAwareSyncCursor<T> {
/// The max chunk size to query for logs.
Expand Down Expand Up @@ -68,7 +71,11 @@ impl<T: Debug> BackwardSequenceAwareSyncCursor<T> {
#[instrument(ret)]
pub async fn get_next_range(&mut self) -> Result<Option<RangeInclusive<u32>>> {
// Skip any already indexed logs.
self.skip_indexed().await?;
tokio::select! {
res = self.skip_indexed() => res?,
// return early to allow the forward cursor to also make progress
_ = sleep(MAX_BACKWARD_SYNC_BLOCKING_TIME) => { return Ok(None); }
};

// If `self.current_indexing_snapshot` is None, we are synced and there are no more ranges to query.
// Otherwise, we query the next range, searching for logs prior to and including the current indexing snapshot.
Expand Down

0 comments on commit 4261df7

Please sign in to comment.