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

Method load_spatial_checkpoints

nodedb/src/data/executor/spatial_checkpoint.rs:90–172  ·  view source on GitHub ↗

Load R-tree checkpoints from disk on startup. When `spatial_checkpoint_kek` is set, plaintext checkpoint files are rejected and encrypted files are decrypted before loading.

(&mut self)

Source from the content-addressed store, hash-verified

88 /// When `spatial_checkpoint_kek` is set, plaintext checkpoint files are
89 /// rejected and encrypted files are decrypted before loading.
90 pub fn load_spatial_checkpoints(&mut self) {
91 let ckpt_dir = self.data_dir.join("spatial-ckpt");
92 if !ckpt_dir.exists() {
93 return;
94 }
95
96 let entries = match std::fs::read_dir(&ckpt_dir) {
97 Ok(e) => e,
98 Err(_) => return,
99 };
100
101 let mut loaded = 0;
102 for entry in entries.flatten() {
103 let path = entry.path();
104 if path.extension().and_then(|e| e.to_str()) != Some("ckpt") {
105 continue;
106 }
107
108 let sanitized = path
109 .file_stem()
110 .and_then(|s| s.to_str())
111 .unwrap_or("")
112 .to_string();
113 if sanitized.is_empty() {
114 continue;
115 }
116
117 // Restore the original key from sanitized form.
118 let key = unsanitize_key(&sanitized);
119
120 let Ok(bytes) = nodedb_wal::segment::read_checkpoint_dontneed(&path) else {
121 continue;
122 };
123
124 let kek = self.spatial_checkpoint_kek.as_ref();
125 let rtree = match crate::engine::spatial::RTree::from_checkpoint(&bytes, kek) {
126 Ok(r) => r,
127 Err(e) => {
128 tracing::warn!(
129 core = self.core_id,
130 %key,
131 error = %e,
132 "spatial checkpoint rejected"
133 );
134 continue;
135 }
136 };
137
138 // Parse key string "{tid}:{coll}:{field}" back to tuple.
139 let Some(map_key) = parse_spatial_key(&key) else {
140 tracing::warn!(
141 core = self.core_id,
142 %key,
143 "failed to parse spatial checkpoint key, skipping"
144 );
145 continue;
146 };
147 tracing::info!(

Callers 1

spawn_coreFunction · 0.80

Calls 11

unsanitize_keyFunction · 0.85
read_checkpoint_dontneedFunction · 0.85
parse_spatial_keyFunction · 0.85
joinMethod · 0.80
to_stringMethod · 0.80
existsMethod · 0.45
pathMethod · 0.45
is_emptyMethod · 0.45
as_refMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected