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

Method index_put

nodedb/src/engine/sparse/btree_index.rs:295–319  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers 4

range_scan_with_indexFunction · 0.80
put_rawMethod · 0.80

Calls 6

with_tenant_key4Function · 0.85
begin_writeMethod · 0.80
redb_errFunction · 0.70
insertMethod · 0.45
as_sliceMethod · 0.45
commitMethod · 0.45

Tested by 2

range_scan_with_indexFunction · 0.64