|
|
|
@ -82,7 +82,7 @@ pub struct PersyEngine { |
|
|
|
impl DatabaseEngine for PersyEngine { |
|
|
|
impl DatabaseEngine for PersyEngine { |
|
|
|
fn open(config: &Config) -> Result<Arc<Self>> { |
|
|
|
fn open(config: &Config) -> Result<Arc<Self>> { |
|
|
|
let mut cfg = persy::Config::new(); |
|
|
|
let mut cfg = persy::Config::new(); |
|
|
|
cfg.change_cache_size(config.cache_capacity as u64); |
|
|
|
cfg.change_cache_size(config.db_cache_capacity_mb as u64 *1048576f64 as u64); |
|
|
|
|
|
|
|
|
|
|
|
let persy = OpenOptions::new() |
|
|
|
let persy = OpenOptions::new() |
|
|
|
.create(true) |
|
|
|
.create(true) |
|
|
|
@ -123,6 +123,10 @@ impl DatabaseEngine for PersyEngine { |
|
|
|
write_cache: self.write_cache.clone(), |
|
|
|
write_cache: self.write_cache.clone(), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn flush(self: &Arc<Self>) -> Result<()> { |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "persy")] |
|
|
|
#[cfg(feature = "persy")] |
|
|
|
@ -262,8 +266,8 @@ impl WriteCache { |
|
|
|
pub fn iter<'a>( |
|
|
|
pub fn iter<'a>( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
index: &str, |
|
|
|
index: &str, |
|
|
|
mut iter: Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + Sync + 'a>, |
|
|
|
mut iter: Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + Sync + 'a>, |
|
|
|
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + Sync + 'a> { |
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + Sync + 'a> { |
|
|
|
if let Some(adds) = self.add_cache.get(index) { |
|
|
|
if let Some(adds) = self.add_cache.get(index) { |
|
|
|
let added = adds.clone().into_iter().map(|(k, v)| (k.into(), v.into())); |
|
|
|
let added = adds.clone().into_iter().map(|(k, v)| (k.into(), v.into())); |
|
|
|
iter = Box::new(UnionIter::new(iter, added, false)) |
|
|
|
iter = Box::new(UnionIter::new(iter, added, false)) |
|
|
|
@ -282,8 +286,8 @@ impl WriteCache { |
|
|
|
index: &str, |
|
|
|
index: &str, |
|
|
|
from: &[u8], |
|
|
|
from: &[u8], |
|
|
|
backwards: bool, |
|
|
|
backwards: bool, |
|
|
|
mut iter: Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a>, |
|
|
|
mut iter: Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send+ 'a>, |
|
|
|
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a> { |
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> { |
|
|
|
if let Some(adds) = self.add_cache.get(index) { |
|
|
|
if let Some(adds) = self.add_cache.get(index) { |
|
|
|
let range = if backwards { |
|
|
|
let range = if backwards { |
|
|
|
adds.range(..from.to_owned()) |
|
|
|
adds.range(..from.to_owned()) |
|
|
|
@ -292,8 +296,8 @@ impl WriteCache { |
|
|
|
}; |
|
|
|
}; |
|
|
|
let added = range |
|
|
|
let added = range |
|
|
|
.map(|(k, v)| (k.to_owned().into(), v.to_owned().into())) |
|
|
|
.map(|(k, v)| (k.to_owned().into(), v.to_owned().into())) |
|
|
|
.collect::<Vec<(Box<[u8]>, Box<[u8]>)>>(); |
|
|
|
.collect::<Vec<(Vec<u8>, Vec<u8>)>>(); |
|
|
|
let add_iter: Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)>> = if backwards { |
|
|
|
let add_iter: Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send> = if backwards { |
|
|
|
Box::new(added.into_iter().rev()) |
|
|
|
Box::new(added.into_iter().rev()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Box::new(added.into_iter()) |
|
|
|
Box::new(added.into_iter()) |
|
|
|
@ -324,15 +328,15 @@ impl WriteCache { |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
index: &str, |
|
|
|
index: &str, |
|
|
|
prefix: Vec<u8>, |
|
|
|
prefix: Vec<u8>, |
|
|
|
mut iter: Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + 'a>, |
|
|
|
mut iter: Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a>, |
|
|
|
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + 'a> { |
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> { |
|
|
|
if let Some(adds) = self.add_cache.get(index) { |
|
|
|
if let Some(adds) = self.add_cache.get(index) { |
|
|
|
let owned_prefix = prefix.to_owned(); |
|
|
|
let owned_prefix = prefix.to_owned(); |
|
|
|
let added = adds |
|
|
|
let added = adds |
|
|
|
.range(prefix.to_owned()..) |
|
|
|
.range(prefix.to_owned()..) |
|
|
|
.take_while(move |(k, _)| k.starts_with(&owned_prefix)) |
|
|
|
.take_while(move |(k, _)| k.starts_with(&owned_prefix)) |
|
|
|
.map(|(k, v)| (k.to_owned().into(), v.to_owned().into())) |
|
|
|
.map(|(k, v)| (k.to_owned().into(), v.to_owned().into())) |
|
|
|
.collect::<Vec<(Box<[u8]>, Box<[u8]>)>>(); |
|
|
|
.collect::<Vec<(Vec<u8>, Vec<u8>)>>(); |
|
|
|
iter = Box::new(UnionIter::new(iter, added.into_iter(), false)) |
|
|
|
iter = Box::new(UnionIter::new(iter, added.into_iter(), false)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -472,7 +476,7 @@ impl Tree for PersyTree { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + Sync + 'a> { |
|
|
|
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> { |
|
|
|
let iter = self.persy.range::<ByteVec, ByteVec, _>(&self.name, ..); |
|
|
|
let iter = self.persy.range::<ByteVec, ByteVec, _>(&self.name, ..); |
|
|
|
match iter { |
|
|
|
match iter { |
|
|
|
Ok(iter) => { |
|
|
|
Ok(iter) => { |
|
|
|
@ -495,7 +499,7 @@ impl Tree for PersyTree { |
|
|
|
&'a self, |
|
|
|
&'a self, |
|
|
|
from: &[u8], |
|
|
|
from: &[u8], |
|
|
|
backwards: bool, |
|
|
|
backwards: bool, |
|
|
|
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + 'a> { |
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send + 'a> { |
|
|
|
let range = if backwards { |
|
|
|
let range = if backwards { |
|
|
|
self.persy |
|
|
|
self.persy |
|
|
|
.range::<ByteVec, ByteVec, _>(&self.name, ..ByteVec(from.to_owned())) |
|
|
|
.range::<ByteVec, ByteVec, _>(&self.name, ..ByteVec(from.to_owned())) |
|
|
|
@ -510,7 +514,7 @@ impl Tree for PersyTree { |
|
|
|
.map(|val| (k.0.to_owned().into(), val.0.to_owned().into())) |
|
|
|
.map(|val| (k.0.to_owned().into(), val.0.to_owned().into())) |
|
|
|
.next() |
|
|
|
.next() |
|
|
|
}); |
|
|
|
}); |
|
|
|
let result: Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)>> = if backwards { |
|
|
|
let result: Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send+'a > = if backwards { |
|
|
|
Box::new(map.rev()) |
|
|
|
Box::new(map.rev()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Box::new(map) |
|
|
|
Box::new(map) |
|
|
|
@ -530,7 +534,7 @@ impl Tree for PersyTree { |
|
|
|
|
|
|
|
|
|
|
|
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> { |
|
|
|
fn increment(&self, key: &[u8]) -> Result<Vec<u8>> { |
|
|
|
let old = self.get(key)?; |
|
|
|
let old = self.get(key)?; |
|
|
|
let new = utils::increment(old.as_deref()).unwrap(); |
|
|
|
let new = crate::utils::increment(old.as_deref()).unwrap(); |
|
|
|
self.insert(key, &new)?; |
|
|
|
self.insert(key, &new)?; |
|
|
|
Ok(new) |
|
|
|
Ok(new) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -538,7 +542,7 @@ impl Tree for PersyTree { |
|
|
|
fn scan_prefix<'a>( |
|
|
|
fn scan_prefix<'a>( |
|
|
|
&'a self, |
|
|
|
&'a self, |
|
|
|
prefix: Vec<u8>, |
|
|
|
prefix: Vec<u8>, |
|
|
|
) -> Box<dyn Iterator<Item = (Box<[u8]>, Box<[u8]>)> + Send + 'a> { |
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + Send+ 'a> { |
|
|
|
let range_prefix = ByteVec(prefix.to_owned()); |
|
|
|
let range_prefix = ByteVec(prefix.to_owned()); |
|
|
|
let range = self |
|
|
|
let range = self |
|
|
|
.persy |
|
|
|
.persy |
|
|
|
|