Skip to content

Commit

Permalink
Add bulk_ingest_entry, Store::FlushError
Browse files Browse the repository at this point in the history
  • Loading branch information
sgwilym committed Aug 21, 2024
1 parent f01dcff commit 38ecd75
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions data-model/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
LengthyEntry, Path,
};

/// Returned when an entry is successfully ingested into a [`Store`].
/// Returned when an entry could be ingested into a [`Store`].
pub enum EntryIngestionSuccess<
const MCL: usize,
const MCC: usize,
Expand All @@ -32,6 +32,7 @@ pub enum EntryIngestionSuccess<
},
}

/// Returned when an entry cannot be ingested into a [`Store`].
pub enum EntryIngestionError<
const MCL: usize,
const MCC: usize,
Expand All @@ -45,6 +46,31 @@ pub enum EntryIngestionError<
WrongNamespace(AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>),
}

/// Returned when an entry failed to be ingested during a bulk ingestion.
pub enum BulkIngestionError<
const MCL: usize,
const MCC: usize,
const MPL: usize,
N: NamespaceId,
S: SubspaceId,
PD: PayloadDigest,
AT,
> {
/// The entry belonged to another namespace.
WrongNamespace(AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>),
/// The consumer failed for some reason.
ConsumerFailure,
}

/// A tuple of an [`AuthorisedEntry`] and how a [`Store`] responded to its ingestion.
pub type BulkIngestionResult<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD, AT> = (
AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>,
Result<
EntryIngestionSuccess<MCL, MCC, MPL, N, S, PD, AT>,
BulkIngestionError<MCL, MCC, MPL, N, S, PD, AT>,
>,
);

/// Return when a payload is successfully appended to the [`Store`].
pub enum PayloadAppendSuccess<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD>
where
Expand Down Expand Up @@ -83,6 +109,8 @@ where
PD: PayloadDigest,
AT: AuthorisationToken<MCL, MCC, MPL, N, S, PD>,
{
type FlushError;

/// The [namespace](https://willowprotocol.org/specs/data-model/index.html#namespace) which all of this store's [`AuthorisedEntry`] belong to.
fn namespace_id() -> N;

Expand All @@ -99,6 +127,12 @@ where
>;

// TODO: Bulk ingestion entry. The annoying there is it needs its own success / error types. We could get around this by exposing a BulkConsumer from the Store, but [then we need to support multi-writer consumption](https://github.com/earthstar-project/willow-rs/pull/21#issuecomment-2192393204).
/// Attempt to store an [`AuthorisedEntry`] in the [`Store`].
/// Will fail if the entry belonged to a different namespace than the store's.
fn bulk_ingest_entry(
&self,
authorised_entries: &[AuthorisedEntry<MCL, MCC, MPL, N, S, PD, AT>],
) -> impl Future<Output = Vec<BulkIngestionResult<MCL, MCC, MPL, N, S, PD, AT>>>;

/// Attempt to append part of a payload for a given [`AuthorisedEntry`].
///
Expand Down Expand Up @@ -181,5 +215,5 @@ where
) -> impl Future<Output = Vec<PD>>;

/// Force persistence of all previous mutations
fn flush() -> impl Future<Output = ()>;
fn flush() -> impl Future<Output = Result<(), Self::FlushError>>;
}

0 comments on commit 38ecd75

Please sign in to comment.