Skip to content

Commit 802e828

Browse files
committed
Log timings of migrations and index/constraint rebuilds
1 parent f31027d commit 802e828

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-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: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use std::{
1515
collections::{HashMap, HashSet},
1616
pin::pin,
17+
time::Instant,
1718
};
1819

1920
use chrono::{DateTime, Utc};
@@ -23,7 +24,7 @@ use mas_storage::Clock;
2324
use rand::RngCore;
2425
use thiserror::Error;
2526
use thiserror_ext::ContextInto;
26-
use tracing::{Level, Span};
27+
use tracing::{info, Level, Span};
2728
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
2829
use ulid::Ulid;
2930
use uuid::Uuid;
@@ -246,6 +247,8 @@ async fn migrate_users(
246247
server_name: &str,
247248
rng: &mut impl RngCore,
248249
) -> Result<UsersMigrated, Error> {
250+
let start = Instant::now();
251+
249252
let span = Span::current();
250253
span.pb_set_style(&ProgressStyle::default_bar());
251254
span.pb_set_length(user_count_hint as u64);
@@ -292,6 +295,11 @@ async fn migrate_users(
292295
.await
293296
.into_mas("writing passwords")?;
294297

298+
info!(
299+
"users migrated in {:.1}s",
300+
Instant::now().duration_since(start).as_secs_f64()
301+
);
302+
295303
Ok(UsersMigrated {
296304
user_localparts_to_uuid,
297305
synapse_admins,
@@ -307,6 +315,8 @@ async fn migrate_threepids(
307315
rng: &mut impl RngCore,
308316
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
309317
) -> Result<(), Error> {
318+
let start = Instant::now();
319+
310320
let span = Span::current();
311321
span.pb_set_style(&ProgressStyle::default_bar());
312322
span.pb_set_length(count_hint);
@@ -386,6 +396,11 @@ async fn migrate_threepids(
386396
.await
387397
.into_mas("writing unsupported threepids")?;
388398

399+
info!(
400+
"third-party IDs migrated in {:.1}s",
401+
Instant::now().duration_since(start).as_secs_f64()
402+
);
403+
389404
Ok(())
390405
}
391406

@@ -403,6 +418,8 @@ async fn migrate_external_ids(
403418
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
404419
provider_id_mapping: &HashMap<String, Uuid>,
405420
) -> Result<(), Error> {
421+
let start = Instant::now();
422+
406423
let span = Span::current();
407424
span.pb_set_style(&ProgressStyle::default_bar());
408425
span.pb_set_length(count_hint);
@@ -464,7 +481,12 @@ async fn migrate_external_ids(
464481
write_buffer
465482
.finish(mas)
466483
.await
467-
.into_mas("writing threepids")?;
484+
.into_mas("writing upstream links")?;
485+
486+
info!(
487+
"upstream links (external IDs) migrated in {:.1}s",
488+
Instant::now().duration_since(start).as_secs_f64()
489+
);
468490

469491
Ok(())
470492
}
@@ -489,6 +511,8 @@ async fn migrate_devices(
489511
devices: &mut HashMap<(Uuid, CompactString), Uuid>,
490512
synapse_admins: &HashSet<Uuid>,
491513
) -> Result<(), Error> {
514+
let start = Instant::now();
515+
492516
let span = Span::current();
493517
span.pb_set_style(&ProgressStyle::default_bar());
494518
span.pb_set_length(count_hint);
@@ -556,6 +580,11 @@ async fn migrate_devices(
556580
.await
557581
.into_mas("writing compat sessions")?;
558582

583+
info!(
584+
"devices migrated in {:.1}s",
585+
Instant::now().duration_since(start).as_secs_f64()
586+
);
587+
559588
Ok(())
560589
}
561590

@@ -573,6 +602,8 @@ async fn migrate_unrefreshable_access_tokens(
573602
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
574603
devices: &mut HashMap<(Uuid, CompactString), Uuid>,
575604
) -> Result<(), Error> {
605+
let start = Instant::now();
606+
576607
let span = Span::current();
577608
span.pb_set_style(&ProgressStyle::default_bar());
578609
span.pb_set_length(count_hint);
@@ -674,6 +705,11 @@ async fn migrate_unrefreshable_access_tokens(
674705
.await
675706
.into_mas("writing deviceless compat sessions")?;
676707

708+
info!(
709+
"non-refreshable access tokens migrated in {:.1}s",
710+
Instant::now().duration_since(start).as_secs_f64()
711+
);
712+
677713
Ok(())
678714
}
679715

@@ -691,6 +727,8 @@ async fn migrate_refreshable_token_pairs(
691727
user_localparts_to_uuid: &HashMap<CompactString, Uuid>,
692728
devices: &mut HashMap<(Uuid, CompactString), Uuid>,
693729
) -> Result<(), Error> {
730+
let start = Instant::now();
731+
694732
let span = Span::current();
695733
span.pb_set_style(&ProgressStyle::default_bar());
696734
span.pb_set_length(count_hint);
@@ -780,6 +818,11 @@ async fn migrate_refreshable_token_pairs(
780818
.await
781819
.into_mas("writing compat refresh tokens")?;
782820

821+
info!(
822+
"refreshable token pairs migrated in {:.1}s",
823+
Instant::now().duration_since(start).as_secs_f64()
824+
);
825+
783826
Ok(())
784827
}
785828

0 commit comments

Comments
 (0)