Struct mz_persist_client::PersistClient
source · pub struct PersistClient {
pub(crate) cfg: PersistConfig,
pub(crate) blob: Arc<dyn Blob + Send + Sync>,
pub(crate) consensus: Arc<dyn Consensus + Send + Sync>,
pub(crate) metrics: Arc<Metrics>,
pub(crate) cpu_heavy_runtime: Arc<CpuHeavyRuntime>,
pub(crate) shared_states: Arc<StateCache>,
pub(crate) pubsub_sender: Arc<dyn PubSubSender>,
}
Expand description
A handle for interacting with the set of persist shard made durable at a single PersistLocation.
All async methods on PersistClient retry for as long as they are able, but the returned std::future::Futures implement “cancel on drop” semantics. This means that callers can add a timeout using tokio::time::timeout or tokio::time::timeout_at.
tokio::time::timeout(timeout, client.open::<String, String, u64, i64>(id, "desc",
Arc::new(StringSchema),Arc::new(StringSchema))).await
Fields§
§cfg: PersistConfig
§blob: Arc<dyn Blob + Send + Sync>
§consensus: Arc<dyn Consensus + Send + Sync>
§metrics: Arc<Metrics>
§cpu_heavy_runtime: Arc<CpuHeavyRuntime>
§pubsub_sender: Arc<dyn PubSubSender>
Implementations§
source§impl PersistClient
impl PersistClient
sourcepub fn new(
cfg: PersistConfig,
blob: Arc<dyn Blob + Send + Sync>,
consensus: Arc<dyn Consensus + Send + Sync>,
metrics: Arc<Metrics>,
cpu_heavy_runtime: Arc<CpuHeavyRuntime>,
shared_states: Arc<StateCache>,
pubsub_sender: Arc<dyn PubSubSender>
) -> Result<Self, ExternalError>
pub fn new( cfg: PersistConfig, blob: Arc<dyn Blob + Send + Sync>, consensus: Arc<dyn Consensus + Send + Sync>, metrics: Arc<Metrics>, cpu_heavy_runtime: Arc<CpuHeavyRuntime>, shared_states: Arc<StateCache>, pubsub_sender: Arc<dyn PubSubSender> ) -> Result<Self, ExternalError>
Returns a new client for interfacing with persist shards made durable to the given Blob and Consensus.
This is exposed mostly for testing. Persist users likely want crate::cache::PersistClientCache::open.
sourcepub async fn open<K, V, T, D>(
&self,
shard_id: ShardId,
purpose: &str,
key_schema: Arc<K::Schema>,
val_schema: Arc<V::Schema>
) -> Result<(WriteHandle<K, V, T, D>, ReadHandle<K, V, T, D>), InvalidUsage<T>>where
K: Debug + Codec,
V: Debug + Codec,
T: Timestamp + Lattice + Codec64,
D: Semigroup + Codec64 + Send + Sync,
pub async fn open<K, V, T, D>( &self, shard_id: ShardId, purpose: &str, key_schema: Arc<K::Schema>, val_schema: Arc<V::Schema> ) -> Result<(WriteHandle<K, V, T, D>, ReadHandle<K, V, T, D>), InvalidUsage<T>>where K: Debug + Codec, V: Debug + Codec, T: Timestamp + Lattice + Codec64, D: Semigroup + Codec64 + Send + Sync,
Provides capabilities for the durable TVC identified by shard_id
at
its current since and upper frontiers.
This method is a best-effort attempt to regain control of the frontiers of a shard. Its most common uses are to recover capabilities that have expired (leases) or to attempt to read a TVC that one did not create (or otherwise receive capabilities for). If the frontiers have been fully released by all other parties, this call may result in capabilities with empty frontiers (which are useless).
If shard_id
has never been used before, initializes a new shard and
returns handles with since
and upper
frontiers set to initial values
of Antichain::from_elem(T::minimum())
.
The schema
parameter is currently unused, but should be an object
that represents the schema of the data in the shard. This will be required
in the future.
sourcepub async fn open_leased_reader<K, V, T, D>(
&self,
shard_id: ShardId,
purpose: &str,
key_schema: Arc<K::Schema>,
val_schema: Arc<V::Schema>
) -> Result<ReadHandle<K, V, T, D>, InvalidUsage<T>>where
K: Debug + Codec,
V: Debug + Codec,
T: Timestamp + Lattice + Codec64,
D: Semigroup + Codec64 + Send + Sync,
pub async fn open_leased_reader<K, V, T, D>( &self, shard_id: ShardId, purpose: &str, key_schema: Arc<K::Schema>, val_schema: Arc<V::Schema> ) -> Result<ReadHandle<K, V, T, D>, InvalidUsage<T>>where K: Debug + Codec, V: Debug + Codec, T: Timestamp + Lattice + Codec64, D: Semigroup + Codec64 + Send + Sync,
Self::open, but returning only a [/eadHandle].
Use this to save latency and a bit of persist traffic if you’re just going to immediately drop or expire the WriteHandle.
The _schema
parameter is currently unused, but should be an object
that represents the schema of the data in the shard. This will be required
in the future.
sourcepub async fn create_batch_fetcher<K, V, T, D>(
&self,
shard_id: ShardId,
key_schema: Arc<K::Schema>,
val_schema: Arc<V::Schema>
) -> BatchFetcher<K, V, T, D>where
K: Debug + Codec,
V: Debug + Codec,
T: Timestamp + Lattice + Codec64,
D: Semigroup + Codec64 + Send + Sync,
pub async fn create_batch_fetcher<K, V, T, D>( &self, shard_id: ShardId, key_schema: Arc<K::Schema>, val_schema: Arc<V::Schema> ) -> BatchFetcher<K, V, T, D>where K: Debug + Codec, V: Debug + Codec, T: Timestamp + Lattice + Codec64, D: Semigroup + Codec64 + Send + Sync,
Creates and returns a BatchFetcher for the given shard id.
The _schema
parameter is currently unused, but should be an object
that represents the schema of the data in the shard. This will be required
in the future.
sourcepub const CONTROLLER_CRITICAL_SINCE: CriticalReaderId = _
pub const CONTROLLER_CRITICAL_SINCE: CriticalReaderId = _
A convenience CriticalReaderId for Materialize controllers.
For most (soon to be all?) shards in Materialize, a centralized “controller” is the authority for when a user no longer needs to read at a given frontier. (Other uses are temporary holds where correctness of the overall system can be maintained through a lease timeout.) To make SinceHandle easier to work with, we offer this convenience id for Materialize controllers, so they don’t have to durably record it.
TODO: We’re still shaking out whether the controller should be the only critical since hold or if there are other places we want them. If the former, we should remove CriticalReaderId and bake in the singular nature of the controller critical handle.
// This prints as something that is not 0 but is visually recognizable.
assert_eq!(
mz_persist_client::PersistClient::CONTROLLER_CRITICAL_SINCE.to_string(),
"c00000000-1111-2222-3333-444444444444",
)
sourcepub async fn open_critical_since<K, V, T, D, O>(
&self,
shard_id: ShardId,
reader_id: CriticalReaderId,
purpose: &str
) -> Result<SinceHandle<K, V, T, D, O>, InvalidUsage<T>>where
K: Debug + Codec,
V: Debug + Codec,
T: Timestamp + Lattice + Codec64,
D: Semigroup + Codec64 + Send + Sync,
O: Opaque + Codec64,
pub async fn open_critical_since<K, V, T, D, O>( &self, shard_id: ShardId, reader_id: CriticalReaderId, purpose: &str ) -> Result<SinceHandle<K, V, T, D, O>, InvalidUsage<T>>where K: Debug + Codec, V: Debug + Codec, T: Timestamp + Lattice + Codec64, D: Semigroup + Codec64 + Send + Sync, O: Opaque + Codec64,
Provides a capability for the durable TVC identified by shard_id
at
its current since frontier.
In contrast to the time-leased ReadHandle returned by Self::open and
Self::open_leased_reader, this handle and its associated capability
are not leased. A SinceHandle only releases its since capability when
SinceHandle::expire is called. Also unlike ReadHandle
, expire is not
called on drop. This is less ergonomic, but useful for “critical” since
holds which must survive even lease timeouts.
IMPORTANT: The above means that if a SinceHandle is registered and then lost, the shard’s since will be permanently “stuck”, forever preventing logical compaction. Users are advised to durably record (preferably in code) the intended CriticalReaderId before registering a SinceHandle (in case the process crashes at the wrong time).
If shard_id
has never been used before, initializes a new shard and
return a handle with its since
frontier set to the initial value of
Antichain::from_elem(T::minimum())
.
sourcepub async fn open_writer<K, V, T, D>(
&self,
shard_id: ShardId,
purpose: &str,
key_schema: Arc<K::Schema>,
val_schema: Arc<V::Schema>
) -> Result<WriteHandle<K, V, T, D>, InvalidUsage<T>>where
K: Debug + Codec,
V: Debug + Codec,
T: Timestamp + Lattice + Codec64,
D: Semigroup + Codec64 + Send + Sync,
pub async fn open_writer<K, V, T, D>( &self, shard_id: ShardId, purpose: &str, key_schema: Arc<K::Schema>, val_schema: Arc<V::Schema> ) -> Result<WriteHandle<K, V, T, D>, InvalidUsage<T>>where K: Debug + Codec, V: Debug + Codec, T: Timestamp + Lattice + Codec64, D: Semigroup + Codec64 + Send + Sync,
Self::open, but returning only a WriteHandle.
Use this to save latency and a bit of persist traffic if you’re just going to immediately drop or expire the ReadHandle.
The _schema
parameter is currently unused, but should be an object
that represents the schema of the data in the shard. This will be required
in the future.
sourcepub async fn inspect_shard<T: Timestamp + Lattice + Codec64>(
&self,
shard_id: &ShardId
) -> Result<impl Serialize, Error>
pub async fn inspect_shard<T: Timestamp + Lattice + Codec64>( &self, shard_id: &ShardId ) -> Result<impl Serialize, Error>
Returns the internal state of the shard for debugging and QA.
We’ll be thoughtful about making unnecessary changes, but the output of this method needs to be gated from users, so that it’s not subject to our backward compatibility guarantees.
Trait Implementations§
source§impl Clone for PersistClient
impl Clone for PersistClient
source§fn clone(&self) -> PersistClient
fn clone(&self) -> PersistClient
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for PersistClient
impl Send for PersistClient
impl Sync for PersistClient
impl Unpin for PersistClient
impl !UnwindSafe for PersistClient
Blanket Implementations§
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.