Skip to content

Commit 31efc3b

Browse files
committed
Better tracing during the migration
1 parent 95fd7f1 commit 31efc3b

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

crates/cli/src/commands/syn2mas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum Subcommand {
8080
const NUM_WRITER_CONNECTIONS: usize = 8;
8181

8282
impl Options {
83+
#[tracing::instrument("cli.syn2mas.run", skip_all)]
8384
#[allow(clippy::too_many_lines)]
8485
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
8586
warn!("This version of the syn2mas tool is EXPERIMENTAL and INCOMPLETE. Do not use it, except for TESTING.");

crates/syn2mas/src/mas_writer/checks.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
//! This module provides safety checks to run against a MAS database before
99
//! running the Synapse-to-MAS migration.
1010
11+
use mas_storage_pg::ExecuteExt;
1112
use thiserror::Error;
1213
use thiserror_ext::ContextInto;
14+
use tracing::Instrument as _;
1315

1416
use super::{is_syn2mas_in_progress, locking::LockedMasDatabase, MAS_TABLES_AFFECTED_BY_MIGRATION};
1517

@@ -46,7 +48,7 @@ pub enum Error {
4648
/// - If any MAS tables involved in the migration are not empty.
4749
/// - If we can't check whether syn2mas is already in progress on this database
4850
/// or not.
49-
#[tracing::instrument(skip_all)]
51+
#[tracing::instrument(name = "syn2mas.mas_pre_migration_checks", skip_all)]
5052
pub async fn mas_pre_migration_checks<'a>(
5153
mas_connection: &mut LockedMasDatabase<'a>,
5254
) -> Result<(), Error> {
@@ -62,8 +64,11 @@ pub async fn mas_pre_migration_checks<'a>(
6264
// empty database.
6365

6466
for &table in MAS_TABLES_AFFECTED_BY_MIGRATION {
65-
let row_present = sqlx::query(&format!("SELECT 1 AS dummy FROM {table} LIMIT 1"))
67+
let query = format!("SELECT 1 AS dummy FROM {table} LIMIT 1");
68+
let span = tracing::info_span!("db.query", db.query.text = query);
69+
let row_present = sqlx::query(&query)
6670
.fetch_optional(mas_connection.as_mut())
71+
.instrument(span)
6772
.await
6873
.into_maybe_not_mas(table)?
6974
.is_some();

crates/syn2mas/src/mas_writer/constraint_pausing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub async fn restore_constraint(
141141
definition,
142142
is_fk: _,
143143
} = &constraint;
144+
info!("rebuilding constraint {name}");
145+
144146
sqlx::query(&format!(
145147
"ALTER TABLE {table_name} ADD CONSTRAINT {name} {definition};"
146148
))

crates/syn2mas/src/mas_writer/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'conn> MasWriter<'conn> {
397397
///
398398
/// - If the database connection experiences an error.
399399
#[allow(clippy::missing_panics_doc)] // not real
400-
#[tracing::instrument(skip_all)]
400+
#[tracing::instrument(name = "syn2mas.mas_writer.new", skip_all)]
401401
pub async fn new(
402402
mut conn: LockedMasDatabase<'conn>,
403403
index_restore_conn: PgConnection,
@@ -526,7 +526,7 @@ impl<'conn> MasWriter<'conn> {
526526
})
527527
}
528528

529-
#[tracing::instrument(skip_all)]
529+
#[tracing::instrument(name = "syn2mas.mas_writer.restore_task", skip_all)]
530530
fn restore_task(
531531
mut conn: PgConnection,
532532
) -> (
@@ -551,9 +551,10 @@ impl<'conn> MasWriter<'conn> {
551551
}
552552
}
553553

554+
tracing::info!("Restoring task done");
554555
Ok(())
555556
}
556-
.instrument(tracing::info_span!("restore")),
557+
.instrument(tracing::info_span!("syn2mas.mas_writer.restore_loop")),
557558
);
558559

559560
(constraint_restore_tx, index_restore_tx, restorer_task)

0 commit comments

Comments
 (0)