Struct mz_storage_client::util::antichain::OffsetAntichain
source · pub struct OffsetAntichain {
inner: BTreeMap<PartitionId, MzOffset>,
}
Expand description
OffsetAntichain is similar to a timely Antichain<(PartitionId, T: TotalOrder)>
,
but additionally:
- Uses a BTreeMap as the implementation to allow absence of a
PartitionId
to mean thatPartitionId
is atT::minimum
. This helps avoid needing to hold onto a HUGEAntichain
for all possiblePartitionId
s- Note this means that a partition being “finished” (like a normal “empty”
Antichain
, is not currently supported, but could be added - Note that this
Antichain
can also have been filtered, as in, missing some partitions for which data exists but we don’t care about. This is semantically different than if we just don’t have data, but it is represented the same
- Note this means that a partition being “finished” (like a normal “empty”
- Is not generic over
T
, but instead usesMzOffset
, which:- implements
TotalOrder
- implements
checked_sub
- implements
- Allows users to go from a frontier to an actual set of offsets that are
connected to real data.
- This is a consequence of implementation, where the frontier is ALWAYS generated from real data offsets, in an invertible way.
OffsetAntichain
has 4 sets of Api’s:
- “read” apis like
get
andas_vec
- “mutation” apis (currently only
filter_by_partition
) - And 2 “write” apis, that should primarily be used separately from each other:
- “Frontier” apis, which directly manipulate the underlying frontier. Useful for implementing primitives like reclocking
- “Data” apis, that maintain special invariants:
insert_data_up_to
updates the frontier based on a given offset that is associated with actual data.as_data_offsets
inverts the behavior ofinsert_data_up_to
and returns aBTreeMap<PartitionId, MzOffset>
of offets of real committed data.
Fields§
§inner: BTreeMap<PartitionId, MzOffset>
Implementations§
source§impl OffsetAntichain
impl OffsetAntichain
sourcepub fn as_data_offsets(&self) -> BTreeMap<PartitionId, MzOffset>
pub fn as_data_offsets(&self) -> BTreeMap<PartitionId, MzOffset>
Produce offsets for all partitions in this OffsetAntichain
that
were at one point given by insert_data_up_to
.
If the partition is yet to make any progress, it may be filtered out.
Invariant: After initialization, only insert_data_up_to
(not insert
and friends) may be used with this OffsetAntichain
for this function to produce meaningful values, unless you are very
careful.
sourcepub fn insert(&mut self, pid: PartitionId, m: MzOffset) -> Option<MzOffset>
pub fn insert(&mut self, pid: PartitionId, m: MzOffset) -> Option<MzOffset>
Insert a new MzOffset
frontier value for the pid
, returning
the old one if it wasn’t there.
sourcepub fn maybe_insert(&mut self, pid: PartitionId, offset: MzOffset)
pub fn maybe_insert(&mut self, pid: PartitionId, offset: MzOffset)
Insert a new MzOffset
frontier value for pid
if it is larger than
the previously stored value.
sourcepub fn extend<T: IntoIterator<Item = (PartitionId, MzOffset)>>(
&mut self,
iter: T
)
pub fn extend<T: IntoIterator<Item = (PartitionId, MzOffset)>>(
&mut self,
iter: T
)
The same as insert
, but for many values.
sourcepub fn advance(&mut self, pid: PartitionId, diff: MzOffset)
pub fn advance(&mut self, pid: PartitionId, diff: MzOffset)
Advance the frontier for PartitionId
by diff
Initializes the offset for pid
if it doesn’t exist.
sourcepub fn less_equal(&self, other: &OffsetAntichain) -> bool
pub fn less_equal(&self, other: &OffsetAntichain) -> bool
Returns true
iff this OffsetAntichain
is <=
other
.
This requires that for all partitions tracked in other
,
the offset in self
is <= or absent.
sourcepub fn bounded(&self, other: &OffsetAntichain) -> OffsetAntichain
pub fn bounded(&self, other: &OffsetAntichain) -> OffsetAntichain
Creates a new OffsetAntichain
that starts out as a copy of self
but where each offset is upper bounded by the corresponding offset from
other
, if there is one.
NOTE: This is not an equivalent of meet
, as known from timely
Antichain
. This operation is asymmetric: we want partitions in the
result only if they exist in self
, we don’t want partitions in the
result that only exist in other. If we did the latter, this could mean that we advance a frontier further than the original
self` would have.
sourcepub fn get(&self, pid: &PartitionId) -> Option<&MzOffset>
pub fn get(&self, pid: &PartitionId) -> Option<&MzOffset>
Attempt to the the MzOffset
value for pid
’s frontier
sourcepub fn partitions(&self) -> impl Iterator<Item = &PartitionId>
pub fn partitions(&self) -> impl Iterator<Item = &PartitionId>
List the contained partitions.
sourcepub fn iter(&self) -> impl Iterator<Item = (&PartitionId, &MzOffset)>
pub fn iter(&self) -> impl Iterator<Item = (&PartitionId, &MzOffset)>
Iterate over the entire frontier.
sourcepub fn into_iter(self) -> impl Iterator<Item = (PartitionId, MzOffset)>
pub fn into_iter(self) -> impl Iterator<Item = (PartitionId, MzOffset)>
Iterate over the entire frontier.
sourcepub fn as_vec(&self) -> Vec<(PartitionId, Option<MzOffset>)> ⓘ
pub fn as_vec(&self) -> Vec<(PartitionId, Option<MzOffset>)> ⓘ
Convert the frontier into a vector. Useful for certain old apis in the storage crate.
sourcepub fn filter_by_partition<F>(&mut self, filter: F)where
F: FnMut(&PartitionId) -> bool,
pub fn filter_by_partition<F>(&mut self, filter: F)where
F: FnMut(&PartitionId) -> bool,
Scope this OffsetAntichain
down to only partitions that pass
this filter callback.
Trait Implementations§
source§impl Clone for OffsetAntichain
impl Clone for OffsetAntichain
source§fn clone(&self) -> OffsetAntichain
fn clone(&self) -> OffsetAntichain
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for OffsetAntichain
impl Debug for OffsetAntichain
source§impl<'de> Deserialize<'de> for OffsetAntichain
impl<'de> Deserialize<'de> for OffsetAntichain
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<Antichain<Partitioned<i32, MzOffset>>> for OffsetAntichain
impl From<Antichain<Partitioned<i32, MzOffset>>> for OffsetAntichain
Implementation that converts from an Antichain to an OffsetAntichain. This translation code is here for compatibility and will be removed once the pipeline is switched to native timestamps throughout.
Native antichains can express a superset of frontiers that the OffsetAntichain can, therefore the conversion here can fail. While it’s non-standard to panic in From implementations this is fine here because it’s just an interim step that will be removed shortly and all uses would have to panic on error anyway.
source§impl From<OffsetAntichain> for Antichain<Partitioned<i32, MzOffset>>
impl From<OffsetAntichain> for Antichain<Partitioned<i32, MzOffset>>
Implementation that converts from an OffsetAntichain to an Antichain. This translation code is here for compatibility and will be removed once the pipeline is switched to native timestamps throughout.
source§fn from(frontier: OffsetAntichain) -> Self
fn from(frontier: OffsetAntichain) -> Self
source§impl PartialEq<BTreeMap<PartitionId, MzOffset, Global>> for OffsetAntichain
impl PartialEq<BTreeMap<PartitionId, MzOffset, Global>> for OffsetAntichain
source§impl PartialEq<OffsetAntichain> for OffsetAntichain
impl PartialEq<OffsetAntichain> for OffsetAntichain
source§fn eq(&self, other: &OffsetAntichain) -> bool
fn eq(&self, other: &OffsetAntichain) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for OffsetAntichain
impl Serialize for OffsetAntichain
impl StructuralPartialEq for OffsetAntichain
Auto Trait Implementations§
impl RefUnwindSafe for OffsetAntichain
impl Send for OffsetAntichain
impl Sync for OffsetAntichain
impl Unpin for OffsetAntichain
impl UnwindSafe for OffsetAntichain
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<T> Pointable for T
impl<T> Pointable for T
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
.