pub struct JournalObject {
pub id: ContentId,
pub bytes: Vec<u8>,
/* private fields */
}Expand description
Immutable semantic value and its convenient payload-byte projection.
JournalObject::from_bytes wraps bytes in journal/exact-bytes-v1, so
their public id is a kernel Datum id rather than a physical storage digest.
Fields§
§id: ContentId§bytes: Vec<u8>Implementations§
Source§impl JournalObject
impl JournalObject
Sourcepub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Self
pub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Self
Constructs a tagged exact-byte semantic value.
Examples found in repository?
examples/cold_replay.rs (line 14)
6fn main() -> ExitCode {
7 let records = std::env::args()
8 .nth(1)
9 .and_then(|value| value.parse::<u64>().ok())
10 .unwrap_or(100_000);
11 let mut state = StoredState::default();
12 let mut previous = None;
13 for sequence in 0..records {
14 let object = JournalObject::from_bytes(sequence.to_be_bytes());
15 let entry = JournalEntry::new(
16 sequence,
17 previous.clone(),
18 Symbol::qualified("benchmark", "cold-replay-record"),
19 vec![object.id.clone()],
20 );
21 let datum = object.datum().clone();
22 state.objects.insert(object.id.clone(), object.bytes);
23 state.datums.insert(object.id, datum);
24 previous = Some(entry.id.clone());
25 state.entries.insert(sequence, entry);
26 }
27 state.head = state
28 .entries
29 .last_key_value()
30 .map(|(_, entry)| JournalHead {
31 sequence: entry.sequence,
32 entry: entry.id.clone(),
33 });
34
35 // Rebuild the maps to discard construction locality before timing the
36 // complete verification and reducer-facing replay materialization.
37 state.objects = BTreeMap::from_iter(state.objects);
38 state.datums = BTreeMap::from_iter(state.datums);
39 state.entries = BTreeMap::from_iter(state.entries);
40 let started = Instant::now();
41 let replayed = match replay(state) {
42 Ok(replay) => replay.count(),
43 Err(error) => {
44 eprintln!("cold replay failed: {error}");
45 return ExitCode::FAILURE;
46 }
47 };
48 let elapsed = started.elapsed();
49 if replayed != records as usize {
50 eprintln!("cold replay count mismatch: expected {records}, observed {replayed}");
51 return ExitCode::FAILURE;
52 }
53 println!(
54 "records={records} elapsed_ns={} elapsed_ms={:.3}",
55 elapsed.as_nanos(),
56 elapsed.as_secs_f64() * 1_000.0
57 );
58 ExitCode::SUCCESS
59}Sourcepub fn from_datum(datum: Datum) -> Result<Self, JournalError>
pub fn from_datum(datum: Datum) -> Result<Self, JournalError>
Constructs an object from any canonical Datum.
Sourcepub fn datum(&self) -> &Datum
pub fn datum(&self) -> &Datum
Borrows the semantic value.
Examples found in repository?
examples/cold_replay.rs (line 21)
6fn main() -> ExitCode {
7 let records = std::env::args()
8 .nth(1)
9 .and_then(|value| value.parse::<u64>().ok())
10 .unwrap_or(100_000);
11 let mut state = StoredState::default();
12 let mut previous = None;
13 for sequence in 0..records {
14 let object = JournalObject::from_bytes(sequence.to_be_bytes());
15 let entry = JournalEntry::new(
16 sequence,
17 previous.clone(),
18 Symbol::qualified("benchmark", "cold-replay-record"),
19 vec![object.id.clone()],
20 );
21 let datum = object.datum().clone();
22 state.objects.insert(object.id.clone(), object.bytes);
23 state.datums.insert(object.id, datum);
24 previous = Some(entry.id.clone());
25 state.entries.insert(sequence, entry);
26 }
27 state.head = state
28 .entries
29 .last_key_value()
30 .map(|(_, entry)| JournalHead {
31 sequence: entry.sequence,
32 entry: entry.id.clone(),
33 });
34
35 // Rebuild the maps to discard construction locality before timing the
36 // complete verification and reducer-facing replay materialization.
37 state.objects = BTreeMap::from_iter(state.objects);
38 state.datums = BTreeMap::from_iter(state.datums);
39 state.entries = BTreeMap::from_iter(state.entries);
40 let started = Instant::now();
41 let replayed = match replay(state) {
42 Ok(replay) => replay.count(),
43 Err(error) => {
44 eprintln!("cold replay failed: {error}");
45 return ExitCode::FAILURE;
46 }
47 };
48 let elapsed = started.elapsed();
49 if replayed != records as usize {
50 eprintln!("cold replay count mismatch: expected {records}, observed {replayed}");
51 return ExitCode::FAILURE;
52 }
53 println!(
54 "records={records} elapsed_ns={} elapsed_ms={:.3}",
55 elapsed.as_nanos(),
56 elapsed.as_secs_f64() * 1_000.0
57 );
58 ExitCode::SUCCESS
59}Sourcepub fn verify(&self) -> Result<(), JournalError>
pub fn verify(&self) -> Result<(), JournalError>
Rejects any object whose claimed semantic id or byte projection differs.
Trait Implementations§
Source§impl Clone for JournalObject
impl Clone for JournalObject
Source§fn clone(&self) -> JournalObject
fn clone(&self) -> JournalObject
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JournalObject
impl Debug for JournalObject
impl Eq for JournalObject
Source§impl PartialEq for JournalObject
impl PartialEq for JournalObject
impl StructuralPartialEq for JournalObject
Auto Trait Implementations§
impl Freeze for JournalObject
impl RefUnwindSafe for JournalObject
impl Send for JournalObject
impl Sync for JournalObject
impl Unpin for JournalObject
impl UnsafeUnpin for JournalObject
impl UnwindSafe for JournalObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more