Skip to content

Commit 1cd080d

Browse files
reivilibresandhose
authored andcommitted
Log timings of migrations and index/constraint rebuilds
1 parent 52da42f commit 1cd080d

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! This module does not implement any of the safety checks that should be run
1212
//! *before* the migration.
1313
14-
use std::{collections::HashMap, pin::pin};
14+
use std::{collections::HashMap, pin::pin, time::Instant};
1515

1616
use chrono::{DateTime, Utc};
1717
use compact_str::CompactString;
@@ -20,7 +20,7 @@ use mas_storage::Clock;
2020
use rand::RngCore;
2121
use thiserror::Error;
2222
use thiserror_ext::ContextInto;
23-
use tracing::{Level, Span};
23+
use tracing::{Level, Span, info};
2424
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
2525
use ulid::Ulid;
2626
use uuid::Uuid;
@@ -230,6 +230,8 @@ async fn migrate_users(
230230
mut state: MigrationState,
231231
rng: &mut impl RngCore,
232232
) -> Result<(MasWriter, MigrationState), Error> {
233+
let start = Instant::now();
234+
233235
let span = Span::current();
234236
span.pb_set_style(&ProgressStyle::default_bar());
235237
span.pb_set_length(count_hint as u64);
@@ -299,6 +301,11 @@ async fn migrate_users(
299301
.await
300302
.into_mas("writing passwords")?;
301303

304+
info!(
305+
"users migrated in {:.1}s",
306+
Instant::now().duration_since(start).as_secs_f64()
307+
);
308+
302309
Ok((mas, state))
303310
}
304311

@@ -310,6 +317,8 @@ async fn migrate_threepids(
310317
rng: &mut impl RngCore,
311318
state: MigrationState,
312319
) -> Result<(MasWriter, MigrationState), Error> {
320+
let start = Instant::now();
321+
313322
let span = Span::current();
314323
span.pb_set_style(&ProgressStyle::default_bar());
315324
span.pb_set_length(count_hint as u64);
@@ -385,6 +394,11 @@ async fn migrate_threepids(
385394
.await
386395
.into_mas("writing unsupported threepids")?;
387396

397+
info!(
398+
"third-party IDs migrated in {:.1}s",
399+
Instant::now().duration_since(start).as_secs_f64()
400+
);
401+
388402
Ok((mas, state))
389403
}
390404

@@ -400,6 +414,7 @@ async fn migrate_external_ids(
400414
rng: &mut impl RngCore,
401415
state: MigrationState,
402416
) -> Result<(MasWriter, MigrationState), Error> {
417+
let start = Instant::now();
403418
let span = Span::current();
404419
span.pb_set_style(&ProgressStyle::default_bar());
405420
span.pb_set_length(count_hint as u64);
@@ -461,7 +476,12 @@ async fn migrate_external_ids(
461476
write_buffer
462477
.finish(&mut mas)
463478
.await
464-
.into_mas("writing threepids")?;
479+
.into_mas("writing upstream links")?;
480+
481+
info!(
482+
"upstream links (external IDs) migrated in {:.1}s",
483+
Instant::now().duration_since(start).as_secs_f64()
484+
);
465485

466486
Ok((mas, state))
467487
}
@@ -483,6 +503,8 @@ async fn migrate_devices(
483503
rng: &mut impl RngCore,
484504
mut state: MigrationState,
485505
) -> Result<(MasWriter, MigrationState), Error> {
506+
let start = Instant::now();
507+
486508
let span = Span::current();
487509
span.pb_set_style(&ProgressStyle::default_bar());
488510
span.pb_set_length(count_hint as u64);
@@ -572,6 +594,11 @@ async fn migrate_devices(
572594
.await
573595
.into_mas("writing compat sessions")?;
574596

597+
info!(
598+
"devices migrated in {:.1}s",
599+
Instant::now().duration_since(start).as_secs_f64()
600+
);
601+
575602
Ok((mas, state))
576603
}
577604

@@ -587,6 +614,8 @@ async fn migrate_unrefreshable_access_tokens(
587614
rng: &mut impl RngCore,
588615
mut state: MigrationState,
589616
) -> Result<(MasWriter, MigrationState), Error> {
617+
let start = Instant::now();
618+
590619
let span = Span::current();
591620
span.pb_set_style(&ProgressStyle::default_bar());
592621
span.pb_set_length(count_hint as u64);
@@ -691,6 +720,11 @@ async fn migrate_unrefreshable_access_tokens(
691720
.await
692721
.into_mas("writing deviceless compat sessions")?;
693722

723+
info!(
724+
"non-refreshable access tokens migrated in {:.1}s",
725+
Instant::now().duration_since(start).as_secs_f64()
726+
);
727+
694728
Ok((mas, state))
695729
}
696730

@@ -706,6 +740,8 @@ async fn migrate_refreshable_token_pairs(
706740
rng: &mut impl RngCore,
707741
mut state: MigrationState,
708742
) -> Result<(MasWriter, MigrationState), Error> {
743+
let start = Instant::now();
744+
709745
let span = Span::current();
710746
span.pb_set_style(&ProgressStyle::default_bar());
711747
span.pb_set_length(count_hint as u64);
@@ -798,6 +834,11 @@ async fn migrate_refreshable_token_pairs(
798834
.await
799835
.into_mas("writing compat refresh tokens")?;
800836

837+
info!(
838+
"refreshable token pairs migrated in {:.1}s",
839+
Instant::now().duration_since(start).as_secs_f64()
840+
);
841+
801842
Ok((mas, state))
802843
}
803844

0 commit comments

Comments
 (0)