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

Commit

Permalink
replace rocksdb with lmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Feb 19, 2019
1 parent d0d8201 commit 48e44cb
Show file tree
Hide file tree
Showing 23 changed files with 360 additions and 311 deletions.
348 changes: 277 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ parity-path = "0.1"
dir = { path = "util/dir" }
panic_hook = { path = "util/panic-hook" }
keccak-hash = "0.1"
migration-rocksdb = { path = "util/migration-rocksdb" }
# migration-rocksdb = { path = "util/migration-rocksdb" }
kvdb = "0.1"
kvdb-lmdb = "0.1"
kvdb-rocksdb = "0.1.3"
# kvdb-rocksdb = "0.1.3"
journaldb = { path = "util/journaldb" }

ethcore-secretstore = { path = "secret-store", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ keccak-hash = "0.1"
keccak-hasher = { path = "../util/keccak-hasher" }
kvdb = "0.1"
kvdb-memorydb = "0.1"
kvdb-rocksdb = { version = "0.1.3", optional = true }
kvdb-lmdb = { version = "0.1", optional = true }
lazy_static = "1.0"
len-caching-lock = { path = "../util/len-caching-lock" }
log = "0.4"
Expand Down Expand Up @@ -109,7 +109,7 @@ ci-skip-issue = []
# Run memory/cpu heavy tests.
test-heavy = []
# Compile test helpers
test-helpers = ["tempdir", "kvdb-rocksdb", "blooms-db"]
test-helpers = ["tempdir", "kvdb-lmdb", "blooms-db"]
# Enables slow 'to-pod-full' method for use in tests and evmbin.
to-pod-full = []

Expand Down
12 changes: 2 additions & 10 deletions ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,10 @@ mod tests {

use tempdir::TempDir;

use ethcore_db::NUM_COLUMNS;
use ethcore::client::ClientConfig;
use ethcore::miner::Miner;
use ethcore::spec::Spec;
use ethcore::test_helpers;
use kvdb_rocksdb::{DatabaseConfig, CompactionProfile};
use super::*;

use ethcore_private_tx;
Expand All @@ -296,15 +294,9 @@ 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);

let client_db_handler = test_helpers::restoration_db_handler(client_db_config.clone());
let client_db_handler = test_helpers::restoration_db_handler();
let client_db = client_db_handler.open(&client_path).unwrap();
let restoration_db_handler = test_helpers::restoration_db_handler(client_db_config);
let restoration_db_handler = test_helpers::restoration_db_handler();

let spec = Spec::new_test();
let service = ClientService::start(
Expand Down
19 changes: 0 additions & 19 deletions ethcore/src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ impl Display for Mode {
}
}

/// Which database to use.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum DatabaseBackend {
/// LMDB
Lmdb,
/// RocksDB
RocksDB {
/// RocksDB column cache-size if not default
db_cache_size: Option<usize>,
/// State db compaction profile
db_compaction: DatabaseCompactionProfile,
},
}

