diff --git a/Cargo.lock b/Cargo.lock index 79ecad7..ca9eb20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,9 +62,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" dependencies = [ "anstyle", "anstyle-parse", @@ -199,12 +199,12 @@ dependencies = [ [[package]] name = "axum" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" dependencies = [ "async-trait", - "axum-core 0.4.2", + "axum-core 0.4.3", "bytes", "futures-util", "http 1.0.0", @@ -250,9 +250,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" dependencies = [ "async-trait", "bytes", @@ -320,9 +320,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -446,9 +446,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.14" +version = "4.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2" +checksum = "58e54881c004cec7895b0068a0a954cd5d62da01aef83fa35b1e594497bf5445" dependencies = [ "clap_builder", "clap_derive", @@ -456,9 +456,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.14" +version = "4.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370" +checksum = "59cb82d7f531603d2fd1f507441cdd35184fa81beff7bd489570de7f773460bb" dependencies = [ "anstream", "anstyle", @@ -966,9 +966,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "h2" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "b553656127a00601c8ae5590fcfdc118e4083a7924b6cf4ffc1ea4b99dc429d7" dependencies = [ "bytes", "fnv", @@ -1185,7 +1185,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.22", + "h2 0.3.23", "http 0.2.11", "http-body 0.4.6", "httparse", @@ -1407,9 +1407,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -2470,7 +2470,7 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2 0.3.22", + "h2 0.3.23", "http 0.2.11", "http-body 0.4.6", "hyper 0.14.28", @@ -2580,9 +2580,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ "bitflags 2.4.1", "errno", @@ -2875,9 +2875,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" [[package]] name = "snafu" @@ -3462,7 +3462,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "h2 0.3.22", + "h2 0.3.23", "http 0.2.11", "http-body 0.4.6", "hyper 0.14.28", @@ -3611,6 +3611,17 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "trait-variant" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e1a477061e97925d81a2f89fb73b2b8038e6baa5a0023bad380ac23b5f4fa6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "treediff" version = "4.0.2" @@ -3624,8 +3635,7 @@ dependencies = [ name = "trino-lb" version = "0.0.1" dependencies = [ - "async-trait", - "axum 0.7.3", + "axum 0.7.4", "axum-server", "chrono", "clap", @@ -3681,7 +3691,6 @@ dependencies = [ name = "trino-lb-core" version = "0.0.1" dependencies = [ - "async-trait", "chrono", "http 1.0.0", "http-serde", @@ -3705,7 +3714,6 @@ dependencies = [ name = "trino-lb-persistence" version = "0.0.1" dependencies = [ - "async-trait", "bincode", "enum_dispatch", "futures", @@ -3718,6 +3726,7 @@ dependencies = [ "sqlx", "tokio", "tracing", + "trait-variant", "trino-lb-core", "url", ] @@ -3866,9 +3875,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3876,9 +3885,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -3891,9 +3900,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -3903,9 +3912,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3913,9 +3922,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -3926,15 +3935,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index ae22f5e..4739a69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ edition = "2021" repository = "https://github.com/stackabletech/trino-lb" [workspace.dependencies] -async-trait = "0.1" axum = { version = "0.7", features = ["tracing"] } axum-server = { version = "0.6", features = ["tls-rustls"] } bincode = "1.3" @@ -51,6 +50,7 @@ tower = "0.4" tracing = "0.1" tracing-opentelemetry = "0.22" tracing-subscriber = { version = "0.3", features = ["env-filter"] } +trait-variant = "0.1" url = { version = "2.5", features = ["serde"] } # For trino-lb-bench diff --git a/trino-lb-core/Cargo.toml b/trino-lb-core/Cargo.toml index aee739d..ab61ed7 100644 --- a/trino-lb-core/Cargo.toml +++ b/trino-lb-core/Cargo.toml @@ -9,7 +9,6 @@ repository.workspace = true publish = false [dependencies] -async-trait.workspace = true chrono.workspace = true http-serde.workspace = true http.workspace = true diff --git a/trino-lb-persistence/Cargo.toml b/trino-lb-persistence/Cargo.toml index f46cf79..1c8bd61 100644 --- a/trino-lb-persistence/Cargo.toml +++ b/trino-lb-persistence/Cargo.toml @@ -11,7 +11,6 @@ publish = false [dependencies] trino-lb-core = { path = "../trino-lb-core" } -async-trait.workspace = true bincode.workspace = true enum_dispatch.workspace = true futures.workspace = true @@ -24,4 +23,5 @@ snafu.workspace = true sqlx.workspace = true tokio.workspace = true tracing.workspace = true +trait-variant.workspace = true url.workspace = true diff --git a/trino-lb-persistence/src/in_memory.rs b/trino-lb-persistence/src/in_memory.rs index 25c96b1..afb9665 100644 --- a/trino-lb-persistence/src/in_memory.rs +++ b/trino-lb-persistence/src/in_memory.rs @@ -5,7 +5,6 @@ use std::{ time::{Duration, SystemTime, SystemTimeError, UNIX_EPOCH}, }; -use async_trait::async_trait; use snafu::{OptionExt, ResultExt, Snafu}; use tokio::sync::RwLock; use tracing::{error, info, instrument}; @@ -54,7 +53,6 @@ impl Default for InMemoryPersistence { } } -#[async_trait] impl Persistence for InMemoryPersistence { #[instrument(skip(self))] async fn store_queued_query(&self, queued_query: QueuedQuery) -> Result<(), super::Error> { diff --git a/trino-lb-persistence/src/lib.rs b/trino-lb-persistence/src/lib.rs index 1656593..0799162 100644 --- a/trino-lb-persistence/src/lib.rs +++ b/trino-lb-persistence/src/lib.rs @@ -1,6 +1,5 @@ use std::{fmt::Debug, time::SystemTime}; -use async_trait::async_trait; use enum_dispatch::enum_dispatch; use snafu::Snafu; use trino_lb_core::{ @@ -29,8 +28,9 @@ pub enum Error { /// multiple replicas of trino-lb and every instance can answer requests for every query correctly. This is especially important /// for increment and decrement operations to not end up with a wrong query count after multiple trino-lb instances modifying the /// counter simultaneous. -#[async_trait] #[enum_dispatch(PersistenceImplementation)] +// According to https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html +#[trait_variant::make(SendPersistence: Send)] pub trait Persistence { async fn store_queued_query(&self, query: QueuedQuery) -> Result<(), Error>; async fn load_queued_query(&self, query_id: &TrinoLbQueryId) -> Result; diff --git a/trino-lb-persistence/src/postgres/mod.rs b/trino-lb-persistence/src/postgres/mod.rs index f691049..ecc5044 100644 --- a/trino-lb-persistence/src/postgres/mod.rs +++ b/trino-lb-persistence/src/postgres/mod.rs @@ -3,7 +3,6 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -use async_trait::async_trait; use http::HeaderMap; use serde::{Deserialize, Serialize}; use snafu::{ResultExt, Snafu}; @@ -135,7 +134,6 @@ struct HeaderMapWrapper { pub inner: HeaderMap, } -#[async_trait] impl Persistence for PostgresPersistence { #[instrument(skip(self))] async fn store_queued_query(&self, queued_query: QueuedQuery) -> Result<(), super::Error> { diff --git a/trino-lb-persistence/src/redis.rs b/trino-lb-persistence/src/redis.rs index 5754f66..65ae0e7 100644 --- a/trino-lb-persistence/src/redis.rs +++ b/trino-lb-persistence/src/redis.rs @@ -4,7 +4,6 @@ use std::{ time::{Duration, SystemTime, SystemTimeError, UNIX_EPOCH}, }; -use async_trait::async_trait; use futures::{future::try_join_all, TryFutureExt}; use redis::{ cluster::ClusterClientBuilder, cluster_async::ClusterConnection, AsyncCommands, RedisError, @@ -161,7 +160,6 @@ impl RedisPersistence { } } -#[async_trait] impl Persistence for RedisPersistence { #[instrument(skip(self))] async fn store_queued_query(&self, queued_query: QueuedQuery) -> Result<(), super::Error> { diff --git a/trino-lb/Cargo.toml b/trino-lb/Cargo.toml index 161c501..5321764 100644 --- a/trino-lb/Cargo.toml +++ b/trino-lb/Cargo.toml @@ -15,7 +15,6 @@ default-run = "trino-lb" trino-lb-core = { path = "../trino-lb-core" } trino-lb-persistence = { path = "../trino-lb-persistence" } -async-trait.workspace = true axum-server.workspace = true axum.workspace = true chrono.workspace = true diff --git a/trino-lb/src/routing/explain_costs.rs b/trino-lb/src/routing/explain_costs.rs index 96fc638..368633e 100644 --- a/trino-lb/src/routing/explain_costs.rs +++ b/trino-lb/src/routing/explain_costs.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use snafu::{ResultExt, Snafu}; use tracing::{instrument, warn}; use trino_lb_core::sanitization::Sanitize; @@ -33,7 +32,6 @@ impl ExplainCostsRouter { } } -#[async_trait] impl RouterImplementationTrait for ExplainCostsRouter { #[instrument( name = "ExplainCostsRouter::route" diff --git a/trino-lb/src/routing/mod.rs b/trino-lb/src/routing/mod.rs index a4c16e0..769fff6 100644 --- a/trino-lb/src/routing/mod.rs +++ b/trino-lb/src/routing/mod.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use enum_dispatch::enum_dispatch; use snafu::{ResultExt, Snafu}; use tracing::instrument; @@ -102,7 +101,6 @@ impl Router { } } -#[async_trait] #[enum_dispatch(RoutingImplementation)] pub trait RouterImplementationTrait { /// The router will be asked to make a decision for the queued query. It can either return diff --git a/trino-lb/src/routing/python_script.rs b/trino-lb/src/routing/python_script.rs index 695b75b..3922a9d 100644 --- a/trino-lb/src/routing/python_script.rs +++ b/trino-lb/src/routing/python_script.rs @@ -1,6 +1,5 @@ use std::collections::{HashMap, HashSet}; -use async_trait::async_trait; use pyo3::{ types::{IntoPyDict, PyModule}, Py, PyAny, Python, @@ -53,7 +52,6 @@ impl PythonScriptRouter { } } -#[async_trait] impl RouterImplementationTrait for PythonScriptRouter { #[instrument( name = "PythonScriptRouter::route" diff --git a/trino-lb/src/routing/trino_routing_group_header.rs b/trino-lb/src/routing/trino_routing_group_header.rs index 78fb1df..eba324c 100644 --- a/trino-lb/src/routing/trino_routing_group_header.rs +++ b/trino-lb/src/routing/trino_routing_group_header.rs @@ -1,6 +1,5 @@ use std::collections::HashSet; -use async_trait::async_trait; use tracing::{instrument, warn}; use trino_lb_core::{config::TrinoRoutingGroupHeaderRouterConfig, sanitization::Sanitize}; @@ -24,7 +23,6 @@ impl TrinoRoutingGroupHeaderRouter { } } -#[async_trait] impl RouterImplementationTrait for TrinoRoutingGroupHeaderRouter { #[instrument( name = "TrinoRoutingGroupHeaderRouter::route" diff --git a/trino-lb/src/scaling/mod.rs b/trino-lb/src/scaling/mod.rs index 18126c9..143948e 100644 --- a/trino-lb/src/scaling/mod.rs +++ b/trino-lb/src/scaling/mod.rs @@ -4,7 +4,6 @@ use std::{ time::{Duration, SystemTime, SystemTimeError}, }; -use async_trait::async_trait; use chrono::{DateTime, Utc}; use enum_dispatch::enum_dispatch; use futures::future::try_join_all; @@ -549,7 +548,6 @@ impl Scaler { } } -#[async_trait] #[enum_dispatch(ScalerImplementation)] pub trait ScalerTrait { async fn activate(&self, cluster: &TrinoClusterName) -> Result<(), Error>; diff --git a/trino-lb/src/scaling/stackable.rs b/trino-lb/src/scaling/stackable.rs index 6de37c2..513ccdb 100644 --- a/trino-lb/src/scaling/stackable.rs +++ b/trino-lb/src/scaling/stackable.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use async_trait::async_trait; use kube::{ api::{Patch, PatchParams}, core::{DynamicObject, GroupVersionKind}, @@ -248,7 +247,6 @@ impl StackableScaler { } } -#[async_trait] impl ScalerTrait for StackableScaler { #[instrument(name = "StackableScaler::activate", skip(self))] async fn activate(&self, cluster: &TrinoClusterName) -> Result<(), super::Error> {