1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-31 12:18:31 +00:00

add frontend threadpool to database

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-11-27 06:28:32 +00:00
parent 94d7b21cf0
commit c7ae951676
10 changed files with 362 additions and 57 deletions

View file

@ -1,17 +1,21 @@
use std::{convert::AsRef, fmt::Debug, future::Future, io::Write};
use std::{convert::AsRef, fmt::Debug, future::Future, io::Write, sync::Arc};
use arrayvec::ArrayVec;
use conduit::{implement, utils::TryFutureExtExt, Err, Result};
use futures::future::ready;
use conduit::{
err, implement,
utils::{future::TryExtExt, result::FlatOk},
Result,
};
use futures::FutureExt;
use serde::Serialize;
use crate::{ser, util};
use crate::ser;
/// Returns true if the map contains the key.
/// - key is serialized into allocated buffer
/// - harder errors may not be reported
#[implement(super::Map)]
pub fn contains<K>(&self, key: &K) -> impl Future<Output = bool> + Send
pub fn contains<K>(self: &Arc<Self>, key: &K) -> impl Future<Output = bool> + Send + '_
where
K: Serialize + ?Sized + Debug,
{
@ -23,7 +27,7 @@ where
/// - key is serialized into stack-buffer
/// - harder errors will panic
#[implement(super::Map)]
pub fn acontains<const MAX: usize, K>(&self, key: &K) -> impl Future<Output = bool> + Send
pub fn acontains<const MAX: usize, K>(self: &Arc<Self>, key: &K) -> impl Future<Output = bool> + Send + '_
where
K: Serialize + ?Sized + Debug,
{
@ -36,7 +40,7 @@ where
/// - harder errors will panic
#[implement(super::Map)]
#[tracing::instrument(skip(self, buf), fields(%self), level = "trace")]
pub fn bcontains<K, B>(&self, key: &K, buf: &mut B) -> impl Future<Output = bool> + Send
pub fn bcontains<K, B>(self: &Arc<Self>, key: &K, buf: &mut B) -> impl Future<Output = bool> + Send + '_
where
K: Serialize + ?Sized + Debug,
B: Write + AsRef<[u8]>,
@ -48,41 +52,36 @@ where
/// Returns Ok if the map contains the key.
/// - key is raw
#[implement(super::Map)]
pub fn exists<K>(&self, key: &K) -> impl Future<Output = Result<()>> + Send
pub fn exists<'a, K>(self: &'a Arc<Self>, key: &K) -> impl Future<Output = Result> + Send + 'a
where
K: AsRef<[u8]> + ?Sized + Debug,
K: AsRef<[u8]> + ?Sized + Debug + 'a,
{
ready(self.exists_blocking(key))
self.get(key).map(|res| res.map(|_| ()))
}
/// Returns Ok if the map contains the key; NotFound otherwise. Harder errors
/// may not always be reported properly.
#[implement(super::Map)]
#[tracing::instrument(skip(self, key), fields(%self), level = "trace")]
pub fn exists_blocking<K>(&self, key: &K) -> Result<()>
pub fn exists_blocking<K>(&self, key: &K) -> Result
where
K: AsRef<[u8]> + ?Sized + Debug,
{
if self.maybe_exists_blocking(key)
&& self
.db
.db
.get_pinned_cf_opt(&self.cf(), key, &self.read_options)
.map_err(util::map_err)?
.is_some()
{
Ok(())
} else {
Err!(Request(NotFound("Not found in database")))
}
self.maybe_exists(key)
.then(|| self.get_blocking(key))
.flat_ok()
.map(|_| ())
.ok_or_else(|| err!(Request(NotFound("Not found in database"))))
}
/// Rocksdb limits this to kBlockCacheTier internally so this is not actually a
/// blocking call; in case that changes we set this as well in our read_options.
#[implement(super::Map)]
fn maybe_exists_blocking<K>(&self, key: &K) -> bool
pub(crate) fn maybe_exists<K>(&self, key: &K) -> bool
where
K: AsRef<[u8]> + ?Sized,
{
self.db
.db
.key_may_exist_cf_opt(&self.cf(), key, &self.read_options)
.key_may_exist_cf_opt(&self.cf(), key, &self.cache_read_options)
}