Decouple rocksdb dependency from ethcore (#8320)
* Move client DB opening logic to CLI * Move restoration db open logic to CLI This adds KeyValueDBHandler which handles opening a new database, thus allow us to move the restoration db open logic out of ethcore. * Move rocksdb's compactionprofile conversion to CLI * Move kvdb_rocksdb as test dependency for ethcore * Fix tests due to interface change * Fix service tests * Remove unused migration dep for ethcore
This commit is contained in:
@@ -8,9 +8,9 @@ ansi_term = "0.10"
|
||||
ethcore = { path = ".." }
|
||||
ethcore-io = { path = "../../util/io" }
|
||||
kvdb = { path = "../../util/kvdb" }
|
||||
kvdb-rocksdb = { path = "../../util/kvdb-rocksdb" }
|
||||
log = "0.3"
|
||||
stop-guard = { path = "../../util/stop-guard" }
|
||||
|
||||
[dev-dependencies]
|
||||
tempdir = "0.3"
|
||||
kvdb-rocksdb = { path = "../../util/kvdb-rocksdb" }
|
||||
|
||||
@@ -18,7 +18,6 @@ extern crate ansi_term;
|
||||
extern crate ethcore;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate kvdb;
|
||||
extern crate kvdb_rocksdb;
|
||||
extern crate stop_guard;
|
||||
|
||||
#[macro_use]
|
||||
@@ -27,6 +26,9 @@ extern crate log;
|
||||
#[cfg(test)]
|
||||
extern crate tempdir;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate kvdb_rocksdb;
|
||||
|
||||
mod service;
|
||||
|
||||
pub use service::ClientService;
|
||||
|
||||
@@ -21,12 +21,10 @@ use std::path::Path;
|
||||
|
||||
use ansi_term::Colour;
|
||||
use io::{IoContext, TimerToken, IoHandler, IoService, IoError};
|
||||
use kvdb::KeyValueDB;
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
use kvdb::{KeyValueDB, KeyValueDBHandler};
|
||||
use stop_guard::StopGuard;
|
||||
|
||||
use ethcore::client::{self, Client, ClientConfig, ChainNotify, ClientIoMessage};
|
||||
use ethcore::db;
|
||||
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
|
||||
use ethcore::error::Error;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
|
||||
@@ -38,7 +36,7 @@ pub struct ClientService {
|
||||
io_service: Arc<IoService<ClientIoMessage>>,
|
||||
client: Arc<Client>,
|
||||
snapshot: Arc<SnapshotService>,
|
||||
database: Arc<Database>,
|
||||
database: Arc<KeyValueDB>,
|
||||
_stop_guard: StopGuard,
|
||||
}
|
||||
|
||||
@@ -47,8 +45,9 @@ impl ClientService {
|
||||
pub fn start(
|
||||
config: ClientConfig,
|
||||
spec: &Spec,
|
||||
client_path: &Path,
|
||||
client_db: Arc<KeyValueDB>,
|
||||
snapshot_path: &Path,
|
||||
restoration_db_handler: Box<KeyValueDBHandler>,
|
||||
_ipc_path: &Path,
|
||||
miner: Arc<Miner>,
|
||||
) -> Result<ClientService, Error>
|
||||
@@ -57,25 +56,13 @@ impl ClientService {
|
||||
|
||||
info!("Configured for {} using {} engine", Colour::White.bold().paint(spec.name.clone()), Colour::Yellow.bold().paint(spec.engine.name()));
|
||||
|
||||
let mut db_config = DatabaseConfig::with_columns(db::NUM_COLUMNS);
|
||||
|
||||
db_config.memory_budget = config.db_cache_size;
|
||||
db_config.compaction = config.db_compaction.compaction_profile(client_path);
|
||||
db_config.wal = config.db_wal;
|
||||
|
||||
let db = Arc::new(Database::open(
|
||||
&db_config,
|
||||
&client_path.to_str().expect("DB path could not be converted to string.")
|
||||
).map_err(client::Error::Database)?);
|
||||
|
||||
|
||||
let pruning = config.pruning;
|
||||
let client = Client::new(config, &spec, db.clone(), miner, io_service.channel())?;
|
||||
let client = Client::new(config, &spec, client_db.clone(), miner, io_service.channel())?;
|
||||
|
||||
let snapshot_params = SnapServiceParams {
|
||||
engine: spec.engine.clone(),
|
||||
genesis_block: spec.genesis_block(),
|
||||
db_config: db_config.clone(),
|
||||
restoration_db_handler: restoration_db_handler,
|
||||
pruning: pruning,
|
||||
channel: io_service.channel(),
|
||||
snapshot_root: snapshot_path.into(),
|
||||
@@ -97,7 +84,7 @@ impl ClientService {
|
||||
io_service: Arc::new(io_service),
|
||||
client: client,
|
||||
snapshot: snapshot,
|
||||
database: db,
|
||||
database: client_db,
|
||||
_stop_guard: stop_guard,
|
||||
})
|
||||
}
|
||||
@@ -208,6 +195,9 @@ mod tests {
|
||||
use ethcore::client::ClientConfig;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::spec::Spec;
|
||||
use ethcore::db::NUM_COLUMNS;
|
||||
use kvdb::Error;
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig, CompactionProfile};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -216,12 +206,39 @@ mod tests {
|
||||
let client_path = tempdir.path().join("client");
|
||||
let snapshot_path = tempdir.path().join("snapshot");
|
||||
|
||||
let client_config = ClientConfig::default();
|
||||
let mut client_db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
|
||||
|
||||
client_db_config.memory_budget = client_config.db_cache_size;
|
||||
client_db_config.compaction = CompactionProfile::auto(&client_path);
|
||||
client_db_config.wal = client_config.db_wal;
|
||||
|
||||
let client_db = Arc::new(Database::open(
|
||||
&client_db_config,
|
||||
&client_path.to_str().expect("DB path could not be converted to string.")
|
||||
).unwrap());
|
||||
|
||||
struct RestorationDBHandler {
|
||||
config: DatabaseConfig,
|
||||
}
|
||||
|
||||
impl KeyValueDBHandler for RestorationDBHandler {
|
||||
fn open(&self, db_path: &Path) -> Result<Arc<KeyValueDB>, Error> {
|
||||
Ok(Arc::new(Database::open(&self.config, &db_path.to_string_lossy())?))
|
||||
}
|
||||
}
|
||||
|
||||
let restoration_db_handler = Box::new(RestorationDBHandler {
|
||||
config: client_db_config,
|
||||
});
|
||||
|
||||
let spec = Spec::new_test();
|
||||
let service = ClientService::start(
|
||||
ClientConfig::default(),
|
||||
&spec,
|
||||
&client_path,
|
||||
client_db,
|
||||
&snapshot_path,
|
||||
restoration_db_handler,
|
||||
tempdir.path(),
|
||||
Arc::new(Miner::with_spec(&spec)),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user