Skip to content

Commit f63d255

Browse files
fix(core): tolerate orphan edges in snapshots
1 parent 365d073 commit f63d255

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

crates/rustyred-core/src/graph_store.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,11 @@ impl InMemoryGraphStore {
598598
store.apply_recovered_node(node)?;
599599
}
600600
for edge in snapshot.edges {
601-
store.apply_recovered_edge(edge)?;
601+
match store.apply_recovered_edge(edge) {
602+
Ok(()) => {}
603+
Err(error) if is_recoverable_orphan_edge(&error) => {}
604+
Err(error) => return Err(error),
605+
}
602606
}
603607
store.version = store.version.max(snapshot.version);
604608
Ok(store)
@@ -3650,8 +3654,8 @@ mod tests {
36503654
use serde_json::json;
36513655

36523656
use super::{
3653-
stable_hash, Direction, EdgeRecord, GraphMutation, GraphMutationBatch, GraphStore,
3654-
InMemoryGraphStore, NeighborQuery, NodeQuery, NodeRecord, RedCoreAofFrame,
3657+
stable_hash, Direction, EdgeRecord, GraphMutation, GraphMutationBatch, GraphSnapshot,
3658+
GraphStore, InMemoryGraphStore, NeighborQuery, NodeQuery, NodeRecord, RedCoreAofFrame,
36553659
RedCoreDurability, RedCoreGraphStore, RedCoreMutation, RedCoreOptions, REDCORE_AOF_FILE,
36563660
REDCORE_AOF_MAGIC, REDCORE_MANIFEST_VERSION,
36573661
};
@@ -4237,6 +4241,31 @@ mod tests {
42374241
std::fs::remove_dir_all(data_dir).ok();
42384242
}
42394243

4244+
#[test]
4245+
fn graph_snapshot_recovery_skips_orphan_edges_instead_of_poisoning_store() {
4246+
let snapshot = GraphSnapshot {
4247+
version: 2,
4248+
nodes: vec![NodeRecord::new(
4249+
"actor:sandbox",
4250+
["Actor"],
4251+
json!({ "actor_id": "sandbox" }),
4252+
)],
4253+
edges: vec![EdgeRecord::new(
4254+
"edge:orphan-created-by",
4255+
"mem:missing-memory-atom",
4256+
"CREATED_BY",
4257+
"actor:sandbox",
4258+
json!({ "actor_kind": "sandbox" }),
4259+
)],
4260+
};
4261+
4262+
let store = InMemoryGraphStore::from_snapshot(snapshot).unwrap();
4263+
4264+
assert!(store.get_node("actor:sandbox").is_some());
4265+
assert!(store.get_edge("edge:orphan-created-by").is_none());
4266+
assert_eq!(store.verify().ok, true);
4267+
}
4268+
42404269
#[test]
42414270
fn redcore_failed_aof_append_does_not_publish_staged_mutation() {
42424271
let data_dir = unique_test_dir("redcore-aof-publish-gate");

0 commit comments

Comments
 (0)