Insert a geometry into the per-field R-tree and the sparse document store on behalf of a Lite client. Both writes use the hex-encoded surrogate as the storage key so cross-engine surrogate prefilters resolve without translation. Fails fast (returns a Response::Error) if either: - the geometry document cannot be msgpack-serialised, or - the sparse document write fails. If an entry with the same
(
&mut self,
task: &ExecutionTask,
tid: u64,
collection: &str,
field: &str,
surrogate: Surrogate,
geometry: &Geometry,
)
| 52 | /// If an entry with the same surrogate already exists, the R-tree entry is |
| 53 | /// replaced (upsert semantics). |
| 54 | pub(in crate::data::executor) fn execute_spatial_insert( |
| 55 | &mut self, |
| 56 | task: &ExecutionTask, |
| 57 | tid: u64, |
| 58 | collection: &str, |
| 59 | field: &str, |
| 60 | surrogate: Surrogate, |
| 61 | geometry: &Geometry, |
| 62 | ) -> Response { |
| 63 | let doc_id = surrogate_to_doc_id(surrogate); |
| 64 | |
| 65 | debug!( |
| 66 | core = self.core_id, |
| 67 | %collection, |
| 68 | %field, |
| 69 | doc_id = %doc_id, |
| 70 | surrogate = surrogate.as_u32(), |
| 71 | "spatial sync: insert geometry" |
| 72 | ); |
| 73 | |
| 74 | // ── 1. Serialise + write minimal geometry document to sparse store ── |
| 75 | let geom_value = geometry_to_value(geometry); |
| 76 | let mut doc_map = std::collections::HashMap::new(); |
| 77 | doc_map.insert(field.to_string(), geom_value); |
| 78 | doc_map.insert( |
| 79 | "id".to_string(), |
| 80 | nodedb_types::Value::String(doc_id.clone()), |
| 81 | ); |
| 82 | let doc_value = nodedb_types::Value::Object(doc_map); |
| 83 | // Use standard msgpack map format so scan_collection / decode_document_value |
| 84 | // can read it back. zerompk::to_msgpack_vec encodes Value in a tagged array |
| 85 | // format the document scan path does not understand. |
| 86 | let msgpack = match nodedb_types::value_to_msgpack(&doc_value) { |
| 87 | Ok(b) => b, |
| 88 | Err(e) => { |
| 89 | error!( |
| 90 | core = self.core_id, |
| 91 | %collection, |
| 92 | %field, |
| 93 | doc_id = %doc_id, |
| 94 | error = %e, |
| 95 | "spatial sync: geometry document msgpack serialisation failed" |
| 96 | ); |
| 97 | return self.response_error( |
| 98 | task, |
| 99 | crate::Error::Internal { |
| 100 | detail: format!("spatial sync: serialise geometry document: {e}"), |
| 101 | }, |
| 102 | ); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | if let Err(e) = self.sparse.put(tid, collection, &doc_id, &msgpack) { |
| 107 | error!( |
| 108 | core = self.core_id, |
| 109 | %collection, |
| 110 | doc_id = %doc_id, |
| 111 | error = %e, |
no test coverage detected