Fix rocks db startup issues
This commit is contained in:
parent
08b1808745
commit
f4bd46fe66
@ -2,6 +2,7 @@ extern crate rocksdb;
|
|||||||
|
|
||||||
use super::rocksdb::Error as RocksError;
|
use super::rocksdb::Error as RocksError;
|
||||||
use super::rocksdb::{Options, DB};
|
use super::rocksdb::{Options, DB};
|
||||||
|
use super::stores::COLUMNS;
|
||||||
use super::{ClientDB, DBError, DBValue};
|
use super::{ClientDB, DBError, DBValue};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -23,31 +24,32 @@ impl DiskDB {
|
|||||||
///
|
///
|
||||||
/// Panics if the database is unable to be created.
|
/// Panics if the database is unable to be created.
|
||||||
pub fn open(path: &Path, columns: Option<&[&str]>) -> Self {
|
pub fn open(path: &Path, columns: Option<&[&str]>) -> Self {
|
||||||
/*
|
// Rocks options.
|
||||||
* Initialise the options
|
|
||||||
*/
|
|
||||||
let mut options = Options::default();
|
let mut options = Options::default();
|
||||||
options.create_if_missing(true);
|
options.create_if_missing(true);
|
||||||
|
|
||||||
// TODO: ensure that columns are created (and remove
|
// Ensure the path exists.
|
||||||
// the dead_code allow)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialise the path
|
|
||||||
*/
|
|
||||||
fs::create_dir_all(&path).unwrap_or_else(|_| panic!("Unable to create {:?}", &path));
|
fs::create_dir_all(&path).unwrap_or_else(|_| panic!("Unable to create {:?}", &path));
|
||||||
let db_path = path.join("database");
|
let db_path = path.join("database");
|
||||||
|
|
||||||
/*
|
let columns = columns.unwrap_or(&COLUMNS);
|
||||||
* Open the database
|
|
||||||
*/
|
|
||||||
let db = match columns {
|
|
||||||
None => DB::open(&options, db_path),
|
|
||||||
Some(columns) => DB::open_cf(&options, db_path, columns),
|
|
||||||
}
|
|
||||||
.expect("Unable to open local database");;
|
|
||||||
|
|
||||||
Self { db }
|
if db_path.exists() {
|
||||||
|
Self {
|
||||||
|
db: DB::open_cf(&options, db_path, &COLUMNS)
|
||||||
|
.expect("Unable to open local database"),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mut db = Self {
|
||||||
|
db: DB::open(&options, db_path).expect("Unable to open local database"),
|
||||||
|
};
|
||||||
|
|
||||||
|
for cf in columns {
|
||||||
|
db.create_col(cf).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
db
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a RocksDB column family. Corresponds to the
|
/// Create a RocksDB column family. Corresponds to the
|
||||||
|
Loading…
Reference in New Issue
Block a user