@@ -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
@@ -1148,7 +1153,7 @@ mod test {
11481153 use uuid:: { NonNilUuid , Uuid } ;
11491154
11501155 use crate :: {
1151- LockedMasDatabase , MasWriter ,
1156+ LockedMasDatabase , MasWriter , Progress ,
11521157 mas_writer:: {
11531158 MasNewCompatAccessToken , MasNewCompatRefreshToken , MasNewCompatSession ,
11541159 MasNewEmailThreepid , MasNewUnsupportedThreepid , MasNewUpstreamOauthLink , MasNewUser ,
@@ -1278,7 +1283,10 @@ mod test {
12781283 . await
12791284 . expect ( "failed to write user" ) ;
12801285
1281- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1286+ let mut conn = writer
1287+ . finish ( & Progress :: default ( ) )
1288+ . await
1289+ . expect ( "failed to finish MasWriter" ) ;
12821290
12831291 assert_db_snapshot ! ( & mut conn) ;
12841292 }
@@ -1312,7 +1320,10 @@ mod test {
13121320 . await
13131321 . expect ( "failed to write password" ) ;
13141322
1315- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1323+ let mut conn = writer
1324+ . finish ( & Progress :: default ( ) )
1325+ . await
1326+ . expect ( "failed to finish MasWriter" ) ;
13161327
13171328 assert_db_snapshot ! ( & mut conn) ;
13181329 }
@@ -1345,7 +1356,10 @@ mod test {
13451356 . await
13461357 . expect ( "failed to write e-mail" ) ;
13471358
1348- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1359+ let mut conn = writer
1360+ . finish ( & Progress :: default ( ) )
1361+ . await
1362+ . expect ( "failed to finish MasWriter" ) ;
13491363
13501364 assert_db_snapshot ! ( & mut conn) ;
13511365 }
@@ -1379,7 +1393,10 @@ mod test {
13791393 . await
13801394 . expect ( "failed to write phone number (unsupported threepid)" ) ;
13811395
1382- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1396+ let mut conn = writer
1397+ . finish ( & Progress :: default ( ) )
1398+ . await
1399+ . expect ( "failed to finish MasWriter" ) ;
13831400
13841401 assert_db_snapshot ! ( & mut conn) ;
13851402 }
@@ -1415,7 +1432,10 @@ mod test {
14151432 . await
14161433 . expect ( "failed to write link" ) ;
14171434
1418- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1435+ let mut conn = writer
1436+ . finish ( & Progress :: default ( ) )
1437+ . await
1438+ . expect ( "failed to finish MasWriter" ) ;
14191439
14201440 assert_db_snapshot ! ( & mut conn) ;
14211441 }
@@ -1453,7 +1473,10 @@ mod test {
14531473 . await
14541474 . expect ( "failed to write compat session" ) ;
14551475
1456- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1476+ let mut conn = writer
1477+ . finish ( & Progress :: default ( ) )
1478+ . await
1479+ . expect ( "failed to finish MasWriter" ) ;
14571480
14581481 assert_db_snapshot ! ( & mut conn) ;
14591482 }
@@ -1502,7 +1525,10 @@ mod test {
15021525 . await
15031526 . expect ( "failed to write access token" ) ;
15041527
1505- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1528+ let mut conn = writer
1529+ . finish ( & Progress :: default ( ) )
1530+ . await
1531+ . expect ( "failed to finish MasWriter" ) ;
15061532
15071533 assert_db_snapshot ! ( & mut conn) ;
15081534 }
@@ -1563,7 +1589,10 @@ mod test {
15631589 . await
15641590 . expect ( "failed to write refresh token" ) ;
15651591
1566- let mut conn = writer. finish ( ) . await . expect ( "failed to finish MasWriter" ) ;
1592+ let mut conn = writer
1593+ . finish ( & Progress :: default ( ) )
1594+ . await
1595+ . expect ( "failed to finish MasWriter" ) ;
15671596
15681597 assert_db_snapshot ! ( & mut conn) ;
15691598 }
0 commit comments