pub struct LeaseKey { /* private fields */ }Expand description
The name one shard’s lease and checkpoint live under: the stream and the shard id.
Shard ids repeat across streams (the first shard of every stream is shardId-000000000000),
so a store keys by both, and one store serves every stream a broker consumes. The stream is the
name the subscription’s KinesisStream was given.
§Examples
A store over a string-keyed table writes each shard’s row under the key’s stream:shard form:
use std::collections::HashMap;
use std::sync::Mutex;
use futures::future::BoxFuture;
use ruststream_kinesis::{LeaseError, LeaseKey, LeaseState, LeaseStore};
/// Checkpoints for a single instance, which owns every shard.
#[derive(Default)]
pub struct Checkpoints(Mutex<HashMap<String, String>>);
impl LeaseStore for Checkpoints {
fn checkpoint<'a>(
&'a self,
key: &'a LeaseKey,
_owner: &'a str,
sequence: &'a str,
) -> BoxFuture<'a, Result<bool, LeaseError>> {
Box::pin(async move {
let mut rows = self.0.lock().map_err(|e| e.to_string())?;
rows.insert(key.to_string(), sequence.to_owned());
Ok(true)
})
}
fn read<'a>(&'a self, key: &'a LeaseKey) -> BoxFuture<'a, Result<LeaseState, LeaseError>> {
Box::pin(async move {
let rows = self.0.lock().map_err(|e| e.to_string())?;
let mut state = LeaseState::default();
state.checkpoint = rows.get(&key.to_string()).cloned();
Ok(state)
})
}
}Implementations§
Trait Implementations§
Source§impl Display for LeaseKey
stream:shard, the form a store that keeps one string key writes. A stream name holds no
colon, so the form is unambiguous.
impl Display for LeaseKey
stream:shard, the form a store that keeps one string key writes. A stream name holds no
colon, so the form is unambiguous.
impl Eq for LeaseKey
impl StructuralPartialEq for LeaseKey
Auto Trait Implementations§
impl Freeze for LeaseKey
impl RefUnwindSafe for LeaseKey
impl Send for LeaseKey
impl Sync for LeaseKey
impl Unpin for LeaseKey
impl UnsafeUnpin for LeaseKey
impl UnwindSafe for LeaseKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.