Fix compile flags for SQL Read Replicas
Some checks failed
trivy / Check (push) Failing after -8m3s

This commit is contained in:
mdecimus 2024-08-20 17:27:03 +02:00
parent 0b91feffad
commit 6d76b26fb8
8 changed files with 61 additions and 25 deletions

View file

@ -65,17 +65,12 @@ impl Core {
#[cfg(feature = "enterprise")] #[cfg(feature = "enterprise")]
if enterprise.is_none() { if enterprise.is_none() {
if matches!(data, Store::SQLReadReplica(_)) { if data.is_enterprise_store() {
config config
.new_build_error("storage.data", "SQL read replicas is an Enterprise feature"); .new_build_error("storage.data", "SQL read replicas is an Enterprise feature");
data = Store::None; data = Store::None;
} }
stores stores.disable_enterprise_only();
.stores
.retain(|_, store| !matches!(store, Store::SQLReadReplica(_)));
stores
.blob_stores
.retain(|_, store| !matches!(store.backend, BlobBackend::Composite(_)));
} }
// SPDX-SnippetEnd // SPDX-SnippetEnd

View file

@ -71,6 +71,10 @@ impl DistributedBlob {
Store::MySQL(store) => store.get_blob(key, read_range).await, Store::MySQL(store) => store.get_blob(key, read_range).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Store::RocksDb(store) => store.get_blob(key, read_range).await, 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::SQLReadReplica(store) => store.get_blob(key, read_range).await,
Store::None => Err(trc::StoreEvent::NotConfigured.into()), Store::None => Err(trc::StoreEvent::NotConfigured.into()),
}, },
@ -97,6 +101,10 @@ impl DistributedBlob {
Store::MySQL(store) => store.put_blob(key, data).await, Store::MySQL(store) => store.put_blob(key, data).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Store::RocksDb(store) => store.put_blob(key, data).await, 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::SQLReadReplica(store) => store.put_blob(key, data).await,
Store::None => Err(trc::StoreEvent::NotConfigured.into()), Store::None => Err(trc::StoreEvent::NotConfigured.into()),
}, },
@ -123,6 +131,10 @@ impl DistributedBlob {
Store::MySQL(store) => store.delete_blob(key).await, Store::MySQL(store) => store.delete_blob(key).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Store::RocksDb(store) => store.delete_blob(key).await, 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::SQLReadReplica(store) => store.delete_blob(key).await,
Store::None => Err(trc::StoreEvent::NotConfigured.into()), Store::None => Err(trc::StoreEvent::NotConfigured.into()),
}, },

View file

@ -9,4 +9,5 @@
*/ */
pub mod distributed_blob; pub mod distributed_blob;
#[cfg(any(feature = "postgres", feature = "mysql"))]
pub mod read_replica; pub mod read_replica;

View file

