Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 897a946

Browse files
sorpaas5chdn
authored andcommitted
Unify and limit rocksdb dependency places (#8371)
* secret_store: remove kvdb_rocksdb dependency * cli: init db mod for open dispatch * cli: move db, client_db, restoration_db, secretstore_db to a separate mod * migration: rename to migration-rocksdb and remove ethcore-migrations * ethcore: re-move kvdb-rocksdb dep to test * mark test_helpers as test only and fix migration mod naming * Move restoration_db_handler to test_helpers_internal * Fix missing preambles in test_helpers_internal and rocksdb/helpers * Move test crates downward * Fix missing docs * cli, db::open_db: move each argument to a separate line * Use featuregate instead of dead code for `open_secretstore_db` * Move pathbuf import to open_secretstore_db Because it's only used there behind a feature gate
1 parent 3f677c6 commit 897a946

27 files changed

+295
-261
lines changed

Cargo.lock

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ ethcore-bytes = { path = "util/bytes" }
3737
ethcore-io = { path = "util/io" }
3838
ethcore-light = { path = "ethcore/light" }
3939
ethcore-logger = { path = "logger" }
40-
ethcore-migrations = { path = "ethcore/migrations" }
4140
ethcore-miner = { path = "miner" }
4241
ethcore-network = { path = "util/network" }
4342
ethcore-private-tx = { path = "ethcore/private-tx" }
@@ -64,7 +63,7 @@ path = { path = "util/path" }
6463
dir = { path = "util/dir" }
6564
panic_hook = { path = "util/panic_hook" }
6665
keccak-hash = { path = "util/hash" }
67-
migration = { path = "util/migration" }
66+
migration-rocksdb = { path = "util/migration-rocksdb" }
6867
kvdb = { path = "util/kvdb" }
6968
kvdb-rocksdb = { path = "util/kvdb-rocksdb" }
7069
journaldb = { path = "util/journaldb" }

ethcore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ rlp_compress = { path = "../util/rlp_compress" }
5151
rlp_derive = { path = "../util/rlp_derive" }
5252
kvdb = { path = "../util/kvdb" }
5353
kvdb-memorydb = { path = "../util/kvdb-memorydb" }
54-
kvdb-rocksdb = { path = "../util/kvdb-rocksdb" }
5554
util-error = { path = "../util/error" }
5655
snappy = { git = "https://github.com/paritytech/rust-snappy" }
5756
stop-guard = { path = "../util/stop-guard" }
@@ -71,6 +70,7 @@ journaldb = { path = "../util/journaldb" }
7170
[dev-dependencies]
7271
tempdir = "0.3"
7372
trie-standardmap = { path = "../util/trie-standardmap" }
73+
kvdb-rocksdb = { path = "../util/kvdb-rocksdb" }
7474

7575
[features]
7676
# Display EVM debug traces.

ethcore/migrations/Cargo.toml

Lines changed: 0 additions & 7 deletions
This file was deleted.

ethcore/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ extern crate ansi_term;
9292
extern crate unexpected;
9393
extern crate kvdb;
9494
extern crate kvdb_memorydb;
95-
extern crate kvdb_rocksdb;
9695
extern crate util_error;
9796
extern crate snappy;
9897

@@ -128,6 +127,9 @@ extern crate evm;
128127

129128
pub extern crate ethstore;
130129

130+
#[cfg(test)]
131+
extern crate kvdb_rocksdb;
132+
131133
pub mod account_provider;
132134
pub mod block;
133135
pub mod client;
@@ -167,6 +169,8 @@ mod tests;
167169
#[cfg(test)]
168170
#[cfg(feature="json-tests")]
169171
mod json_tests;
172+
#[cfg(test)]
173+
mod test_helpers_internal;
170174

171175
pub use types::*;
172176
pub use executive::contract_address;

ethcore/src/snapshot/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ mod tests {
635635
use snapshot::{ManifestData, RestorationStatus, SnapshotService};
636636
use super::*;
637637
use tempdir::TempDir;
638-
use test_helpers::restoration_db_handler;
638+
use test_helpers_internal::restoration_db_handler;
639639

640640
struct NoopDBRestore;
641641
impl DatabaseRestore for NoopDBRestore {

ethcore/src/snapshot/tests/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use ids::BlockId;
2424
use snapshot::service::{Service, ServiceParams};
2525
use snapshot::{self, ManifestData, SnapshotService};
2626
use spec::Spec;
27-
use test_helpers::{generate_dummy_client_with_spec_and_data, restoration_db_handler};
27+
use test_helpers::generate_dummy_client_with_spec_and_data;
28+
use test_helpers_internal::restoration_db_handler;
2829

2930
use io::IoChannel;
3031
use kvdb_rocksdb::{Database, DatabaseConfig};

ethcore/src/test_helpers.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ use spec::Spec;
3535
use state_db::StateDB;
3636
use state::*;
3737
use std::sync::Arc;
38-
use std::path::Path;
3938
use transaction::{Action, Transaction, SignedTransaction};
4039
use views::BlockView;
41-
use kvdb::{KeyValueDB, KeyValueDBHandler};
42-
use kvdb_rocksdb::{Database, DatabaseConfig};
4340

4441
/// Creates test block with corresponding header
4542
pub fn create_test_block(header: &Header) -> Bytes {
@@ -402,20 +399,3 @@ impl ChainNotify for TestNotify {
402399
self.messages.write().push(data);
403400
}
404401
}
405-
406-
/// Creates new instance of KeyValueDBHandler
407-
pub fn restoration_db_handler(config: DatabaseConfig) -> Box<KeyValueDBHandler> {
408-
use kvdb::Error;
409-
410-
struct RestorationDBHandler {
411-
config: DatabaseConfig,
412-
}
413-
414-
impl KeyValueDBHandler for RestorationDBHandler {
415-
fn open(&self, db_path: &Path) -> Result<Arc<KeyValueDB>, Error> {
416-
Ok(Arc::new(Database::open(&self.config, &db_path.to_string_lossy())?))
417-
}
418-
}
419-
420-
Box::new(RestorationDBHandler { config })
421-
}

ethcore/src/test_helpers_internal.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity.
3+
4+
// Parity is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Internal helpers for client tests
18+
19+
use std::path::Path;
20+
use std::sync::Arc;
21+
use kvdb::{KeyValueDB, KeyValueDBHandler};
22+
use kvdb_rocksdb::{Database, DatabaseConfig};
23+
24+
/// Creates new instance of KeyValueDBHandler
25+
pub fn restoration_db_handler(config: DatabaseConfig) -> Box<KeyValueDBHandler> {
26+
use kvdb::Error;
27+
28+
struct RestorationDBHandler {
29+
config: DatabaseConfig,
30+
}
31+
32+
impl KeyValueDBHandler for RestorationDBHandler {
33+
fn open(&self, db_path: &Path) -> Result<Arc<KeyValueDB>, Error> {
34+
Ok(Arc::new(Database::open(&self.config, &db_path.to_string_lossy())?))
35+
}
36+
}
37+
38+
Box::new(RestorationDBHandler { config })
39+
}

parity/blockchain.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@ use bytes::ToPretty;
2727
use rlp::PayloadInfo;
2828
use ethcore::account_provider::AccountProvider;
2929
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock};
30-
use ethcore::db::NUM_COLUMNS;
3130
use ethcore::error::ImportError;
3231
use ethcore::miner::Miner;
3332
use ethcore::verification::queue::VerifierSettings;
3433
use ethcore_service::ClientService;
3534
use cache::CacheConfig;
3635
use informant::{Informant, FullNodeInformantData, MillisecondDuration};
37-
use kvdb_rocksdb::{Database, DatabaseConfig};
3836
use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool};
39-
use helpers::{to_client_config, execute_upgrades, open_client_db, client_db_config, restoration_db_handler, compaction_profile};
37+
use helpers::{to_client_config, execute_upgrades};
4038
use dir::Directories;
4139
use user_defaults::UserDefaults;
4240
use fdlimit;
4341
use ethcore_private_tx;
42+
use db;
4443

4544
#[derive(Debug, PartialEq)]
4645
pub enum DataFormat {
@@ -188,8 +187,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
188187
let client_path = db_dirs.client_path(algorithm);
189188

190189
// execute upgrades
191-
let compaction = compaction_profile(&cmd.compaction, db_dirs.db_root_path().as_path());
192-
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, compaction)?;
190+
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, &cmd.compaction)?;
193191

