@@ -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
@@ -1145,7 +1150,7 @@ mod test {
1145
1150
use uuid:: { NonNilUuid , Uuid } ;
1146
1151
1147
1152
use crate :: {
1148
- LockedMasDatabase , MasWriter ,
1153
+ LockedMasDatabase , MasWriter , Progress ,
1149
1154
mas_writer:: {
1150
1155
MasNewCompatAccessToken , MasNewCompatRefreshToken , MasNewCompatSession ,
1151
1156
MasNewEmailThreepid , MasNewUnsupportedThreepid , MasNewUpstreamOauthLink , MasNewUser ,
@@ -1275,7 +1280,10 @@ mod test {
1275
1280
. await
1276
1281
. expect ( "failed to write user" ) ;
1277
1282
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" ) ;
1279
1287
1280
1288
assert_db_snapshot ! ( & mut conn) ;
1281
1289
}
@@ -1309,7 +1317,10 @@ mod test {
1309
1317
. await
1310
1318
. expect ( "failed to write password" ) ;
1311
1319
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" ) ;
1313
1324
1314
1325
assert_db_snapshot ! ( & mut conn) ;
1315
1326
}
@@ -1342,7 +1353,10 @@ mod test {
1342
1353
. await
1343
1354
. expect ( "failed to write e-mail" ) ;
1344
1355
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" ) ;
1346
1360
1347
1361
assert_db_snapshot ! ( & mut conn) ;
1348
1362
}
@@ -1376,7 +1390,10 @@ mod test {
1376
1390
. await
1377
1391
. expect ( "failed to write phone number (unsupported threepid)" ) ;
1378
1392
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" ) ;
1380
1397
1381
1398
assert_db_snapshot ! ( & mut conn) ;
1382
1399
}
@@ -1412,7 +1429,10 @@ mod test {
1412
1429
. await
1413
1430
. expect ( "failed to write link" ) ;
1414
1431
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" ) ;
1416
1436
1417
1437
assert_db_snapshot ! ( & mut conn) ;
1418
1438
}
@@ -1450,7 +1470,10 @@ mod test {
1450
1470
. await
1451
1471
. expect ( "failed to write compat session" ) ;
1452
1472
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" ) ;
1454
1477
1455
1478
assert_db_snapshot ! ( & mut conn) ;
1456
1479
}
@@ -1499,7 +1522,10 @@ mod test {
1499
1522
. await
1500
1523
. expect ( "failed to write access token" ) ;
1501
1524
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" ) ;
1503
1529
1504
1530
assert_db_snapshot ! ( & mut conn) ;
1505
1531
}
@@ -1560,7 +1586,10 @@ mod test {
1560
1586
. await
1561
1587
. expect ( "failed to write refresh token" ) ;
1562
1588
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" ) ;
1564
1593
1565
1594
assert_db_snapshot ! ( & mut conn) ;
1566
1595
}
0 commit comments