Skip to content

Commit

Permalink
Delete full db directory with purge-chain subcommand (#1786)
Browse files Browse the repository at this point in the history
Closes #1767 

Until now the `purge-chain` command would only remove the `full`
subfolder of the db folder. However there is also the `parachains` db
that currently remains and can cause problems on node restart.

Example wiht old code:
```
polkadot purge-chain --database paritydb --base-path /tmp/some-folder
Are you sure to remove "/tmp/some-folder/chains/polkadot/paritydb/full"? [y/N]: y
"/tmp/some-folder/chains/polkadot/paritydb/full" removed.
```
In this case `/tmp/some-folder/chains/polkadot/paritydb/parachains`
would remain and might cause problem on node restart because of version
conflicts as described in #1767. After this PR the whole
`/tmp/some-folder/chains/polkadot/paritydb` folder will be deleted.
  • Loading branch information
skunert authored Oct 5, 2023
1 parent 51c0c24 commit d21113c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
4 changes: 0 additions & 4 deletions polkadot/tests/purge_chain_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ async fn purge_chain_rocksdb_works() {
assert!(cmd.wait().unwrap().success());
assert!(tmpdir.path().join("chains/rococo_dev").exists());
assert!(tmpdir.path().join("chains/rococo_dev/db/full").exists());
assert!(tmpdir.path().join("chains/rococo_dev/db/full/parachains").exists());

// Purge chain
let status = Command::new(cargo_bin("polkadot"))
Expand Down Expand Up @@ -102,7 +101,6 @@ async fn purge_chain_paritydb_works() {
assert!(cmd.wait().unwrap().success());
assert!(tmpdir.path().join("chains/rococo_dev").exists());
assert!(tmpdir.path().join("chains/rococo_dev/paritydb/full").exists());
assert!(tmpdir.path().join("chains/rococo_dev/paritydb/parachains").exists());

// Purge chain
let status = Command::new(cargo_bin("polkadot"))
Expand All @@ -118,8 +116,6 @@ async fn purge_chain_paritydb_works() {
// Make sure that the chain folder exists, but `db/full` is deleted.
assert!(tmpdir.path().join("chains/rococo_dev").exists());
assert!(!tmpdir.path().join("chains/rococo_dev/paritydb/full").exists());
// Parachains removal requires calling "purge-chain --parachains".
assert!(tmpdir.path().join("chains/rococo_dev/paritydb/parachains").exists());
})
.await;
}
2 changes: 1 addition & 1 deletion substrate/client/cli/src/commands/purge_chain_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct PurgeChainCmd {
impl PurgeChainCmd {
/// Run the purge command
pub fn run(&self, database_config: DatabaseSource) -> error::Result<()> {
let db_path = database_config.path().ok_or_else(|| {
let db_path = database_config.path().and_then(|p| p.parent()).ok_or_else(|| {
error::Error::Input("Cannot purge custom database implementation".into())
})?;

Expand Down

0 comments on commit d21113c

Please sign in to comment.