@@ -29,6 +29,7 @@ use self::{
2929 constraint_pausing:: { ConstraintDescription , IndexDescription } ,
3030 locking:: LockedMasDatabase ,
3131} ;
32+ use crate :: Progress ;
3233
3334pub mod checks;
3435pub mod locking;
@@ -550,16 +551,19 @@ impl MasWriter {
550551 conn : & mut LockedMasDatabase ,
551552 indices_to_restore : & [ IndexDescription ] ,
552553 constraints_to_restore : & [ ConstraintDescription ] ,
554+ progress : & Progress ,
553555 ) -> Result < ( ) , Error > {
554556 // First restore all indices. The order is not important as far as I know.
555557 // However the indices are needed before constraints.
556558 for index in indices_to_restore. iter ( ) . rev ( ) {
559+ progress. rebuild_index ( index. name . clone ( ) ) ;
557560 constraint_pausing:: restore_index ( conn. as_mut ( ) , index) . await ?;
558561 }
559562 // Then restore all constraints.
560563 // The order here is the reverse of drop order, since some constraints may rely
561564 // on other constraints to work.
562565 for constraint in constraints_to_restore. iter ( ) . rev ( ) {
566+ progress. rebuild_constraint ( constraint. name . clone ( ) ) ;
563567 constraint_pausing:: restore_constraint ( conn. as_mut ( ) , constraint) . await ?;
564568 }
565569 Ok ( ( ) )
@@ -574,7 +578,7 @@ impl MasWriter {
574578 ///
575579 /// - If the database connection experiences an error.
576580 #[ tracing:: instrument( skip_all) ]
577- pub async fn finish ( mut self ) -> Result < PgConnection , Error > {
581+ pub async fn finish ( mut self , progress : & Progress ) -> Result < PgConnection , Error > {
578582 self . write_buffer_finish_checker . check_all_finished ( ) ?;
579583
580584 // Commit all writer transactions to the database.
@@ -595,6 +599,7 @@ impl MasWriter {
595599 & mut self . conn ,
596600 & self . indices_to_restore ,
597601 & self . constraints_to_restore ,
602+ progress,
598603 )
599604 . await ?;
600605
@@ -1145,7 +1150,7 @@ mod test {
11451150 use uuid:: { NonNilUuid , Uuid } ;
11461151
11471152 use crate :: {
1148- LockedMasDatabase , MasWriter ,
1153+ LockedMasDatabase , MasWriter , Progress ,
11491154 mas_writer:: {
11501155 MasNewCompatAccessToken , MasNewCompatRefreshToken , MasNewCompatSession ,
11511156 MasNewEmailThreepid , MasNewUnsupportedThreepid , MasNewUpstreamOauthLink , MasNewUser ,
@@ -1275,7 +1280,10 @@ mod test {
12751280 . await
12761281 . expect ( "failed to write user" ) ;
12771282
1278- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1283+ let mut conn = writer
1284+ . finish ( & Progress :: default ( ) )
1285+ . await
1286+ . expect ( "failed to finish MasWriter" ) ;
12791287
12801288 assert_db_snapshot ! ( & mut conn) ;
12811289 }
@@ -1309,7 +1317,10 @@ mod test {
13091317 . await
13101318 . expect ( "failed to write password" ) ;
13111319
1312- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1320+ let mut conn = writer
1321+ . finish ( & Progress :: default ( ) )
1322+ . await
1323+ . expect ( "failed to finish MasWriter" ) ;
13131324
13141325 assert_db_snapshot ! ( & mut conn) ;
13151326 }
@@ -1342,7 +1353,10 @@ mod test {
13421353 . await
13431354 . expect ( "failed to write e-mail" ) ;
13441355
1345- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1356+ let mut conn = writer
1357+ . finish ( & Progress :: default ( ) )
1358+ . await
1359+ . expect ( "failed to finish MasWriter" ) ;
13461360
13471361 assert_db_snapshot ! ( & mut conn) ;
13481362 }
@@ -1376,7 +1390,10 @@ mod test {
13761390 . await
13771391 . expect ( "failed to write phone number (unsupported threepid)" ) ;
13781392
1379- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1393+ let mut conn = writer
1394+ . finish ( & Progress :: default ( ) )
1395+ . await
1396+ . expect ( "failed to finish MasWriter" ) ;
13801397
13811398 assert_db_snapshot ! ( & mut conn) ;
13821399 }
@@ -1412,7 +1429,10 @@ mod test {
14121429 . await
14131430 . expect ( "failed to write link" ) ;
14141431
1415- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1432+ let mut conn = writer
1433+ . finish ( & Progress :: default ( ) )
1434+ . await
1435+ . expect ( "failed to finish MasWriter" ) ;
14161436
14171437 assert_db_snapshot ! ( & mut conn) ;
14181438 }
@@ -1450,7 +1470,10 @@ mod test {
14501470 . await
14511471 . expect ( "failed to write compat session" ) ;
14521472
1453- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1473+ let mut conn = writer
1474+ . finish ( & Progress :: default ( ) )
1475+ . await
1476+ . expect ( "failed to finish MasWriter" ) ;
14541477
14551478 assert_db_snapshot ! ( & mut conn) ;
14561479 }
@@ -1499,7 +1522,10 @@ mod test {
14991522 . await
15001523 . expect ( "failed to write access token" ) ;
15011524
1502- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1525+ let mut conn = writer
1526+ . finish ( & Progress :: default ( ) )
1527+ . await
1528+ . expect ( "failed to finish MasWriter" ) ;
15031529
15041530 assert_db_snapshot ! ( & mut conn) ;
15051531 }
@@ -1560,7 +1586,10 @@ mod test {
15601586 . await
15611587 . expect ( "failed to write refresh token" ) ;
15621588
1563- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1589+ let mut conn = writer
1590+ . finish ( & Progress :: default ( ) )
1591+ . await
1592+ . expect ( "failed to finish MasWriter" ) ;
15641593
15651594 assert_db_snapshot ! ( & mut conn) ;
15661595 }
0 commit comments