MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / to_physical_plan

Function to_physical_plan

nodedb/src/control/wal_replication/decode.rs:58–383  ·  view source on GitHub ↗

Convert a ReplicatedWrite back into a PhysicalPlan for Data Plane execution.

(
    write: &ReplicatedWrite,
    assigner: Option<&SurrogateAssigner>,
)

Source from the content-addressed store, hash-verified

56
57/// Convert a ReplicatedWrite back into a PhysicalPlan for Data Plane execution.
58fn to_physical_plan(
59 write: &ReplicatedWrite,
60 assigner: Option<&SurrogateAssigner>,
61) -> crate::Result<PhysicalPlan> {
62 Ok(match write {
63 ReplicatedWrite::PointPut {
64 collection,
65 document_id,
66 value,
67 } => {
68 let pk_bytes = document_id.as_bytes().to_vec();
69 let surrogate = assign_or_zero(assigner, collection, &pk_bytes)?;
70 PhysicalPlan::Document(DocumentOp::PointPut {
71 collection: collection.clone(),
72 document_id: document_id.clone(),
73 value: value.clone(),
74 surrogate,
75 pk_bytes,
76 })
77 }
78 ReplicatedWrite::PointInsert {
79 collection,
80 document_id,
81 value,
82 if_absent,
83 } => {
84 let surrogate = assign_or_zero(assigner, collection, document_id.as_bytes())?;
85 PhysicalPlan::Document(DocumentOp::PointInsert {
86 collection: collection.clone(),
87 document_id: document_id.clone(),
88 value: value.clone(),
89 if_absent: *if_absent,
90 surrogate,
91 })
92 }
93 ReplicatedWrite::PointDelete {
94 collection,
95 document_id,
96 } => {
97 let pk_bytes = document_id.as_bytes().to_vec();
98 // Followers re-derive the surrogate via the local catalog
99 // rev table; a missing binding means the row is unknown to
100 // this replica and the delete is a no-op once dispatched.
101 let surrogate = match assigner {
102 Some(a) => a
103 .lookup(collection, &pk_bytes)?
104 .unwrap_or(nodedb_types::Surrogate::ZERO),
105 None => nodedb_types::Surrogate::ZERO,
106 };
107 PhysicalPlan::Document(DocumentOp::PointDelete {
108 collection: collection.clone(),
109 document_id: document_id.clone(),
110 surrogate,
111 pk_bytes,
112 returning: None,
113 })
114 }
115 ReplicatedWrite::PointUpdate {

Callers 1

from_replicated_entryFunction · 0.85

Calls 10

assign_or_zeroFunction · 0.85
DocumentClass · 0.85
assign_anonymousMethod · 0.80
to_vecMethod · 0.45
as_bytesMethod · 0.45
cloneMethod · 0.45
lookupMethod · 0.45
assignMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected