@@ -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, soft_assert_or_log } ;
27+ use mz_ore:: instrument;
2828use mz_persist:: location:: { Blob , Consensus , ExternalError } ;
2929use mz_persist_types:: schema:: SchemaId ;
3030use mz_persist_types:: { Codec , Codec64 , Opaque } ;
@@ -490,10 +490,6 @@ 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.
497493 #[ instrument( level = "debug" , fields( shard = %shard_id) ) ]
498494 pub async fn open_writer < K , V , T , D > (
499495 & self ,
@@ -511,23 +507,11 @@ impl PersistClient {
511507 let machine = self . make_machine ( shard_id, diagnostics. clone ( ) ) . await ?;
512508 let gc = GarbageCollector :: new ( machine. clone ( ) , Arc :: clone ( & self . isolated_runtime ) ) ;
513509
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- ) ;
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) ;
531515
532516 let writer_id = WriterId :: new ( ) ;
533517 let schemas = Schemas {
@@ -1992,7 +1976,6 @@ mod tests {
19921976 #[ mz_persist_proc:: test( tokio:: test) ]
19931977 #[ cfg_attr( miri, ignore) ] // unsupported operation: returning ready events from epoll_wait is not yet implemented
19941978 async fn finalize_empty_shard ( dyncfgs : ConfigUpdates ) {
1995- const EMPTY : & [ ( ( ( ) , ( ) ) , u64 , i64 ) ] = & [ ] ;
19961979 let persist_client = new_test_client ( & dyncfgs) . await ;
19971980
19981981 let shard_id = ShardId :: new ( ) ;
@@ -2006,11 +1989,7 @@ mod tests {
20061989 // Advance since and upper to empty, which is a pre-requisite for
20071990 // finalization/tombstoning.
20081991 let ( ) = read. downgrade_since ( & 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" ) ;
1992+ let ( ) = write. advance_upper ( & Antichain :: new ( ) ) . await ;
20141993
20151994 let mut since_handle: SinceHandle < ( ) , ( ) , u64 , i64 , u64 > = persist_client
20161995 . open_critical_since ( shard_id, CRITICAL_SINCE , Diagnostics :: for_tests ( ) )
@@ -2047,7 +2026,6 @@ mod tests {
20472026 #[ mz_persist_proc:: test( tokio:: test) ]
20482027 #[ cfg_attr( miri, ignore) ] // unsupported operation: returning ready events from epoll_wait is not yet implemented
20492028 async fn finalize_shard ( dyncfgs : ConfigUpdates ) {
2050- const EMPTY : & [ ( ( ( ) , ( ) ) , u64 , i64 ) ] = & [ ] ;
20512029 const DATA : & [ ( ( ( ) , ( ) ) , u64 , i64 ) ] = & [ ( ( ( ) , ( ) ) , 0 , 1 ) ] ;
20522030 let persist_client = new_test_client ( & dyncfgs) . await ;
20532031
@@ -2069,11 +2047,7 @@ mod tests {
20692047 // Advance since and upper to empty, which is a pre-requisite for
20702048 // finalization/tombstoning.
20712049 let ( ) = read. downgrade_since ( & 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" ) ;
2050+ let ( ) = write. advance_upper ( & Antichain :: new ( ) ) . await ;
20772051
20782052 let mut since_handle: SinceHandle < ( ) , ( ) , u64 , i64 , u64 > = persist_client
20792053 . open_critical_since ( shard_id, CRITICAL_SINCE , Diagnostics :: for_tests ( ) )
0 commit comments