mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2024-09-20 07:16:18 +08:00
This commit is contained in:
parent
0b91feffad
commit
6d76b26fb8
|
@ -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
|
||||
|
||||
|
|
|
@ -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()),
|
||||
},
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
*/
|
||||
|
||||
pub mod distributed_blob;
|
||||
#[cfg(any(feature = "postgres", feature = "mysql"))]
|
||||
pub mod read_replica;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()),
|
||||
},
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ pub enum Store {
|
|||
MySQL(Arc<MysqlStore>),
|
||||
#[cfg(feature = "rocks")]
|
||||
RocksDb(Arc<RocksDbStore>),
|
||||
#[cfg(feature = "enterprise")]
|
||||
#[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))]
|
||||
SQLReadReplica(Arc<backend::composite::read_replica::SQLReadReplica>),
|
||||
#[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<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(_)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue