Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions apps/origin-src/src/oplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
//! some of a batch's records were published, or none; an acceptance was
//! written but the target's head didn't move to it (the next landing on the
//! target publishes it, and logs the acceptance again); a waiting landing
//! wasn't kept; a working copy didn't move. Its writer's lock file is then
//! left behind, unlocked: readers sync the segments holding its entries,
//! which may not be durable, remove the file, and take the entries' effects
//! as what they find published. So a crashed writer holds nothing back.
//! wasn't kept; a working copy didn't move (see
//! [`workspace`](crate::workspace) for how a move cut short is finished).
//! Its writer's lock file is then left behind, unlocked: readers sync the
//! segments holding its entries, which may not be durable, remove the file,
//! and take the entries' effects as what they find published. So a crashed
//! writer holds nothing back.
//!
//! **Damage.** A crash in the middle of an append leaves part of a frame at
//! the end of the last segment. It never was an entry: readers skip it, and
Expand Down Expand Up @@ -245,6 +247,17 @@ pub enum Why {
Undo(u64),
}

impl Why {
/// Parses what [`Why`]'s `Display` writes.
pub(crate) fn parse(text: &str) -> Option<Self> {
Some(match text {
"draft" => Self::Draft,
"command" => Self::Command,
_ => Self::Undo(text.strip_prefix("undo ")?.parse().ok()?),
})
}
}

impl fmt::Display for Why {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -1026,6 +1039,9 @@ mod tests {
let payload = &frame[4..frame.len() - Frames::FRAMING + 4];
assert_eq!(Entry::decode(payload), Ok(entry));
}
for why in [Why::Draft, Why::Command, Why::Undo(12)] {
assert_eq!(Why::parse(&why.to_string()), Some(why));
}
}

#[test]
Expand Down
Loading