@ -235,6 +235,7 @@ impl Stores {
) )
.unwrap_or(CompressionAlgo::None); .unwrap_or(CompressionAlgo::None);
match protocol.as_str() { match protocol.as_str() {
#[cfg(any(feature = "postgres", feature = "mysql"))]
"sql-read-replica" => { "sql-read-replica" => {
if let Some(db) = crate::backend::composite::read_replica::SQLReadReplica::open( if let Some(db) = crate::backend::composite::read_replica::SQLReadReplica::open(
config, config,

View file

@ -30,7 +30,7 @@ impl BlobStore {
Store::MySQL(store) => store.get_blob(key, read_range).await, Store::MySQL(store) => store.get_blob(key, read_range).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Store::RocksDb(store) => store.get_blob(key, read_range).await, 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::SQLReadReplica(store) => store.get_blob(key, read_range).await,
Store::None => Err(trc::StoreEvent::NotConfigured.into()), Store::None => Err(trc::StoreEvent::NotConfigured.into()),
}, },
@ -110,7 +110,7 @@ impl BlobStore {
Store::MySQL(store) => store.put_blob(key, data.as_ref()).await, Store::MySQL(store) => store.put_blob(key, data.as_ref()).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Store::RocksDb(store) => store.put_blob(key, data.as_ref()).await, 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::SQLReadReplica(store) => store.put_blob(key, data.as_ref()).await,
Store::None => Err(trc::StoreEvent::NotConfigured.into()), Store::None => Err(trc::StoreEvent::NotConfigured.into()),
}, },
@ -146,7 +146,7 @@ impl BlobStore {
Store::MySQL(store) => store.delete_blob(key).await, Store::MySQL(store) => store.delete_blob(key).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Store::RocksDb(store) => store.delete_blob(key).await, 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::SQLReadReplica(store) => store.delete_blob(key).await,
Store::None => Err(trc::StoreEvent::NotConfigured.into()), Store::None => Err(trc::StoreEvent::NotConfigured.into()),
}, },

View file

@ -26,7 +26,7 @@ impl Store {
Self::MySQL(_) => "mysql", Self::MySQL(_) => "mysql",
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(_) => "rocksdb", Self::RocksDb(_) => "rocksdb",
#[cfg(feature = "enterprise")] #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))]
Self::SQLReadReplica(_) => "read_replica", Self::SQLReadReplica(_) => "read_replica",
Self::None => "none", Self::None => "none",
} }

View file

@ -50,7 +50,7 @@ impl Store {
Self::MySQL(store) => store.get_value(key).await, Self::MySQL(store) => store.get_value(key).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.get_value(key).await, 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::SQLReadReplica(store) => store.get_value(key).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -72,7 +72,7 @@ impl Store {
Self::MySQL(store) => store.get_bitmap(key).await, Self::MySQL(store) => store.get_bitmap(key).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.get_bitmap(key).await, 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::SQLReadReplica(store) => store.get_bitmap(key).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -118,7 +118,7 @@ impl Store {
Self::MySQL(store) => store.iterate(params, cb).await, Self::MySQL(store) => store.iterate(params, cb).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.iterate(params, cb).await, 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::SQLReadReplica(store) => store.iterate(params, cb).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -147,7 +147,7 @@ impl Store {
Self::MySQL(store) => store.get_counter(key).await, Self::MySQL(store) => store.get_counter(key).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.get_counter(key).await, 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::SQLReadReplica(store) => store.get_counter(key).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -212,7 +212,7 @@ impl Store {
Self::MySQL(store) => store.write(batch).await, Self::MySQL(store) => store.write(batch).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.write(batch).await, 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::SQLReadReplica(store) => store.write(batch).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -259,7 +259,7 @@ impl Store {
Self::MySQL(store) => store.write(batch).await, Self::MySQL(store) => store.write(batch).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.write(batch).await, 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::SQLReadReplica(store) => store.write(batch).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
}; };
@ -315,7 +315,7 @@ impl Store {
Self::MySQL(store) => store.purge_store().await, Self::MySQL(store) => store.purge_store().await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.purge_store().await, 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::SQLReadReplica(store) => store.purge_store().await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -334,7 +334,7 @@ impl Store {
Self::MySQL(store) => store.delete_range(from, to).await, Self::MySQL(store) => store.delete_range(from, to).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.delete_range(from, to).await, 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::SQLReadReplica(store) => store.delete_range(from, to).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -489,7 +489,7 @@ impl Store {
Self::MySQL(store) => store.get_blob(key, range).await, Self::MySQL(store) => store.get_blob(key, range).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.get_blob(key, range).await, 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::SQLReadReplica(store) => store.get_blob(key, range).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -508,7 +508,7 @@ impl Store {
Self::MySQL(store) => store.put_blob(key, data).await, Self::MySQL(store) => store.put_blob(key, data).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.put_blob(key, data).await, 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::SQLReadReplica(store) => store.put_blob(key, data).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }
@ -527,7 +527,7 @@ impl Store {
Self::MySQL(store) => store.delete_blob(key).await, Self::MySQL(store) => store.delete_blob(key).await,
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(store) => store.delete_blob(key).await, 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::SQLReadReplica(store) => store.delete_blob(key).await,
Self::None => Err(trc::StoreEvent::NotConfigured.into()), Self::None => Err(trc::StoreEvent::NotConfigured.into()),
} }

View file

@ -184,7 +184,7 @@ pub enum Store {
MySQL(Arc<MysqlStore>), MySQL(Arc<MysqlStore>),
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
RocksDb(Arc<RocksDbStore>), RocksDb(Arc<RocksDbStore>),
#[cfg(feature = "enterprise")] #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))]
SQLReadReplica(Arc<backend::composite::read_replica::SQLReadReplica>), SQLReadReplica(Arc<backend::composite::read_replica::SQLReadReplica>),
#[default] #[default]
None, None,
@ -669,7 +669,7 @@ impl Store {
Store::PostgreSQL(_) => true, Store::PostgreSQL(_) => true,
#[cfg(feature = "mysql")] #[cfg(feature = "mysql")]
Store::MySQL(_) => true, Store::MySQL(_) => true,
#[cfg(feature = "enterprise")] #[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))]
Store::SQLReadReplica(_) => true, Store::SQLReadReplica(_) => true,
_ => false, _ => false,
} }
@ -684,6 +684,20 @@ impl Store {
_ => false, _ => 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 { impl std::fmt::Debug for Store {
@ -699,7 +713,7 @@ impl std::fmt::Debug for Store {
Self::MySQL(_) => f.debug_tuple("MySQL").finish(), Self::MySQL(_) => f.debug_tuple("MySQL").finish(),
#[cfg(feature = "rocks")] #[cfg(feature = "rocks")]
Self::RocksDb(_) => f.debug_tuple("RocksDb").finish(), 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::SQLReadReplica(_) => f.debug_tuple("SQLReadReplica").finish(),
Self::None => f.debug_tuple("None").finish(), Self::None => f.debug_tuple("None").finish(),
} }
@ -718,3 +732,16 @@ impl From<Value<'_>> 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(_)));
}
}
}