Skip to content
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
18 changes: 4 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ diesel = { version = "2.2.7", features = [
"chrono",
"i-implement-a-third-party-backend-and-opt-into-breaking-changes",
] }
diesel-async = { version = "0.8.0", features = ["deadpool", "async-connection-wrapper", "tokio", "postgres"] }
diesel-async = { version = "0.9.0", features = ["deadpool", "async-connection-wrapper", "tokio", "postgres"] }
diesel-derive-enum = { version = "2.1.0", features = ["postgres"] }
diesel-dynamic-schema = { version = "0.2.3", features = ["postgres"] }
diesel_derives = "2.3.8"
Expand Down
46 changes: 23 additions & 23 deletions node/src/manager/commands/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use graph_chain_ethereum::chain::BlockFinality;
use graph_store_postgres::BlockStore;
use graph_store_postgres::ChainStore;
use graph_store_postgres::PoolCoordinator;
use graph_store_postgres::ScopedFutureExt;
use graph_store_postgres::Shard;
use graph_store_postgres::add_chain;
use graph_store_postgres::find_chain;
Expand Down Expand Up @@ -260,34 +259,35 @@ pub async fn change_block_cache_shard(
let new_name = format!("{}-old", &chain_name);
let ident = chain_store.chain_identifier().await?;

conn.transaction::<(), StoreError, _>(|conn| {
async {
let shard = Shard::new(shard.to_string())?;
conn.transaction::<(), StoreError, _>(async |conn| {
let shard = Shard::new(shard.to_string())?;

let chain = BlockStore::allocate_chain(conn, &chain_name, &shard, &ident).await?;
let chain = BlockStore::allocate_chain(conn, &chain_name, &shard, &ident).await?;

store.add_chain_store(&chain, true).await?;
store.add_chain_store(&chain, true).await?;

// Drop the foreign key constraint on deployment_schemas
sql_query(
"alter table deployment_schemas drop constraint deployment_schemas_network_fkey;",
)
.execute(conn).await?;
// Drop the foreign key constraint on deployment_schemas
sql_query(
"alter table deployment_schemas drop constraint deployment_schemas_network_fkey;",
)
.execute(conn)
.await?;

// Update the current chain name to chain-old
update_chain_name(conn, &chain_name, &new_name).await?;
// Update the current chain name to chain-old
update_chain_name(conn, &chain_name, &new_name).await?;

// Create a new chain with the name in the destination shard
let _ = add_chain(conn, &chain_name, &shard, ident).await?;
// Create a new chain with the name in the destination shard
let _ = add_chain(conn, &chain_name, &shard, ident).await?;

// Re-add the foreign key constraint
sql_query(
"alter table deployment_schemas add constraint deployment_schemas_network_fkey foreign key (network) references chains(name);",
)
.execute(conn).await?;
Ok(())
}.scope_boxed()
}).await?;
// Re-add the foreign key constraint
sql_query(
"alter table deployment_schemas add constraint deployment_schemas_network_fkey foreign key (network) references chains(name);",
)
.execute(conn)
.await?;
Ok(())
})
.await?;

chain_store.update_name(&new_name).await?;

Expand Down
25 changes: 10 additions & 15 deletions store/postgres/src/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use graph::{components::store::BLOCK_CACHE_SIZE, parking_lot::RwLock};
use anyhow::anyhow;
use async_trait::async_trait;
use diesel::{ExpressionMethods as _, QueryDsl, sql_query};
use diesel_async::{RunQueryDsl, scoped_futures::ScopedFutureExt};
use diesel_async::RunQueryDsl;
use graph::{
blockchain::ChainIdentifier,
components::store::{BlockStore as BlockStoreTrait, QueryPermit},
Expand Down Expand Up @@ -253,9 +253,7 @@ impl BlockStore {
const CHAIN_HEAD_CACHE_TTL: Duration = Duration::from_secs(2);

let mirror = PrimaryMirror::new(&pools);
let existing_chains = mirror
.read_async(|conn| primary::load_chains(conn).scope_boxed())
.await?;
let existing_chains = mirror.read_async(primary::load_chains).await?;
let chain_head_cache = TimedCache::new(CHAIN_HEAD_CACHE_TTL);
let chains = shards.clone();

Expand Down Expand Up @@ -437,18 +435,15 @@ impl BlockStore {
let chain = chain.to_string();
let this = self.cheap_clone();
self.mirror
.read_async(|conn| {
async {
match primary::find_chain(conn, &chain).await? {
Some(chain) => {
let chain_store = this.add_chain_store(&chain, false).await?;
Ok(Some(chain_store))
}
None => Ok(None),
.read_async(
async |conn| match primary::find_chain(conn, &chain).await? {
Some(chain) => {
let chain_store = this.add_chain_store(&chain, false).await?;
Ok(Some(chain_store))
}
}
.scope_boxed()
})
None => Ok(None),
},
)
.await
}

Expand Down
Loading
Loading