![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Persistent mmap-backed representation of the provenance circuit. More...
#include "MMappedCircuit.h"

Public Member Functions | |
| MMappedCircuit (Oid db_oid, bool read_only=false) | |
| Open all four mmap backing files for the given database. | |
| ~MMappedCircuit () | |
| Sync all backing files before destruction. | |
| void | createGate (pg_uuid_t token, gate_type type, const std::vector< pg_uuid_t > &children) |
| Persist a new gate to the mmap store. | |
| void | setInfos (pg_uuid_t token, unsigned info1, unsigned info2) |
Update the info1 / info2 annotations of a gate. | |
| void | setExtra (pg_uuid_t token, const std::string &s) |
| Attach a variable-length string annotation to a gate. | |
| bool | setProb (pg_uuid_t token, double prob) |
| Set the probability associated with a gate. | |
| void | sync () |
Flush all backing files to disk with msync(). | |
| gate_type | getGateType (pg_uuid_t token) const |
Return the type of the gate identified by token. | |
| std::vector< pg_uuid_t > | getChildren (pg_uuid_t token) const |
Return the child UUIDs of the gate identified by token. | |
| double | getProb (pg_uuid_t token) const |
Return the probability stored for the gate identified by token. | |
| std::pair< unsigned, unsigned > | getInfos (pg_uuid_t token) const |
Return the info1 / info2 pair for the gate token. | |
| std::string | getExtra (pg_uuid_t token) const |
Return the variable-length string annotation for gate token. | |
| unsigned long | getNbGates () const |
| Return the total number of gates stored in the circuit. | |
| void | setTableInfo (const ProvenanceTableInfo &info) |
Insert or update the kind / block_key half of a per-table metadata record, preserving any existing ancestor fields. | |
| void | setTableAncestry (Oid relid, uint16_t ancestor_n, const Oid *ancestors) |
Insert or update the ancestor set of a per-table metadata record, preserving any existing kind / block_key fields. | |
| void | removeTableInfo (Oid relid) |
| Remove a per-table metadata entry (both halves). | |
| void | removeTableAncestry (Oid relid) |
Clear just the ancestor set of a per-table metadata record, preserving kind / block_key. | |
| bool | getTableInfo (Oid relid, ProvenanceTableInfo &out) const |
| Look up the full per-table metadata record (both halves). | |
| GenericCircuit | createGenericCircuit (pg_uuid_t token) const |
Build an in-memory GenericCircuit rooted at token. | |
| GenericCircuit | createGenericCircuit (const std::vector< pg_uuid_t > &roots) const |
Build an in-memory GenericCircuit reachable from any of roots. | |
Static Public Attributes | |
| static constexpr uint64_t | MAGIC_GATES |
| 8-byte magic constants identifying each mmap file type. | |
| static constexpr uint64_t | MAGIC_WIRES |
| static constexpr uint64_t | MAGIC_MAPPING |
| static constexpr uint64_t | MAGIC_EXTRA |
| static constexpr uint64_t | MAGIC_TABLE_INFO |
Private Member Functions | |
| MMappedCircuit (const std::string &mp, const std::string &gp, const std::string &wp, const std::string &ep, const std::string &tp, bool read_only) | |
| Delegating constructor that accepts pre-built paths. | |
Static Private Member Functions | |
| static std::string | makePath (Oid db_oid, const char *filename) |
Build the full path for a mmap file under $PGDATA/base/<db_oid>/. | |
Private Attributes | |
| MMappedUUIDHashTable | mapping |
| UUID → gate-index hash table. | |
| MMappedVector< GateInformation > | gates |
| Gate metadata array. | |
| MMappedVector< pg_uuid_t > | wires |
| Flattened child UUID array. | |
| MMappedVector< char > | extra |
| Variable-length string data. | |
| MMappedVector< ProvenanceTableInfo > | tableInfo |
| Per-relation TID/BID metadata (safe-query optimisation). | |
Static Private Attributes | |
| static constexpr const char * | GATES_FILENAME ="provsql_gates.mmap" |
Backing file for gates. | |
| static constexpr const char * | WIRES_FILENAME ="provsql_wires.mmap" |
Backing file for wires. | |
| static constexpr const char * | MAPPING_FILENAME ="provsql_mapping.mmap" |
Backing file for mapping. | |
| static constexpr const char * | EXTRA_FILENAME ="provsql_extra.mmap" |
Backing file for extra. | |
| static constexpr const char * | TABLE_INFO_FILENAME ="provsql_table_info.mmap" |
Backing file for tableInfo. | |
Persistent mmap-backed representation of the provenance circuit.
MMappedCircuit is the single writer for circuit data; only the background worker should call its mutating methods. Reading methods may be called from any process that has mapped the files read-only.
Definition at line 90 of file MMappedCircuit.h.
|
inlineprivate |
Delegating constructor that accepts pre-built paths.
Definition at line 108 of file MMappedCircuit.h.

|
explicit |
Open all four mmap backing files for the given database.
| db_oid | OID of the target database; files go under $PGDATA/base/<db_oid>/. |
| read_only | If true, all files are mapped read-only. |
Definition at line 46 of file MMappedCircuit.cpp.

|
inline |
Sync all backing files before destruction.
Definition at line 144 of file MMappedCircuit.h.

| void MMappedCircuit::createGate | ( | pg_uuid_t | token, |
| gate_type | type, | ||
| const std::vector< pg_uuid_t > & | children ) |
Persist a new gate to the mmap store.
Allocates a GateInformation record, appends the children to the wires vector, and records the UUID→index mapping. Existing gates with the same token are silently skipped.
| token | UUID identifying the new gate. |
| type | Gate type. |
| children | Ordered list of child gate UUIDs. |
Definition at line 67 of file MMappedCircuit.cpp.

| GenericCircuit MMappedCircuit::createGenericCircuit | ( | const std::vector< pg_uuid_t > & | roots | ) | const |
Build an in-memory GenericCircuit reachable from any of roots.
Multi-root variant of createGenericCircuit. Seeds the BFS with every UUID in roots so a shared subgraph reachable from more than one root is represented by a single gate_t (the GenericCircuit::setGate / getGate pair is idempotent on the UUID key). Used by getJointCircuit to load an RV's sub-DAG together with a conditioning gate that sits above it in the persisted DAG.
| roots | UUIDs whose reachable closure to load. Order is irrelevant; identical UUIDs collapse via the std::set deduplication of the work list. |
GenericCircuit containing every gate reachable from any root. Definition at line 655 of file MMappedCircuit.cpp.

| GenericCircuit MMappedCircuit::createGenericCircuit | ( | pg_uuid_t | token | ) | const |
Build an in-memory GenericCircuit rooted at token.
Performs a depth-first traversal of the mmap-backed circuit starting from token and copies all reachable gates and wires into a newly constructed GenericCircuit.
| token | UUID of the root gate. |
GenericCircuit containing the sub-circuit. Definition at line 650 of file MMappedCircuit.cpp.


Return the child UUIDs of the gate identified by token.
| token | UUID of the gate. |
Definition at line 118 of file MMappedCircuit.cpp.

| std::string MMappedCircuit::getExtra | ( | pg_uuid_t | token | ) | const |
Return the variable-length string annotation for gate token.
| token | UUID of the gate. |
Definition at line 183 of file MMappedCircuit.cpp.

Return the type of the gate identified by token.
| token | UUID of the gate. |
gate_input if not found (lazy default). Definition at line 109 of file MMappedCircuit.cpp.

| std::pair< unsigned, unsigned > MMappedCircuit::getInfos | ( | pg_uuid_t | token | ) | const |
Return the info1 / info2 pair for the gate token.
| token | UUID of the gate. |
{info1, info2}, or {0,0} if not found. Definition at line 172 of file MMappedCircuit.cpp.

|
inline |
Return the total number of gates stored in the circuit.
Definition at line 229 of file MMappedCircuit.h.

| double MMappedCircuit::getProb | ( | pg_uuid_t | token | ) | const |
Return the probability stored for the gate identified by token.
| token | UUID of the gate. |
Definition at line 142 of file MMappedCircuit.cpp.

| bool MMappedCircuit::getTableInfo | ( | Oid | relid, |
| ProvenanceTableInfo & | out ) const |
Look up the full per-table metadata record (both halves).
| relid | pg_class OID of the relation to look up. |
| out | On success, filled with the stored record. |
true if a record was found, false otherwise. Definition at line 626 of file MMappedCircuit.cpp.

|
staticprivate |
Build the full path for a mmap file under $PGDATA/base/<db_oid>/.
Definition at line 41 of file MMappedCircuit.cpp.

| void MMappedCircuit::removeTableAncestry | ( | Oid | relid | ) |
Clear just the ancestor set of a per-table metadata record, preserving kind / block_key.
No-op when relid has no existing record. Useful when a derived relation's source list changes (e.g. a CTAS is re-run) without disturbing its kind classification.
Definition at line 613 of file MMappedCircuit.cpp.

| void MMappedCircuit::removeTableInfo | ( | Oid | relid | ) |
Remove a per-table metadata entry (both halves).
No-op when relid is not present. Removal is done by tombstoning the matching entry with relid == InvalidOid; the next setTableInfo over the same relid reuses the slot.
| relid | pg_class OID of the relation whose entry to remove. |
Definition at line 600 of file MMappedCircuit.cpp.

| void MMappedCircuit::setExtra | ( | pg_uuid_t | token, |
| const std::string & | s ) |
Attach a variable-length string annotation to a gate.
| token | UUID of the gate. |
| s | String to store. |
Definition at line 161 of file MMappedCircuit.cpp.

| void MMappedCircuit::setInfos | ( | pg_uuid_t | token, |
| unsigned | info1, | ||
| unsigned | info2 ) |
Update the info1 / info2 annotations of a gate.
| token | UUID of the gate to update. |
| info1 | New value for info1. |
| info2 | New value for info2. |
Definition at line 152 of file MMappedCircuit.cpp.

| bool MMappedCircuit::setProb | ( | pg_uuid_t | token, |
| double | prob ) |
Set the probability associated with a gate.
| token | UUID of the gate. |
| prob | Probability value in [0, 1]. |
true if the gate was updated; false if the token is a non-input gate. If the token is not yet in the circuit, an input gate is created lazily. Definition at line 130 of file MMappedCircuit.cpp.

| void MMappedCircuit::setTableAncestry | ( | Oid | relid, |
| uint16_t | ancestor_n, | ||
| const Oid * | ancestors ) |
Insert or update the ancestor set of a per-table metadata record, preserving any existing kind / block_key fields.
No-op when relid has no existing record: the safe-query rewriter only consults ancestry for tracked relations, so a caller setting ancestry on an unknown relation has missed a setTableInfo step. Callers in this codebase always set kind first.
| relid | pg_class OID of the relation to update. |
| ancestor_n | Number of valid entries in ancestors (must be <= PROVSQL_TABLE_INFO_MAX_ANCESTORS). |
| ancestors | Sorted, deduplicated base-relation OIDs. |
Definition at line 576 of file MMappedCircuit.cpp.

| void MMappedCircuit::setTableInfo | ( | const ProvenanceTableInfo & | info | ) |
Insert or update the kind / block_key half of a per-table metadata record, preserving any existing ancestor fields.
If an entry for info.relid already exists, its kind and block_key fields are overwritten in place and its ancestors fields are preserved. Otherwise a fresh record is appended with ancestor_n == 0.
| info | The record to store; only kind / block_key are consumed (ancestor fields are sourced from the existing entry or zeroed for fresh ones). |
Definition at line 550 of file MMappedCircuit.cpp.

| void MMappedCircuit::sync | ( | ) |
Flush all backing files to disk with msync().
Definition at line 522 of file MMappedCircuit.cpp.

|
private |
Variable-length string data.
Definition at line 95 of file MMappedCircuit.h.
|
staticconstexprprivate |
Backing file for extra.
Definition at line 101 of file MMappedCircuit.h.
|
private |
Gate metadata array.
Definition at line 93 of file MMappedCircuit.h.
|
staticconstexprprivate |
Backing file for gates.
Definition at line 98 of file MMappedCircuit.h.
|
staticconstexpr |
Definition at line 129 of file MMappedCircuit.h.
|
staticconstexpr |
8-byte magic constants identifying each mmap file type.
Definition at line 120 of file MMappedCircuit.h.
|
staticconstexpr |
Definition at line 126 of file MMappedCircuit.h.
|
staticconstexpr |
Definition at line 132 of file MMappedCircuit.h.
|
staticconstexpr |
Definition at line 123 of file MMappedCircuit.h.
|
private |
UUID → gate-index hash table.
Definition at line 92 of file MMappedCircuit.h.
|
staticconstexprprivate |
Backing file for mapping.
Definition at line 100 of file MMappedCircuit.h.
|
staticconstexprprivate |
Backing file for tableInfo.
Definition at line 102 of file MMappedCircuit.h.
|
private |
Per-relation TID/BID metadata (safe-query optimisation).
Definition at line 96 of file MMappedCircuit.h.
|
private |
Flattened child UUID array.
Definition at line 94 of file MMappedCircuit.h.
|
staticconstexprprivate |
Backing file for wires.
Definition at line 99 of file MMappedCircuit.h.