Skip to content

Commit bc45146

Browse files
reivilibresandhose
authored andcommitted
Log timings of migrations and index/constraint rebuilds
1 parent 42107ab commit bc45146

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::{info, Level, Span};
2424
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
2525
use ulid::Ulid;
2626
use uuid::Uuid;
@@ -223,6 +223,8 @@ async fn migrate_users(
223223
mut state: MigrationState,
224224
rng: &mut impl RngCore,
225225
) -> Result<(MasWriter, MigrationState), Error> {
226+
let start = Instant::now();
227+
226228
let span = Span::current();
227229
span.pb_set_style(&ProgressStyle::default_bar());
228230
span.pb_set_length(count_hint as u64);
@@ -278,6 +280,11 @@ async fn migrate_users(
278280
.await
279281
.into_mas("writing passwords")?;
280282

283+
info!(
284+
"users migrated in {:.1}s",
285+
Instant::now().duration_since(start).as_secs_f64()
286+
);
287+
281288
Ok((mas, state))
282289
}
283290

@@ -289,6 +296,8 @@ async fn migrate_threepids(
289296
rng: &mut impl RngCore,
290297
state: MigrationState,
291298
) -> Result<(MasWriter, MigrationState), Error> {
299+
let start = Instant::now();
300+
292301
let span = Span::current();
293302
span.pb_set_style(&ProgressStyle::default_bar());
294303
span.pb_set_length(count_hint as u64);
@@ -367,6 +376,11 @@ async fn migrate_threepids(
367376
.await
368377
.into_mas("writing unsupported threepids")?;
369378

379+
info!(
380+
"third-party IDs migrated in {:.1}s",
381+
Instant::now().duration_since(start).as_secs_f64()
382+
);
383+
370384
Ok((mas, state))
371385
}
372386

@@ -382,6 +396,7 @@ async fn migrate_external_ids(
382396
rng: &mut impl RngCore,
383397
state: MigrationState,
384398
) -> Result<(MasWriter, MigrationState), Error> {
399+
let start = Instant::now();
385400
let span = Span::current();
386401
span.pb_set_style(&ProgressStyle::default_bar());
387402
span.pb_set_length(count_hint as u64);
@@ -442,7 +457,12 @@ async fn migrate_external_ids(
442457
write_buffer
443458
.finish(&mut mas)
444459
.await
445-
.into_mas("writing threepids")?;
460+
.into_mas("writing upstream links")?;
461+
462+
info!(
463+
"upstream links (external IDs) migrated in {:.1}s",
464+
Instant::now().duration_since(start).as_secs_f64()
465+
);
446466

447467
Ok((mas, state))
448468
}
@@ -464,6 +484,8 @@ async fn migrate_devices(
464484
rng: &mut impl RngCore,
465485
mut state: MigrationState,
466486
) -> Result<(MasWriter, MigrationState), Error> {
487+
let start = Instant::now();
488+
467489
let span = Span::current();
468490
span.pb_set_style(&ProgressStyle::default_bar());
469491
span.pb_set_length(count_hint as u64);
@@ -551,6 +573,11 @@ async fn migrate_devices(
551573
.await
552574
.into_mas("writing compat sessions")?;
553575

576+
info!(
577+
"devices migrated in {:.1}s",
578+
Instant::now().duration_since(start).as_secs_f64()
579+
);
580+
554581
Ok((mas, state))
555582
}
556583

@@ -566,6 +593,8 @@ async fn migrate_unrefreshable_access_tokens(
566593
rng: &mut impl RngCore,
567594
mut state: MigrationState,
568595
) -> Result<(MasWriter, MigrationState), Error> {
596+
let start = Instant::now();
597+
569598
let span = Span::current();
570599
span.pb_set_style(&ProgressStyle::default_bar());
571600
span.pb_set_length(count_hint as u64);
@@ -670,6 +699,11 @@ async fn migrate_unrefreshable_access_tokens(
670699
.await
671700
.into_mas("writing deviceless compat sessions")?;
672701

702+
info!(
703+
"non-refreshable access tokens migrated in {:.1}s",
704+
Instant::now().duration_since(start).as_secs_f64()
705+
);
706+
673707
Ok((mas, state))
674708
}
675709

@@ -685,6 +719,8 @@ async fn migrate_refreshable_token_pairs(
685719
rng: &mut impl RngCore,
686720
mut state: MigrationState,
687721
) -> Result<(MasWriter, MigrationState), Error> {
722+
let start = Instant::now();
723+
688724
let span = Span::current();
689725
span.pb_set_style(&ProgressStyle::default_bar());
690726
span.pb_set_length(count_hint as u64);
@@ -777,6 +813,11 @@ async fn migrate_refreshable_token_pairs(
777813
.await
778814
.into_mas("writing compat refresh tokens")?;
779815

816+
info!(
817+
"refreshable token pairs migrated in {:.1}s",
818+
Instant::now().duration_since(start).as_secs_f64()
819+
);
820+
780821
Ok((mas, state))
781822
}
782823

0 commit comments

Comments
 (0)