Insert a secondary index entry (tenant-scoped). Opens its own write transaction. Callers already inside a write transaction — the PointPut / BatchInsert apply path — MUST use [`SparseEngine::index_put_in_txn`] instead; redb allows only one active writer so a nested `begin_write` here deadlocks.
(
&self,
tenant_id: u64,
collection: &str,
field: &str,
value: &str,
document_id: &str,
)
| 293 | /// [`SparseEngine::index_put_in_txn`] instead; redb allows only one |
| 294 | /// active writer so a nested `begin_write` here deadlocks. |
| 295 | pub fn index_put( |
| 296 | &self, |
| 297 | tenant_id: u64, |
| 298 | collection: &str, |
| 299 | field: &str, |
| 300 | value: &str, |
| 301 | document_id: &str, |
| 302 | ) -> crate::Result<()> { |
| 303 | super::btree::with_tenant_key4(tenant_id, collection, field, value, document_id, |key| { |
| 304 | let write_txn = self |
| 305 | .db |
| 306 | .begin_write() |
| 307 | .map_err(|e| redb_err("write txn", e))?; |
| 308 | { |
| 309 | let mut table = write_txn |
| 310 | .open_table(INDEXES) |
| 311 | .map_err(|e| redb_err("open table", e))?; |
| 312 | table |
| 313 | .insert(key, [].as_slice()) |
| 314 | .map_err(|e| redb_err("index insert", e))?; |
| 315 | } |
| 316 | write_txn.commit().map_err(|e| redb_err("commit", e))?; |
| 317 | Ok(()) |
| 318 | }) |
| 319 | } |
| 320 | |
| 321 | /// Insert a secondary index entry into an already-open write txn. |
| 322 | /// |