coven_database/
journal.rs1use super::FileWrite;
7use crate::{
8 DbError, NewOperation, OperationId, OperationRecord, OperationUpdate, RetrySubject, StoreState,
9};
10
11pub struct Journal<'write> {
13 files: &'write FileWrite<'write>,
14}
15
16impl<'write> Journal<'write> {
17 pub(crate) fn new(files: &'write FileWrite<'write>) -> Self {
18 Self { files }
19 }
20
21 pub fn operation(&self, id: OperationId) -> Result<Option<OperationRecord>, DbError> {
24 crate::operation::find(self.files.database, id)
25 }
26
27 pub fn operations(&self, kind: &str) -> Result<Vec<OperationRecord>, DbError> {
29 crate::operation::of_kind(self.files.database, kind)
30 }
31
32 pub fn advance_operation(&self, update: &OperationUpdate) -> Result<(), DbError> {
36 crate::operation::advance(self.files.database, update)
37 }
38
39 pub fn store_state(&self) -> Result<StoreState, DbError> {
42 crate::store_state_tables::read(self.files.database)
43 }
44
45 pub fn applied_slot(&self) -> Result<u64, DbError> {
47 crate::sequence::applied(self.files.database)
48 }
49
50 pub fn start_operation(&self, operation: &NewOperation) -> Result<OperationId, DbError> {
53 crate::operation::insert(self.files.database, operation)
54 }
55
56 pub fn start_app_operation(
60 &self,
61 operation: &NewOperation,
62 kind: &str,
63 ) -> Result<OperationId, DbError> {
64 crate::operation::insert_for_app(self.files.database, operation, kind)
65 }
66
67 pub(crate) fn acknowledge(&self, id: OperationId) -> Result<(), DbError> {
72 crate::operation::acknowledge(self.files.database, id)
73 }
74
75 pub fn operation_pending<P: crate::PendingValue>(
77 &self,
78 id: OperationId,
79 ) -> Result<Option<P>, DbError> {
80 crate::pending::operation(self.files.database, id)
81 }
82
83 pub fn pending_can_retry<P: crate::PendingValue>(
86 &self,
87 subject: &P::Subject,
88 ) -> Result<bool, DbError> {
89 crate::pending::retry::<P>(self.files.database, subject)
90 }
91
92 pub fn clear_pending<S: serde::Serialize>(&self, subject: &S) -> Result<(), DbError> {
94 crate::pending::clear(self.files.database, subject)
95 }
96
97 pub fn clear_retry(&self, subject: RetrySubject) -> Result<(), DbError> {
99 crate::retry::clear(self.files.database, subject)
100 }
101}
102
103#[cfg(test)]
104#[path = "journal_tests.rs"]
105mod tests;