Modify runtime to allow memory or disk db

DiskDB is not working yet, but we'll get there!
This commit is contained in:
Paul Hauner
2019-03-31 18:57:48 +11:00
parent 9a0ebac687
commit 08b1808745
6 changed files with 107 additions and 13 deletions

View File

@@ -58,6 +58,15 @@ fn main() {
.help("Listen port for RPC endpoint.")
.takes_value(true),
)
.arg(
Arg::with_name("db")
.long("db")
.value_name("DB")
.help("Type of database to use.")
.takes_value(true)
.possible_values(&["rocks", "memory"])
.default_value("memory"),
)
.get_matches();
// invalid arguments, panic

View File

@@ -1,15 +1,18 @@
use client::client_types::TestingClientType;
use client::client_types::{DiskDBTestingClientType, MemoryDBTestingClientType};
use client::error;
use client::{notifier, Client, ClientConfig};
use client::{notifier, Client, ClientConfig, ClientTypes};
use db::DBType;
use futures::sync::oneshot;
use futures::Future;
use slog::info;
use std::cell::RefCell;
use tokio::runtime::Builder;
use tokio::runtime::Runtime;
use tokio::runtime::TaskExecutor;
use tokio_timer::clock::Clock;
pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Result<()> {
let mut runtime = Builder::new()
let runtime = Builder::new()
.name_prefix("main-")
.clock(Clock::system())
.build()
@@ -20,8 +23,32 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul
"data_dir" => &config.data_dir.to_str(),
"port" => &config.net_conf.listen_port);
let executor = runtime.executor();
match config.db_type {
DBType::RocksDB => {
let client: Client<DiskDBTestingClientType> =
Client::new(config, log.clone(), &executor)?;
run(client, executor, runtime, log)
}
DBType::Memory => {
let client: Client<MemoryDBTestingClientType> =
Client::new(config, log.clone(), &executor)?;
run(client, executor, runtime, log)
}
}
}
pub fn run<T: ClientTypes>(
client: Client<T>,
executor: TaskExecutor,
mut runtime: Runtime,
log: &slog::Logger,
) -> error::Result<()> {
// run service until ctrl-c
let (ctrlc_send, ctrlc) = oneshot::channel();
let (ctrlc_send, ctrlc_oneshot) = oneshot::channel();
let ctrlc_send_c = RefCell::new(Some(ctrlc_send));
ctrlc::set_handler(move || {
if let Some(ctrlc_send) = ctrlc_send_c.try_borrow_mut().unwrap().take() {
@@ -32,14 +59,10 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul
let (exit_signal, exit) = exit_future::signal();
let executor = runtime.executor();
// currently testing - using TestingClientType
let client: Client<TestingClientType> = Client::new(config, log.clone(), &executor)?;
notifier::run(&client, executor, exit);
runtime
.block_on(ctrlc)
.block_on(ctrlc_oneshot)
.map_err(|e| format!("Ctrlc oneshot failed: {:?}", e))?;
// perform global shutdown operations.