diff --git a/Cargo.lock b/Cargo.lock index 3b5d3fe5fc..6ab3703f13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1142,7 +1142,7 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "glean" -version = "0.18.1" +version = "0.17.15" dependencies = [ "chrono", "serde 1.0.203", @@ -1241,9 +1241,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -2045,15 +2045,15 @@ checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" [[package]] name = "pyo3" -version = "0.21.2" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "3d922163ba1f79c04bc49073ba7b32fd5a8d3b76a87c955921234b8e77333c51" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -2063,9 +2063,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "bc38c5feeb496c8321091edf3d63e9a6829eab4b863b4a6a65f26f3e9cc6b179" dependencies = [ "once_cell", "target-lexicon", @@ -2073,9 +2073,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "94845622d88ae274d2729fcefc850e63d7a3ddff5e3ce11bd88486db9f1d357d" dependencies = [ "libc", "pyo3-build-config", @@ -2083,9 +2083,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "e655aad15e09b94ffdb3ce3d217acf652e26bbc37697ef012f5e5e348c716e5e" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -2095,9 +2095,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "ae1e3f09eecd94618f60a455a23def79f79eba4dc561a97324bf9ac8c6df30ce" dependencies = [ "heck", "proc-macro2", @@ -2455,8 +2455,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "sentry" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "016958f51b96861dead7c1e02290f138411d05e94fad175c8636a835dee6e51e" dependencies = [ "curl", "httpdate", @@ -2469,8 +2470,9 @@ dependencies = [ [[package]] name = "sentry-backtrace" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57712c24e99252ef175b4b06c485294f10ad6bc5b5e1567ff3803ee7a0b7d3f" dependencies = [ "backtrace", "once_cell", @@ -2480,8 +2482,9 @@ dependencies = [ [[package]] name = "sentry-contexts" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eba8754ec3b9279e00aa6d64916f211d44202370a1699afde1db2c16cbada089" dependencies = [ "hostname", "libc", @@ -2493,8 +2496,9 @@ dependencies = [ [[package]] name = "sentry-core" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8b6dcd4fbae1e3e22b447f32670360b27e31b62ab040f7fb04e0f80c04d92" dependencies = [ "once_cell", "rand", @@ -2505,8 +2509,9 @@ dependencies = [ [[package]] name = "sentry-debug-images" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8982a69133d3f5e4efdbfa0776937fca43c3a2e275a8fe184f50b1b0aa92e07c" dependencies = [ "findshlibs", "once_cell", @@ -2515,8 +2520,9 @@ dependencies = [ [[package]] name = "sentry-tracing" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "263f73c757ed7915d3e1e34625eae18cad498a95b4261603d4ce3f87b159a6f0" dependencies = [ "sentry-backtrace", "sentry-core", @@ -2526,8 +2532,9 @@ dependencies = [ [[package]] name = "sentry-types" -version = "0.34.0" -source = "git+https://github.com/getsentry/sentry-rust?rev=1b65b5c#1b65b5c99af975496880e7325218479e0037d097" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a71ed3a389948a6a6d92b98e997a2723ca22f09660c5a7b7388ecd509a70a527" dependencies = [ "debugid", "hex", @@ -2999,6 +3006,7 @@ dependencies = [ name = "syncstorage-spanner" version = "0.18.1" dependencies = [ + "actix-web", "async-trait", "backtrace", "cadence", diff --git a/Cargo.toml b/Cargo.toml index f368953b81..fa5c74a93b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,15 +65,13 @@ regex = "1.4" reqwest = { version = "0.12", default-features = false, features = [ "rustls-tls", ] } -# rev 1b65b5c includes https://github.com/getsentry/sentry-rust/pull/701 -# TODO: bump to 0.35 as soon as it's available -sentry = { version = "0.34", git = "https://github.com/getsentry/sentry-rust", rev = "1b65b5c", default-features = false, features = [ +sentry = { version = "0.35", default-features = false, features = [ "curl", "backtrace", "contexts", "debug-images", ] } -sentry-backtrace = { version = "0.34", git = "https://github.com/getsentry/sentry-rust", rev = "1b65b5c" } +sentry-backtrace = "0.35" serde = "1.0" serde_derive = "1.0" serde_json = { version = "1.0", features = ["arbitrary_precision"] } diff --git a/syncserver-db-common/src/error.rs b/syncserver-db-common/src/error.rs index 42ed4473af..a414985624 100644 --- a/syncserver-db-common/src/error.rs +++ b/syncserver-db-common/src/error.rs @@ -5,17 +5,17 @@ use http::StatusCode; use syncserver_common::{from_error, impl_fmt_display, ReportableError}; use thiserror::Error; -/// Error specific to any MySQL database backend. These errors are not related to the syncstorage +/// Error specific to any SQL database backend. These errors are not related to the syncstorage /// or tokenserver application logic; rather, they are lower-level errors arising from diesel. #[derive(Debug)] -pub struct MysqlError { - kind: MysqlErrorKind, +pub struct SqlError { + kind: SqlErrorKind, pub status: StatusCode, pub backtrace: Backtrace, } #[derive(Debug, Error)] -enum MysqlErrorKind { +enum SqlErrorKind { #[error("A database error occurred: {}", _0)] DieselQuery(#[from] diesel::result::Error), @@ -29,8 +29,8 @@ enum MysqlErrorKind { Migration(diesel_migrations::RunMigrationsError), } -impl From for MysqlError { - fn from(kind: MysqlErrorKind) -> Self { +impl From for SqlError { + fn from(kind: SqlErrorKind) -> Self { Self { kind, status: StatusCode::INTERNAL_SERVER_ERROR, @@ -39,11 +39,11 @@ impl From for MysqlError { } } -impl ReportableError for MysqlError { +impl ReportableError for SqlError { fn is_sentry_event(&self) -> bool { #[allow(clippy::match_like_matches_macro)] match &self.kind { - MysqlErrorKind::Pool(_) => false, + SqlErrorKind::Pool(_) => false, _ => true, } } @@ -51,10 +51,10 @@ impl ReportableError for MysqlError { fn metric_label(&self) -> Option { Some( match self.kind { - MysqlErrorKind::DieselQuery(_) => "storage.mysql.error.diesel_query", - MysqlErrorKind::DieselConnection(_) => "storage.mysql.error.diesel_connection", - MysqlErrorKind::Pool(_) => "storage.mysql.error.pool", - MysqlErrorKind::Migration(_) => "storage.mysql.error.migration", + SqlErrorKind::DieselQuery(_) => "storage.sql.error.diesel_query", + SqlErrorKind::DieselConnection(_) => "storage.sql.error.diesel_connection", + SqlErrorKind::Pool(_) => "storage.sql.error.pool", + SqlErrorKind::Migration(_) => "storage.sql.error.migration", } .to_string(), ) @@ -65,21 +65,17 @@ impl ReportableError for MysqlError { } } -impl_fmt_display!(MysqlError, MysqlErrorKind); +impl_fmt_display!(SqlError, SqlErrorKind); -from_error!( - diesel::result::Error, - MysqlError, - MysqlErrorKind::DieselQuery -); +from_error!(diesel::result::Error, SqlError, SqlErrorKind::DieselQuery); from_error!( diesel::result::ConnectionError, - MysqlError, - MysqlErrorKind::DieselConnection + SqlError, + SqlErrorKind::DieselConnection ); -from_error!(diesel::r2d2::PoolError, MysqlError, MysqlErrorKind::Pool); +from_error!(diesel::r2d2::PoolError, SqlError, SqlErrorKind::Pool); from_error!( diesel_migrations::RunMigrationsError, - MysqlError, - MysqlErrorKind::Migration + SqlError, + SqlErrorKind::Migration ); diff --git a/syncserver/src/server/mod.rs b/syncserver/src/server/mod.rs index 1539ebcc71..f1e0a189f7 100644 --- a/syncserver/src/server/mod.rs +++ b/syncserver/src/server/mod.rs @@ -273,6 +273,13 @@ impl Server { &Metrics::from(&metrics), blocking_threadpool.clone(), )?; + // Spawns sweeper that calls Deadpool `retain` method, clearing unused connections. + db_pool.spawn_sweeper(Duration::from_secs( + settings + .syncstorage + .database_pool_sweeper_task_interval + .into(), + )); let glean_logger = Arc::new(GleanEventsLogger { // app_id corresponds to probe-scraper entry. // https://github.com/mozilla/probe-scraper/blob/main/repositories.yaml diff --git a/syncserver/src/web/handlers.rs b/syncserver/src/web/handlers.rs index 4af2259f8d..c1827ed822 100644 --- a/syncserver/src/web/handlers.rs +++ b/syncserver/src/web/handlers.rs @@ -40,34 +40,33 @@ pub async fn get_collections( request: HttpRequest, state: Data, ) -> Result { - if state.glean_enabled { - // Values below are be passed to the Glean logic to emit metrics. - // This is used to measure DAU (Daily Active Use) of Sync. - let user_agent = request - .headers() - .get(header::USER_AGENT) - .and_then(|header| header.to_str().ok()) - .unwrap_or(""); - let device_info: DeviceInfo = get_device_info(user_agent); - - state.glean_logger.record_events_ping( - &RequestInfo { - user_agent: user_agent.to_owned(), - ip_address: "".to_owned(), - }, - &EventsPing { - syncstorage_device_family: device_info.device_family.to_string(), - syncstorage_hashed_device_id: meta.user_id.hashed_device_id.clone(), - syncstorage_hashed_fxa_uid: meta.user_id.hashed_fxa_uid.clone(), - syncstorage_platform: device_info.platform.to_string(), - event: Some(Box::new(SyncstorageGetCollectionsEvent {})), - }, - ); - } - db_pool - .transaction_http(request, |db| async move { + .transaction_http(request.clone(), |db| async move { meta.emit_api_metric("request.get_collections"); + if state.glean_enabled { + // Values below are be passed to the Glean logic to emit metrics. + // This is used to measure DAU (Daily Active Use) of Sync. + let user_agent = request + .headers() + .get(header::USER_AGENT) + .and_then(|header| header.to_str().ok()) + .unwrap_or(""); + let device_info: DeviceInfo = get_device_info(user_agent); + + state.glean_logger.record_events_ping( + &RequestInfo { + user_agent: user_agent.to_owned(), + ip_address: "".to_owned(), + }, + &EventsPing { + syncstorage_device_family: device_info.device_family.to_string(), + syncstorage_hashed_device_id: meta.user_id.hashed_device_id.clone(), + syncstorage_hashed_fxa_uid: meta.user_id.hashed_fxa_uid.clone(), + syncstorage_platform: device_info.platform.to_string(), + event: Some(Box::new(SyncstorageGetCollectionsEvent {})), + }, + ); + } let result = db.get_collection_timestamps(meta.user_id).await?; Ok(HttpResponse::build(StatusCode::OK) diff --git a/syncstorage-db-common/src/util.rs b/syncstorage-db-common/src/util.rs index 97350eee6e..4e2858a634 100644 --- a/syncstorage-db-common/src/util.rs +++ b/syncstorage-db-common/src/util.rs @@ -1,4 +1,4 @@ -use std::{convert::TryInto, u64}; +use std::convert::TryInto; use chrono::{ offset::{FixedOffset, TimeZone, Utc}, diff --git a/syncstorage-mysql/src/error.rs b/syncstorage-mysql/src/error.rs index 2216844690..d9a66d96ad 100644 --- a/syncstorage-mysql/src/error.rs +++ b/syncstorage-mysql/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; use backtrace::Backtrace; use http::StatusCode; use syncserver_common::{from_error, impl_fmt_display, InternalError, ReportableError}; -use syncserver_db_common::error::MysqlError; +use syncserver_db_common::error::SqlError; use syncstorage_db_common::error::{DbErrorIntrospect, SyncstorageDbError}; use thiserror::Error; @@ -49,7 +49,7 @@ enum DbErrorKind { Common(SyncstorageDbError), #[error("{}", _0)] - Mysql(MysqlError), + Mysql(SqlError), } impl From for DbError { @@ -140,24 +140,24 @@ from_error!(SyncstorageDbError, DbError, DbErrorKind::Common); from_error!( diesel::result::Error, DbError, - |error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(MysqlError::from(error))) + |error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(SqlError::from(error))) ); from_error!( diesel::result::ConnectionError, DbError, - |error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(MysqlError::from( + |error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(SqlError::from( error ))) ); from_error!( diesel::r2d2::PoolError, DbError, - |error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(MysqlError::from(error))) + |error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(SqlError::from(error))) ); from_error!( diesel_migrations::RunMigrationsError, DbError, |error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Mysql( - MysqlError::from(error) + SqlError::from(error) )) ); diff --git a/syncstorage-mysql/src/pool.rs b/syncstorage-mysql/src/pool.rs index f2bf0d143b..ea6030b9b5 100644 --- a/syncstorage-mysql/src/pool.rs +++ b/syncstorage-mysql/src/pool.rs @@ -99,6 +99,13 @@ impl MysqlDbPool { }) } + /// Spawn a task to periodically evict idle connections. Calls wrapper sweeper fn + /// to use pool.retain, retaining objects only if they are shorter in duration than + /// defined max_idle. Noop for mysql impl. + pub fn spawn_sweeper(&self, _interval: Duration) { + sweeper() + } + pub fn get_sync(&self) -> DbResult { Ok(MysqlDb::new( self.pool.get()?, @@ -110,6 +117,13 @@ impl MysqlDbPool { } } +/// Sweeper to retain only the objects specified within the closure. +/// In this context, if a Spanner connection is unutilized, we want it +/// to release the given connections. +/// See: https://docs.rs/deadpool/latest/deadpool/managed/struct.Pool.html#method.retain +/// Noop for mysql impl +fn sweeper() {} + #[async_trait] impl DbPool for MysqlDbPool { type Error = DbError; diff --git a/syncstorage-settings/src/lib.rs b/syncstorage-settings/src/lib.rs index 0bf7769033..202e4335bb 100644 --- a/syncstorage-settings/src/lib.rs +++ b/syncstorage-settings/src/lib.rs @@ -78,6 +78,8 @@ pub struct Settings { pub database_pool_connection_lifespan: Option, /// Max time a connection should sit idle before being dropped. pub database_pool_connection_max_idle: Option, + /// Interval for sweeper task releasing unused connections. + pub database_pool_sweeper_task_interval: u32, #[cfg(debug_assertions)] pub database_use_test_transactions: bool, #[cfg(debug_assertions)] @@ -115,6 +117,7 @@ impl Default for Settings { database_pool_min_idle: None, database_pool_connection_lifespan: None, database_pool_connection_max_idle: None, + database_pool_sweeper_task_interval: 30, database_pool_connection_timeout: Some(30), #[cfg(debug_assertions)] database_use_test_transactions: false, diff --git a/syncstorage-spanner/Cargo.toml b/syncstorage-spanner/Cargo.toml index c2eae5f3a1..9472a67637 100644 --- a/syncstorage-spanner/Cargo.toml +++ b/syncstorage-spanner/Cargo.toml @@ -6,6 +6,7 @@ authors.workspace = true edition.workspace = true [dependencies] +actix-web.workspace = true backtrace.workspace = true cadence.workspace = true deadpool.workspace = true diff --git a/syncstorage-spanner/src/manager/deadpool.rs b/syncstorage-spanner/src/manager/deadpool.rs index 721d305e70..3762ce44db 100644 --- a/syncstorage-spanner/src/manager/deadpool.rs +++ b/syncstorage-spanner/src/manager/deadpool.rs @@ -13,7 +13,7 @@ use crate::error::DbError; pub(crate) type Conn = deadpool::managed::Object; pub(crate) struct SpannerSessionManager { - settings: SpannerSessionSettings, + pub settings: SpannerSessionSettings, /// The gRPC environment env: Arc, metrics: Metrics, diff --git a/syncstorage-spanner/src/models.rs b/syncstorage-spanner/src/models.rs index 8e6a636f8c..f270962b38 100644 --- a/syncstorage-spanner/src/models.rs +++ b/syncstorage-spanner/src/models.rs @@ -1292,11 +1292,7 @@ impl SpannerDb { // most databases) so we specify a max value with offset subtracted // to avoid overflow errors (that only occur w/ a FORCE_INDEX= // directive) OutOfRange: 400 int64 overflow: + offset - query = format!( - "{} LIMIT {}", - query, - i64::max_value() - offset.offset as i64 - ); + query = format!("{} LIMIT {}", query, i64::MAX - offset.offset as i64); }; if let Some(offset) = params.offset { diff --git a/syncstorage-spanner/src/pool.rs b/syncstorage-spanner/src/pool.rs index 4035b52c50..a62de811dc 100644 --- a/syncstorage-spanner/src/pool.rs +++ b/syncstorage-spanner/src/pool.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, fmt, sync::Arc, time::Duration}; +use actix_web::rt; use async_trait::async_trait; use syncserver_common::{BlockingThreadpool, Metrics}; use syncserver_db_common::{GetPoolState, PoolState}; @@ -49,7 +50,9 @@ impl SpannerDbPool { let config = deadpool::managed::PoolConfig { max_size, timeouts, - ..Default::default() + // Prefer LIFO to allow the sweeper task to evict least frequently + // used connections. + queue_mode: deadpool::managed::QueueMode::Lifo, }; let pool = deadpool::managed::Pool::builder(manager) .config(config) @@ -84,6 +87,30 @@ impl SpannerDbPool { self.quota, )) } + + /// Spawn a task to periodically evict idle connections. Calls wrapper sweeper fn + /// to use pool.retain, retaining objects only if they are shorter in duration than + /// defined max_idle. + pub fn spawn_sweeper(&self, interval: Duration) { + let Some(max_idle) = self.pool.manager().settings.max_idle else { + return; + }; + let pool = self.pool.clone(); + rt::spawn(async move { + loop { + sweeper(&pool, Duration::from_secs(max_idle.into())); + rt::time::sleep(interval).await; + } + }); + } +} + +/// Sweeper to retain only the objects specified within the closure. +/// In this context, if a Spanner connection is unutilized, we want it +/// to release the given connection. +/// See: https://docs.rs/deadpool/latest/deadpool/managed/struct.Pool.html#method.retain +fn sweeper(pool: &deadpool::managed::Pool, max_idle: Duration) { + pool.retain(|_, metrics| metrics.last_used() < max_idle); } #[async_trait] diff --git a/tokenserver-auth/Cargo.toml b/tokenserver-auth/Cargo.toml index 5ee8f95e7b..7dacffafcc 100644 --- a/tokenserver-auth/Cargo.toml +++ b/tokenserver-auth/Cargo.toml @@ -28,7 +28,7 @@ syncserver-common = { path = "../syncserver-common" } tokenserver-common = { path = "../tokenserver-common" } tokenserver-settings = { path = "../tokenserver-settings" } tokio = { workspace = true } -pyo3 = { version = "0.21", features = ["auto-initialize"], optional = true } +pyo3 = { version = "0.22", features = ["auto-initialize"], optional = true } [dev-dependencies] diff --git a/tokenserver-auth/src/oauth/py.rs b/tokenserver-auth/src/oauth/py.rs index d6f0c45b12..3569b3f777 100644 --- a/tokenserver-auth/src/oauth/py.rs +++ b/tokenserver-auth/src/oauth/py.rs @@ -19,9 +19,8 @@ use std::{sync::Arc, time::Duration}; /// The verifier used to verify OAuth tokens. #[derive(Clone)] pub struct Verifier { - // Note that we do not need to use an Arc here, since Py is already a reference-counted // pointer - inner: Py, + inner: Arc>, timeout: u64, blocking_threadpool: Arc, } @@ -103,7 +102,7 @@ impl Verifier { })?; Ok(Self { - inner, + inner: Arc::new(inner), timeout: settings.fxa_oauth_request_timeout, blocking_threadpool, }) diff --git a/tokenserver-db/src/error.rs b/tokenserver-db/src/error.rs index b9efcbd50b..bff809f5d7 100644 --- a/tokenserver-db/src/error.rs +++ b/tokenserver-db/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; use backtrace::Backtrace; use http::StatusCode; use syncserver_common::{from_error, impl_fmt_display, InternalError, ReportableError}; -use syncserver_db_common::error::MysqlError; +use syncserver_db_common::error::SqlError; use thiserror::Error; use tokenserver_common::TokenserverError; @@ -28,21 +28,21 @@ impl DbError { impl ReportableError for DbError { fn backtrace(&self) -> Option<&Backtrace> { match &self.kind { - DbErrorKind::Mysql(e) => e.backtrace(), + DbErrorKind::Sql(e) => e.backtrace(), _ => Some(&self.backtrace), } } fn is_sentry_event(&self) -> bool { match &self.kind { - DbErrorKind::Mysql(e) => e.is_sentry_event(), + DbErrorKind::Sql(e) => e.is_sentry_event(), _ => true, } } fn metric_label(&self) -> Option { match &self.kind { - DbErrorKind::Mysql(e) => e.metric_label(), + DbErrorKind::Sql(e) => e.metric_label(), _ => None, } } @@ -51,7 +51,7 @@ impl ReportableError for DbError { #[derive(Debug, Error)] enum DbErrorKind { #[error("{}", _0)] - Mysql(MysqlError), + Sql(SqlError), #[error("Unexpected error: {}", _0)] Internal(String), @@ -60,7 +60,7 @@ enum DbErrorKind { impl From for DbError { fn from(kind: DbErrorKind) -> Self { match kind { - DbErrorKind::Mysql(ref mysql_error) => Self { + DbErrorKind::Sql(ref mysql_error) => Self { status: mysql_error.status, backtrace: Box::new(mysql_error.backtrace.clone()), kind, @@ -105,24 +105,22 @@ impl_fmt_display!(DbError, DbErrorKind); from_error!( diesel::result::Error, DbError, - |error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(MysqlError::from(error))) + |error: diesel::result::Error| DbError::from(DbErrorKind::Sql(SqlError::from(error))) ); from_error!( diesel::result::ConnectionError, DbError, - |error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(MysqlError::from( - error - ))) + |error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Sql(SqlError::from(error))) ); from_error!( diesel::r2d2::PoolError, DbError, - |error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(MysqlError::from(error))) + |error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Sql(SqlError::from(error))) ); from_error!( diesel_migrations::RunMigrationsError, DbError, - |error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Mysql( - MysqlError::from(error) - )) + |error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Sql(SqlError::from( + error + ))) );