mirror of
https://github.com/element-hq/matrix-authentication-service.git
synced 2026-09-17 08:05:15 +00:00
Better tracing during the migration
This commit is contained in:
committed by
Olivier 'reivilibre
parent
fe5ca2de87
commit
06a2ca33fb
@@ -80,6 +80,7 @@ enum Subcommand {
|
||||
const NUM_WRITER_CONNECTIONS: usize = 8;
|
||||
|
||||
impl Options {
|
||||
#[tracing::instrument("cli.syn2mas.run", skip_all)]
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
|
||||
warn!(
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
use thiserror::Error;
|
||||
use thiserror_ext::ContextInto;
|
||||
use tracing::Instrument as _;
|
||||
|
||||
use super::{MAS_TABLES_AFFECTED_BY_MIGRATION, is_syn2mas_in_progress, locking::LockedMasDatabase};
|
||||
|
||||
@@ -46,7 +47,7 @@ pub enum Error {
|
||||
/// - If any MAS tables involved in the migration are not empty.
|
||||
/// - If we can't check whether syn2mas is already in progress on this database
|
||||
/// or not.
|
||||
#[tracing::instrument(skip_all)]
|
||||
#[tracing::instrument(name = "syn2mas.mas_pre_migration_checks", skip_all)]
|
||||
pub async fn mas_pre_migration_checks(mas_connection: &mut LockedMasDatabase) -> Result<(), Error> {
|
||||
if is_syn2mas_in_progress(mas_connection.as_mut())
|
||||
.await
|
||||
@@ -60,8 +61,11 @@ pub async fn mas_pre_migration_checks(mas_connection: &mut LockedMasDatabase) ->
|
||||
// empty database.
|
||||
|
||||
for &table in MAS_TABLES_AFFECTED_BY_MIGRATION {
|
||||
let row_present = sqlx::query(&format!("SELECT 1 AS dummy FROM {table} LIMIT 1"))
|
||||
let query = format!("SELECT 1 AS dummy FROM {table} LIMIT 1");
|
||||
let span = tracing::info_span!("db.query", db.query.text = query);
|
||||
let row_present = sqlx::query(&query)
|
||||
.fetch_optional(mas_connection.as_mut())
|
||||
.instrument(span)
|
||||
.await
|
||||
.into_maybe_not_mas(table)?
|
||||
.is_some();
|
||||
|
||||
@@ -123,6 +123,8 @@ pub async fn restore_constraint(
|
||||
table_name,
|
||||
definition,
|
||||
} = &constraint;
|
||||
info!("rebuilding constraint {name}");
|
||||
|
||||
sqlx::query(&format!(
|
||||
"ALTER TABLE {table_name} ADD CONSTRAINT {name} {definition};"
|
||||
))
|
||||
|
||||
@@ -389,7 +389,7 @@ impl MasWriter {
|
||||
///
|
||||
/// - If the database connection experiences an error.
|
||||
#[allow(clippy::missing_panics_doc)] // not real
|
||||
#[tracing::instrument(skip_all)]
|
||||
#[tracing::instrument(name = "syn2mas.mas_writer.new", skip_all)]
|
||||
pub async fn new(
|
||||
mut conn: LockedMasDatabase,
|
||||
mut writer_connections: Vec<PgConnection>,
|
||||
|
||||
Reference in New Issue
Block a user