Skip to content

Commit

Permalink
Add Vector clock snapshot type that holds the state of a vector clock…
Browse files Browse the repository at this point in the history
… frozen in time. Things that hold vectorclocks they are working with should continue to use VectorClock, things that were storing a vector clock to record the state of a clock for future comaprison should use the snapshot
  • Loading branch information
jscatena88 committed Jun 27, 2024
1 parent 829aa1f commit 7ec7fc6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 106 deletions.
6 changes: 3 additions & 3 deletions src/codec/meta/actor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::codec::crypto::{
AccessKey, AsymLockedAccessKey, AsymLockedAccessKeyError, SigningKey, VerifyingKey,
};
use crate::codec::header::AccessMask;
use crate::codec::meta::{UserAgent, VectorClock};
use crate::codec::meta::{UserAgent, VectorClock, VectorClockSnapshot};
use crate::codec::{ParserResult, Stream};

const KEY_PRESENT_BIT: u8 = 0b0000_0001;
Expand Down Expand Up @@ -234,8 +234,8 @@ impl ActorSettings {
self.user_agent.clone()
}

pub fn vector_clock(&self) -> VectorClock {
self.vector_clock.clone()
pub fn vector_clock(&self) -> VectorClockSnapshot {
VectorClockSnapshot::from(&self.vector_clock)
}

pub fn verifying_key(&self) -> VerifyingKey {
Expand Down
20 changes: 8 additions & 12 deletions src/codec/meta/journal_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

use futures::io::AsyncWrite;

use crate::codec::meta::{Cid, VectorClock};
use crate::codec::meta::{Cid, VectorClockSnapshot};
use crate::codec::{ParserResult, Stream};

#[derive(Clone, Debug, PartialEq)]
pub struct JournalCheckpoint {
merkle_root_cid: Cid,
vector: VectorClock,
vector: VectorClockSnapshot,
}

impl JournalCheckpoint {
Expand All @@ -25,16 +25,9 @@ impl JournalCheckpoint {
Ok(written_bytes)
}

pub(crate) fn initialize() -> Self {
JournalCheckpoint {
merkle_root_cid: Cid::IDENTITY,
vector: VectorClock::initialize(),
}
}

pub fn parse(input: Stream) -> ParserResult<Self> {
let (input, merkle_root_cid) = Cid::parse(input)?;
let (input, vector) = VectorClock::parse(input)?;
let (input, vector) = VectorClockSnapshot::parse(input)?;

let journal_checkpoint = JournalCheckpoint {
merkle_root_cid,
Expand All @@ -45,7 +38,7 @@ impl JournalCheckpoint {
}

pub const fn size() -> usize {
Cid::size() + VectorClock::size()
Cid::size() + VectorClockSnapshot::size()
}
}

Expand All @@ -61,7 +54,10 @@ mod tests {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test(async))]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_user_agent_roundtrip() {
let checkpoint = JournalCheckpoint::initialize();
let checkpoint = JournalCheckpoint {
merkle_root_cid: Cid::from([0; 32]),
vector: VectorClockSnapshot::from(0),
};

let mut buffer = Vec::with_capacity(JournalCheckpoint::size());
checkpoint
Expand Down
2 changes: 1 addition & 1 deletion src/codec/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pub use journal_checkpoint::JournalCheckpoint;
pub use meta_key::MetaKey;
pub use permanent_id::PermanentId;
pub use user_agent::UserAgent;
pub use vector_clock::VectorClock;
pub use vector_clock::{VectorClock, VectorClockSnapshot};
87 changes: 0 additions & 87 deletions src/codec/meta/vector_clock.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/filesystem/drive/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ impl InnerDrive {
self.root_pid
}

pub(crate) fn vector_clock(&self) -> VectorClock {
self.vector_clock.clone()
pub fn vector_clock(&self) -> VectorClockSnapshot {
VectorClockSnapshot::from(&self.vector_clock)
}
}

Expand Down Expand Up @@ -563,7 +563,7 @@ pub(crate) mod test {
let (remaining, parsed) = InnerDrive::parse(
Partial::new(encoded.as_slice()),
access.to_owned(),
vector_clock,
vector_clock.into(),
)
.unwrap();
assert!(remaining.is_empty());
Expand Down

0 comments on commit 7ec7fc6

Please sign in to comment.