@@ -24,7 +24,7 @@ use differential_dataflow::lattice::Lattice;
2424use itertools:: Itertools ;
2525use mz_build_info:: { BuildInfo , build_info} ;
2626use mz_dyncfg:: ConfigSet ;
27- use mz_ore:: instrument;
27+ use mz_ore:: { instrument, soft_assert_or_log } ;
2828use mz_persist:: location:: { Blob , Consensus , ExternalError } ;
2929use mz_persist_types:: schema:: SchemaId ;
3030use mz_persist_types:: { Codec , Codec64 , Opaque } ;
@@ -490,6 +490,10 @@ impl PersistClient {
490490 ///
491491 /// Use this to save latency and a bit of persist traffic if you're just
492492 /// going to immediately drop or expire the [ReadHandle].
493+ ///
494+ /// The `_schema` parameter is currently unused, but should be an object
495+ /// that represents the schema of the data in the shard. This will be required
496+ /// in the future.
493497 #[ instrument( level = "debug" , fields( shard = %shard_id) ) ]
494498 pub async fn open_writer < K , V , T , D > (
495499 & self ,
@@ -507,11 +511,23 @@ impl PersistClient {
507511 let machine = self . make_machine ( shard_id, diagnostics. clone ( ) ) . await ?;
508512 let gc = GarbageCollector :: new ( machine. clone ( ) , Arc :: clone ( & self . isolated_runtime ) ) ;
509513
510- // We defer registering the schema until write time, to allow opening
511- // write handles in a "read-only" mode where they don't implicitly
512- // modify persist state. But it might already be registered, in which
513- // case we can fetch its ID.
514- let schema_id = machine. find_schema ( & * key_schema, & * val_schema) ;
514+ // TODO: Because schemas are ordered, as part of the persist schema
515+ // changes work, we probably want to build some way to allow persist
516+ // users to control the order. For example, maybe a
517+ // `PersistClient::compare_and_append_schema(current_schema_id,
518+ // next_schema)`. Presumably this would then be passed in to open_writer
519+ // instead of us implicitly registering it here.
520+ // NB: The overwhelming common case is that this schema is already
521+ // registered. In this case, the cmd breaks early and nothing is
522+ // written to (or read from) CRDB.
523+ let ( schema_id, maintenance) = machine. register_schema ( & * key_schema, & * val_schema) . await ;
524+ maintenance. start_performing ( & machine, & gc) ;
525+ soft_assert_or_log ! (
526+ schema_id. is_some( ) ,
527+ "unable to register schemas {:?} {:?}" ,
528+ key_schema,
529+ val_schema,
530+ ) ;
515531
516532 let writer_id = WriterId :: new ( ) ;
517533 let schemas = Schemas {
@@ -1976,6 +1992,7 @@ mod tests {
19761992 #[ mz_persist_proc:: test( tokio:: test) ]
19771993 #[ cfg_attr( miri, ignore) ] // unsupported operation: returning ready events from epoll_wait is not yet implemented
19781994 async fn finalize_empty_shard ( dyncfgs : ConfigUpdates ) {
1995+ const EMPTY : & [ ( ( ( ) , ( ) ) , u64 , i64 ) ] = & [ ] ;
19791996 let persist_client = new_test_client ( & dyncfgs) . await ;
19801997
19811998 let shard_id = ShardId :: new ( ) ;
@@ -1989,7 +2006,11 @@ mod tests {
19892006 // Advance since and upper to empty, which is a pre-requisite for
19902007 // finalization/tombstoning.
19912008 let ( ) = read. downgrade_since ( & Antichain :: new ( ) ) . await ;
1992- let ( ) = write. advance_upper ( & Antichain :: new ( ) ) . await ;
2009+ let ( ) = write
2010+ . compare_and_append ( EMPTY , Antichain :: from_elem ( 0 ) , Antichain :: new ( ) )
2011+ . await
2012+ . expect ( "usage should be valid" )
2013+ . expect ( "upper should match" ) ;
19932014
19942015 let mut since_handle: SinceHandle < ( ) , ( ) , u64 , i64 , u64 > = persist_client
19952016 . open_critical_since ( shard_id, CRITICAL_SINCE , Diagnostics :: for_tests ( ) )
@@ -2026,6 +2047,7 @@ mod tests {
20262047 #[ mz_persist_proc:: test( tokio:: test) ]
20272048 #[ cfg_attr( miri, ignore) ] // unsupported operation: returning ready events from epoll_wait is not yet implemented
20282049 async fn finalize_shard ( dyncfgs : ConfigUpdates ) {
2050+ const EMPTY : & [ ( ( ( ) , ( ) ) , u64 , i64 ) ] = & [ ] ;
20292051 const DATA : & [ ( ( ( ) , ( ) ) , u64 , i64 ) ] = & [ ( ( ( ) , ( ) ) , 0 , 1 ) ] ;
20302052 let persist_client = new_test_client ( & dyncfgs) . await ;
20312053
@@ -2047,7 +2069,11 @@ mod tests {
20472069 // Advance since and upper to empty, which is a pre-requisite for
20482070 // finalization/tombstoning.
20492071 let ( ) = read. downgrade_since ( & Antichain :: new ( ) ) . await ;
2050- let ( ) = write. advance_upper ( & Antichain :: new ( ) ) . await ;
2072+ let ( ) = write
2073+ . compare_and_append ( EMPTY , Antichain :: from_elem ( 1 ) , Antichain :: new ( ) )
2074+ . await
2075+ . expect ( "usage should be valid" )
2076+ . expect ( "upper should match" ) ;
20512077
20522078 let mut since_handle: SinceHandle < ( ) , ( ) , u64 , i64 , u64 > = persist_client
20532079 . open_critical_since ( shard_id, CRITICAL_SINCE , Diagnostics :: for_tests ( ) )
0 commit comments