wasmer_journal/lib.rs
1mod base64;
2mod concrete;
3mod entry;
4mod snapshot;
5mod util;
6
7pub use concrete::*;
8pub use entry::*;
9pub use snapshot::*;
10pub use util::*;
11
12use serde::{Deserialize, Serialize};
13use std::{ops::Deref, str::FromStr};
14
15/// The results of an operation to write a log entry to the log
16#[derive(Debug)]
17pub struct LogWriteResult {
18 // Start of the actual entry
19 pub record_start: u64,
20 // End of the actual entry
21 pub record_end: u64,
22}
23
24impl LogWriteResult {
25 pub fn record_size(&self) -> u64 {
26 self.record_end - self.record_start
27 }
28}
29
30/// The snapshot capturer will take a series of objects that represents the state of
31/// a WASM process at a point in time and saves it so that it can be restored.
32/// It also allows for the restoration of that state at a later moment
33#[allow(unused_variables)]
34pub trait WritableJournal: std::fmt::Debug {
35 /// Takes in a stream of snapshot log entries and saves them so that they
36 /// may be restored at a later moment
37 fn write<'a>(&'a self, entry: JournalEntry<'a>) -> anyhow::Result<LogWriteResult>;
38
39 /// Flushes the data to disk or network
40 fn flush(&self) -> anyhow::Result<()>;
41
42 /// Commits the transaction
43 /// Returns the number of events committed
44 fn commit(&self) -> anyhow::Result<usize> {
45 Ok(0)
46 }
47
48 /// Rolls back the transaction and aborts its changes
49 /// Returns the number of events rolled back
50 fn rollback(&self) -> anyhow::Result<usize> {
51 Ok(0)
52 }
53}
54
55/// The results of an operation to read a log entry from the log
56#[derive(Debug)]
57pub struct LogReadResult<'a> {
58 /// Offset into the journal where this entry exists
59 pub record_start: u64,
60 /// Offset of the end of the entry
61 pub record_end: u64,
62 /// Represents the journal entry
63 pub record: JournalEntry<'a>,
64}
65
66impl<'a> LogReadResult<'a> {
67 pub fn into_inner(self) -> JournalEntry<'a> {
68 self.record
69 }
70}
71
72impl<'a> Deref for LogReadResult<'a> {
73 type Target = JournalEntry<'a>;
74
75 fn deref(&self) -> &Self::Target {
76 &self.record
77 }
78}
79
80/// The snapshot capturer will take a series of objects that represents the state of
81/// a WASM process at a point in time and saves it so that it can be restored.
82/// It also allows for the restoration of that state at a later moment
83#[allow(unused_variables)]
84pub trait ReadableJournal: std::fmt::Debug {
85 /// Returns a stream of snapshot objects that the runtime will use
86 /// to restore the state of a WASM process to a previous moment in time
87 fn read(&self) -> anyhow::Result<Option<LogReadResult<'_>>>;
88
89 /// Resets the journal so that reads will start from the
90 /// beginning again
91 fn as_restarted(&self) -> anyhow::Result<Box<DynReadableJournal>>;
92}
93
94/// The snapshot capturer will take a series of objects that represents the state of
95/// a WASM process at a point in time and saves it so that it can be restored.
96/// It also allows for the restoration of that state at a later moment
97#[allow(unused_variables)]
98pub trait Journal: WritableJournal + ReadableJournal + std::fmt::Debug {
99 /// Splits the journal into a read and write side
100 fn split(self) -> (Box<DynWritableJournal>, Box<DynReadableJournal>);
101}
102
103pub type DynJournal = dyn Journal + Send + Sync;
104pub type DynWritableJournal = dyn WritableJournal + Send + Sync;
105pub type DynReadableJournal = dyn ReadableJournal + Send + Sync;