mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2026-02-07 01:01:24 +01:00
To clear caches, restart the server. We may want to consider adding the cache sizes and database memory usage as metrics in the future.
67 lines
1.7 KiB
Rust
67 lines
1.7 KiB
Rust
use std::{future::Future, pin::Pin, sync::Arc};
|
|
|
|
use crate::Result;
|
|
|
|
#[cfg(feature = "sqlite")]
|
|
pub(crate) mod sqlite;
|
|
|
|
#[cfg(feature = "rocksdb")]
|
|
pub(crate) mod rocksdb;
|
|
|
|
#[cfg(any(feature = "sqlite", feature = "rocksdb",))]
|
|
pub(crate) mod watchers;
|
|
|
|
pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
|
|
#[cfg(any(feature = "sqlite", feature = "rocksdb"))]
|
|
fn open(config: &super::Config) -> Result<Self>
|
|
where
|
|
Self: Sized;
|
|
fn open_tree(&self, name: &'static str) -> Result<Arc<dyn KvTree>>;
|
|
fn cleanup(&self) -> Result<()> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub(crate) trait KvTree: Send + Sync {
|
|
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
|
|
|
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
|
|
fn insert_batch(
|
|
&self,
|
|
iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>,
|
|
) -> Result<()>;
|
|
|
|
fn remove(&self, key: &[u8]) -> Result<()>;
|
|
|
|
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
|
|
|
fn iter_from<'a>(
|
|
&'a self,
|
|
from: &[u8],
|
|
backwards: bool,
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
|
|
|
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>;
|
|
fn increment_batch(
|
|
&self,
|
|
iter: &mut dyn Iterator<Item = Vec<u8>>,
|
|
) -> Result<()>;
|
|
|
|
fn scan_prefix<'a>(
|
|
&'a self,
|
|
prefix: Vec<u8>,
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
|
|
|
fn watch_prefix<'a>(
|
|
&'a self,
|
|
prefix: &[u8],
|
|
) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
|
|
|
|
fn clear(&self) -> Result<()> {
|
|
for (key, _) in self.iter() {
|
|
self.remove(&key)?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|