37#ifndef MMAPPED_CIRCUIT_H
38#define MMAPPED_CIRCUIT_H
105 const std::vector<pg_uuid_t> &children);
115 const std::string &wp,
const std::string &ep,
155static std::string
storePath(Oid db_oid, Oid db_tablespace,
156 const char *filename);
173 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'G') << 24 |
174 uint64_t(
'a') << 32 | uint64_t(
't') << 40 | uint64_t(
'e') << 48 | uint64_t(
's') << 56;
176 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'W') << 24 |
177 uint64_t(
'i') << 32 | uint64_t(
'r') << 40 | uint64_t(
'e') << 48 | uint64_t(
's') << 56;
179 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'M') << 24 |
180 uint64_t(
'a') << 32 | uint64_t(
'p') << 40 | uint64_t(
'n') << 48 | uint64_t(
'g') << 56;
182 uint64_t(
'P') | uint64_t(
'v') << 8 | uint64_t(
'S') << 16 | uint64_t(
'E') << 24 |
183 uint64_t(
'x') << 32 | uint64_t(
't') << 40 | uint64_t(
'r') << 48 | uint64_t(
'a') << 56;
193MMappedCircuit(Oid db_oid, Oid db_tablespace,
bool read_only =
false);
230 std::pair<unsigned, unsigned> *existing =
nullptr);
247 std::string *existing =
nullptr);
332unsigned long mark(
const std::vector<pg_uuid_t> &roots,
333 std::vector<bool> &live)
const;
360Counts
sweepInto(
const std::vector<bool> &live,
361 const std::string &mp,
const std::string &gp,
362 const std::string &wp,
const std::string &ep)
const;
419 return gates.nbElements();
453 const std::vector<pg_uuid_t> &roots)
const;
456#ifdef PROVSQL_INPROCESS_STORE
468 const std::vector<pg_uuid_t> &roots);
Semiring-agnostic in-memory provenance circuit.
Open-addressing hash table mapping UUIDs to integers, backed by an mmap file.
Template implementation of MMappedVector<T>.
In-memory provenance circuit with semiring-generic evaluation.
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.
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.
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.
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.
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.
GenericCircuit createGenericCircuit(pg_uuid_t token) const
Build an in-memory GenericCircuit rooted at token.
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.
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.