Skip to content

Commit

Permalink
node, store: Actually setup databases in parallel
Browse files Browse the repository at this point in the history
The previous code didn't parallelize setup, since setup makes blocking
calls, and so databases still started up one after the other.
  • Loading branch information
lutter committed Nov 30, 2021
1 parent 1f24b38 commit 85ac00c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion node/src/store_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl StoreBuilder {
// attempt doesn't work for all of them because the database is
// unavailable, they will try again later in the normal course of
// using the pool
join_all(pools.iter().map(|(_, pool)| async move { pool.setup() })).await;
join_all(pools.iter().map(|(_, pool)| pool.setup())).await;

let chains = HashMap::from_iter(config.chains.chains.iter().map(|(name, chain)| {
let shard = ShardName::new(chain.shard.to_string())
Expand Down
10 changes: 8 additions & 2 deletions store/postgres/src/connection_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,14 @@ impl ConnectionPool {
/// # Panics
///
/// If any errors happen during the migration, the process panics
pub fn setup(&self) {
self.get_ready().ok();
pub async fn setup(&self) {
let pool = self.clone();
graph::spawn_blocking_allow_panic(move || {
pool.get_ready().ok();
})
.await
// propagate panics
.unwrap();
}

pub(crate) async fn query_permit(&self) -> tokio::sync::OwnedSemaphorePermit {
Expand Down

0 comments on commit 85ac00c

Please sign in to comment.