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

feat(api): Retry read_value #2352

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/lib/state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tracing.workspace = true
itertools.workspace = true
chrono.workspace = true
once_cell.workspace = true
backon.workspace = true

[dev-dependencies]
assert_matches.workspace = true
Expand Down
25 changes: 21 additions & 4 deletions core/lib/state/src/postgres/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{
mem,
sync::{Arc, RwLock},
time::Duration,
};

use anyhow::Context as _;
use backon::{BlockingRetryable, ConstantBuilder};
use tokio::{
runtime::Handle,
sync::{
Expand Down Expand Up @@ -489,11 +491,26 @@ impl ReadStorage for PostgresStorage<'_> {
values_cache.and_then(|cache| cache.get(self.l2_block_number, hashed_key));

let value = cached_value.unwrap_or_else(|| {
const RETRY_INTERVAL: Duration = Duration::from_millis(500);
const MAX_TRIES: usize = 20;

perekopskiy marked this conversation as resolved.
Show resolved Hide resolved
let mut dal = self.connection.storage_web3_dal();
let value = self
.rt_handle
.block_on(dal.get_historical_value_unchecked(hashed_key, self.l2_block_number))
.expect("Failed executing `read_value`");
let value = (|| {
self.rt_handle
.block_on(dal.get_historical_value_unchecked(hashed_key, self.l2_block_number))
slowli marked this conversation as resolved.
Show resolved Hide resolved
})
.retry(
&ConstantBuilder::default()
.with_delay(RETRY_INTERVAL)
.with_max_times(MAX_TRIES),
)
.when(|e| {
e.inner()
.as_database_error()
.is_some_and(|e| e.message() == "canceling statement due to statement timeout")
perekopskiy marked this conversation as resolved.
Show resolved Hide resolved
})
.call()
.expect("Failed executing `read_value`");
if let Some(cache) = self.values_cache() {
cache.insert(self.l2_block_number, hashed_key, value);
}
Expand Down
13 changes: 13 additions & 0 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading