From 7c8fc04b9645d4cbccd30749735d30aad18c9575 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 5 Feb 2025 19:37:38 +0100 Subject: [PATCH] massively speed up compilation of garage_api_admin by not using async_trait --- src/api/admin/api.rs | 1 - src/api/admin/block.rs | 6 ------ src/api/admin/bucket.rs | 12 ------------ src/api/admin/cluster.rs | 9 --------- src/api/admin/key.rs | 8 -------- src/api/admin/lib.rs | 7 ++----- src/api/admin/macros.rs | 3 --- src/api/admin/node.rs | 5 ----- src/api/admin/repair.rs | 9 ++------- src/api/admin/special.rs | 6 ------ src/api/admin/worker.rs | 6 ------ 11 files changed, 4 insertions(+), 68 deletions(-) diff --git a/src/api/admin/api.rs b/src/api/admin/api.rs index 48c9ee0b..97cde158 100644 --- a/src/api/admin/api.rs +++ b/src/api/admin/api.rs @@ -3,7 +3,6 @@ use std::convert::TryFrom; use std::net::SocketAddr; use std::sync::Arc; -use async_trait::async_trait; use paste::paste; use serde::{Deserialize, Serialize}; diff --git a/src/api/admin/block.rs b/src/api/admin/block.rs index 8f0e63eb..73d186a6 100644 --- a/src/api/admin/block.rs +++ b/src/api/admin/block.rs @@ -1,7 +1,5 @@ use std::sync::Arc; -use async_trait::async_trait; - use garage_util::data::*; use garage_util::error::Error as GarageError; use garage_util::time::now_msec; @@ -18,7 +16,6 @@ use crate::api::*; use crate::error::*; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for LocalListBlockErrorsRequest { type Response = LocalListBlockErrorsResponse; @@ -43,7 +40,6 @@ impl RequestHandler for LocalListBlockErrorsRequest { } } -#[async_trait] impl RequestHandler for LocalGetBlockInfoRequest { type Response = LocalGetBlockInfoResponse; @@ -109,7 +105,6 @@ impl RequestHandler for LocalGetBlockInfoRequest { } } -#[async_trait] impl RequestHandler for LocalRetryBlockResyncRequest { type Response = LocalRetryBlockResyncResponse; @@ -143,7 +138,6 @@ impl RequestHandler for LocalRetryBlockResyncRequest { } } -#[async_trait] impl RequestHandler for LocalPurgeBlocksRequest { type Response = LocalPurgeBlocksResponse; diff --git a/src/api/admin/bucket.rs b/src/api/admin/bucket.rs index 73e63df0..d2bb62e0 100644 --- a/src/api/admin/bucket.rs +++ b/src/api/admin/bucket.rs @@ -2,8 +2,6 @@ use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; -use async_trait::async_trait; - use garage_util::crdt::*; use garage_util::data::*; use garage_util::time::*; @@ -23,7 +21,6 @@ use crate::api::*; use crate::error::*; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for ListBucketsRequest { type Response = ListBucketsResponse; @@ -74,7 +71,6 @@ impl RequestHandler for ListBucketsRequest { } } -#[async_trait] impl RequestHandler for GetBucketInfoRequest { type Response = GetBucketInfoResponse; @@ -230,7 +226,6 @@ async fn bucket_info_results( Ok(res) } -#[async_trait] impl RequestHandler for CreateBucketRequest { type Response = CreateBucketResponse; @@ -305,7 +300,6 @@ impl RequestHandler for CreateBucketRequest { } } -#[async_trait] impl RequestHandler for DeleteBucketRequest { type Response = DeleteBucketResponse; @@ -358,7 +352,6 @@ impl RequestHandler for DeleteBucketRequest { } } -#[async_trait] impl RequestHandler for UpdateBucketRequest { type Response = UpdateBucketResponse; @@ -409,7 +402,6 @@ impl RequestHandler for UpdateBucketRequest { } } -#[async_trait] impl RequestHandler for CleanupIncompleteUploadsRequest { type Response = CleanupIncompleteUploadsResponse; @@ -435,7 +427,6 @@ impl RequestHandler for CleanupIncompleteUploadsRequest { // ---- BUCKET/KEY PERMISSIONS ---- -#[async_trait] impl RequestHandler for AllowBucketKeyRequest { type Response = AllowBucketKeyResponse; @@ -449,7 +440,6 @@ impl RequestHandler for AllowBucketKeyRequest { } } -#[async_trait] impl RequestHandler for DenyBucketKeyRequest { type Response = DenyBucketKeyResponse; @@ -502,7 +492,6 @@ pub async fn handle_bucket_change_key_perm( // ---- BUCKET ALIASES ---- -#[async_trait] impl RequestHandler for AddBucketAliasRequest { type Response = AddBucketAliasResponse; @@ -537,7 +526,6 @@ impl RequestHandler for AddBucketAliasRequest { } } -#[async_trait] impl RequestHandler for RemoveBucketAliasRequest { type Response = RemoveBucketAliasResponse; diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs index 6a7a3d69..cb1fa493 100644 --- a/src/api/admin/cluster.rs +++ b/src/api/admin/cluster.rs @@ -1,8 +1,6 @@ use std::collections::HashMap; use std::sync::Arc; -use async_trait::async_trait; - use garage_util::crdt::*; use garage_util::data::*; @@ -14,7 +12,6 @@ use crate::api::*; use crate::error::*; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for GetClusterStatusRequest { type Response = GetClusterStatusResponse; @@ -120,7 +117,6 @@ impl RequestHandler for GetClusterStatusRequest { } } -#[async_trait] impl RequestHandler for GetClusterHealthRequest { type Response = GetClusterHealthResponse; @@ -150,7 +146,6 @@ impl RequestHandler for GetClusterHealthRequest { } } -#[async_trait] impl RequestHandler for ConnectClusterNodesRequest { type Response = ConnectClusterNodesResponse; @@ -177,7 +172,6 @@ impl RequestHandler for ConnectClusterNodesRequest { } } -#[async_trait] impl RequestHandler for GetClusterLayoutRequest { type Response = GetClusterLayoutResponse; @@ -241,7 +235,6 @@ fn format_cluster_layout(layout: &layout::LayoutHistory) -> GetClusterLayoutResp // ---- update functions ---- -#[async_trait] impl RequestHandler for UpdateClusterLayoutRequest { type Response = UpdateClusterLayoutResponse; @@ -291,7 +284,6 @@ impl RequestHandler for UpdateClusterLayoutRequest { } } -#[async_trait] impl RequestHandler for ApplyClusterLayoutRequest { type Response = ApplyClusterLayoutResponse; @@ -316,7 +308,6 @@ impl RequestHandler for ApplyClusterLayoutRequest { } } -#[async_trait] impl RequestHandler for RevertClusterLayoutRequest { type Response = RevertClusterLayoutResponse; diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs index 440a8322..dc6ae4e9 100644 --- a/src/api/admin/key.rs +++ b/src/api/admin/key.rs @@ -1,8 +1,6 @@ use std::collections::HashMap; use std::sync::Arc; -use async_trait::async_trait; - use garage_table::*; use garage_model::garage::Garage; @@ -12,7 +10,6 @@ use crate::api::*; use crate::error::*; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for ListKeysRequest { type Response = ListKeysResponse; @@ -38,7 +35,6 @@ impl RequestHandler for ListKeysRequest { } } -#[async_trait] impl RequestHandler for GetKeyInfoRequest { type Response = GetKeyInfoResponse; @@ -66,7 +62,6 @@ impl RequestHandler for GetKeyInfoRequest { } } -#[async_trait] impl RequestHandler for CreateKeyRequest { type Response = CreateKeyResponse; @@ -84,7 +79,6 @@ impl RequestHandler for CreateKeyRequest { } } -#[async_trait] impl RequestHandler for ImportKeyRequest { type Response = ImportKeyResponse; @@ -112,7 +106,6 @@ impl RequestHandler for ImportKeyRequest { } } -#[async_trait] impl RequestHandler for UpdateKeyRequest { type Response = UpdateKeyResponse; @@ -147,7 +140,6 @@ impl RequestHandler for UpdateKeyRequest { } } -#[async_trait] impl RequestHandler for DeleteKeyRequest { type Response = DeleteKeyResponse; diff --git a/src/api/admin/lib.rs b/src/api/admin/lib.rs index fe4b0598..dd9b7ffd 100644 --- a/src/api/admin/lib.rs +++ b/src/api/admin/lib.rs @@ -22,8 +22,6 @@ mod worker; use std::sync::Arc; -use async_trait::async_trait; - use garage_model::garage::Garage; pub use api_server::AdminApiServer as Admin; @@ -34,13 +32,12 @@ pub enum Authorization { AdminToken, } -#[async_trait] pub trait RequestHandler { type Response; - async fn handle( + fn handle( self, garage: &Arc, admin: &Admin, - ) -> Result; + ) -> impl std::future::Future> + Send; } diff --git a/src/api/admin/macros.rs b/src/api/admin/macros.rs index 4b183bec..df2762fe 100644 --- a/src/api/admin/macros.rs +++ b/src/api/admin/macros.rs @@ -70,7 +70,6 @@ macro_rules! admin_endpoints { } )* - #[async_trait] impl RequestHandler for AdminApiRequest { type Response = AdminApiResponse; @@ -133,7 +132,6 @@ macro_rules! local_admin_endpoints { } } - #[async_trait] impl RequestHandler for [< $endpoint Request >] { type Response = [< $endpoint Response >]; @@ -202,7 +200,6 @@ macro_rules! local_admin_endpoints { } } - #[async_trait] impl RequestHandler for LocalAdminApiRequest { type Response = LocalAdminApiResponse; diff --git a/src/api/admin/node.rs b/src/api/admin/node.rs index 870db9fb..f6f43d95 100644 --- a/src/api/admin/node.rs +++ b/src/api/admin/node.rs @@ -2,8 +2,6 @@ use std::collections::HashMap; use std::fmt::Write; use std::sync::Arc; -use async_trait::async_trait; - use format_table::format_table_to_string; use garage_util::data::*; @@ -20,7 +18,6 @@ use crate::api::*; use crate::error::Error; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for LocalCreateMetadataSnapshotRequest { type Response = LocalCreateMetadataSnapshotResponse; @@ -34,7 +31,6 @@ impl RequestHandler for LocalCreateMetadataSnapshotRequest { } } -#[async_trait] impl RequestHandler for LocalGetNodeStatisticsRequest { type Response = LocalGetNodeStatisticsResponse; @@ -99,7 +95,6 @@ impl RequestHandler for LocalGetNodeStatisticsRequest { } } -#[async_trait] impl RequestHandler for GetClusterStatisticsRequest { type Response = GetClusterStatisticsResponse; diff --git a/src/api/admin/repair.rs b/src/api/admin/repair.rs index 19bb4d51..113ef636 100644 --- a/src/api/admin/repair.rs +++ b/src/api/admin/repair.rs @@ -27,7 +27,6 @@ use crate::{Admin, RequestHandler}; const RC_REPAIR_ITER_COUNT: usize = 64; -#[async_trait] impl RequestHandler for LocalLaunchRepairOperationRequest { type Response = LocalLaunchRepairOperationResponse; @@ -96,17 +95,16 @@ impl RequestHandler for LocalLaunchRepairOperationRequest { // ---- -#[async_trait] trait TableRepair: Send + Sync + 'static { type T: TableSchema; fn table(garage: &Garage) -> &Table; - async fn process( + fn process( &mut self, garage: &Garage, entry: <::T as TableSchema>::E, - ) -> Result; + ) -> impl std::future::Future> + Send; } struct TableRepairWorker { @@ -180,7 +178,6 @@ impl Worker for TableRepairWorker { struct RepairVersions; -#[async_trait] impl TableRepair for RepairVersions { type T = VersionTable; @@ -227,7 +224,6 @@ impl TableRepair for RepairVersions { struct RepairBlockRefs; -#[async_trait] impl TableRepair for RepairBlockRefs { type T = BlockRefTable; @@ -267,7 +263,6 @@ impl TableRepair for RepairBlockRefs { struct RepairMpu; -#[async_trait] impl TableRepair for RepairMpu { type T = MultipartUploadTable; diff --git a/src/api/admin/special.rs b/src/api/admin/special.rs index 79f1f4d7..0ecf82bc 100644 --- a/src/api/admin/special.rs +++ b/src/api/admin/special.rs @@ -1,7 +1,5 @@ use std::sync::Arc; -use async_trait::async_trait; - use http::header::{ ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW, }; @@ -20,7 +18,6 @@ use crate::api_server::ResBody; use crate::error::*; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for OptionsRequest { type Response = Response; @@ -39,7 +36,6 @@ impl RequestHandler for OptionsRequest { } } -#[async_trait] impl RequestHandler for MetricsRequest { type Response = Response; @@ -76,7 +72,6 @@ impl RequestHandler for MetricsRequest { } } -#[async_trait] impl RequestHandler for HealthRequest { type Response = Response; @@ -110,7 +105,6 @@ impl RequestHandler for HealthRequest { } } -#[async_trait] impl RequestHandler for CheckDomainRequest { type Response = Response; diff --git a/src/api/admin/worker.rs b/src/api/admin/worker.rs index d143e5be..b3f4537b 100644 --- a/src/api/admin/worker.rs +++ b/src/api/admin/worker.rs @@ -1,8 +1,6 @@ use std::collections::HashMap; use std::sync::Arc; -use async_trait::async_trait; - use garage_util::background::*; use garage_util::time::now_msec; @@ -12,7 +10,6 @@ use crate::api::*; use crate::error::Error; use crate::{Admin, RequestHandler}; -#[async_trait] impl RequestHandler for LocalListWorkersRequest { type Response = LocalListWorkersResponse; @@ -35,7 +32,6 @@ impl RequestHandler for LocalListWorkersRequest { } } -#[async_trait] impl RequestHandler for LocalGetWorkerInfoRequest { type Response = LocalGetWorkerInfoResponse; @@ -56,7 +52,6 @@ impl RequestHandler for LocalGetWorkerInfoRequest { } } -#[async_trait] impl RequestHandler for LocalGetWorkerVariableRequest { type Response = LocalGetWorkerVariableResponse; @@ -78,7 +73,6 @@ impl RequestHandler for LocalGetWorkerVariableRequest { } } -#[async_trait] impl RequestHandler for LocalSetWorkerVariableRequest { type Response = LocalSetWorkerVariableResponse;