37#ifndef MMAPPED_CIRCUIT_H
38#define MMAPPED_CIRCUIT_H
109 const std::vector<pg_uuid_t> &children);
119 const std::string &wp,
const std::string &ep,
159static std::string
storePath(Oid db_oid, Oid db_tablespace,
160 const char *filename);
164static bool storeExists(Oid db_oid, Oid db_tablespace);
181 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'G') << 24 |
182 uint64_t(
'a') << 32 | uint64_t(
't') << 40 | uint64_t(
'e') << 48 | uint64_t(
's') << 56;
184 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'W') << 24 |
185 uint64_t(
'i') << 32 | uint64_t(
'r') << 40 | uint64_t(
'e') << 48 | uint64_t(
's') << 56;
187 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'M') << 24 |
188 uint64_t(
'a') << 32 | uint64_t(
'p') << 40 | uint64_t(
'n') << 48 | uint64_t(
'g') << 56;
190 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'E') << 24 |
191 uint64_t(
'x') << 32 | uint64_t(
't') << 40 | uint64_t(
'r') << 48 | uint64_t(
'a') << 56;
201MMappedCircuit(Oid db_oid, Oid db_tablespace,
bool read_only =
false);
238 std::pair<unsigned, unsigned> *existing =
nullptr);
255 std::string *existing =
nullptr);
340unsigned long mark(
const std::vector<pg_uuid_t> &roots,
341 std::vector<bool> &live)
const;
368Counts
sweepInto(
const std::vector<bool> &live,
369 const std::string &mp,
const std::string &gp,
370 const std::string &wp,
const std::string &ep)
const;
427 return gates.nbElements();
445 std::size_t budget = 0)
const;
467 const std::vector<pg_uuid_t> &roots, std::size_t budget = 0)
const;
480 unsigned long wide_cap)
const;
490double probAt(
unsigned long idx)
const;
492std::string
extraAt(
unsigned long idx)
const;
502 const char *
what() const noexcept
override {
503 return "the circuit is larger than provsql.max_memory allows";
519 const char *
what() const noexcept
override {
520 return "the statement was cancelled";
528#ifdef PROVSQL_INPROCESS_STORE
541 const std::vector<pg_uuid_t> &roots, std::size_t budget);
544 const std::vector<FormulaRequest> &requests,
unsigned long cap,
545 unsigned long wide_cap);
gate_t
Strongly-typed gate identifier.
Semiring-agnostic in-memory provenance circuit.
constexpr unsigned long PROVSQL_CIRCUIT_OVER_BUDGET
The size the worker answers a 'g' / 'j' request with, in place of a circuit, when building it went pa...
constexpr unsigned long PROVSQL_CIRCUIT_CANCELLED
The size the worker answers a 'g' / 'j' request with, in place of a circuit, when the requesting stat...
Open-addressing hash table mapping UUIDs to integers, backed by an mmap file.
Template implementation of MMappedVector<T>.
Thrown by MMappedCircuit::createGenericCircuit when the circuit it builds takes the process past the ...
const char * what() const noexcept override
Thrown by MMappedCircuit::createGenericCircuit when the statement that asked for the circuit is cance...
const char * what() const noexcept override
static constexpr uint16_t GATES_VERSION
Format version of the gates file this build writes.
unsigned long mark(const std::vector< pg_uuid_t > &roots, std::vector< bool > &live) const
Mark every gate reachable from roots.
FormulaRegions formulaRegions(const std::vector< FormulaRequest > &requests, unsigned long cap, unsigned long wide_cap) const
The regions of requests, for sr_formula_rows (see FormulaRegions).
SetAnnotationResult setInfos(pg_uuid_t token, unsigned info1, unsigned info2, std::pair< unsigned, unsigned > *existing=nullptr)
Write the info1 / info2 annotations of a gate, once.
MMappedUUIDHashTable mapping
UUID → gate-index hash table.
void createGate(pg_uuid_t token, gate_type type, const std::vector< pg_uuid_t > &children)
Persist a new gate to the mmap store.
Counts counts() const
This store's current size.
std::string getExtra(pg_uuid_t token) const
Return the variable-length string annotation for gate token.
bool legacyProbabilities() const
Whether this store's gates file predates the NaN unset-probability convention (see GATES_VERSION).
SetProbResult setProb(pg_uuid_t token, double prob, double *existing=nullptr)
Write a gate's probability, once.
void appendGate(pg_uuid_t token, gate_type type, const std::vector< pg_uuid_t > &children)
Append a complete gate record, then publish token for it.
double probAt(unsigned long idx) const
getProb of the record idx.
unsigned long getNbGates() const
Return the total number of gates stored in the circuit.
SetProbResult
Outcome of setProb.
@ NotProbGate
The token names a gate that carries no probability.
@ Unchanged
The gate already held exactly this probability.
@ Written
The gate had no probability and now holds the given one.
@ AlreadySet
The gate holds a different probability; refused.
std::string extraAt(unsigned long idx) const
getExtra of the record idx.
static constexpr const char * GATES_FILENAME
Backing file for gates.
Counts sweepInto(const std::vector< bool > &live, const std::string &mp, const std::string &gp, const std::string &wp, const std::string &ep) const
Copy the gates flagged in live into a fresh set of files beside the current ones (suffix "....
gate_type getGateType(pg_uuid_t token) const
Return the type of the gate identified by token.
Check check() const
Walk the store and report what does not add up.
void sync()
Flush all backing files to disk with msync().
static std::string storePath(Oid db_oid, Oid db_tablespace, const char *filename)
Build the full path of a file in a database's store directory, the one GetDatabasePath resolves for d...
static constexpr const char * WIRES_FILENAME
Backing file for wires.
void copyGateAt(GenericCircuit &result, gate_t id, unsigned long idx) const
Give the gate id of result what the record idx (NOTHING for a gate not stored: an input) records but ...
MMappedCircuit(const std::string &mp, const std::string &gp, const std::string &wp, const std::string &ep, bool read_only)
Delegating constructor that accepts pre-built paths.
gate_t copyGate(GenericCircuit &result, pg_uuid_t uuid) const
Add the gate uuid to result, with what it records but its wires.
static bool storeExists(Oid db_oid, Oid db_tablespace)
Whether the store of db_oid in db_tablespace still has its gates file: false once the database is dro...
bool uncleanShutdown() const
Whether any backing file was found still marked open-for-writing when it was opened – the previous wr...
static constexpr const char * EXTRA_FILENAME
Backing file for extra.
static constexpr uint64_t MAGIC_WIRES
static constexpr uint64_t MAGIC_GATES
8-byte magic constants identifying each mmap file type.
static constexpr const char * MAPPING_FILENAME
Backing file for mapping.
bool hasProb(pg_uuid_t token, double *prob) const
Report whether token names a gate that holds a probability.
MMappedVector< char > extra
Variable-length string data.
static constexpr uint64_t MAGIC_EXTRA
double getProb(pg_uuid_t token) const
Return the probability an evaluation would use for token.
std::vector< pg_uuid_t > getChildren(pg_uuid_t token) const
Return the child UUIDs of the gate identified by token.
MMappedVector< GateInformation > gates
Gate metadata array.
SetAnnotationResult setExtra(pg_uuid_t token, const std::string &s, std::string *existing=nullptr)
Attach a variable-length string annotation to a gate, once.
SetAnnotationResult
Outcome of setInfos or setExtra.
@ NoSuchGate
The token names no gate.
~MMappedCircuit()
Sync all backing files before destruction.
bool hasProbAt(unsigned long idx) const
Whether the gate record at index idx holds a written probability (see GATES_VERSION for the version-1...
MMappedVector< pg_uuid_t > wires
Flattened child UUID array.
GenericCircuit createGenericCircuit(pg_uuid_t token, std::size_t budget=0) const
Build an in-memory GenericCircuit rooted at token.
static constexpr uint64_t MAGIC_MAPPING
std::pair< unsigned, unsigned > getInfos(pg_uuid_t token) const
Return the info1 / info2 pair for the gate token.
void flush()
Force every backing file to stable storage.
Persistent open-addressing hash table mapping UUIDs to integers.
Append-only, mmap-backed vector of elements of type T.
Core types, constants, and utilities shared across ProvSQL.
What provsql.check_store() reports about a store.
unsigned long dangling_indices
Mapping entries indexing past the records.
unsigned long nb_gates
Gate records.
unsigned long bad_extra
Records whose extra runs past the extra file.
bool unclean
A file was left marked open-for-writing.
unsigned long nb_mapping
Mapping entries.
unsigned long unreferenced
Records no mapping entry points at.
unsigned long bad_wires
Records whose children run past the wires.
unsigned long next_value
Next index the mapping would assign.
The size of a store, in the three units that matter.
unsigned long extra_bytes
Bytes of variable-length annotation.
unsigned long gates
Gate records.
unsigned long wires
Child wires.