Update all modules to use registry - part 3

This commit is contained in:
mdecimus
2026-02-11 21:30:17 +00:00
parent c4064082ea
commit f7c2fe10c1
86 changed files with 1010 additions and 1037 deletions

View File

@@ -238,8 +238,4 @@ impl SQLReadReplica {
pub fn primary_store(&self) -> &Store {
&self.primary
}
pub fn into_primary(self) -> Store {
self.primary
}
}

View File

@@ -45,7 +45,7 @@ impl LookupStores {
id: http.namespace,
};
match self.stores.entry(http_config.id.clone()) {
match self.stores.entry(http_config.id.as_str().into()) {
Entry::Vacant(entry) => {
let store = HttpStore {
entries: ArcSwap::from_pointee(AHashMap::new()),

View File

@@ -56,8 +56,10 @@ impl LookupStores {
}
for (namespace, store) in lookups {
self.stores
.insert(namespace, InMemoryStore::Static(store.into()));
self.stores.insert(
namespace.into_boxed_str(),
InMemoryStore::Static(store.into()),
);
}
}
}

View File

@@ -1,31 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::Store;
use registry::schema::structs::DataStore;
impl Store {
pub async fn build(config: DataStore) -> Result<Self, String> {
#[allow(unreachable_patterns)]
match config {
#[cfg(feature = "rocks")]
DataStore::RocksDb(store) => crate::backend::rocksdb::RocksDbStore::open(store).await,
#[cfg(feature = "foundation")]
DataStore::FoundationDb(store) => {
crate::backend::foundationdb::FdbStore::open(store).await
}
#[cfg(feature = "postgres")]
DataStore::PostgreSql(store) => {
crate::backend::postgres::PostgresStore::open(store).await
}
#[cfg(feature = "mysql")]
DataStore::MySql(store) => crate::backend::mysql::MysqlStore::open(store).await,
#[cfg(feature = "sqlite")]
DataStore::Sqlite(store) => crate::backend::sqlite::SqliteStore::open(store),
_ => Err("Binary was not compiled with the selected data store backend".to_string()),
}
}
}

View File

@@ -57,4 +57,21 @@ impl BlobStore {
}
}
}
// SPDX-SnippetBegin
// SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
// SPDX-License-Identifier: LicenseRef-SEL
#[cfg(feature = "enterprise")]
pub fn downgrade_store(self) -> BlobStore {
match self {
BlobStore::Sharded(_) => BlobStore::default(),
other => other,
}
}
#[cfg(feature = "enterprise")]
pub fn is_enterprise(&self) -> bool {
matches!(self, BlobStore::Sharded(_))
}
// SPDX-SnippetEnd
}

View File

