Storage layer refactoring: faster id generation, automatic batching and virtual thread ids

This commit is contained in:
mdecimus
2025-04-02 17:37:14 +02:00
parent 76f085ab7c
commit fac2975a5a
152 changed files with 3489 additions and 4039 deletions

View File

@@ -190,7 +190,7 @@ impl FormHandler for Server {
0u32.serialize(),
);
self.store()
.write(batch.build())
.write(batch.build_all())
.await
.caused_by(trc::location!())?;
self.blob_store()

View File

@@ -39,7 +39,7 @@ pub trait CryptoHandler: Sync + Send {
impl CryptoHandler for Server {
async fn handle_crypto_get(&self, access_token: Arc<AccessToken>) -> trc::Result<HttpResponse> {
let ec = if let Some(params_) = self
.get_property::<Archive<AlignedBytes>>(
.get_archive_by_property(
access_token.primary_id(),
Collection::Principal,
0,
@@ -97,7 +97,7 @@ impl CryptoHandler for Server {
.with_collection(Collection::Principal)
.update_document(0)
.clear(Property::Parameters);
self.core.storage.data.write(batch.build()).await?;
self.core.storage.data.write(batch.build_all()).await?;
return Ok(JsonResponse::new(json!({
"data": (),
}))
@@ -147,7 +147,7 @@ impl CryptoHandler for Server {
.with_collection(Collection::Principal)
.update_document(0)
.set(Property::Parameters, params);
self.core.storage.data.write(batch.build()).await?;
self.core.storage.data.write(batch.build_all()).await?;
Ok(JsonResponse::new(json!({
"data": num_certs,

View File

@@ -260,7 +260,7 @@ impl UndeleteApi for Server {
self.core
.storage
.data
.write(batch.build())
.write(batch.build_all())
.await
.caused_by(trc::location!())?;
}

View File

@@ -30,6 +30,7 @@ use dns::DnsManagement;
use enterprise::telemetry::TelemetryApi;
use hyper::{Method, StatusCode, header};
use jmap::api::{ToJmapHttpResponse, ToRequestError};
use jmap_proto::error::request::RequestError;
use log::LogManagement;
use mail_parser::DateTime;
use principal::PrincipalManager;
@@ -276,6 +277,10 @@ impl ToManageHttpResponse for &trc::Error {
HttpResponse::new(StatusCode::UNAUTHORIZED)
.with_header(header::WWW_AUTHENTICATE, "Bearer realm=\"Stalwart Server\"")
.with_header(header::WWW_AUTHENTICATE, "Basic realm=\"Stalwart Server\"")
.with_content_type("application/problem+json")
.with_text_body(
serde_json::to_string(&RequestError::unauthorized()).unwrap_or_default(),
)
}
_ => self.to_request_error().into_http_response(),
}

View File

@@ -213,9 +213,9 @@ impl ManageReports for Server {
batch.clear(ValueClass::Report(report_id));
if batch.ops.len() > 1000 {
if batch.len() > 1000 {
if let Err(err) =
server.core.storage.data.write(batch.build()).await
server.core.storage.data.write(batch.build_all()).await
{
trc::error!(err.caused_by(trc::location!()));
}
@@ -223,8 +223,10 @@ impl ManageReports for Server {
}
}
if !batch.ops.is_empty() {
if let Err(err) = server.core.storage.data.write(batch.build()).await {
if !batch.is_empty() {
if let Err(err) =
server.core.storage.data.write(batch.build_all()).await
{
trc::error!(err.caused_by(trc::location!()));
}
}
@@ -280,7 +282,7 @@ impl ManageReports for Server {
let mut batch = BatchBuilder::new();
batch.clear(ValueClass::Report(report_id));
self.core.storage.data.write(batch.build()).await?;
self.core.storage.data.write(batch.build_all()).await?;
Ok(JsonResponse::new(json!({
"data": true,

View File

@@ -23,7 +23,7 @@ use serde_json::json;
use services::index::Indexer;
use store::{
Serialize, rand,
write::{AlignedBytes, Archive, Archiver, BatchBuilder, ValueClass},
write::{Archiver, BatchBuilder, ValueClass},
};
use trc::AddContext;
use utils::url_params::UrlParams;
@@ -332,12 +332,7 @@ pub async fn reset_imap_uids(server: &Server, account_id: u32) -> trc::Result<(u
.unwrap_or_default()
{
let mailbox = server
.get_property::<Archive<AlignedBytes>>(
account_id,
Collection::Mailbox,
mailbox_id,
Property::Value,
)
.get_archive(account_id, Collection::Mailbox, mailbox_id)
.await
.caused_by(trc::location!())?
.ok_or_else(|| trc::ImapEvent::Error.into_err().caused_by(trc::location!()))?
@@ -359,7 +354,7 @@ pub async fn reset_imap_uids(server: &Server, account_id: u32) -> trc::Result<(u
.clear(Property::EmailIds);
server
.store()
.write(batch)
.write(batch.build_all())
.await
.caused_by(trc::location!())?;
mailbox_count += 1;
@@ -373,12 +368,7 @@ pub async fn reset_imap_uids(server: &Server, account_id: u32) -> trc::Result<(u
.unwrap_or_default()
{
let data = server
.get_property::<Archive<AlignedBytes>>(
account_id,
Collection::Email,
message_id,
Property::Value,
)
.get_archive(account_id, Collection::Email, message_id)
.await
.caused_by(trc::location!())?;
let data_ = if let Some(data) = data {
@@ -415,7 +405,7 @@ pub async fn reset_imap_uids(server: &Server, account_id: u32) -> trc::Result<(u
);
server
.store()
.write(batch)
.write(batch.build_all())
.await
.caused_by(trc::location!())?;
email_count += 1;