Allow multiple FoundationDB instances in the same process

This commit is contained in:
Maurus Decimus
2026-05-04 18:05:08 +02:00
parent 7e21ff6f4b
commit 8632f9b43a
8 changed files with 77 additions and 28 deletions

View File

@@ -29,7 +29,7 @@ use crate::registry::{
};
use common::{
Server, auth::AccessToken, cache::invalidate::CacheInvalidationBuilder,
expr::if_block::BootstrapExprExt,
expr::if_block::BootstrapExprExt, ipc::CacheInvalidation,
};
use http_proto::HttpSessionData;
use jmap_proto::{
@@ -649,8 +649,18 @@ impl RegistrySet for Server {
.await?
{
RegistryWriteResult::Success(_) => {
// Schedule account deletion
if let ObjectInner::Account(account) = &object.inner {
for sharee_id in self
.store()
.acl_revoke_all(id.document_id())
.await
.caused_by(trc::location!())?
{
cache_invalidator.invalidate(
CacheInvalidation::AccessToken(sharee_id),
);
}
schedule_account_destruction(set.server, id, account).await?;
}

View File

@@ -6,19 +6,28 @@
use super::FdbStore;
use crate::Store;
use foundationdb::{Database, api, options::DatabaseOption};
use foundationdb::{Database, api, api::NetworkAutoStop, options::DatabaseOption};
use parking_lot::Mutex;
use registry::schema::structs;
use std::sync::Arc;
static FDB_NETWORK: Mutex<Option<NetworkAutoStop>> = Mutex::new(None);
impl FdbStore {
pub async fn open(config: structs::FoundationDbStore) -> Result<Store, String> {
let guard = unsafe {
api::FdbApiBuilder::default()
.build()
.map_err(|err| format!("Failed to boot FoundationDB: {err:?}"))?
.boot()
.map_err(|err| format!("Failed to boot FoundationDB: {err:?}"))?
};
{
let mut guard = FDB_NETWORK.lock();
if guard.is_none() {
let network = unsafe {
api::FdbApiBuilder::default()
.build()
.map_err(|err| format!("Failed to boot FoundationDB: {err:?}"))?
.boot()
.map_err(|err| format!("Failed to boot FoundationDB: {err:?}"))?
};
*guard = Some(network);
}
}
let db = Database::new(config.cluster_file.as_deref())
.map_err(|err| format!("Failed to create FoundationDB database: {err:?}"))?;
@@ -49,7 +58,6 @@ impl FdbStore {
}
Ok(Store::FoundationDb(Arc::new(Self {
guard,
db,
version: Default::default(),
})))

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use foundationdb::{Database, FdbError, api::NetworkAutoStop};
use foundationdb::{Database, FdbError};
use std::time::{Duration, Instant};
pub mod blob;
@@ -15,10 +15,8 @@ pub mod write;
const MAX_VALUE_SIZE: usize = 100000;
pub const TRANSACTION_EXPIRY: Duration = Duration::from_secs(1);
#[allow(dead_code)]
pub struct FdbStore {
db: Database,
guard: NetworkAutoStop,
version: parking_lot::Mutex<ReadVersion>,
}