194192
// create dirs used by parity
195193
cmd.dirs.create_dirs(false, false, false)?;
@@ -210,19 +208,10 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
210208
config.queue.verifier_settings = cmd.verifier_settings;
211209

212210
// initialize database.
213-
let db = {
214-
let db_config = DatabaseConfig {
215-
memory_budget: Some(cmd.cache_config.blockchain() as usize * 1024 * 1024),
216-
compaction: compaction,
217-
wal: cmd.wal,
218-
.. DatabaseConfig::with_columns(NUM_COLUMNS)
219-
};
220-
221-
Arc::new(Database::open(
222-
&db_config,
223-
&client_path.to_str().expect("DB path could not be converted to string.")
224-
).map_err(|e| format!("Failed to open database: {}", e))?)
225-
};
211+
let db = db::open_db(&client_path.to_str().expect("DB path could not be converted to string."),
212+
&cmd.cache_config,
213+
&cmd.compaction,
214+
cmd.wal)?;
226215

227216
// TODO: could epoch signals be avilable at the end of the file?
228217
let fetch = ::light::client::fetch::unavailable();
@@ -354,7 +343,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
354343
let snapshot_path = db_dirs.snapshot_path();
355344

356345
// execute upgrades
357-
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, compaction_profile(&cmd.compaction, db_dirs.db_root_path().as_path()))?;
346+
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, &cmd.compaction)?;
358347

