offload initial iterator seeks to threadpool
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
320b0680bd
commit
b5006a4c41
20 changed files with 361 additions and 131 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt::Debug, future::Future};
|
||||
use std::{fmt::Debug, future::Future, sync::Arc};
|
||||
|
||||
use conduit::implement;
|
||||
use futures::stream::StreamExt;
|
||||
|
@ -14,7 +14,7 @@ pub fn count(&self) -> impl Future<Output = usize> + Send + '_ { self.raw_keys()
|
|||
/// - From is a structured key
|
||||
#[implement(super::Map)]
|
||||
#[inline]
|
||||
pub fn count_from<'a, P>(&'a self, from: &P) -> impl Future<Output = usize> + Send + 'a
|
||||
pub fn count_from<'a, P>(self: &'a Arc<Self>, from: &P) -> impl Future<Output = usize> + Send + 'a
|
||||
where
|
||||
P: Serialize + ?Sized + Debug + 'a,
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ where
|
|||
/// - From is a raw
|
||||
#[implement(super::Map)]
|
||||
#[inline]
|
||||
pub fn raw_count_from<'a, P>(&'a self, from: &'a P) -> impl Future<Output = usize> + Send + 'a
|
||||
pub fn raw_count_from<'a, P>(self: &'a Arc<Self>, from: &'a P) -> impl Future<Output = usize> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ where
|
|||
/// - Prefix is structured key
|
||||
#[implement(super::Map)]
|
||||
#[inline]
|
||||
pub fn count_prefix<'a, P>(&'a self, prefix: &P) -> impl Future<Output = usize> + Send + 'a
|
||||
pub fn count_prefix<'a, P>(self: &'a Arc<Self>, prefix: &P) -> impl Future<Output = usize> + Send + 'a
|
||||
where
|
||||
P: Serialize + ?Sized + Debug + 'a,
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ where
|
|||
/// - Prefix is raw
|
||||
#[implement(super::Map)]
|
||||
#[inline]
|
||||
pub fn raw_count_prefix<'a, P>(&'a self, prefix: &'a P) -> impl Future<Output = usize> + Send + 'a
|
||||
pub fn raw_count_prefix<'a, P>(self: &'a Arc<Self>, prefix: &'a P) -> impl Future<Output = usize> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
{
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
use std::{convert::AsRef, fmt::Debug, io::Write, sync::Arc};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use conduit::{err, implement, utils::IterStream, Err, Result};
|
||||
use conduit::{
|
||||
err, implement,
|
||||
utils::{result::MapExpect, IterStream},
|
||||
Err, Result,
|
||||
};
|
||||
use futures::{future, Future, FutureExt, Stream, StreamExt};
|
||||
use rocksdb::DBPinnableSlice;
|
||||
use serde::Serialize;
|
||||
|
@ -74,21 +78,21 @@ pub fn get<K>(self: &Arc<Self>, key: &K) -> impl Future<Output = Result<Handle<'
|
|||
where
|
||||
K: AsRef<[u8]> + Debug + ?Sized,
|
||||
{
|
||||
use crate::pool::{Cmd, Get};
|
||||
use crate::pool::Get;
|
||||
|
||||
let cached = self.get_cached(key);
|
||||
if matches!(cached, Err(_) | Ok(Some(_))) {
|
||||
return future::ready(cached.map(|res| res.expect("Option is Some"))).boxed();
|
||||
return future::ready(cached.map_expect("data found in cache")).boxed();
|
||||
}
|
||||
|
||||
debug_assert!(matches!(cached, Ok(None)), "expected status Incomplete");
|
||||
let cmd = Cmd::Get(Get {
|
||||
let cmd = Get {
|
||||
map: self.clone(),
|
||||
key: key.as_ref().into(),
|
||||
res: None,
|
||||
});
|
||||
};
|
||||
|
||||
self.db.pool.execute(cmd).boxed()
|
||||
self.db.pool.execute_get(cmd).boxed()
|
||||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use conduit::{implement, Result};
|
|||
use futures::{Stream, StreamExt};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{keyval, keyval::Key, stream};
|
||||
use crate::{keyval, keyval::Key, stream, stream::Cursor};
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn keys<'a, K>(&'a self) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
|
@ -16,5 +16,5 @@ where
|
|||
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||
pub fn raw_keys(&self) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
||||
let opts = super::read_options_default();
|
||||
stream::Keys::new(&self.db, &self.cf, opts, None)
|
||||
stream::Keys::new(&self.db, &self.cf, opts).init(None)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::{Stream, StreamExt};
|
||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||
use rocksdb::Direction;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
|
@ -10,7 +11,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn keys_from<'a, K, P>(&'a self, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
pub fn keys_from<'a, K, P>(self: &'a Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -20,7 +21,7 @@ where
|
|||
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn keys_from_raw<P>(&self, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
pub fn keys_from_raw<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ where
|
|||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn keys_raw_from<'a, K, P>(&'a self, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
pub fn keys_raw_from<'a, K, P>(self: &'a Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -39,10 +40,27 @@ where
|
|||
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||
pub fn raw_keys_from<P>(&self, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
pub fn raw_keys_from<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug,
|
||||
{
|
||||
use crate::pool::Seek;
|
||||
|
||||
let opts = super::read_options_default();
|
||||
stream::Keys::new(&self.db, &self.cf, opts, Some(from.as_ref()))
|
||||
let state = stream::State::new(&self.db, &self.cf, opts);
|
||||
let seek = Seek {
|
||||
map: self.clone(),
|
||||
dir: Direction::Forward,
|
||||
key: Some(from.as_ref().into()),
|
||||
state: crate::pool::into_send_seek(state),
|
||||
res: None,
|
||||
};
|
||||
|
||||
self.db
|
||||
.pool
|
||||
.execute_iter(seek)
|
||||
.ok_into::<stream::Keys<'_>>()
|
||||
.into_stream()
|
||||
.try_flatten()
|
||||
.boxed()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::{
|
||||
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::keyval::{result_deserialize_key, serialize_key, Key};
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn keys_prefix<'a, K, P>(&'a self, prefix: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
pub fn keys_prefix<'a, K, P>(self: &'a Arc<Self>, prefix: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -22,7 +22,7 @@ where
|
|||
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn keys_prefix_raw<P>(&self, prefix: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
pub fn keys_prefix_raw<P>(self: &Arc<Self>, prefix: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -32,7 +32,9 @@ where
|
|||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn keys_raw_prefix<'a, K, P>(&'a self, prefix: &'a P) -> impl Stream<Item = Result<Key<'_, K>>> + Send + 'a
|
||||
pub fn keys_raw_prefix<'a, K, P>(
|
||||
self: &'a Arc<Self>, prefix: &'a P,
|
||||
) -> impl Stream<Item = Result<Key<'_, K>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
K: Deserialize<'a> + Send + 'a,
|
||||
|
@ -42,7 +44,7 @@ where
|
|||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn raw_keys_prefix<'a, P>(&'a self, prefix: &'a P) -> impl Stream<Item = Result<Key<'_>>> + Send + 'a
|
||||
pub fn raw_keys_prefix<'a, P>(self: &'a Arc<Self>, prefix: &'a P) -> impl Stream<Item = Result<Key<'_>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ use conduit::{implement, Result};
|
|||
use futures::{Stream, StreamExt};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{keyval, keyval::Key, stream};
|
||||
use crate::{keyval, keyval::Key, stream, stream::Cursor};
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_keys<'a, K>(&'a self) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
|
@ -16,5 +16,5 @@ where
|
|||
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||
pub fn rev_raw_keys(&self) -> impl Stream<Item = Result<Key<'_>>> + Send {
|
||||
let opts = super::read_options_default();
|
||||
stream::KeysRev::new(&self.db, &self.cf, opts, None)
|
||||
stream::KeysRev::new(&self.db, &self.cf, opts).init(None)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::{Stream, StreamExt};
|
||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
|
||||
use rocksdb::Direction;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
|
@ -10,7 +11,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_keys_from<'a, K, P>(&'a self, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
pub fn rev_keys_from<'a, K, P>(self: &'a Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -21,7 +22,7 @@ where
|
|||
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn rev_keys_from_raw<P>(&self, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
pub fn rev_keys_from_raw<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -30,7 +31,7 @@ where
|
|||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_keys_raw_from<'a, K, P>(&'a self, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
pub fn rev_keys_raw_from<'a, K, P>(self: &'a Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -41,10 +42,27 @@ where
|
|||
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||
pub fn rev_raw_keys_from<P>(&self, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
pub fn rev_raw_keys_from<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug,
|
||||
{
|
||||
use crate::pool::Seek;
|
||||
|
||||
let opts = super::read_options_default();
|
||||
stream::KeysRev::new(&self.db, &self.cf, opts, Some(from.as_ref()))
|
||||
let state = stream::State::new(&self.db, &self.cf, opts);
|
||||
let seek = Seek {
|
||||
map: self.clone(),
|
||||
dir: Direction::Reverse,
|
||||
key: Some(from.as_ref().into()),
|
||||
state: crate::pool::into_send_seek(state),
|
||||
res: None,
|
||||
};
|
||||
|
||||
self.db
|
||||
.pool
|
||||
.execute_iter(seek)
|
||||
.ok_into::<stream::KeysRev<'_>>()
|
||||
.into_stream()
|
||||
.try_flatten()
|
||||
.boxed()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::{
|
||||
|
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::keyval::{result_deserialize_key, serialize_key, Key};
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_keys_prefix<'a, K, P>(&'a self, prefix: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
pub fn rev_keys_prefix<'a, K, P>(self: &'a Arc<Self>, prefix: &P) -> impl Stream<Item = Result<Key<'_, K>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -22,7 +22,7 @@ where
|
|||
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn rev_keys_prefix_raw<P>(&self, prefix: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
pub fn rev_keys_prefix_raw<P>(self: &Arc<Self>, prefix: &P) -> impl Stream<Item = Result<Key<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -32,7 +32,9 @@ where
|
|||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_keys_raw_prefix<'a, K, P>(&'a self, prefix: &'a P) -> impl Stream<Item = Result<Key<'_, K>>> + Send + 'a
|
||||
pub fn rev_keys_raw_prefix<'a, K, P>(
|
||||
self: &'a Arc<Self>, prefix: &'a P,
|
||||
) -> impl Stream<Item = Result<Key<'_, K>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
K: Deserialize<'a> + Send + 'a,
|
||||
|
@ -42,7 +44,7 @@ where
|
|||
}
|
||||
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_raw_keys_prefix<'a, P>(&'a self, prefix: &'a P) -> impl Stream<Item = Result<Key<'_>>> + Send + 'a
|
||||
pub fn rev_raw_keys_prefix<'a, P>(self: &'a Arc<Self>, prefix: &'a P) -> impl Stream<Item = Result<Key<'_>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ use conduit::{implement, Result};
|
|||
use futures::stream::{Stream, StreamExt};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{keyval, keyval::KeyVal, stream};
|
||||
use crate::{keyval, keyval::KeyVal, stream, stream::Cursor};
|
||||
|
||||
/// Iterate key-value entries in the map from the end.
|
||||
///
|
||||
|
@ -24,5 +24,5 @@ where
|
|||
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||
pub fn rev_raw_stream(&self) -> impl Stream<Item = Result<KeyVal<'_>>> + Send {
|
||||
let opts = super::read_options_default();
|
||||
stream::ItemsRev::new(&self.db, &self.cf, opts, None)
|
||||
stream::ItemsRev::new(&self.db, &self.cf, opts).init(None)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use futures::{
|
||||
stream::{Stream, StreamExt},
|
||||
FutureExt, TryFutureExt, TryStreamExt,
|
||||
};
|
||||
use rocksdb::Direction;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
|
@ -14,7 +18,9 @@ use crate::{
|
|||
/// - Query is serialized
|
||||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_stream_from<'a, K, V, P>(&'a self, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
pub fn rev_stream_from<'a, K, V, P>(
|
||||
self: &'a Arc<Self>, from: &P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -30,7 +36,7 @@ where
|
|||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn rev_stream_from_raw<P>(&self, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
pub fn rev_stream_from_raw<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -43,7 +49,9 @@ where
|
|||
/// - Query is raw
|
||||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_stream_raw_from<'a, K, V, P>(&'a self, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
pub fn rev_stream_raw_from<'a, K, V, P>(
|
||||
self: &'a Arc<Self>, from: &P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -59,10 +67,27 @@ where
|
|||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||
pub fn rev_raw_stream_from<P>(&self, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
pub fn rev_raw_stream_from<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug,
|
||||
{
|
||||
use crate::pool::Seek;
|
||||
|
||||
let opts = super::read_options_default();
|
||||
stream::ItemsRev::new(&self.db, &self.cf, opts, Some(from.as_ref()))
|
||||
let state = stream::State::new(&self.db, &self.cf, opts);
|
||||
let seek = Seek {
|
||||
map: self.clone(),
|
||||
dir: Direction::Reverse,
|
||||
key: Some(from.as_ref().into()),
|
||||
state: crate::pool::into_send_seek(state),
|
||||
res: None,
|
||||
};
|
||||
|
||||
self.db
|
||||
.pool
|
||||
.execute_iter(seek)
|
||||
.ok_into::<stream::ItemsRev<'_>>()
|
||||
.into_stream()
|
||||
.try_flatten()
|
||||
.boxed()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::{
|
||||
|
@ -15,7 +15,9 @@ use crate::keyval::{result_deserialize, serialize_key, KeyVal};
|
|||
/// - Query is serialized
|
||||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_stream_prefix<'a, K, V, P>(&'a self, prefix: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
pub fn rev_stream_prefix<'a, K, V, P>(
|
||||
self: &'a Arc<Self>, prefix: &P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -31,7 +33,7 @@ where
|
|||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn rev_stream_prefix_raw<P>(&self, prefix: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
pub fn rev_stream_prefix_raw<P>(self: &Arc<Self>, prefix: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -46,7 +48,7 @@ where
|
|||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_stream_raw_prefix<'a, K, V, P>(
|
||||
&'a self, prefix: &'a P,
|
||||
self: &'a Arc<Self>, prefix: &'a P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
|
@ -62,7 +64,9 @@ where
|
|||
/// - Query is raw
|
||||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
pub fn rev_raw_stream_prefix<'a, P>(&'a self, prefix: &'a P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + 'a
|
||||
pub fn rev_raw_stream_prefix<'a, P>(
|
||||
self: &'a Arc<Self>, prefix: &'a P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ use conduit::{implement, Result};
|
|||
use futures::stream::{Stream, StreamExt};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{keyval, keyval::KeyVal, stream};
|
||||
use crate::{keyval, keyval::KeyVal, stream, stream::Cursor};
|
||||
|
||||
/// Iterate key-value entries in the map from the beginning.
|
||||
///
|
||||
|
@ -23,5 +23,5 @@ where
|
|||
#[tracing::instrument(skip(self), fields(%self), level = "trace")]
|
||||
pub fn raw_stream(&self) -> impl Stream<Item = Result<KeyVal<'_>>> + Send {
|
||||
let opts = super::read_options_default();
|
||||
stream::Items::new(&self.db, &self.cf, opts, None)
|
||||
stream::Items::new(&self.db, &self.cf, opts).init(None)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use futures::{
|
||||
stream::{Stream, StreamExt},
|
||||
FutureExt, TryFutureExt, TryStreamExt,
|
||||
};
|
||||
use rocksdb::Direction;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
|
@ -14,7 +18,7 @@ use crate::{
|
|||
/// - Query is serialized
|
||||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn stream_from<'a, K, V, P>(&'a self, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
pub fn stream_from<'a, K, V, P>(self: &'a Arc<Self>, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -29,7 +33,7 @@ where
|
|||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn stream_from_raw<P>(&self, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
pub fn stream_from_raw<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -42,7 +46,9 @@ where
|
|||
/// - Query is raw
|
||||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn stream_raw_from<'a, K, V, P>(&'a self, from: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
pub fn stream_raw_from<'a, K, V, P>(
|
||||
self: &'a Arc<Self>, from: &P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -57,10 +63,27 @@ where
|
|||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self, from), fields(%self), level = "trace")]
|
||||
pub fn raw_stream_from<P>(&self, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
pub fn raw_stream_from<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug,
|
||||
{
|
||||
use crate::pool::Seek;
|
||||
|
||||
let opts = super::read_options_default();
|
||||
stream::Items::new(&self.db, &self.cf, opts, Some(from.as_ref()))
|
||||
let state = stream::State::new(&self.db, &self.cf, opts);
|
||||
let seek = Seek {
|
||||
map: self.clone(),
|
||||
dir: Direction::Forward,
|
||||
key: Some(from.as_ref().into()),
|
||||
state: crate::pool::into_send_seek(state),
|
||||
res: None,
|
||||
};
|
||||
|
||||
self.db
|
||||
.pool
|
||||
.execute_iter(seek)
|
||||
.ok_into::<stream::Items<'_>>()
|
||||
.into_stream()
|
||||
.try_flatten()
|
||||
.boxed()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{convert::AsRef, fmt::Debug};
|
||||
use std::{convert::AsRef, fmt::Debug, sync::Arc};
|
||||
|
||||
use conduit::{implement, Result};
|
||||
use futures::{
|
||||
|
@ -15,7 +15,9 @@ use crate::keyval::{result_deserialize, serialize_key, KeyVal};
|
|||
/// - Query is serialized
|
||||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn stream_prefix<'a, K, V, P>(&'a self, prefix: &P) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
pub fn stream_prefix<'a, K, V, P>(
|
||||
self: &'a Arc<Self>, prefix: &P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
K: Deserialize<'a> + Send,
|
||||
|
@ -31,7 +33,7 @@ where
|
|||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
#[tracing::instrument(skip(self), level = "trace")]
|
||||
pub fn stream_prefix_raw<P>(&self, prefix: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
pub fn stream_prefix_raw<P>(self: &Arc<Self>, prefix: &P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send
|
||||
where
|
||||
P: Serialize + ?Sized + Debug,
|
||||
{
|
||||
|
@ -46,7 +48,7 @@ where
|
|||
/// - Result is deserialized
|
||||
#[implement(super::Map)]
|
||||
pub fn stream_raw_prefix<'a, K, V, P>(
|
||||
&'a self, prefix: &'a P,
|
||||
self: &'a Arc<Self>, prefix: &'a P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_, K, V>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
|
@ -62,7 +64,9 @@ where
|
|||
/// - Query is raw
|
||||
/// - Result is raw
|
||||
#[implement(super::Map)]
|
||||
pub fn raw_stream_prefix<'a, P>(&'a self, prefix: &'a P) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + 'a
|
||||
pub fn raw_stream_prefix<'a, P>(
|
||||
self: &'a Arc<Self>, prefix: &'a P,
|
||||
) -> impl Stream<Item = Result<KeyVal<'_>>> + Send + 'a
|
||||
where
|
||||
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue