From 6d76b26fb806734cdab1764e40845882b93aeebe Mon Sep 17 00:00:00 2001 From: mdecimus Date: Tue, 20 Aug 2024 17:27:03 +0200 Subject: [PATCH] Fix compile flags for SQL Read Replicas --- crates/common/src/config/mod.rs | 9 ++--- .../src/backend/composite/distributed_blob.rs | 12 +++++++ crates/store/src/backend/composite/mod.rs | 1 + crates/store/src/config.rs | 1 + crates/store/src/dispatch/blob.rs | 6 ++-- crates/store/src/dispatch/mod.rs | 2 +- crates/store/src/dispatch/store.rs | 22 ++++++------- crates/store/src/lib.rs | 33 +++++++++++++++++-- 8 files changed, 61 insertions(+), 25 deletions(-) diff --git a/crates/common/src/config/mod.rs b/crates/common/src/config/mod.rs index c74fab95..75dbd200 100644 --- a/crates/common/src/config/mod.rs +++ b/crates/common/src/config/mod.rs @@ -65,17 +65,12 @@ impl Core { #[cfg(feature = "enterprise")] if enterprise.is_none() { - if matches!(data, Store::SQLReadReplica(_)) { + if data.is_enterprise_store() { config .new_build_error("storage.data", "SQL read replicas is an Enterprise feature"); data = Store::None; } - stores - .stores - .retain(|_, store| !matches!(store, Store::SQLReadReplica(_))); - stores - .blob_stores - .retain(|_, store| !matches!(store.backend, BlobBackend::Composite(_))); + stores.disable_enterprise_only(); } // SPDX-SnippetEnd diff --git a/crates/store/src/backend/composite/distributed_blob.rs b/crates/store/src/backend/composite/distributed_blob.rs index 04230bce..a51c93ef 100644 --- a/crates/store/src/backend/composite/distributed_blob.rs +++ b/crates/store/src/backend/composite/distributed_blob.rs @@ -71,6 +71,10 @@ impl DistributedBlob { Store::MySQL(store) => store.get_blob(key, read_range).await, #[cfg(feature = "rocks")] Store::RocksDb(store) => store.get_blob(key, read_range).await, + #[cfg(all( + feature = "enterprise", + any(feature = "postgres", feature = "mysql") + ))] Store::SQLReadReplica(store) => store.get_blob(key, read_range).await, Store::None => Err(trc::StoreEvent::NotConfigured.into()), }, @@ -97,6 +101,10 @@ impl DistributedBlob { Store::MySQL(store) => store.put_blob(key, data).await, #[cfg(feature = "rocks")] Store::RocksDb(store) => store.put_blob(key, data).await, + #[cfg(all( + feature = "enterprise", + any(feature = "postgres", feature = "mysql") + ))] Store::SQLReadReplica(store) => store.put_blob(key, data).await, Store::None => Err(trc::StoreEvent::NotConfigured.into()), }, @@ -123,6 +131,10 @@ impl DistributedBlob { Store::MySQL(store) => store.delete_blob(key).await, #[cfg(feature = "rocks")] Store::RocksDb(store) => store.delete_blob(key).await, + #[cfg(all( + feature = "enterprise", + any(feature = "postgres", feature = "mysql") + ))] Store::SQLReadReplica(store) => store.delete_blob(key).await, Store::None => Err(trc::StoreEvent::NotConfigured.into()), }, diff --git a/crates/store/src/backend/composite/mod.rs b/crates/store/src/backend/composite/mod.rs index 8410db36..eee8cb74 100644 --- a/crates/store/src/backend/composite/mod.rs +++ b/crates/store/src/backend/composite/mod.rs @@ -9,4 +9,5 @@ */ pub mod distributed_blob; +#[cfg(any(feature = "postgres", feature = "mysql"))] pub mod read_replica; diff --git a/crates/store/src/config.rs b/crates/store/src/config.rs index 4d0d37af..29e79c99 100644 --- a/crates/store/src/config.rs +++ b/crates/store/src/config.rs @@ -235,6 +235,7 @@ impl Stores { ) .unwrap_or(CompressionAlgo::None); match protocol.as_str() { + #[cfg(any(feature = "postgres", feature = "mysql"))] "sql-read-replica" => { if let Some(db) = crate::backend::composite::read_replica::SQLReadReplica::open( config, diff --git a/crates/store/src/dispatch/blob.rs b/crates/store/src/dispatch/blob.rs index 75b2cdca..a06b6f4d 100644 --- a/crates/store/src/dispatch/blob.rs +++ b/crates/store/src/dispatch/blob.rs @@ -30,7 +30,7 @@ impl BlobStore { Store::MySQL(store) => store.get_blob(key, read_range).await, #[cfg(feature = "rocks")] Store::RocksDb(store) => store.get_blob(key, read_range).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Store::SQLReadReplica(store) => store.get_blob(key, read_range).await, Store::None => Err(trc::StoreEvent::NotConfigured.into()), }, @@ -110,7 +110,7 @@ impl BlobStore { Store::MySQL(store) => store.put_blob(key, data.as_ref()).await, #[cfg(feature = "rocks")] Store::RocksDb(store) => store.put_blob(key, data.as_ref()).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Store::SQLReadReplica(store) => store.put_blob(key, data.as_ref()).await, Store::None => Err(trc::StoreEvent::NotConfigured.into()), }, @@ -146,7 +146,7 @@ impl BlobStore { Store::MySQL(store) => store.delete_blob(key).await, #[cfg(feature = "rocks")] Store::RocksDb(store) => store.delete_blob(key).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Store::SQLReadReplica(store) => store.delete_blob(key).await, Store::None => Err(trc::StoreEvent::NotConfigured.into()), }, diff --git a/crates/store/src/dispatch/mod.rs b/crates/store/src/dispatch/mod.rs index acd94afa..b6d1c32a 100644 --- a/crates/store/src/dispatch/mod.rs +++ b/crates/store/src/dispatch/mod.rs @@ -26,7 +26,7 @@ impl Store { Self::MySQL(_) => "mysql", #[cfg(feature = "rocks")] Self::RocksDb(_) => "rocksdb", - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(_) => "read_replica", Self::None => "none", } diff --git a/crates/store/src/dispatch/store.rs b/crates/store/src/dispatch/store.rs index f293e178..06282bff 100644 --- a/crates/store/src/dispatch/store.rs +++ b/crates/store/src/dispatch/store.rs @@ -50,7 +50,7 @@ impl Store { Self::MySQL(store) => store.get_value(key).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.get_value(key).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.get_value(key).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -72,7 +72,7 @@ impl Store { Self::MySQL(store) => store.get_bitmap(key).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.get_bitmap(key).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.get_bitmap(key).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -118,7 +118,7 @@ impl Store { Self::MySQL(store) => store.iterate(params, cb).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.iterate(params, cb).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.iterate(params, cb).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -147,7 +147,7 @@ impl Store { Self::MySQL(store) => store.get_counter(key).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.get_counter(key).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.get_counter(key).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -212,7 +212,7 @@ impl Store { Self::MySQL(store) => store.write(batch).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.write(batch).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.write(batch).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -259,7 +259,7 @@ impl Store { Self::MySQL(store) => store.write(batch).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.write(batch).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.write(batch).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), }; @@ -315,7 +315,7 @@ impl Store { Self::MySQL(store) => store.purge_store().await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.purge_store().await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.purge_store().await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -334,7 +334,7 @@ impl Store { Self::MySQL(store) => store.delete_range(from, to).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.delete_range(from, to).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.delete_range(from, to).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -489,7 +489,7 @@ impl Store { Self::MySQL(store) => store.get_blob(key, range).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.get_blob(key, range).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.get_blob(key, range).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -508,7 +508,7 @@ impl Store { Self::MySQL(store) => store.put_blob(key, data).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.put_blob(key, data).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.put_blob(key, data).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } @@ -527,7 +527,7 @@ impl Store { Self::MySQL(store) => store.delete_blob(key).await, #[cfg(feature = "rocks")] Self::RocksDb(store) => store.delete_blob(key).await, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(store) => store.delete_blob(key).await, Self::None => Err(trc::StoreEvent::NotConfigured.into()), } diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index e7890cc0..114d0088 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -184,7 +184,7 @@ pub enum Store { MySQL(Arc), #[cfg(feature = "rocks")] RocksDb(Arc), - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] SQLReadReplica(Arc), #[default] None, @@ -669,7 +669,7 @@ impl Store { Store::PostgreSQL(_) => true, #[cfg(feature = "mysql")] Store::MySQL(_) => true, - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Store::SQLReadReplica(_) => true, _ => false, } @@ -684,6 +684,20 @@ impl Store { _ => false, } } + + #[cfg(feature = "enterprise")] + pub fn is_enterprise_store(&self) -> bool { + match self { + #[cfg(any(feature = "postgres", feature = "mysql"))] + Store::SQLReadReplica(_) => true, + _ => false, + } + } + + #[cfg(not(feature = "enterprise"))] + pub fn is_enterprise_store(&self) -> bool { + false + } } impl std::fmt::Debug for Store { @@ -699,7 +713,7 @@ impl std::fmt::Debug for Store { Self::MySQL(_) => f.debug_tuple("MySQL").finish(), #[cfg(feature = "rocks")] Self::RocksDb(_) => f.debug_tuple("RocksDb").finish(), - #[cfg(feature = "enterprise")] + #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))] Self::SQLReadReplica(_) => f.debug_tuple("SQLReadReplica").finish(), Self::None => f.debug_tuple("None").finish(), } @@ -718,3 +732,16 @@ impl From> for trc::Value { } } } + +impl Stores { + pub fn disable_enterprise_only(&mut self) { + #[cfg(feature = "enterprise")] + { + #[cfg(any(feature = "postgres", feature = "mysql"))] + self.stores + .retain(|_, store| !matches!(store, Store::SQLReadReplica(_))); + self.blob_stores + .retain(|_, store| !matches!(store.backend, BlobBackend::Composite(_))); + } + } +}