add rocksdb secondary; fix read_only mode.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
6b80361c31
commit
96fcf7f94d
5 changed files with 27 additions and 2 deletions
|
@ -38,6 +38,14 @@ impl Database {
|
|||
|
||||
#[inline]
|
||||
pub fn iter_maps(&self) -> impl Iterator<Item = (&MapsKey, &MapsVal)> + Send + '_ { self.map.iter() }
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_read_only(&self) -> bool { self.db.secondary || self.db.read_only }
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_secondary(&self) -> bool { self.db.secondary }
|
||||
}
|
||||
|
||||
impl Index<&str> for Database {
|
||||
|
|
|
@ -28,6 +28,8 @@ pub struct Engine {
|
|||
cfs: Mutex<BTreeSet<String>>,
|
||||
pub(crate) db: Db,
|
||||
corks: AtomicU32,
|
||||
pub(super) read_only: bool,
|
||||
pub(super) secondary: bool,
|
||||
}
|
||||
|
||||
pub(crate) type Db = DBWithThreadMode<MultiThreaded>;
|
||||
|
@ -80,10 +82,13 @@ impl Engine {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
debug!("Opening database...");
|
||||
let path = &config.database_path;
|
||||
let res = if config.rocksdb_read_only {
|
||||
Db::open_cf_for_read_only(&db_opts, &config.database_path, cfs.clone(), false)
|
||||
Db::open_cf_descriptors_read_only(&db_opts, path, cfds, false)
|
||||
} else if config.rocksdb_secondary {
|
||||
Db::open_cf_descriptors_as_secondary(&db_opts, path, path, cfds)
|
||||
} else {
|
||||
Db::open_cf_descriptors(&db_opts, &config.database_path, cfds)
|
||||
Db::open_cf_descriptors(&db_opts, path, cfds)
|
||||
};
|
||||
|
||||
let db = res.or_else(or_else)?;
|
||||
|
@ -103,6 +108,8 @@ impl Engine {
|
|||
cfs: Mutex::new(cfs),
|
||||
db,
|
||||
corks: AtomicU32::new(0),
|
||||
read_only: config.rocksdb_read_only,
|
||||
secondary: config.rocksdb_secondary,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue