diff --git a/src/ingest/firehose.rs b/src/ingest/firehose.rs --- a/src/ingest/firehose.rs +++ b/src/ingest/firehose.rs @@ -139,9 +139,11 @@ impl AddJitter for R {} fn select_start_cursor(local_cursor: Option, is_pds: bool) -> Option { - local_cursor - .filter(|cursor| *cursor > 0) - .or_else(|| is_pds.then_some(0)) + match local_cursor { + Some(cursor) if cursor > 0 => Some(cursor), + Some(cursor) if cursor < 0 => None, + _ => is_pds.then_some(0), + } } pub struct FirehoseIngestor { state: Arc, @@ -508,12 +510,11 @@ } fn clear_stale_cursor(&self) -> Result<()> { - let key = crate::db::keys::firehose_cursor_key_from_url(&self.relay_host); - self.state.db.cursors.remove(key).into_diagnostic()?; + crate::db::set_firehose_cursor(&self.state.db, &self.relay_host, -1)?; self.state .firehose_cursors .peek_with(&self.relay_host, |_, cursor| { - cursor.store(0, Ordering::SeqCst) + cursor.store(-1, Ordering::SeqCst) }); Ok(()) } @@ -652,16 +653,15 @@ ingestor.clear_stale_cursor()?; - assert!( - crate::db::get_firehose_cursor(&state.db, &relay_host) - .await? - .is_none() + assert_eq!( + crate::db::get_firehose_cursor(&state.db, &relay_host).await?, + Some(-1) ); let in_memory = state .firehose_cursors .peek_with(&relay_host, |_, cursor| cursor.load(Ordering::SeqCst)) - .unwrap_or(-1); - assert_eq!(in_memory, 0); + .unwrap_or(0); + assert_eq!(in_memory, -1); Ok(()) } @@ -673,7 +673,7 @@ assert_eq!(select_start_cursor(None, true), Some(0)); assert_eq!(select_start_cursor(Some(0), false), None); assert_eq!(select_start_cursor(None, false), None); - assert_eq!(select_start_cursor(Some(-5), true), Some(0)); + assert_eq!(select_start_cursor(Some(-5), true), None); assert_eq!(select_start_cursor(Some(-5), false), None); } }