![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
C-linkage interface to the in-process provenance circuit cache. More...
#include "provsql_utils.h"

Go to the source code of this file.
Functions | |
| bool | circuit_cache_create_gate (pg_uuid_t token, gate_type type, unsigned nb_children, pg_uuid_t *children) |
| Insert a new gate into the circuit cache. | |
| unsigned | circuit_cache_get_children (pg_uuid_t token, pg_uuid_t **children) |
| Retrieve the children of a cached gate. | |
| gate_type | circuit_cache_get_type (pg_uuid_t token) |
| Retrieve the type of a cached gate. | |
C-linkage interface to the in-process provenance circuit cache.
The circuit cache is a bounded, LRU-evicting in-memory store that avoids repeated round-trips to the mmap-backed persistent circuit storage for recently accessed gates. It is implemented in C++ (see CircuitCache.h / CircuitCache.cpp) but exposed to the C parts of the extension through this header.
The cache is a pure read accelerator on top of a write-through design: create_gate (in provsql_mmap.c) populates the cache and unconditionally also forwards the IPC to the background worker, so the worker is always at least as up-to-date as any backend's cache. Evicted entries are therefore simply discarded (no flush hook is needed: the worker already has them). Lookups that miss the cache fall back to an IPC fetch from the worker.
Two cache-poisoning hazards motivated the call-site skip rules in provsql_mmap.c (search for "Skip caching" there): MMappedCircuit returns gate_input as a default for unknown tokens, and reports zero children for both real zero-child gates and unknown tokens, so caching such ambiguous results would short-circuit subsequent real create_gate calls in the same session. The cache itself is agnostic to that policy.
Definition in file circuit_cache.h.
| bool circuit_cache_create_gate | ( | pg_uuid_t | token, |
| gate_type | type, | ||
| unsigned | nb_children, | ||
| pg_uuid_t * | children ) |
Insert a new gate into the circuit cache.
Records the gate identified by token with the given type and nb_children children. If the cache is full the oldest entry is dropped from memory to make room (the worker already holds it under the write-through invariant, so no flush is performed). If an entry for token is already present, its type and children are overwritten when the incoming call carries strictly more information (a real gate_type replacing a previously stored gate_invalid, or a non-empty children list replacing an empty one); otherwise the entry is left untouched and just refreshed in LRU order.
| token | UUID identifying the new gate. |
| type | Gate type (e.g. gate_input, gate_plus). |
| nb_children | Number of child gates. |
| children | Array of nb_children child UUIDs. |
true if the gate was newly inserted, false if it was already present in the cache (regardless of whether its contents were upgraded). Definition at line 74 of file CircuitCache.cpp.

Retrieve the children of a cached gate.
Looks up token in the cache and, on a hit with at least one child, allocates an array of child UUIDs (via calloc) and writes its address to *children.
| token | UUID of the gate to look up. |
| children | Output parameter: set to a freshly calloc'd array of child UUIDs on a hit with children; set to NULL on a miss or on a hit for a zero-child entry (the two are deliberately indistinguishable to callers, see the file-level note). |
0 on a miss or zero-child hit. Callers should detect a miss via *children==NULL, not via the return value. Definition at line 79 of file CircuitCache.cpp.

Retrieve the type of a cached gate.
| token | UUID of the gate to look up. |
gate_type of the gate, or gate_invalid on a miss. Definition at line 102 of file CircuitCache.cpp.
