rocksdb abstraction layer
This commit is contained in:
@@ -10,7 +10,6 @@ authors = ["Ethcore <admin@ethcore.io>"]
|
||||
log = "0.3"
|
||||
env_logger = "0.3"
|
||||
rustc-serialize = "0.3"
|
||||
rocksdb = "0.3"
|
||||
heapsize = "0.2.0"
|
||||
rust-crypto = "0.2.34"
|
||||
time = "0.1"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Blockchain database.
|
||||
|
||||
use util::*;
|
||||
use rocksdb::{DB, WriteBatch, Writable};
|
||||
use header::*;
|
||||
use extras::*;
|
||||
use transaction::*;
|
||||
@@ -162,8 +161,8 @@ pub struct BlockChain {
|
||||
block_logs: RwLock<HashMap<H256, BlockLogBlooms>>,
|
||||
blocks_blooms: RwLock<HashMap<H256, BlocksBlooms>>,
|
||||
|
||||
extras_db: DB,
|
||||
blocks_db: DB,
|
||||
extras_db: Database,
|
||||
blocks_db: Database,
|
||||
|
||||
cache_man: RwLock<CacheManager>,
|
||||
}
|
||||
@@ -250,12 +249,12 @@ impl BlockChain {
|
||||
// open extras db
|
||||
let mut extras_path = path.to_path_buf();
|
||||
extras_path.push("extras");
|
||||
let extras_db = DB::open_default(extras_path.to_str().unwrap()).unwrap();
|
||||
let extras_db = Database::open_default(extras_path.to_str().unwrap()).unwrap();
|
||||
|
||||
// open blocks db
|
||||
let mut blocks_path = path.to_path_buf();
|
||||
blocks_path.push("blocks");
|
||||
let blocks_db = DB::open_default(blocks_path.to_str().unwrap()).unwrap();
|
||||
let blocks_db = Database::open_default(blocks_path.to_str().unwrap()).unwrap();
|
||||
|
||||
let mut cache_man = CacheManager{cache_usage: VecDeque::new(), in_use: HashSet::new()};
|
||||
(0..COLLECTION_QUEUE_SIZE).foreach(|_| cache_man.cache_usage.push_back(HashSet::new()));
|
||||
@@ -294,7 +293,7 @@ impl BlockChain {
|
||||
|
||||
bc.blocks_db.put(&hash, genesis).unwrap();
|
||||
|
||||
let batch = WriteBatch::new();
|
||||
let batch = DBTransaction::new();
|
||||
batch.put_extras(&hash, &details);
|
||||
batch.put_extras(&header.number(), &hash);
|
||||
batch.put(b"best", &hash).unwrap();
|
||||
@@ -457,7 +456,7 @@ impl BlockChain {
|
||||
|
||||
/// Transforms block into WriteBatch that may be written into database
|
||||
/// Additionally, if it's new best block it returns new best block object.
|
||||
fn block_to_extras_insert_batch(&self, bytes: &[u8]) -> (WriteBatch, Option<BestBlock>, BlockDetails) {
|
||||
fn block_to_extras_insert_batch(&self, bytes: &[u8]) -> (DBTransaction, Option<BestBlock>, BlockDetails) {
|
||||
// create views onto rlp
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
@@ -478,7 +477,7 @@ impl BlockChain {
|
||||
};
|
||||
|
||||
// prepare the batch
|
||||
let batch = WriteBatch::new();
|
||||
let batch = DBTransaction::new();
|
||||
|
||||
// insert new block details
|
||||
batch.put_extras(&hash, &details);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
use util::*;
|
||||
use util::panics::*;
|
||||
use rocksdb::{Options, DB, DBCompactionStyle};
|
||||
use blockchain::{BlockChain, BlockProvider, CacheSize};
|
||||
use views::BlockView;
|
||||
use error::*;
|
||||
@@ -179,7 +178,7 @@ pub struct Client {
|
||||
}
|
||||
|
||||
const HISTORY: u64 = 1000;
|
||||
const CLIENT_DB_VER_STR: &'static str = "2.1";
|
||||
const CLIENT_DB_VER_STR: &'static str = "3.0";
|
||||
|
||||
impl Client {
|
||||
/// Create a new client with given spec and DB path.
|
||||
@@ -191,34 +190,11 @@ impl Client {
|
||||
let path = dir.as_path();
|
||||
let gb = spec.genesis_block();
|
||||
let chain = Arc::new(RwLock::new(BlockChain::new(&gb, path)));
|
||||
let mut opts = Options::new();
|
||||
opts.set_max_open_files(256);
|
||||
opts.create_if_missing(true);
|
||||
opts.set_use_fsync(false);
|
||||
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
|
||||
/*
|
||||
opts.set_bytes_per_sync(8388608);
|
||||
opts.set_disable_data_sync(false);
|
||||
opts.set_block_cache_size_mb(1024);
|
||||
opts.set_table_cache_num_shard_bits(6);
|
||||
opts.set_max_write_buffer_number(32);
|
||||
opts.set_write_buffer_size(536870912);
|
||||
opts.set_target_file_size_base(1073741824);
|
||||
opts.set_min_write_buffer_number_to_merge(4);
|
||||
opts.set_level_zero_stop_writes_trigger(2000);
|
||||
opts.set_level_zero_slowdown_writes_trigger(0);
|
||||
opts.set_compaction_style(DBUniversalCompaction);
|
||||
opts.set_max_background_compactions(4);
|
||||
opts.set_max_background_flushes(4);
|
||||
opts.set_filter_deletes(false);
|
||||
opts.set_disable_auto_compactions(false);*/
|
||||
|
||||
let mut state_path = path.to_path_buf();
|
||||
state_path.push("state");
|
||||
let db = Arc::new(DB::open(&opts, state_path.to_str().unwrap()).unwrap());
|
||||
|
||||
let engine = Arc::new(try!(spec.to_engine()));
|
||||
let mut state_db = JournalDB::new_with_arc(db.clone());
|
||||
let mut state_db = JournalDB::new(state_path.to_str().unwrap());
|
||||
if state_db.is_empty() && engine.spec().ensure_db_good(&mut state_db) {
|
||||
state_db.commit(0, &engine.spec().genesis_header().hash(), None).expect("Error commiting genesis state to state DB");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
use util::*;
|
||||
use header::BlockNumber;
|
||||
use rocksdb::{DB, Writable};
|
||||
|
||||
/// Represents index of extra data in database
|
||||
#[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)]
|
||||
@@ -56,7 +55,7 @@ pub trait ExtrasReadable {
|
||||
K: ExtrasSliceConvertable;
|
||||
}
|
||||
|
||||
impl<W> ExtrasWritable for W where W: Writable {
|
||||
impl ExtrasWritable for DBTransaction {
|
||||
fn put_extras<K, T>(&self, hash: &K, value: &T) where
|
||||
T: ExtrasIndexable + Encodable,
|
||||
K: ExtrasSliceConvertable {
|
||||
@@ -65,7 +64,7 @@ impl<W> ExtrasWritable for W where W: Writable {
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtrasReadable for DB {
|
||||
impl ExtrasReadable for Database {
|
||||
fn get_extras<K, T>(&self, hash: &K) -> Option<T> where
|
||||
T: ExtrasIndexable + Decodable,
|
||||
K: ExtrasSliceConvertable {
|
||||
|
||||
@@ -86,7 +86,6 @@
|
||||
#[macro_use] extern crate ethcore_util as util;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate rustc_serialize;
|
||||
extern crate rocksdb;
|
||||
extern crate heapsize;
|
||||
extern crate crypto;
|
||||
extern crate time;
|
||||
|
||||
@@ -22,7 +22,6 @@ use spec::*;
|
||||
use std::fs::{remove_dir_all};
|
||||
use blockchain::{BlockChain};
|
||||
use state::*;
|
||||
use rocksdb::*;
|
||||
use evm::{Schedule, Factory};
|
||||
use engine::*;
|
||||
use ethereum;
|
||||
@@ -258,8 +257,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
|
||||
|
||||
pub fn get_temp_journal_db() -> GuardedTempResult<JournalDB> {
|
||||
let temp = RandomTempPath::new();
|
||||
let db = DB::open_default(temp.as_str()).unwrap();
|
||||
let journal_db = JournalDB::new(db);
|
||||
let journal_db = JournalDB::new(temp.as_str());
|
||||
GuardedTempResult {
|
||||
_temp: temp,
|
||||
result: Some(journal_db)
|
||||
@@ -276,8 +274,7 @@ pub fn get_temp_state() -> GuardedTempResult<State> {
|
||||
}
|
||||
|
||||
pub fn get_temp_journal_db_in(path: &Path) -> JournalDB {
|
||||
let db = DB::open_default(path.to_str().unwrap()).unwrap();
|
||||
JournalDB::new(db)
|
||||
JournalDB::new(path.to_str().unwrap())
|
||||
}
|
||||
|
||||
pub fn get_temp_state_in(path: &Path) -> State {
|
||||
|
||||
Reference in New Issue
Block a user