feat: spawn block write wal

This commit is contained in:
evenyag
2024-11-04 17:35:12 +08:00
parent 9c5d044238
commit 960f6d821b
2 changed files with 17 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ use std::any::Any;
use common_error::ext::ErrorExt;
use common_macro::stack_trace_debug;
use common_runtime::error::Error as RuntimeError;
use common_runtime::JoinError;
use serde_json::error::Error as JsonError;
use snafu::{Location, Snafu};
use store_api::storage::RegionId;
@@ -306,6 +307,14 @@ pub enum Error {
#[snafu(implicit)]
location: Location,
},
#[snafu(display("Join error"))]
Join {
#[snafu(implicit)]
location: Location,
#[snafu(source)]
error: JoinError,
},
}
impl ErrorExt for Error {

View File

@@ -31,8 +31,8 @@ use store_api::storage::RegionId;
use crate::error::{
AddEntryLogBatchSnafu, DiscontinuousLogIndexSnafu, Error, FetchEntrySnafu,
IllegalNamespaceSnafu, IllegalStateSnafu, InvalidProviderSnafu, OverrideCompactedEntrySnafu,
RaftEngineSnafu, Result, StartGcTaskSnafu, StopGcTaskSnafu,
IllegalNamespaceSnafu, IllegalStateSnafu, InvalidProviderSnafu, JoinSnafu,
OverrideCompactedEntrySnafu, RaftEngineSnafu, Result, StartGcTaskSnafu, StopGcTaskSnafu,
};
use crate::metrics;
use crate::raft_engine::backend::SYSTEM_NAMESPACE;
@@ -250,6 +250,12 @@ impl LogStore for RaftEngineLogStore {
.engine
.write(&mut batch, sync)
.context(RaftEngineSnafu)?;
let engine = self.engine.clone();
let _ = common_runtime::spawn_blocking_global(move || {
engine.write(&mut batch, sync).context(RaftEngineSnafu)
})
.await
.context(JoinSnafu)?;
Ok(AppendBatchResponse { last_entry_ids })
}