-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dal): new edge in identical vector clock corner cases
- Loading branch information
1 parent
4f1c203
commit 5059dfd
Showing
5 changed files
with
195 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{env, fs::File, io::prelude::*}; | ||
|
||
use si_layer_cache::db::serialize; | ||
|
||
use dal::WorkspaceSnapshotGraph; | ||
|
||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + 'static>>; | ||
|
||
const USAGE: &str = "usage: cargo run --example rebase <TO_REBASE_FILE_PATH> <ONTO_FILE_PATH>"; | ||
|
||
fn load_snapshot_graph(path: &str) -> Result<WorkspaceSnapshotGraph> { | ||
let mut file = File::open(path)?; | ||
let mut bytes = vec![]; | ||
file.read_to_end(&mut bytes)?; | ||
|
||
Ok(serialize::from_bytes(&bytes)?) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args: Vec<String> = env::args().take(3).map(Into::into).collect(); | ||
let to_rebase_path = args.get(1).expect(USAGE); | ||
let onto_path = args.get(2).expect(USAGE); | ||
|
||
let mut to_rebase_graph = load_snapshot_graph(&to_rebase_path)?; | ||
let onto_graph = load_snapshot_graph(&onto_path)?; | ||
|
||
let to_rebase_vector_clock_id = to_rebase_graph | ||
.max_recently_seen_clock_id(None) | ||
.expect("Unable to find a vector clock id in to_rebase"); | ||
let onto_vector_clock_id = onto_graph | ||
.max_recently_seen_clock_id(None) | ||
.expect("Unable to find a vector clock id in onto"); | ||
|
||
let conflicts_and_updates = to_rebase_graph.detect_conflicts_and_updates( | ||
to_rebase_vector_clock_id, | ||
&onto_graph, | ||
onto_vector_clock_id, | ||
)?; | ||
|
||
dbg!(&conflicts_and_updates); | ||
|
||
to_rebase_graph.perform_updates( | ||
to_rebase_vector_clock_id, | ||
&onto_graph, | ||
&conflicts_and_updates.updates, | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use petgraph::prelude::{EdgeIndex, NodeIndex}; | ||
|
||
use crate::{EdgeWeightKindDiscriminants, WorkspaceSnapshotGraph}; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct EdgeInfo { | ||
pub source_node_index: NodeIndex, | ||
pub target_node_index: NodeIndex, | ||
pub edge_kind: EdgeWeightKindDiscriminants, | ||
pub edge_index: EdgeIndex, | ||
} | ||
|
||
impl EdgeInfo { | ||
pub fn simple_debug_string(&self, graph: &WorkspaceSnapshotGraph) -> String { | ||
let source = graph.graph().node_weight(self.source_node_index); | ||
let target = graph.graph().node_weight(self.target_node_index); | ||
let edge_weight = graph.graph().edge_weight(self.edge_index); | ||
|
||
format!( | ||
"{:?} -- {:?} --> {:?}", | ||
source.map(|s| s.id()), | ||
edge_weight.map(|e| e.kind()), | ||
target.map(|t| t.id()) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters