1mod admission;
14mod backend;
15mod datum_codec;
16mod entry;
17mod head;
18mod host;
19mod lease;
20mod memory;
21mod native_codec;
22mod object;
23mod persistent;
24mod projection;
25mod replay;
26mod snapshot;
27mod verify;
28
29pub use admission::{AdmissionDisposition, CommitAction, GuardedAdmission};
30pub use backend::{Admission, JournalBackend, StoredState};
31pub use entry::JournalEntry;
32pub use head::JournalHead;
33pub use host::HostDirJournalBackend;
34pub use lease::Lease;
35pub use memory::MemoryBackend;
36pub use native_codec::{
37 BackendCapabilities, EntryLocation, EntryNamespace, Failpoint, NativeFormatId,
38 NativeStateEnvelope, VerifiedNativePrefixRef,
39};
40pub use object::JournalObject;
41pub use persistent::{
42 PersistentObjectStore, PersistentSemanticObjects, StoreError, StoredDatumRef,
43};
44pub use projection::{DirProjection, ProjectionRow, TableProjection};
45pub use replay::{Replay, replay};
46pub use snapshot::VerifiedSnapshot;
47pub use verify::{JournalError, Verification};
48
49use sim_kernel::{ContentId, Symbol};
50
51pub struct Journal<B> {
53 backend: B,
54}
55
56impl<B: JournalBackend> Journal<B> {
57 pub fn new(backend: B) -> Self {
59 Self { backend }
60 }
61
62 pub fn acquire_lease(&self) -> Result<Lease, JournalError> {
64 self.backend.acquire_lease()
65 }
66
67 pub fn head(&self) -> Result<Option<JournalHead>, JournalError> {
69 let state = self.backend.read_state()?;
70 verify::verify_state(&state).map(|v| v.head)
71 }
72
73 pub fn publish(
78 &self,
79 lease: &Lease,
80 expected: Option<&JournalHead>,
81 objects: Vec<JournalObject>,
82 entries: Vec<JournalEntry>,
83 ) -> Result<JournalHead, JournalError> {
84 self.backend
85 .admit(self.verified_admission(lease, expected, objects, entries)?)
86 }
87
88 pub fn verify(&self) -> Result<Verification, JournalError> {
90 verify::verify_state(&self.backend.read_state()?)
91 }
92
93 pub fn replay(&self) -> Result<Replay, JournalError> {
95 replay(self.backend.read_state()?)
96 }
97
98 pub fn verified_snapshot(&self) -> Result<VerifiedSnapshot, JournalError> {
104 VerifiedSnapshot::from_state(self.backend.read_state()?)
105 }
106
107 pub fn table_projection(&self) -> Result<TableProjection, JournalError> {
109 Ok(TableProjection::from_verification(self.verify()?))
110 }
111
112 pub fn dir_projection(&self) -> Result<DirProjection, JournalError> {
114 Ok(DirProjection::from_verification(self.verify()?))
115 }
116
117 pub fn entry(
119 sequence: u64,
120 previous: Option<ContentId>,
121 kind: Symbol,
122 payloads: Vec<ContentId>,
123 ) -> JournalEntry {
124 JournalEntry::new(sequence, previous, kind, payloads)
125 }
126}
127
128#[cfg(test)]
129mod tests;