Skip to content

Commit 40e67e4

Browse files
committed
Log timings of migrations and index/constraint rebuilds
1 parent a431ccb commit 40e67e4

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-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: 45 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;
23+
use tracing::{Level, info};
2424
use ulid::Ulid;
2525
use uuid::{NonNilUuid, Uuid};
2626

@@ -177,6 +177,8 @@ async fn migrate_users(
177177
mut state: MigrationState,
178178
rng: &mut impl RngCore,
179179
) -> Result<(MasWriter, MigrationState), Error> {
180+
let start = Instant::now();
181+
180182
let mut user_buffer = MasWriteBuffer::new(&mas, MasWriter::write_users);
181183
let mut password_buffer = MasWriteBuffer::new(&mas, MasWriter::write_passwords);
182184
let mut users_stream = pin!(synapse.read_users());
@@ -254,6 +256,11 @@ async fn migrate_users(
254256
.await
255257
.into_mas("writing passwords")?;
256258

259+
info!(
260+
"users migrated in {:.1}s",
261+
Instant::now().duration_since(start).as_secs_f64()
262+
);
263+
257264
Ok((mas, state))
258265
}
259266

@@ -264,6 +271,8 @@ async fn migrate_threepids(
264271
rng: &mut impl RngCore,
265272
state: MigrationState,
266273
) -> Result<(MasWriter, MigrationState), Error> {
274+
let start = Instant::now();
275+
267276
let mut email_buffer = MasWriteBuffer::new(&mas, MasWriter::write_email_threepids);
268277
let mut unsupported_buffer = MasWriteBuffer::new(&mas, MasWriter::write_unsupported_threepids);
269278
let mut users_stream = pin!(synapse.read_threepids());
@@ -333,6 +342,11 @@ async fn migrate_threepids(
333342
.await
334343
.into_mas("writing unsupported threepids")?;
335344

345+
info!(
346+
"third-party IDs migrated in {:.1}s",
347+
Instant::now().duration_since(start).as_secs_f64()
348+
);
349+
336350
Ok((mas, state))
337351
}
338352

@@ -347,6 +361,8 @@ async fn migrate_external_ids(
347361
rng: &mut impl RngCore,
348362
state: MigrationState,
349363
) -> Result<(MasWriter, MigrationState), Error> {
364+
let start = Instant::now();
365+
350366
let mut write_buffer = MasWriteBuffer::new(&mas, MasWriter::write_upstream_oauth_links);
351367
let mut extids_stream = pin!(synapse.read_user_external_ids());
352368

@@ -402,7 +418,12 @@ async fn migrate_external_ids(
402418
write_buffer
403419
.finish(&mut mas)
404420
.await
405-
.into_mas("writing threepids")?;
421+
.into_mas("writing upstream links")?;
422+
423+
info!(
424+
"upstream links (external IDs) migrated in {:.1}s",
425+
Instant::now().duration_since(start).as_secs_f64()
426+
);
406427

407428
Ok((mas, state))
408429
}
@@ -422,6 +443,8 @@ async fn migrate_devices(
422443
rng: &mut impl RngCore,
423444
mut state: MigrationState,
424445
) -> Result<(MasWriter, MigrationState), Error> {
446+
let start = Instant::now();
447+
425448
let mut devices_stream = pin!(synapse.read_devices());
426449
let mut write_buffer = MasWriteBuffer::new(&mas, MasWriter::write_compat_sessions);
427450

@@ -509,6 +532,11 @@ async fn migrate_devices(
509532
.await
510533
.into_mas("writing compat sessions")?;
511534

535+
info!(
536+
"devices migrated in {:.1}s",
537+
Instant::now().duration_since(start).as_secs_f64()
538+
);
539+
512540
Ok((mas, state))
513541
}
514542

@@ -522,6 +550,8 @@ async fn migrate_unrefreshable_access_tokens(
522550
rng: &mut impl RngCore,
523551
mut state: MigrationState,
524552
) -> Result<(MasWriter, MigrationState), Error> {
553+
let start = Instant::now();
554+
525555
let mut token_stream = pin!(synapse.read_unrefreshable_access_tokens());
526556
let mut write_buffer = MasWriteBuffer::new(&mas, MasWriter::write_compat_access_tokens);
527557
let mut deviceless_session_write_buffer =
@@ -624,6 +654,11 @@ async fn migrate_unrefreshable_access_tokens(
624654
.await
625655
.into_mas("writing deviceless compat sessions")?;
626656

657+
info!(
658+
"non-refreshable access tokens migrated in {:.1}s",
659+
Instant::now().duration_since(start).as_secs_f64()
660+
);
661+
627662
Ok((mas, state))
628663
}
629664

@@ -637,6 +672,8 @@ async fn migrate_refreshable_token_pairs(
637672
rng: &mut impl RngCore,
638673
mut state: MigrationState,
639674
) -> Result<(MasWriter, MigrationState), Error> {
675+
let start = Instant::now();
676+
640677
let mut token_stream = pin!(synapse.read_refreshable_token_pairs());
641678
let mut access_token_write_buffer =
642679
MasWriteBuffer::new(&mas, MasWriter::write_compat_access_tokens);
@@ -727,6 +764,11 @@ async fn migrate_refreshable_token_pairs(
727764
.await
728765
.into_mas("writing compat refresh tokens")?;
729766

767+
info!(
768+
"refreshable token pairs migrated in {:.1}s",
769+
Instant::now().duration_since(start).as_secs_f64()
770+
);
771+
730772
Ok((mas, state))
731773
}
732774

0 commit comments

Comments
 (0)