Skip to content

Commit

Permalink
Drop extra references to storage before releasing it
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Apr 23, 2024
1 parent e1d9782 commit fa674ce
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions crates/bin/pd/src/migrate/testnet72.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub async fn migrate(
path_to_export: PathBuf,
genesis_start: Option<tendermint::time::Time>,
) -> anyhow::Result<()> {
let start_time = std::time::SystemTime::now();
let rocksdb_dir = path_to_export.join("rocksdb");
let storage = Storage::load(rocksdb_dir.clone(), SUBSTORE_PREFIXES.to_vec()).await?;
let export_state = storage.latest_snapshot();
Expand All @@ -142,18 +141,21 @@ pub async fn migrate(
let post_upgrade_height = pre_upgrade_height.wrapping_add(1);

let mut delta = StateDelta::new(export_state);
let ctx = Context::new(storage.clone());
let (migration_duration, post_upgrade_root_hash) = {
let start_time = std::time::SystemTime::now();
let ctx = Context::new(storage.clone());

// Translate inside dex storage.
translate_dex_storage(ctx.clone(), &mut delta).await?;
// Translate inside compact block storage.
translate_compact_block_storage(ctx.clone(), &mut delta).await?;
// Translate inside dex storage.
translate_dex_storage(ctx.clone(), &mut delta).await?;
// Translate inside compact block storage.
translate_compact_block_storage(ctx.clone(), &mut delta).await?;

delta.put_block_height(0u64);
let post_upgrade_root_hash = storage.commit_in_place(delta).await?;
tracing::info!(?post_upgrade_root_hash, "post-upgrade root hash");
delta.put_block_height(0u64);
let post_upgrade_root_hash = storage.commit_in_place(delta).await?;
tracing::info!(?post_upgrade_root_hash, "post-upgrade root hash");

let migration_duration = start_time.elapsed().unwrap();
(start_time.elapsed().unwrap(), post_upgrade_root_hash)
};

storage.release().await;
let storage = Storage::load(rocksdb_dir, SUBSTORE_PREFIXES.to_vec()).await?;
Expand Down

0 comments on commit fa674ce

Please sign in to comment.