@@ -0,0 +1,94 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::{Store, registry::bootstrap::Bootstrap};
use registry::schema::{
prelude::Object,
structs::{DataStore, MetricsStore, TracingStore},
};
impl Store {
pub async fn build(config: DataStore) -> Result<Self, String> {
#[allow(unreachable_patterns)]
match config {
#[cfg(feature = "rocks")]
DataStore::RocksDb(store) => crate::backend::rocksdb::RocksDbStore::open(store).await,
#[cfg(feature = "foundation")]
DataStore::FoundationDb(store) => {
crate::backend::foundationdb::FdbStore::open(store).await
}
#[cfg(feature = "postgres")]
DataStore::PostgreSql(store) => {
crate::backend::postgres::PostgresStore::open(store).await
}
#[cfg(feature = "mysql")]
DataStore::MySql(store) => crate::backend::mysql::MysqlStore::open(store).await,
#[cfg(feature = "sqlite")]
DataStore::Sqlite(store) => crate::backend::sqlite::SqliteStore::open(store),
_ => Err("Binary was not compiled with the selected data store backend".to_string()),
}
}
pub async fn build_tracing(bp: &mut Bootstrap) -> Option<Self> {
let result = match bp.setting_infallible::<TracingStore>().await {
TracingStore::Disabled => Ok(None),
TracingStore::Default => Ok(Some(bp.data_store.clone())),
#[cfg(feature = "foundation")]
TracingStore::FoundationDb(store) => {
crate::backend::foundationdb::FdbStore::open(store)
.await
.map(Some)
}
#[cfg(feature = "postgres")]
TracingStore::PostgreSql(store) => crate::backend::postgres::PostgresStore::open(store)
.await
.map(Some),
#[cfg(feature = "mysql")]
TracingStore::MySql(store) => crate::backend::mysql::MysqlStore::open(store)
.await
.map(Some),
_ => Err("Binary was not compiled with the selected tracing store backend".to_string()),
};
match result {
Ok(store) => store,
Err(err) => {
bp.build_warning(Object::TracingStore.singleton(), err);
None
}
}
}
pub async fn build_metrics(bp: &mut Bootstrap) -> Option<Self> {
let result = match bp.setting_infallible::<MetricsStore>().await {
MetricsStore::Disabled => Ok(None),
MetricsStore::Default => Ok(Some(bp.data_store.clone())),
#[cfg(feature = "foundation")]
MetricsStore::FoundationDb(store) => {
crate::backend::foundationdb::FdbStore::open(store)
.await
.map(Some)
}
#[cfg(feature = "postgres")]
MetricsStore::PostgreSql(store) => crate::backend::postgres::PostgresStore::open(store)
.await
.map(Some),
#[cfg(feature = "mysql")]
MetricsStore::MySql(store) => crate::backend::mysql::MysqlStore::open(store)
.await
.map(Some),
_ => Err("Binary was not compiled with the selected metrics store backend".to_string()),
};
match result {
Ok(store) => store,
Err(err) => {
bp.build_warning(Object::MetricsStore.singleton(), err);
None
}
}
}
}

View File

