mz_storage_client/util/
remap_handle.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Reclocking compatibility code until the whole ingestion pipeline is transformed to native
11//! timestamps
12
13use mz_persist_client::error::UpperMismatch;
14use mz_repr::Diff;
15use timely::progress::Timestamp;
16use timely::progress::frontier::Antichain;
17
18/// A handle that can produce the data expressing the translation of FromTime to
19/// IntoTime.
20///
21/// This trait is a subtrait of `RemapHandle` so it can be shared between the
22/// primary reclocking implementation and remap collection migrations.
23#[async_trait::async_trait(?Send)]
24pub trait RemapHandleReader {
25    type FromTime: Timestamp;
26    type IntoTime: Timestamp;
27
28    /// Produces the next batch of data contained in the remap collection and the upper frontier of
29    /// that batch. The return batch should contain all the updates that happened at times not
30    /// beyond ther returned upper.
31    async fn next(
32        &mut self,
33    ) -> Option<(
34        Vec<(Self::FromTime, Self::IntoTime, Diff)>,
35        Antichain<Self::IntoTime>,
36    )>;
37}
38
39/// A handle that can be used to durably persist a remap collection translating FromTime to
40/// IntoTime.
41#[async_trait::async_trait(?Send)]
42pub trait RemapHandle: RemapHandleReader {
43    /// Attempt to write the batch of remap collection updates to the collection. If the remap
44    /// collection was already written by some other process an error will return with the current
45    /// upper.
46    async fn compare_and_append(
47        &mut self,
48        updates: Vec<(Self::FromTime, Self::IntoTime, Diff)>,
49        upper: Antichain<Self::IntoTime>,
50        new_upper: Antichain<Self::IntoTime>,
51    ) -> Result<(), UpperMismatch<Self::IntoTime>>;
52
53    fn upper(&self) -> &Antichain<Self::IntoTime>;
54}