Skip to content

Commit e72135e

Browse files
reivilibresandhose
authored andcommitted
Log timings of migrations and index/constraint rebuilds
1 parent 86a2377 commit e72135e

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

crates/syn2mas/src/mas_writer/constraint_pausing.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// SPDX-License-Identifier: AGPL-3.0-only
44
// Please see LICENSE in the repository root for full details.
55

6+
use std::time::Instant;
7+
68
use sqlx::PgConnection;
7-
use tracing::debug;
9+
use tracing::{debug, info};
810

911
use super::{Error, IntoDatabase};
1012

@@ -114,6 +116,8 @@ pub async fn restore_constraint(
114116
conn: &mut PgConnection,
115117
constraint: &ConstraintDescription,
116118
) -> Result<(), Error> {
119+
let start = Instant::now();
120+
117121
let ConstraintDescription {
118122
name,
119123
table_name,
@@ -128,6 +132,11 @@ pub async fn restore_constraint(
128132
format!("failed to recreate constraint {name} on {table_name} with {definition}")
129133
})?;
130134

135+
info!(
136+
"constraint {name} rebuilt in {:.1}s",
137+
Instant::now().duration_since(start).as_secs_f64()
138+
);
139+
131140
Ok(())
132141
}
133142

@@ -136,6 +145,8 @@ pub async fn restore_constraint(
136145
/// The index must not exist prior to this call.
137146
#[tracing::instrument(name = "syn2mas.restore_index", skip_all, fields(index.name = index.name))]
138147
pub async fn restore_index(conn: &mut PgConnection, index: &IndexDescription) -> Result<(), Error> {
148+
let start = Instant::now();
149+
139150
let IndexDescription {
140151
name,
141152
table_name,
@@ -149,5 +160,10 @@ pub async fn restore_index(conn: &mut PgConnection, index: &IndexDescription) ->
149160
format!("failed to recreate index {name} on {table_name} with {definition}")
150161
})?;
151162

163+
info!(
164+
"index {name} rebuilt in {:.1}s",
165+
Instant::now().duration_since(start).as_secs_f64()
166+
);
167+
152168
Ok(())
153169
}

crates/syn2mas/src/migration.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use mas_storage::Clock;
2929
use rand::RngCore;
3030
use thiserror::Error;
3131
use thiserror_ext::ContextInto;
32-
use tracing::{Level, Span};
32+
use tracing::{info, Level, Span};
3333
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
3434
use ulid::Ulid;
3535
use uuid::Uuid;
@@ -252,6 +252,8 @@ async fn migrate_users(
252252
server_name: &str,
253253
rng: &mut impl RngCore,
254254
) -> Result<UsersMigrated, Error> {
255+
let start = Instant::now();
256+
255257
let span = Span::current();
256258
span.pb_set_style(&ProgressStyle::default_bar());
257259
span.pb_set_length(user_count_hint as u64);
@@ -298,6 +300,11 @@ async fn migrate_users(
298300
.await
299301
.into_mas("writing passwords")?;
300302

303+
info!(
304+
"users migrated in {:.1}s",
305+
Instant::now().duration_since(start).as_secs_f64()
306+
);
307+
301308
Ok(UsersMigrated {
302309
user_localparts_to_uuid,
303310
synapse_admins,
@@ -313,6 +320,8 @@ async fn migrate_threepids(
313320
rng: &mut impl RngCore,
314321
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
315322
) -> Result<(), Error> {
323+
let start = Instant::now();
324+
316325
let span = Span::current();
317326
span.pb_set_style(&ProgressStyle::default_bar());
318327
span.pb_set_length(count_hint);
@@ -392,6 +401,11 @@ async fn migrate_threepids(
392401
.await
393402
.into_mas("writing unsupported threepids")?;
394403

404+
info!(
405+
"third-party IDs migrated in {:.1}s",
406+
Instant::now().duration_since(start).as_secs_f64()
407+
);
408+
395409
Ok(())
396410
}
397411

@@ -409,6 +423,8 @@ async fn migrate_external_ids(
409423
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
410424
provider_id_mapping: &HashMap<String, Uuid>,
411425
) -> Result<(), Error> {
426+
let start = Instant::now();
427+
412428
let span = Span::current();
413429
span.pb_set_style(&ProgressStyle::default_bar());
414430
span.pb_set_length(count_hint);
@@ -470,7 +486,12 @@ async fn migrate_external_ids(
470486
write_buffer
471487
.finish(mas)
472488
.await
473-
.into_mas("writing threepids")?;
489+
.into_mas("writing upstream links")?;
490+
491+
info!(
492+
"upstream links (external IDs) migrated in {:.1}s",
493+
Instant::now().duration_since(start).as_secs_f64()
494+
);
474495

475496
Ok(())
476497
}
@@ -495,6 +516,8 @@ async fn migrate_devices(
495516
devices: &mut HashMap<(Uuid, CompactString), Uuid>,
496517
synapse_admins: &HashSet<Uuid>,
497518
) -> Result<(), Error> {
519+
let start = Instant::now();
520+
498521
let span = Span::current();
499522
span.pb_set_style(&ProgressStyle::default_bar());
500523
span.pb_set_length(count_hint);
@@ -579,6 +602,11 @@ async fn migrate_devices(
579602
.await
580603
.into_mas("writing compat sessions")?;
581604

605+
info!(
606+
"devices migrated in {:.1}s",
607+
Instant::now().duration_since(start).as_secs_f64()
608+
);
609+
582610
Ok(())
583611
}
584612

@@ -596,6 +624,8 @@ async fn migrate_unrefreshable_access_tokens(
596624
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
597625
devices: &mut HashMap<(Uuid, CompactString), Uuid>,
598626
) -> Result<(), Error> {
627+
let start = Instant::now();
628+
599629
let span = Span::current();
600630
span.pb_set_style(&ProgressStyle::default_bar());
601631
span.pb_set_length(count_hint);
@@ -697,6 +727,11 @@ async fn migrate_unrefreshable_access_tokens(
697727
.await
698728
.into_mas("writing deviceless compat sessions")?;
699729

730+
info!(
731+
"non-refreshable access tokens migrated in {:.1}s",
732+
Instant::now().duration_since(start).as_secs_f64()
733+
);
734+
700735
Ok(())
701736
}
702737

@@ -714,6 +749,8 @@ async fn migrate_refreshable_token_pairs(
714749
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
715750
devices: &mut HashMap<(Uuid, CompactString), Uuid>,
716751
) -> Result<(), Error> {
752+
let start = Instant::now();
753+
717754
let span = Span::current();
718755
span.pb_set_style(&ProgressStyle::default_bar());
719756
span.pb_set_length(count_hint);
@@ -803,6 +840,11 @@ async fn migrate_refreshable_token_pairs(
803840
.await
804841
.into_mas("writing compat refresh tokens")?;
805842

843+
info!(
844+
"refreshable token pairs migrated in {:.1}s",
845+
Instant::now().duration_since(start).as_secs_f64()
846+
);
847+
806848
Ok(())
807849
}
808850

0 commit comments

Comments
 (0)