/// Client configuration. Includes configs for all sub-systems.
#[derive(Debug, PartialEq, Clone)]
Expand All @@ -113,8 +100,6 @@ pub struct ClientConfig {
pub pruning: journaldb::Algorithm,
/// The name of the client instance.
pub name: String,
/// The database backend.
pub db_backend: DatabaseBackend,
/// Operating mode
pub mode: Mode,
/// The chain spec name
Expand Down Expand Up @@ -150,10 +135,6 @@ impl Default for ClientConfig {
fat_db: false,
pruning: journaldb::Algorithm::OverlayRecent,
name: "default".into(),
db_backend: DatabaseBackend::RocksDB {
db_cache_size: None,
db_compaction: Default::default(),
},
mode: Mode::Active,
spec_name: "".into(),
verifier_type: VerifierType::Canon,
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod test_client;
mod trace;

pub use self::client::*;
pub use self::config::{Mode, ClientConfig, DatabaseBackend, DatabaseCompactionProfile, BlockChainConfig, VMType};
pub use self::config::{Mode, ClientConfig, BlockChainConfig, VMType};
#[cfg(any(test, feature = "test-helpers"))]
pub use self::evm_test_client::{EvmTestClient, EvmTestError, TransactResult};
pub use self::io_message::ClientIoMessage;
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ extern crate ethcore_accounts as accounts;
extern crate ethcore_stratum;
#[cfg(any(test, feature = "tempdir"))]
extern crate tempdir;
#[cfg(any(test, feature = "kvdb-rocksdb"))]
extern crate kvdb_rocksdb;
#[cfg(any(test, feature = "kvdb-lmdb"))]
extern crate kvdb_lmdb;
#[cfg(any(test, feature = "blooms-db"))]
extern crate blooms_db;
#[cfg(any(test, feature = "env_logger"))]
Expand Down
6 changes: 2 additions & 4 deletions ethcore/src/snapshot/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ mod tests {
let snapshot_params = ServiceParams {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
restoration_db_handler: restoration_db_handler(Default::default()),
restoration_db_handler: restoration_db_handler(),
pruning: Algorithm::Archive,
channel: service.channel(),
snapshot_root: dir,
Expand Down Expand Up @@ -912,14 +912,12 @@ mod tests {
#[test]
fn cannot_finish_with_invalid_chunks() {
use ethereum_types::H256;
use kvdb_rocksdb::DatabaseConfig;

let spec = Spec::new_test();
let tempdir = TempDir::new("").unwrap();

let state_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect();
let block_hashes: Vec<_> = (0..5).map(|_| H256::random()).collect();
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
let gb = spec.genesis_block();
let flag = ::std::sync::atomic::AtomicBool::new(true);

Expand All @@ -933,7 +931,7 @@ mod tests {
block_hash: H256::default(),
},
pruning: Algorithm::Archive,
db: restoration_db_handler(db_config).open(&tempdir.path().to_owned()).unwrap(),
db: restoration_db_handler().open(&tempdir.path().to_owned()).unwrap(),
writer: None,
genesis: &gb,
guard: Guard::benign(),
Expand Down
12 changes: 4 additions & 8 deletions ethcore/src/snapshot/tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use test_helpers::{new_db, new_temp_db, generate_dummy_client_with_spec_and_data

use parking_lot::Mutex;
use io::IoChannel;
use kvdb_rocksdb::DatabaseConfig;
use verification::queue::kind::blocks::Unverified;

#[test]
Expand All @@ -48,8 +47,7 @@ fn restored_is_equivalent() {
let client_db = tempdir.path().join("client_db");
let path = tempdir.path().join("snapshot");

let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
let restoration = restoration_db_handler(db_config);
let restoration = restoration_db_handler();
let blockchain_db = restoration.open(&client_db).unwrap();

let spec = Spec::new_null();
Expand Down Expand Up @@ -113,7 +111,7 @@ fn guards_delete_folders() {
let service_params = ServiceParams {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
restoration_db_handler: restoration_db_handler(DatabaseConfig::with_columns(::db::NUM_COLUMNS)),
restoration_db_handler: restoration_db_handler(),
pruning: ::journaldb::Algorithm::Archive,
channel: IoChannel::disconnected(),
snapshot_root: tempdir.path().to_owned(),
Expand Down Expand Up @@ -203,7 +201,6 @@ fn keep_ancient_blocks() {
writer.into_inner().finish(manifest.clone()).unwrap();

// Initialize the Client
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
let client_db = new_temp_db(&tempdir.path());
let client2 = Client::new(
ClientConfig::default(),
Expand All @@ -228,7 +225,7 @@ fn keep_ancient_blocks() {
let service_params = ServiceParams {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
restoration_db_handler: restoration_db_handler(db_config),
restoration_db_handler: restoration_db_handler(),
pruning: ::journaldb::Algorithm::Archive,
channel: IoChannel::disconnected(),
snapshot_root: tempdir.path().to_owned(),
Expand Down Expand Up @@ -278,7 +275,6 @@ fn recover_aborted_recovery() {

let spec = Spec::new_null();
let tempdir = TempDir::new("").unwrap();
let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
let client_db = new_db();
let client2 = Client::new(
Default::default(),
Expand All @@ -290,7 +286,7 @@ fn recover_aborted_recovery() {
let service_params = ServiceParams {
engine: spec.engine.clone(),
genesis_block: spec.genesis_block(),
restoration_db_handler: restoration_db_handler(db_config),
restoration_db_handler: restoration_db_handler(),
pruning: ::journaldb::Algorithm::Archive,
channel: IoChannel::disconnected(),
snapshot_root: tempdir.path().to_owned(),
Expand Down
11 changes: 4 additions & 7 deletions ethcore/src/snapshot/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use error::{Error, ErrorKind};
use rand::{XorShiftRng, SeedableRng};
use ethereum_types::H256;
use journaldb::{self, Algorithm};
use kvdb_rocksdb::{Database, DatabaseConfig};
use kvdb_lmdb::Database;
use memorydb::MemoryDB;
use parking_lot::Mutex;
use tempdir::TempDir;
Expand All @@ -41,7 +41,6 @@ fn snap_and_restore() {
let mut producer = StateProducer::new();
let mut rng = XorShiftRng::from_seed([1, 2, 3, 4]);
let mut old_db = MemoryDB::new();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);

for _ in 0..150 {
producer.tick(&mut rng, &mut old_db);
Expand Down Expand Up @@ -70,7 +69,7 @@ fn snap_and_restore() {

let db_path = tempdir.path().join("db");
let db = {
let new_db = Arc::new(Database::open(&db_cfg, &db_path.to_string_lossy()).unwrap());
let new_db = Arc::new(Database::open(&db_path.to_string_lossy(), ::db::NUM_COLUMNS.unwrap()).unwrap());
let mut rebuilder = StateRebuilder::new(new_db.clone(), Algorithm::OverlayRecent);
let reader = PackedReader::new(&snap_file).unwrap().unwrap();

Expand Down Expand Up @@ -134,8 +133,7 @@ fn get_code_from_prev_chunk() {
let chunk2 = make_chunk(acc, h2);

let tempdir = TempDir::new("").unwrap();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
let new_db = Arc::new(Database::open(&db_cfg, tempdir.path().to_str().unwrap()).unwrap());
let new_db = Arc::new(Database::open(tempdir.path().to_str().unwrap(), ::db::NUM_COLUMNS.unwrap()).unwrap());

{
let mut rebuilder = StateRebuilder::new(new_db.clone(), Algorithm::OverlayRecent);
Expand All @@ -156,7 +154,6 @@ fn checks_flag() {
let mut producer = StateProducer::new();
let mut rng = XorShiftRng::from_seed([5, 6, 7, 8]);
let mut old_db = MemoryDB::new();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);

for _ in 0..10 {
producer.tick(&mut rng, &mut old_db);
Expand All @@ -182,7 +179,7 @@ fn checks_flag() {
let tempdir = TempDir::new("").unwrap();
let db_path = tempdir.path().join("db");
{
let new_db = Arc::new(Database::open(&db_cfg, &db_path.to_string_lossy()).unwrap());
let new_db = Arc::new(Database::open(&db_path.to_string_lossy(), ::db::NUM_COLUMNS.unwrap()).unwrap());
let mut rebuilder = StateRebuilder::new(new_db.clone(), Algorithm::OverlayRecent);
let reader = PackedReader::new(&snap_file).unwrap().unwrap();

Expand Down
15 changes: 6 additions & 9 deletions ethcore/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use evm::Factory as EvmFactory;
use hash::keccak;
use io::IoChannel;
use kvdb::KeyValueDB;
use kvdb_rocksdb::{self, Database, DatabaseConfig};
use kvdb_lmdb::Database;
use parking_lot::RwLock;
use rlp::{self, RlpStream};
use tempdir::TempDir;
Expand Down Expand Up @@ -306,8 +306,7 @@ pub fn new_temp_db(tempdir: &Path) -> Arc<BlockChainDB> {
let trace_blooms_dir = TempDir::new("").unwrap();
let key_value_dir = tempdir.join("key_value");

let db_config = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
let key_value_db = Database::open(&db_config, key_value_dir.to_str().unwrap()).unwrap();
let key_value_db = Database::open(key_value_dir.to_str().unwrap(), ::db::NUM_COLUMNS.unwrap()).unwrap();

let db = TestBlockChainDB {
blooms: blooms_db::Database::open(blooms_dir.path()).unwrap(),
Expand All @@ -321,10 +320,8 @@ pub fn new_temp_db(tempdir: &Path) -> Arc<BlockChainDB> {
}

/// Creates new instance of KeyValueDBHandler
pub fn restoration_db_handler(config: kvdb_rocksdb::DatabaseConfig) -> Box<BlockChainDBHandler> {
struct RestorationDBHandler {
config: kvdb_rocksdb::DatabaseConfig,
}
pub fn restoration_db_handler() -> Box<BlockChainDBHandler> {
struct RestorationDBHandler {}

struct RestorationDB {
blooms: blooms_db::Database,
Expand All @@ -348,7 +345,7 @@ pub fn restoration_db_handler(config: kvdb_rocksdb::DatabaseConfig) -> Box<Block

impl BlockChainDBHandler for RestorationDBHandler {
fn open(&self, db_path: &Path) -> io::Result<Arc<BlockChainDB>> {
let key_value = Arc::new(kvdb_rocksdb::Database::open(&self.config, &db_path.to_string_lossy())?);
let key_value = Arc::new(Database::open(&db_path.to_string_lossy(), ::db::NUM_COLUMNS.unwrap())?);
let blooms_path = db_path.join("blooms");
let trace_blooms_path = db_path.join("trace_blooms");
fs::create_dir_all(&blooms_path)?;
Expand All @@ -364,7 +361,7 @@ pub fn restoration_db_handler(config: kvdb_rocksdb::DatabaseConfig) -> Box<Block
}
}

Box::new(RestorationDBHandler { config })
Box::new(RestorationDBHandler { })
}

/// Generates dummy blockchain with corresponding amount of blocks
Expand Down
Loading

0 comments on commit 48e44cb

Please sign in to comment.