pub struct DynamoLeaseStore { /* private fields */ }Expand description
A DynamoDB-backed lease store.
The table needs a string partition key named lease_key and nothing else; create it with
on-demand billing. Instances race leases with conditional writes and steal only expired
ones. One row holds one shard of one stream, under the key stream:shard, so one table
serves every stream a service consumes.
§Rows from earlier versions
Earlier versions of this crate keyed a row by the shard id alone (shardId-000000000000), and
a table written by them still holds those rows. A row keyed by a bare shard id does not say
which stream it belongs to, so the store reads one only for the stream named by
legacy_stream: when a shard has no checkpoint under its own key, the
bare row’s checkpoint is used and copied under the new key. For any other stream the bare rows
are ignored. With no stream named, a shard whose bare row holds a checkpoint is refused with an
error naming the table, the shard and the stream that asked, and it is not read until the
operator names the stream or deletes the row.
The two versions lease different rows, so an instance of each can read the same shard at once: stop the old instances before starting the new ones, or accept the duplicates.
Implementations§
Source§impl DynamoLeaseStore
impl DynamoLeaseStore
Sourcepub fn new(config: &SdkConfig, table: impl Into<String>) -> Self
pub fn new(config: &SdkConfig, table: impl Into<String>) -> Self
Uses table in the account and region of config.
§Examples
use std::error::Error;
use std::sync::Arc;
use aws_config::BehaviorVersion;
use ruststream_kinesis::prelude::*;
pub async fn run() -> Result<(), Box<dyn Error>> {
let config = aws_config::defaults(BehaviorVersion::latest()).load().await;
let leases = Arc::new(DynamoLeaseStore::new(&config, "orders-leases"));
let broker = KinesisBroker::from_config(config).lease_store(leases);
RustStream::new(AppInfo::new("orders", "0.1.0"))
.with_broker(broker, |b| {
b.include(handle);
})
.run()
.await?;
Ok(())
}Sourcepub fn legacy_stream(self, stream: impl Into<String>) -> Self
pub fn legacy_stream(self, stream: impl Into<String>) -> Self
Names the stream the table’s rows keyed by a bare shard id belong to: the rows an earlier version of this crate wrote, before a row was kept per stream and shard.
A shard of stream with no checkpoint under its own key resumes from its bare row, and the
first read copies that checkpoint under the new key. Other streams ignore the bare rows.
Once the upgraded service has started a subscription on every stream it consumes, every
bare row that held progress has its copy, and the bare rows and this setting can go.
A table that served more than one stream before the upgrade holds, in each bare row, whichever stream checkpointed last: no stream can resume from it safely. Delete those rows and open each stream at a chosen position instead.
§Examples
use std::error::Error;
use std::sync::Arc;
use aws_config::BehaviorVersion;
use ruststream_kinesis::prelude::*;
pub async fn run() -> Result<(), Box<dyn Error>> {
let config = aws_config::defaults(BehaviorVersion::latest()).load().await;
// The table was written by an earlier version for the `orders` stream only.
let leases =
Arc::new(DynamoLeaseStore::new(&config, "orders-leases").legacy_stream("orders"));
let broker = KinesisBroker::from_config(config).lease_store(leases);
RustStream::new(AppInfo::new("orders", "0.1.0"))
.with_broker(broker, |b| {
b.include(handle);
})
.run()
.await?;
Ok(())
}Trait Implementations§
Source§impl Clone for DynamoLeaseStore
impl Clone for DynamoLeaseStore
Source§impl Debug for DynamoLeaseStore
impl Debug for DynamoLeaseStore
Source§impl LeaseStore for DynamoLeaseStore
impl LeaseStore for DynamoLeaseStore
Source§fn acquire<'a>(
&'a self,
key: &'a LeaseKey,
owner: &'a str,
ttl: Duration,
) -> BoxFuture<'a, Result<bool, LeaseError>>
fn acquire<'a>( &'a self, key: &'a LeaseKey, owner: &'a str, ttl: Duration, ) -> BoxFuture<'a, Result<bool, LeaseError>>
owner, valid for ttl. Returns false when
another live owner holds it.Source§fn renew<'a>(
&'a self,
key: &'a LeaseKey,
owner: &'a str,
ttl: Duration,
) -> BoxFuture<'a, Result<bool, LeaseError>>
fn renew<'a>( &'a self, key: &'a LeaseKey, owner: &'a str, ttl: Duration, ) -> BoxFuture<'a, Result<bool, LeaseError>>
false when the lease is no longer held (fenced).Source§fn checkpoint<'a>(
&'a self,
key: &'a LeaseKey,
owner: &'a str,
sequence: &'a str,
) -> BoxFuture<'a, Result<bool, LeaseError>>
fn checkpoint<'a>( &'a self, key: &'a LeaseKey, owner: &'a str, sequence: &'a str, ) -> BoxFuture<'a, Result<bool, LeaseError>>
sequence as the shard’s checkpoint, conditional on owner holding the
lease. Returns false when fenced.Source§fn read<'a>(
&'a self,
key: &'a LeaseKey,
) -> BoxFuture<'a, Result<LeaseState, LeaseError>>
fn read<'a>( &'a self, key: &'a LeaseKey, ) -> BoxFuture<'a, Result<LeaseState, LeaseError>>
Auto Trait Implementations§
impl !RefUnwindSafe for DynamoLeaseStore
impl !UnwindSafe for DynamoLeaseStore
impl Freeze for DynamoLeaseStore
impl Send for DynamoLeaseStore
impl Sync for DynamoLeaseStore
impl Unpin for DynamoLeaseStore
impl UnsafeUnpin for DynamoLeaseStore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 more