@@ -40,6 +40,7 @@ use smallvec::SmallVec;
4040use timely:: progress:: frontier:: { Antichain , MutableAntichain } ;
4141use timely:: PartialOrder ;
4242use tonic:: { Request , Status as TonicStatus , Streaming } ;
43+ use uuid:: Uuid ;
4344
4445use crate :: client:: proto_storage_server:: ProtoStorage ;
4546use crate :: metrics:: ReplicaMetrics ;
@@ -123,18 +124,29 @@ pub enum StorageCommand<T = mz_repr::Timestamp> {
123124 UpdateConfiguration ( StorageParameters ) ,
124125 /// Run the enumerated sources, each associated with its identifier.
125126 RunIngestions ( Vec < RunIngestionCommand > ) ,
126- /// Run a dataflow which will ingest data from an external source and only __stage__ it in
127- /// Persist.
128- ///
129- /// Unlike regular ingestions/sources, some other component (e.g. `environmentd`) is
130- /// responsible for linking the staged data into a shard.
131- RunOneshotIngestion ( RunOneshotIngestionCommand ) ,
132127 /// Enable compaction in storage-managed collections.
133128 ///
134129 /// Each entry in the vector names a collection and provides a frontier after which
135130 /// accumulations must be correct.
136131 AllowCompaction ( Vec < ( GlobalId , Antichain < T > ) > ) ,
137132 RunSinks ( Vec < RunSinkCommand < T > > ) ,
133+ /// Run a dataflow which will ingest data from an external source and only __stage__ it in
134+ /// Persist.
135+ ///
136+ /// Unlike regular ingestions/sources, some other component (e.g. `environmentd`) is
137+ /// responsible for linking the staged data into a shard.
138+ RunOneshotIngestion ( Vec < RunOneshotIngestion > ) ,
139+ /// `CancelOneshotIngestion` instructs the replica to cancel the identified oneshot ingestions.
140+ ///
141+ /// It is invalid to send a [`CancelOneshotIngestion`] command that references a oneshot
142+ /// ingestion that was not created by a corresponding [`RunOneshotIngestion`] command before.
143+ /// Doing so may cause the replica to exhibit undefined behavior.
144+ ///
145+ /// [`CancelOneshotIngestion`]: crate::client::StorageCommand::CancelOneshotIngestion
146+ /// [`RunOneshotIngestion`]: crate::client::StorageCommand::RunOneshotIngestion
147+ CancelOneshotIngestion {
148+ ingestions : Vec < Uuid > ,
149+ } ,
138150}
139151
140152impl < T > StorageCommand < T > {
@@ -146,7 +158,8 @@ impl<T> StorageCommand<T> {
146158 | InitializationComplete
147159 | AllowWrites
148160 | UpdateConfiguration ( _)
149- | AllowCompaction ( _) => false ,
161+ | AllowCompaction ( _)
162+ | CancelOneshotIngestion { .. } => false ,
150163 // TODO(cf2): multi-replica oneshot ingestions. At the moment returning
151164 // true here means we can't run `COPY FROM` on multi-replica clusters, this
152165 // should be easy enough to support though.
@@ -199,7 +212,7 @@ impl RustType<ProtoRunIngestionCommand> for RunIngestionCommand {
199212
200213/// A command that starts ingesting the given ingestion description
201214#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
202- pub struct RunOneshotIngestionCommand {
215+ pub struct RunOneshotIngestion {
203216 /// The ID of the ingestion dataflow.
204217 pub ingestion_id : uuid:: Uuid ,
205218 /// The ID of collection we'll stage batches for.
@@ -210,30 +223,30 @@ pub struct RunOneshotIngestionCommand {
210223 pub request : OneshotIngestionRequest ,
211224}
212225
213- impl RustType < ProtoRunOneshotIngestionCommand > for RunOneshotIngestionCommand {
214- fn into_proto ( & self ) -> ProtoRunOneshotIngestionCommand {
215- ProtoRunOneshotIngestionCommand {
226+ impl RustType < ProtoRunOneshotIngestion > for RunOneshotIngestion {
227+ fn into_proto ( & self ) -> ProtoRunOneshotIngestion {
228+ ProtoRunOneshotIngestion {
216229 ingestion_id : Some ( self . ingestion_id . into_proto ( ) ) ,
217230 collection_id : Some ( self . collection_id . into_proto ( ) ) ,
218231 storage_metadata : Some ( self . collection_meta . into_proto ( ) ) ,
219232 request : Some ( self . request . into_proto ( ) ) ,
220233 }
221234 }
222235
223- fn from_proto ( proto : ProtoRunOneshotIngestionCommand ) -> Result < Self , TryFromProtoError > {
224- Ok ( RunOneshotIngestionCommand {
236+ fn from_proto ( proto : ProtoRunOneshotIngestion ) -> Result < Self , TryFromProtoError > {
237+ Ok ( RunOneshotIngestion {
225238 ingestion_id : proto
226239 . ingestion_id
227- . into_rust_if_some ( "ProtoRunOneshotIngestionCommand ::ingestion_id" ) ?,
240+ . into_rust_if_some ( "ProtoRunOneshotIngestion ::ingestion_id" ) ?,
228241 collection_id : proto
229242 . collection_id
230- . into_rust_if_some ( "ProtoRunOneshotIngestionCommand ::collection_id" ) ?,
243+ . into_rust_if_some ( "ProtoRunOneshotIngestion ::collection_id" ) ?,
231244 collection_meta : proto
232245 . storage_metadata
233- . into_rust_if_some ( "ProtoRunOneshotIngestionCommand ::storage_metadata" ) ?,
246+ . into_rust_if_some ( "ProtoRunOneshotIngestion ::storage_metadata" ) ?,
234247 request : proto
235248 . request
236- . into_rust_if_some ( "ProtoRunOneshotIngestionCommand ::request" ) ?,
249+ . into_rust_if_some ( "ProtoRunOneshotIngestion ::request" ) ?,
237250 } )
238251 }
239252}
@@ -300,12 +313,19 @@ impl RustType<ProtoStorageCommand> for StorageCommand<mz_repr::Timestamp> {
300313 StorageCommand :: RunIngestions ( sources) => CreateSources ( ProtoCreateSources {
301314 sources : sources. into_proto ( ) ,
302315 } ) ,
303- StorageCommand :: RunOneshotIngestion ( oneshot) => {
304- OneshotIngestion ( oneshot. into_proto ( ) )
305- }
306316 StorageCommand :: RunSinks ( sinks) => RunSinks ( ProtoRunSinks {
307317 sinks : sinks. into_proto ( ) ,
308318 } ) ,
319+ StorageCommand :: RunOneshotIngestion ( ingestions) => {
320+ RunOneshotIngestions ( ProtoRunOneshotIngestionsCommand {
321+ ingestions : ingestions. iter ( ) . map ( |cmd| cmd. into_proto ( ) ) . collect ( ) ,
322+ } )
323+ }
324+ StorageCommand :: CancelOneshotIngestion { ingestions } => {
325+ CancelOneshotIngestions ( ProtoCancelOneshotIngestionsCommand {
326+ ingestions : ingestions. iter ( ) . map ( |uuid| uuid. into_proto ( ) ) . collect ( ) ,
327+ } )
328+ }
309329 } ) ,
310330 }
311331 }
@@ -334,8 +354,21 @@ impl RustType<ProtoStorageCommand> for StorageCommand<mz_repr::Timestamp> {
334354 Some ( RunSinks ( ProtoRunSinks { sinks } ) ) => {
335355 Ok ( StorageCommand :: RunSinks ( sinks. into_rust ( ) ?) )
336356 }
337- Some ( OneshotIngestion ( oneshot) ) => {
338- Ok ( StorageCommand :: RunOneshotIngestion ( oneshot. into_rust ( ) ?) )
357+ Some ( RunOneshotIngestions ( oneshot) ) => {
358+ let ingestions = oneshot
359+ . ingestions
360+ . into_iter ( )
361+ . map ( |cmd| cmd. into_rust ( ) )
362+ . collect :: < Result < _ , _ > > ( ) ?;
363+ Ok ( StorageCommand :: RunOneshotIngestion ( ingestions) )
364+ }
365+ Some ( CancelOneshotIngestions ( oneshot) ) => {
366+ let ingestions = oneshot
367+ . ingestions
368+ . into_iter ( )
369+ . map ( |uuid| uuid. into_rust ( ) )
370+ . collect :: < Result < _ , _ > > ( ) ?;
371+ Ok ( StorageCommand :: CancelOneshotIngestion { ingestions } )
339372 }
340373 None => Err ( TryFromProtoError :: missing_field (
341374 "ProtoStorageCommand::kind" ,
@@ -802,7 +835,8 @@ where
802835 | StorageCommand :: AllowWrites
803836 | StorageCommand :: UpdateConfiguration ( _)
804837 | StorageCommand :: AllowCompaction ( _)
805- | StorageCommand :: RunOneshotIngestion ( _) => { }
838+ | StorageCommand :: RunOneshotIngestion ( _)
839+ | StorageCommand :: CancelOneshotIngestion { .. } => { }
806840 } ;
807841 }
808842
0 commit comments