#[cfg(not(target_os = "wasi"))]
use crate::error::Error;
use crate::error::Result;
use crate::options::DurabilityMode;
use crate::types::Sequence;
use crate::wal::WalFrontDoorStats;
use crate::write_batch::BatchOperation;
#[cfg(not(target_os = "wasi"))]
pub(crate) use object_store::ObjectWalWaiter;
pub(crate) use object_store::{
ObjectLeaseState, ObjectWriterLease, object_store_wal_batches_after_replay_floor,
validate_object_lease_wal_key_capacity,
};
mod filesystem;
mod object_store;
pub(crate) use filesystem::FilesystemSubstrate;
pub(crate) use object_store::ObjectStoreSubstrate;
#[cfg(feature = "fuzzing")]
pub(crate) use object_store::fuzz_decode_object_control;
#[derive(Debug)]
pub(crate) enum DurabilitySubstrate {
Filesystem(FilesystemSubstrate),
ObjectStore(ObjectStoreSubstrate),
}
impl DurabilitySubstrate {
pub(crate) fn wal_is_present(&self) -> bool {
match self {
Self::Filesystem(substrate) => substrate.wal_is_present(),
Self::ObjectStore(_) => true,
}
}
pub(crate) fn object_fencing_epoch(&self) -> Option<u64> {
match self {
Self::Filesystem(_) => None,
Self::ObjectStore(substrate) => Some(substrate.fencing_epoch()),
}
}
pub(crate) fn accept_commit(
&self,
sequence: Sequence,
operations: &[BatchOperation],
durability: DurabilityMode,
) -> Result<()> {
match self {
Self::Filesystem(substrate) => {
substrate.accept_commit(sequence, operations, durability)
}
Self::ObjectStore(substrate) => {
substrate.accept_commit(sequence, operations, durability)
}
}
}
#[cfg(not(target_os = "wasi"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(dead_code))]
pub(crate) async fn accept_commit_async(
&self,
sequence: Sequence,
operations: &[BatchOperation],
durability: DurabilityMode,
) -> Result<()> {
match self {
Self::Filesystem(substrate) => {
substrate
.accept_commit_async(sequence, operations, durability)
.await
}
Self::ObjectStore(substrate) => {
substrate
.enqueue_commit(sequence, operations, durability)?
.wait()
.await
}
}
}
#[cfg(not(target_os = "wasi"))]
pub(crate) fn enqueue_object_commit(
&self,
sequence: Sequence,
operations: &[BatchOperation],
durability: DurabilityMode,
) -> Result<ObjectWalWaiter> {
match self {
Self::ObjectStore(substrate) => {
substrate.enqueue_commit(sequence, operations, durability)
}
Self::Filesystem(_) => Err(Error::unsupported_backend(
"object WAL enqueue requires object-store persistence",
)),
}
}
pub(crate) async fn fence_object_mutation_async(&self) -> Result<()> {
match self {
Self::Filesystem(_) => Ok(()),
Self::ObjectStore(substrate) => substrate.fence_mutation_async().await,
}
}
pub(crate) fn persist_wal(&self, durability: DurabilityMode) -> Result<()> {
match self {
Self::Filesystem(substrate) => substrate.persist_wal(durability),
Self::ObjectStore(substrate) => substrate.persist_wal(durability),
}
}
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(dead_code))]
pub(crate) async fn persist_wal_async(&self, durability: DurabilityMode) -> Result<()> {
match self {
Self::Filesystem(substrate) => substrate.persist_wal_async(durability).await,
Self::ObjectStore(substrate) => substrate.persist_wal(durability),
}
}
pub(crate) fn wal_stats(&self) -> Option<WalFrontDoorStats> {
match self {
Self::Filesystem(substrate) => substrate.wal_stats(),
Self::ObjectStore(substrate) => Some(substrate.wal_stats()),
}
}
pub(crate) fn rewrite_wal_after_replay_floor(&self, replay_floor: Sequence) -> Result<()> {
match self {
Self::Filesystem(substrate) => substrate.rewrite_wal_after_replay_floor(replay_floor),
Self::ObjectStore(substrate) => substrate.rewrite_wal_after_replay_floor(replay_floor),
}
}
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(dead_code))]
pub(crate) async fn rewrite_wal_after_replay_floor_async(
&self,
replay_floor: Sequence,
) -> Result<()> {
match self {
Self::Filesystem(substrate) => {
substrate
.rewrite_wal_after_replay_floor_async(replay_floor)
.await
}
Self::ObjectStore(substrate) => substrate.rewrite_wal_after_replay_floor(replay_floor),
}
}
pub(crate) fn release_writer_lease(&self) {
match self {
Self::Filesystem(substrate) => substrate.release_writer_lease(),
Self::ObjectStore(substrate) => substrate.release_writer_lease(),
}
}
}