Browse Source

fixed compilation issues after migration

merge-requests/107/merge^2
Tglman 5 years ago
parent
commit
d4f9f958b1
  1. 34
      src/database/abstraction.rs
  2. 1
      src/error.rs

34
src/database/abstraction.rs

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

1
src/error.rs

@ -35,6 +35,7 @@ pub enum Error { @@ -35,6 +35,7 @@ pub enum Error {
SqliteError {
#[from]
source: rusqlite::Error,
},
#[cfg(feature = "persy")]
#[error("There was a problem with the connection to the persy database.")]
PersyError {

Loading…
Cancel
Save