MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / log_operation

Method log_operation

graphlite/src/txn/log.rs:78–227  ·  view source on GitHub ↗

Add an undo operation to the log

(&mut self, operation: UndoOperation)

Source from the content-addressed store, hash-verified

76
77 /// Add an undo operation to the log
78 pub fn log_operation(&mut self, operation: UndoOperation) {
79 // Estimate memory usage
80 let op_size = match &operation {
81 UndoOperation::InsertNode {
82 graph_path,
83 node_id,
84 } => std::mem::size_of::<UndoOperation>() + graph_path.len() + node_id.len(),
85 UndoOperation::UpdateNode {
86 graph_path,
87 node_id,
88 old_properties,
89 old_labels,
90 } => {
91 let props_size = old_properties
92 .iter()
93 .map(|(k, v)| k.len() + estimate_value_size(v))
94 .sum::<usize>();
95 let labels_size = old_labels.iter().map(|l| l.len()).sum::<usize>();
96 std::mem::size_of::<UndoOperation>()
97 + graph_path.len()
98 + node_id.len()
99 + props_size
100 + labels_size
101 }
102 UndoOperation::DeleteNode {
103 graph_path,
104 node_id,
105 deleted_node,
106 } => {
107 std::mem::size_of::<UndoOperation>()
108 + graph_path.len()
109 + node_id.len()
110 + estimate_node_size(deleted_node)
111 }
112 UndoOperation::InsertEdge {
113 graph_path,
114 edge_id,
115 } => std::mem::size_of::<UndoOperation>() + graph_path.len() + edge_id.len(),
116 UndoOperation::UpdateEdge {
117 graph_path,
118 edge_id,
119 old_properties,
120 old_label,
121 } => {
122 let props_size = old_properties
123 .iter()
124 .map(|(k, v)| k.len() + estimate_value_size(v))
125 .sum::<usize>();
126 let label_size = old_label.len();
127 std::mem::size_of::<UndoOperation>()
128 + graph_path.len()
129 + edge_id.len()
130 + props_size
131 + label_size
132 }
133 UndoOperation::DeleteEdge {
134 graph_path,
135 edge_id,

Callers 5

test_log_operationsFunction · 0.45
test_rollback_orderFunction · 0.45
log_operation_to_walMethod · 0.45
log_operation_to_walMethod · 0.45

Calls 5

estimate_value_sizeFunction · 0.85
estimate_node_sizeFunction · 0.85
estimate_edge_sizeFunction · 0.85
lenMethod · 0.45
iterMethod · 0.45

Tested by 2

test_log_operationsFunction · 0.36
test_rollback_orderFunction · 0.36