@@ -299,6 +299,12 @@ impl<'a, 'b> Migration<'a, 'b> {
299299 bail ! ( "downgrade not supported" ) ;
300300 }
301301
302+ // In leader mode, upgrade the version of the migration shard to the target version.
303+ // This fences out any readers at lower versions.
304+ if !self . config . read_only {
305+ self . upgrade_migration_shard_version ( ) . await ;
306+ }
307+
302308 info ! ( "executing migration plan: {plan:?}" ) ;
303309
304310 self . migrate_evolve ( & plan. evolve ) . await ?;
@@ -415,6 +421,24 @@ impl<'a, 'b> Migration<'a, 'b> {
415421 plan
416422 }
417423
424+ /// Upgrade the migration shard to the target version.
425+ async fn upgrade_migration_shard_version ( & self ) {
426+ let persist = & self . config . persist_client ;
427+ let shard_id = self . txn . get_builtin_migration_shard ( ) . expect ( "must exist" ) ;
428+ let diagnostics = Diagnostics {
429+ shard_name : "builtin_migration" . to_string ( ) ,
430+ handle_purpose : format ! ( "migration shard upgrade @ {}" , self . target_version) ,
431+ } ;
432+
433+ persist
434+ . upgrade_version :: < migration_shard:: Key , ShardId , Timestamp , StorageDiff > (
435+ shard_id,
436+ diagnostics,
437+ )
438+ . await
439+ . expect ( "valid usage" ) ;
440+ }
441+
418442 /// Migrate the given objects using the `Evolution` mechanism.
419443 async fn migrate_evolve ( & self , objects : & [ SystemObjectDescription ] ) -> anyhow:: Result < ( ) > {
420444 for object in objects {
0 commit comments