@@ -8,8 +8,16 @@ use crate::{InMemoryStore, LookupStores, registry::bootstrap::Bootstrap};
use registry::schema::structs::{LookupStore, StoreLookup};
use std::collections::hash_map::Entry;
#[allow(unreachable_patterns)]
impl LookupStores {
pub async fn build(bp: &mut Bootstrap) -> Self {
let mut stores = LookupStores::default();
stores.parse_stores(bp).await;
stores.parse_static(bp).await;
stores.parse_http(bp).await;
stores
}
#[allow(unreachable_patterns)]
pub async fn parse_stores(&mut self, bp: &mut Bootstrap) {
for store in bp.list_infallible::<StoreLookup>().await {
let id = store.id;
@@ -53,7 +61,7 @@ impl LookupStores {
};
match result {
Ok(lookup) => match self.stores.entry(store.namespace.clone()) {
Ok(lookup) => match self.stores.entry(store.namespace.as_str().into()) {
Entry::Vacant(entry) => {
entry.insert(lookup);
}
@@ -61,7 +69,7 @@ impl LookupStores {
bp.build_error(
id,
format!(
"An lookup store with the {} namespace already exists",
"A lookup store with the {} namespace already exists",
store.namespace
),
);

View File

@@ -41,4 +41,21 @@ impl InMemoryStore {
}
}
}
// SPDX-SnippetBegin
// SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
// SPDX-License-Identifier: LicenseRef-SEL
#[cfg(feature = "enterprise")]
pub fn downgrade_store(self) -> InMemoryStore {
match self {
InMemoryStore::Sharded(_) => InMemoryStore::default(),
other => other,
}
}
#[cfg(feature = "enterprise")]
pub fn is_enterprise(&self) -> bool {
matches!(self, InMemoryStore::Sharded(_))
}
// SPDX-SnippetEnd
}

View File

@@ -8,4 +8,5 @@ pub mod blob;
pub mod data;
pub mod lookup;
pub mod memory;
pub mod registry;
pub mod search;

View File

@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::RegistryStore;
use std::path::PathBuf;
impl RegistryStore {
pub fn init(local: PathBuf) -> Self {
let todo = "environment variables and reading from files";
/*
match std::fs::read_to_string(&cfg_local_path) {
Ok(value) => {
config.parse(&value).failed("Invalid local registry file");
}
Err(err) => {
config.new_build_error("*", format!("Could not read registry file: {err}"));
}
}
*/
todo!()
}
}

View File

@@ -469,7 +469,7 @@ impl Store {
// SPDX-SnippetBegin
// SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
// SPDX-License-Identifier: LicenseRef-SEL
#[cfg(feature = "enterprise")]
#[cfg(all(feature = "enterprise", any(feature = "postgres", feature = "mysql")))]
Store::SQLReadReplica(store) => Box::pin(store.primary_store().create_tables()).await,
// SPDX-SnippetEnd
_ => Ok(()),

View File

@@ -5,7 +5,7 @@
*/
pub mod backend;
pub mod bootstrap;
pub mod build;
pub mod dispatch;
pub mod query;
pub mod registry;
@@ -126,7 +126,7 @@ pub struct IterateParams<T: Key> {
#[derive(Clone, Default)]
pub struct LookupStores {
pub stores: AHashMap<String, InMemoryStore>,
pub stores: AHashMap<Box<str>, InMemoryStore>,
}
#[derive(Clone, Default)]
@@ -261,6 +261,12 @@ impl From<Store> for InMemoryStore {
}
}
impl Default for BlobStore {
fn default() -> Self {
Self::Store(Store::None)
}
}
impl Default for InMemoryStore {
fn default() -> Self {
Self::Store(Store::None)
@@ -603,6 +609,11 @@ impl Store {
matches!(self, Self::None)
}
#[inline(always)]
pub fn is_active(&self) -> bool {
!matches!(self, Self::None)
}
#[inline(always)]
pub fn is_sql(&self) -> bool {
match self {
@@ -646,7 +657,16 @@ impl Store {
// SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
// SPDX-License-Identifier: LicenseRef-SEL
#[cfg(feature = "enterprise")]
pub fn is_enterprise_store(&self) -> bool {
pub fn downgrade_store(self) -> Self {
match self {
#[cfg(any(feature = "postgres", feature = "mysql"))]
Store::SQLReadReplica(store) => store.primary_store().clone(),
other => other,
}
}
#[cfg(feature = "enterprise")]
pub fn is_enterprise(&self) -> bool {
match self {
#[cfg(any(feature = "postgres", feature = "mysql"))]
Store::SQLReadReplica(_) => true,
@@ -654,11 +674,6 @@ impl Store {
}
}
// SPDX-SnippetEnd
#[cfg(not(feature = "enterprise"))]
pub fn is_enterprise_store(&self) -> bool {
false
}
}
impl std::fmt::Debug for Store {

View File

@@ -174,4 +174,12 @@ impl Bootstrap {
pub fn hostname(&self) -> &str {
&self.node.hostname
}
pub fn log_errors(&self) {
let todo = "implement";
}
pub fn log_warnings(&self) {
let todo = "implement";
}
}

View File

@@ -40,6 +40,7 @@ pub enum RegistryFilterOp {
pub enum RegistryFilterValue {
String(String),
Integer(u64),
U64(u64),
U16(u16),
Boolean(bool),
}

View File

@@ -8,7 +8,10 @@ use crate::{
RegistryStore,
registry::{RegistryFilter, RegistryFilterOp, RegistryFilterValue, RegistryQuery},
};
use registry::schema::prelude::{Object, Property};
use registry::{
schema::prelude::{Object, Property},
types::EnumType,
};
use roaring::RoaringBitmap;
impl RegistryStore {
@@ -193,12 +196,18 @@ impl From<&str> for RegistryFilterValue {
impl From<u64> for RegistryFilterValue {
fn from(value: u64) -> Self {
RegistryFilterValue::Integer(value)
RegistryFilterValue::U64(value)
}
}
impl From<u32> for RegistryFilterValue {
fn from(value: u32) -> Self {
RegistryFilterValue::Integer(value as u64)
RegistryFilterValue::U64(value as u64)
}
}
impl From<u16> for RegistryFilterValue {
fn from(value: u16) -> Self {
RegistryFilterValue::U16(value)
}
}