-
Notifications
You must be signed in to change notification settings - Fork 301
feat(fortuna): Multiple replica support #2812
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
Changes from 9 commits
a66fe6e
4801859
0c76fa6
b3f630f
631e71d
ac5fb7a
02f280d
07d67bc
3ebfbb9
4755ce6
1a3a401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,56 @@ pub async fn process_event_with_backoff( | |
return Ok(()); | ||
} | ||
|
||
// If replica config is present, we're running with multiple instances | ||
// The incoming request is assigned by modulo operation on the sequence number | ||
// and the total number of replicas. If our replica_id is the primary for this sequence number, | ||
// we process the request directly. If our replica_id is a backup, we wait for the delay and | ||
// then check if the request is still open. If it is, we process it as a failover. | ||
if let Some(replica_config) = &process_param.replica_config { | ||
let assigned_replica = event.sequence_number % replica_config.total_replicas; | ||
let is_primary_replica = assigned_replica == replica_config.replica_id; | ||
|
||
if is_primary_replica { | ||
tracing::debug!("Processing request as primary replica"); | ||
} else { | ||
tracing::debug!("Processing request as backup replica"); | ||
|
||
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. I think we can merge these 2 logs |
||
tracing::info!("Waiting before processing as backup replica"); | ||
tokio::time::sleep(tokio::time::Duration::from_secs( | ||
replica_config.backup_delay_seconds, | ||
)) | ||
.await; | ||
|
||
// Check if the request is still open after the delay. | ||
// If it is, we will process it as a backup replica. | ||
match chain_state | ||
.contract | ||
.get_request(event.provider_address, event.sequence_number) | ||
.await | ||
{ | ||
Ok(Some(_)) => { | ||
tracing::info!( | ||
delay_seconds = replica_config.backup_delay_seconds, | ||
"Request still open after delay, processing as backup replica" | ||
); | ||
} | ||
Ok(None) => { | ||
tracing::debug!( | ||
"Request already fulfilled by primary replica during delay, skipping" | ||
); | ||
return Ok(()); | ||
} | ||
Err(e) => { | ||
tracing::warn!( | ||
error = ?e, | ||
"Error checking request status after delay, processing as backup replica" | ||
); | ||
} | ||
} | ||
} | ||
} | ||
// If no replica config we are running standalone, process all requests directly | ||
|
||
|
||
let account_label = AccountLabel { | ||
chain_id: chain_state.id.clone(), | ||
address: chain_state.provider_address.to_string(), | ||
|
Uh oh!
There was an error while loading. Please reload this page.