@@ -29,6 +29,7 @@ use self::{
29
29
constraint_pausing:: { ConstraintDescription , IndexDescription } ,
30
30
locking:: LockedMasDatabase ,
31
31
} ;
32
+ use crate :: Progress ;
32
33
33
34
pub mod checks;
34
35
pub mod locking;
@@ -550,16 +551,19 @@ impl MasWriter {
550
551
conn : & mut LockedMasDatabase ,
551
552
indices_to_restore : & [ IndexDescription ] ,
552
553
constraints_to_restore : & [ ConstraintDescription ] ,
554
+ progress : & Progress ,
553
555
) -> Result < ( ) , Error > {
554
556
// First restore all indices. The order is not important as far as I know.
555
557
// However the indices are needed before constraints.
556
558
for index in indices_to_restore. iter ( ) . rev ( ) {
559
+ progress. rebuild_index ( index. name . clone ( ) ) ;
557
560
constraint_pausing:: restore_index ( conn. as_mut ( ) , index) . await ?;
558
561
}
559
562
// Then restore all constraints.
560
563
// The order here is the reverse of drop order, since some constraints may rely
561
564
// on other constraints to work.
562
565
for constraint in constraints_to_restore. iter ( ) . rev ( ) {
566
+ progress. rebuild_constraint ( constraint. name . clone ( ) ) ;
563
567
constraint_pausing:: restore_constraint ( conn. as_mut ( ) , constraint) . await ?;
564
568
}
565
569
Ok ( ( ) )
@@ -574,7 +578,7 @@ impl MasWriter {
574
578
///
575
579
/// - If the database connection experiences an error.
576
580
#[ 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 > {
578
582
self . write_buffer_finish_checker . check_all_finished ( ) ?;
579
583
580
584
// Commit all writer transactions to the database.
@@ -595,6 +599,7 @@ impl MasWriter {
595
599
& mut self . conn ,
596
600
& self . indices_to_restore ,
597
601
& self . constraints_to_restore ,
602
+ progress,
598
603
)
599
604
. await ?;
600
605
@@ -1148,7 +1153,7 @@ mod test {
1148
1153
use uuid:: { NonNilUuid , Uuid } ;
1149
1154
1150
1155
use crate :: {
1151
- LockedMasDatabase , MasWriter ,
1156
+ LockedMasDatabase , MasWriter , Progress ,
1152
1157
mas_writer:: {
1153
1158
MasNewCompatAccessToken , MasNewCompatRefreshToken , MasNewCompatSession ,
1154
1159
MasNewEmailThreepid , MasNewUnsupportedThreepid , MasNewUpstreamOauthLink , MasNewUser ,
@@ -1278,7 +1283,10 @@ mod test {
1278
1283
. await
1279
1284
. expect ( "failed to write user" ) ;
1280
1285
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" ) ;
1282
1290
1283
1291
assert_db_snapshot ! ( & mut conn) ;
1284
1292
}
@@ -1312,7 +1320,10 @@ mod test {
1312
1320
. await
1313
1321
. expect ( "failed to write password" ) ;
1314
1322
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" ) ;
1316
1327
1317
1328
assert_db_snapshot ! ( & mut conn) ;
1318
1329
}
@@ -1345,7 +1356,10 @@ mod test {
1345
1356
. await
1346
1357
. expect ( "failed to write e-mail" ) ;
1347
1358
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" ) ;
1349
1363
1350
1364
assert_db_snapshot ! ( & mut conn) ;
1351
1365
}
@@ -1379,7 +1393,10 @@ mod test {
1379
1393
. await
1380
1394
. expect ( "failed to write phone number (unsupported threepid)" ) ;
1381
1395
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" ) ;
1383
1400
1384
1401
assert_db_snapshot ! ( & mut conn) ;
1385
1402
}
@@ -1415,7 +1432,10 @@ mod test {
1415
1432
. await
1416
1433
. expect ( "failed to write link" ) ;
1417
1434
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" ) ;
1419
1439
1420
1440
assert_db_snapshot ! ( & mut conn) ;
1421
1441
}
@@ -1453,7 +1473,10 @@ mod test {
1453
1473
. await
1454
1474
. expect ( "failed to write compat session" ) ;
1455
1475
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" ) ;
1457
1480
1458
1481
assert_db_snapshot ! ( & mut conn) ;
1459
1482
}
@@ -1502,7 +1525,10 @@ mod test {
1502
1525
. await
1503
1526
. expect ( "failed to write access token" ) ;
1504
1527
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" ) ;
1506
1532
1507
1533
assert_db_snapshot ! ( & mut conn) ;
1508
1534
}
@@ -1563,7 +1589,10 @@ mod test {
1563
1589
. await
1564
1590
. expect ( "failed to write refresh token" ) ;
1565
1591
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" ) ;
1567
1596
1568
1597
assert_db_snapshot ! ( & mut conn) ;
1569
1598
}
0 commit comments