mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-07-02 16:38:36 +00:00
incorperate feedback
This commit is contained in:
parent
318d9c1a35
commit
3a76fda92b
6 changed files with 40 additions and 45 deletions
|
@ -7,15 +7,15 @@ use super::{DatabaseEngine, Tree};
|
|||
|
||||
use std::{collections::BTreeMap, sync::RwLock};
|
||||
|
||||
pub struct RocksDbEngine(rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>);
|
||||
pub struct Engine(rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>);
|
||||
|
||||
pub struct RocksDbEngineTree<'a> {
|
||||
db: Arc<RocksDbEngine>,
|
||||
db: Arc<Engine>,
|
||||
name: &'a str,
|
||||
watchers: RwLock<BTreeMap<Vec<u8>, Vec<tokio::sync::oneshot::Sender<()>>>>,
|
||||
}
|
||||
|
||||
impl DatabaseEngine for RocksDbEngine {
|
||||
impl DatabaseEngine for Engine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
let mut db_opts = rocksdb::Options::default();
|
||||
db_opts.create_if_missing(true);
|
||||
|
@ -45,7 +45,7 @@ impl DatabaseEngine for RocksDbEngine {
|
|||
.map(|name| rocksdb::ColumnFamilyDescriptor::new(name, options.clone())),
|
||||
)?;
|
||||
|
||||
Ok(Arc::new(RocksDbEngine(db)))
|
||||
Ok(Arc::new(Engine(db)))
|
||||
}
|
||||
|
||||
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>> {
|
||||
|
|
|
@ -5,13 +5,13 @@ use std::{future::Future, pin::Pin, sync::Arc};
|
|||
|
||||
use super::{DatabaseEngine, Tree};
|
||||
|
||||
pub struct SledEngine(sled::Db);
|
||||
pub struct Engine(sled::Db);
|
||||
|
||||
pub struct SledEngineTree(sled::Tree);
|
||||
|
||||
impl DatabaseEngine for SledEngine {
|
||||
impl DatabaseEngine for Engine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
Ok(Arc::new(SledEngine(
|
||||
Ok(Arc::new(Engine(
|
||||
sled::Config::default()
|
||||
.path(&config.database_path)
|
||||
.cache_capacity(config.cache_capacity as u64)
|
||||
|
|
|
@ -119,22 +119,22 @@ impl Pool {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct SqliteEngine {
|
||||
pub struct Engine {
|
||||
pool: Pool,
|
||||
}
|
||||
|
||||
impl DatabaseEngine for SqliteEngine {
|
||||
impl DatabaseEngine for Engine {
|
||||
fn open(config: &Config) -> Result<Arc<Self>> {
|
||||
let pool = Pool::new(
|
||||
Path::new(&config.database_path).join("conduit.db"),
|
||||
config.sqlite_read_pool_size,
|
||||
config.sqlite_cache_kib,
|
||||
config.db_cache_capacity / 1024, // bytes -> kb
|
||||
)?;
|
||||
|
||||
pool.write_lock()
|
||||
.execute("CREATE TABLE IF NOT EXISTS _noop (\"key\" INT)", params![])?;
|
||||
|
||||
let arc = Arc::new(SqliteEngine { pool });
|
||||
let arc = Arc::new(Engine { pool });
|
||||
|
||||
Ok(arc)
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ impl DatabaseEngine for SqliteEngine {
|
|||
}
|
||||
}
|
||||
|
||||
impl SqliteEngine {
|
||||
impl Engine {
|
||||
pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
|
||||
self.pool
|
||||
.write_lock()
|
||||
|
@ -185,7 +185,7 @@ impl SqliteEngine {
|
|||
}
|
||||
|
||||
pub struct SqliteTable {
|
||||
engine: Arc<SqliteEngine>,
|
||||
engine: Arc<Engine>,
|
||||
name: String,
|
||||
watchers: RwLock<BTreeMap<Vec<u8>, Vec<Sender<()>>>>,
|
||||
}
|
||||
|
@ -257,19 +257,19 @@ impl Tree for SqliteTable {
|
|||
}
|
||||
|
||||
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
||||
{
|
||||
let guard = self.engine.pool.write_lock();
|
||||
let guard = self.engine.pool.write_lock();
|
||||
|
||||
let start = Instant::now();
|
||||
let start = Instant::now();
|
||||
|
||||
self.insert_with_guard(&guard, key, value)?;
|
||||
self.insert_with_guard(&guard, key, value)?;
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
if elapsed > MILLI {
|
||||
debug!("insert: took {:012?} : {}", elapsed, &self.name);
|
||||
}
|
||||
let elapsed = start.elapsed();
|
||||
if elapsed > MILLI {
|
||||
debug!("insert: took {:012?} : {}", elapsed, &self.name);
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
||||
let watchers = self.watchers.read();
|
||||
let mut triggered = Vec::new();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue