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

Method exists_in_txn

nodedb/src/engine/sparse/btree.rs:167–184  ·  view source on GitHub ↗

Check whether a document exists within an externally-owned write transaction — the probe used by INSERT-with-unique-PK semantics. Uses the caller's write txn so the check is linearizable with the subsequent `put_in_txn`: no other writer can slip a row in between the "does it exist" read and the insert commit. Returns `Ok(true)` if a document with this (tenant, collection, document_id) is already

(
        &self,
        txn: &WriteTransaction,
        tenant_id: u64,
        collection: &str,
        document_id: &str,
    )

Source from the content-addressed store, hash-verified

165 /// if a document with this (tenant, collection, document_id) is
166 /// already present.
167 pub fn exists_in_txn(
168 &self,
169 txn: &WriteTransaction,
170 tenant_id: u64,
171 collection: &str,
172 document_id: &str,
173 ) -> crate::Result<bool> {
174 with_tenant_key(tenant_id, collection, document_id, |key| {
175 let table = txn
176 .open_table(DOCUMENTS)
177 .map_err(|e| redb_err("open table", e))?;
178 match table.get(key) {
179 Ok(Some(_)) => Ok(true),
180 Ok(None) => Ok(false),
181 Err(e) => Err(redb_err("exists_in_txn", e)),
182 }
183 })
184 }
185
186 /// Batch insert or update multiple documents in a single redb transaction.
187 pub fn batch_put(

Callers 1

execute_point_insertMethod · 0.80

Calls 3

with_tenant_keyFunction · 0.85
redb_errFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected