vortex_layout/segments/sink.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::sync::Arc;
5
6use async_trait::async_trait;
7use vortex_buffer::ByteBuffer;
8use vortex_error::VortexResult;
9
10use crate::segments::SegmentId;
11use crate::sequence::SequenceId;
12
13pub type SegmentSinkRef = Arc<dyn SegmentSink>;
14
15#[async_trait]
16pub trait SegmentSink: Send + Sync {
17 /// Write the given data into a segment, ordered based on the provided sequence identifier.
18 ///
19 /// Implementations of this trait should call [`SequenceId::collapse`] on the provided
20 /// `sequence_id` if they need to ensure that the segment IDs are monotonically increasing.
21 /// While they hold onto the returned `SequenceId`, they can be sure that no other subsequent
22 /// calls to [`SequenceId::collapse`] will complete.
23 ///
24 /// If they do not require ordered segment IDs, for example if segments are stored in
25 /// random-access key/values storage, then the sequence ID can be dropped and the segment
26 /// written immediately.
27 async fn write(
28 &self,
29 sequence_id: SequenceId,
30 buffers: Vec<ByteBuffer>,
31 ) -> VortexResult<SegmentId>;
32}