mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Store the database in a role specific subdirectory (#9645)
* Store the database in a role specific subdirectory This is a cleaned up version of #8658 fixing #6880 polkadot companion: paritytech/polkadot#2923 * Disable prometheus in tests * Also change p2p port * Fix migration logic * Use different identification file for rocks and parity db Add tests for paritydb migration
This commit is contained in:
committed by
GitHub
parent
4849e34270
commit
16144e7404
@@ -28,7 +28,7 @@ pub mod common;
|
||||
fn check_block_works() {
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
|
||||
common::run_dev_node_for_a_while(base_path.path());
|
||||
common::run_node_for_a_while(base_path.path(), &["--dev"]);
|
||||
|
||||
let status = Command::new(cargo_bin("substrate"))
|
||||
.args(&["check-block", "--dev", "--pruning", "archive", "-d"])
|
||||
|
||||
@@ -54,10 +54,10 @@ pub fn wait_for(child: &mut Child, secs: usize) -> Option<ExitStatus> {
|
||||
}
|
||||
|
||||
/// Run the node for a while (30 seconds)
|
||||
pub fn run_dev_node_for_a_while(base_path: &Path) {
|
||||
pub fn run_node_for_a_while(base_path: &Path, args: &[&str]) {
|
||||
let mut cmd = Command::new(cargo_bin("substrate"));
|
||||
|
||||
let mut cmd = cmd.args(&["--dev"]).arg("-d").arg(base_path).spawn().unwrap();
|
||||
let mut cmd = cmd.args(args).arg("-d").arg(base_path).spawn().unwrap();
|
||||
|
||||
// Let it produce some blocks.
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
@@ -67,3 +67,14 @@ pub fn run_dev_node_for_a_while(base_path: &Path) {
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
assert!(wait_for(&mut cmd, 40).map(|x| x.success()).unwrap_or_default());
|
||||
}
|
||||
|
||||
/// Run the node asserting that it fails with an error
|
||||
pub fn run_node_assert_fail(base_path: &Path, args: &[&str]) {
|
||||
let mut cmd = Command::new(cargo_bin("substrate"));
|
||||
|
||||
let mut cmd = cmd.args(args).arg("-d").arg(base_path).spawn().unwrap();
|
||||
|
||||
// Let it produce some blocks.
|
||||
thread::sleep(Duration::from_secs(10));
|
||||
assert!(cmd.try_wait().unwrap().is_some(), "the process should not be running anymore");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use sc_client_db::{
|
||||
light::LightStorage, DatabaseSettings, DatabaseSource, KeepBlocks, PruningMode,
|
||||
TransactionStorageMode,
|
||||
};
|
||||
use sp_runtime::testing::{Block as RawBlock, ExtrinsicWrapper};
|
||||
use tempfile::tempdir;
|
||||
|
||||
pub mod common;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn database_role_subdir_migration() {
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
let path = base_path.path().join("chains/dev/db");
|
||||
// create a dummy database dir
|
||||
{
|
||||
let _old_db = LightStorage::<Block>::new(DatabaseSettings {
|
||||
state_cache_size: 0,
|
||||
state_cache_child_ratio: None,
|
||||
state_pruning: PruningMode::ArchiveAll,
|
||||
source: DatabaseSource::RocksDb { path: path.to_path_buf(), cache_size: 128 },
|
||||
keep_blocks: KeepBlocks::All,
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
assert!(path.join("db_version").exists());
|
||||
assert!(!path.join("light").exists());
|
||||
|
||||
// start a light client
|
||||
common::run_node_for_a_while(
|
||||
base_path.path(),
|
||||
&[
|
||||
"--dev",
|
||||
"--light",
|
||||
"--port",
|
||||
"30335",
|
||||
"--rpc-port",
|
||||
"44444",
|
||||
"--ws-port",
|
||||
"44445",
|
||||
"--no-prometheus",
|
||||
],
|
||||
);
|
||||
|
||||
// check if the database dir had been migrated
|
||||
assert!(!path.join("db_version").exists());
|
||||
assert!(path.join("light/db_version").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn database_role_subdir_migration_fail_on_different_role() {
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
let path = base_path.path().join("chains/dev/db");
|
||||
|
||||
// create a database with the old layout
|
||||
{
|
||||
let _old_db = LightStorage::<Block>::new(DatabaseSettings {
|
||||
state_cache_size: 0,
|
||||
state_cache_child_ratio: None,
|
||||
state_pruning: PruningMode::ArchiveAll,
|
||||
source: DatabaseSource::RocksDb { path: path.to_path_buf(), cache_size: 128 },
|
||||
keep_blocks: KeepBlocks::All,
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
assert!(path.join("db_version").exists());
|
||||
assert!(!path.join("light/db_version").exists());
|
||||
|
||||
// start a client with a different role (full), it should fail and not change any files on disk
|
||||
common::run_node_assert_fail(
|
||||
&base_path.path(),
|
||||
&[
|
||||
"--dev",
|
||||
"--port",
|
||||
"30334",
|
||||
"--rpc-port",
|
||||
"44446",
|
||||
"--ws-port",
|
||||
"44447",
|
||||
"--no-prometheus",
|
||||
],
|
||||
);
|
||||
|
||||
// check if the files are unchanged
|
||||
assert!(path.join("db_version").exists());
|
||||
assert!(!path.join("light/db_version").exists());
|
||||
assert!(!path.join("full/db_version").exists());
|
||||
}
|
||||
@@ -188,7 +188,7 @@ fn export_import_revert() {
|
||||
let exported_blocks_file = base_path.path().join("exported_blocks");
|
||||
let db_path = base_path.path().join("db");
|
||||
|
||||
common::run_dev_node_for_a_while(base_path.path());
|
||||
common::run_node_for_a_while(base_path.path(), &["--dev"]);
|
||||
|
||||
let mut executor = ExportImportRevertExecutor::new(&base_path, &exported_blocks_file, &db_path);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ pub mod common;
|
||||
fn inspect_works() {
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
|
||||
common::run_dev_node_for_a_while(base_path.path());
|
||||
common::run_node_for_a_while(base_path.path(), &["--dev"]);
|
||||
|
||||
let status = Command::new(cargo_bin("substrate"))
|
||||
.args(&["inspect", "--dev", "--pruning", "archive", "-d"])
|
||||
|
||||
@@ -27,7 +27,7 @@ pub mod common;
|
||||
fn purge_chain_works() {
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
|
||||
common::run_dev_node_for_a_while(base_path.path());
|
||||
common::run_node_for_a_while(base_path.path(), &["--dev"]);
|
||||
|
||||
let status = Command::new(cargo_bin("substrate"))
|
||||
.args(&["purge-chain", "--dev", "-d"])
|
||||
@@ -39,5 +39,5 @@ fn purge_chain_works() {
|
||||
|
||||
// Make sure that the `dev` chain folder exists, but the `db` is deleted.
|
||||
assert!(base_path.path().join("chains/dev/").exists());
|
||||
assert!(!base_path.path().join("chains/dev/db").exists());
|
||||
assert!(!base_path.path().join("chains/dev/db/full").exists());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user