359348
// create dirs used by parity
360349
cmd.dirs.create_dirs(false, false, false)?;
@@ -378,9 +367,8 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
378367

379368
client_config.queue.verifier_settings = cmd.verifier_settings;
380369

381-
let client_db_config = client_db_config(&client_path, &client_config);
382-
let client_db = open_client_db(&client_path, &client_db_config)?;
383-
let restoration_db_handler = restoration_db_handler(client_db_config);
370+
let client_db = db::open_client_db(&client_path, &client_config)?;
371+
let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config);
384372

385373
// build client
386374
let service = ClientService::start(
@@ -549,7 +537,7 @@ fn start_client(
549537
let snapshot_path = db_dirs.snapshot_path();
550538

551539
// execute upgrades
552-
execute_upgrades(&dirs.base, &db_dirs, algorithm, compaction_profile(&compaction, db_dirs.db_root_path().as_path()))?;
540+
execute_upgrades(&dirs.base, &db_dirs, algorithm, &compaction)?;
553541

554542
// create dirs used by parity
555543
dirs.create_dirs(false, false, false)?;
@@ -571,9 +559,8 @@ fn start_client(
571559
true,
572560
);
573561

574-
let client_db_config = client_db_config(&client_path, &client_config);
575-
let client_db = open_client_db(&client_path, &client_db_config)?;
576-
let restoration_db_handler = restoration_db_handler(client_db_config);
562+
let client_db = db::open_client_db(&client_path, &client_config)?;
563+
let restoration_db_handler = db::restoration_db_handler(&client_path, &client_config);
577564

578565
let service = ClientService::start(
579566
client_config,
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
1+
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
22
// This file is part of Parity.
33

44
// Parity is free software: you can redistribute it and/or modify
@@ -14,24 +14,12 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//! Database migrations.
17+
//! Database-related operations.
1818
19-
extern crate migration;
19+
#[path="rocksdb/mod.rs"]
20+
mod impls;
2021

21-
use migration::ChangeColumns;
22+
pub use self::impls::{open_db, open_client_db, restoration_db_handler, migrate};
2223

23-
/// The migration from v10 to v11.
24-
/// Adds a column for node info.
25-
pub const TO_V11: ChangeColumns = ChangeColumns {
26-
pre_columns: Some(6),
27-
post_columns: Some(7),
28-
version: 11,
29-
};
30-
31-
/// The migration from v11 to v12.
32-
/// Adds a column for light chain storage.
33-
pub const TO_V12: ChangeColumns = ChangeColumns {
34-
pre_columns: Some(7),
35-
post_columns: Some(8),
36-
version: 12,
37-
};
24+
#[cfg(feature = "secretstore")]
25+
pub use self::impls::open_secretstore_db;

parity/db/rocksdb/helpers.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity.
3+
4+
// Parity is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
16+
17+
use std::path::Path;
18+
use ethcore::db::NUM_COLUMNS;
19+
use ethcore::client::{ClientConfig, DatabaseCompactionProfile};
20+
use super::kvdb_rocksdb::{CompactionProfile, DatabaseConfig};
21+
22+
pub fn compaction_profile(profile: &DatabaseCompactionProfile, db_path: &Path) -> CompactionProfile {
23+
match profile {
24+
&DatabaseCompactionProfile::Auto => CompactionProfile::auto(db_path),
25+
&DatabaseCompactionProfile::SSD => CompactionProfile::ssd(),
26+
&DatabaseCompactionProfile::HDD => CompactionProfile::hdd(),
27+
}
28+
}
29+
30+
pub fn client_db_config(client_path: &Path, client_config: &ClientConfig) -> DatabaseConfig {
31+
let mut client_db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
32+
33+
client_db_config.memory_budget = client_config.db_cache_size;
34+
client_db_config.compaction = compaction_profile(&client_config.db_compaction, &client_path);
35+
client_db_config.wal = client_config.db_wal;
36+
37+
client_db_config
38+
}

0 commit comments

Comments
 (0)