25#include <unordered_map>
26#include <unordered_set>
40#ifndef PROVSQL_INPROCESS_STORE
41#include <boost/iostreams/device/back_inserter.hpp>
42#include <boost/iostreams/stream.hpp>
50#include "common/relpath.h"
51#include "utils/palloc.h"
56#ifdef PROVSQL_INPROCESS_STORE
57#define PROVSQL_FROM_SPOOL false
59#define PROVSQL_FROM_SPOOL provsql_worker_from_spool
86 char *rel = GetDatabasePath(db_oid, db_tablespace);
87 std::string path = std::string(DataDir) +
"/" + rel +
"/" + filename;
103 return !(access(
gates.c_str(), F_OK) != 0 && errno == ENOENT);
127 const std::vector<pg_uuid_t> &children)
129 const unsigned long idx =
gates.nbElements();
130 const unsigned long wires_idx =
wires.nbElements();
131 for(
const auto &c: children)
133 gates.add({type,
static_cast<unsigned>(children.size()), wires_idx});
151 &&
gates[idx].nb_children == 0;
152 bool real_create = type !=
gate_input || !children.empty();
153 if(placeholder && real_create) {
154 const unsigned long wires_idx =
wires.nbElements();
155 for(
const auto &c: children)
159 gates[idx].children_idx = wires_idx;
160 gates[idx].nb_children =
static_cast<unsigned>(children.size());
161 gates[idx].type = type;
162 for(
const auto &c: children)
171 for(
const auto &c: children)
182 return gates[idx].type;
187 std::vector<pg_uuid_t> result;
192 result.push_back(
wires[k]);
204 pg_uuid_t token,
double prob,
double *existing)
208 idx =
gates.nbElements();
217 if(std::isnan(prob)) {
218 gates[idx].prob = NAN;
223 gates[idx].prob = prob;
226 if(
gates[idx].prob == prob)
229 *existing =
gates[idx].prob;
240 double p =
gates[idx].prob;
243 if(
gates.version() < 2 && p == 1.)
257 if(!std::isnan(
gates[idx].prob))
258 return gates[idx].prob;
262 return 1. /
gates[idx].info2;
276 *prob =
gates[idx].prob;
288 pg_uuid_t token,
unsigned info1,
unsigned info2,
289 std::pair<unsigned, unsigned> *existing)
297 if((info1 != 0 && gi.
info1 != 0 && gi.
info1 != info1)
298 || (info2 != 0 && gi.
info2 != 0 && gi.
info2 != info2)) {
300 *existing = std::make_pair(gi.
info1, gi.
info2);
304 const unsigned w1 = info1 != 0 ? info1 : gi.
info1;
305 const unsigned w2 = info2 != 0 ? info2 : gi.
info2;
315 pg_uuid_t token,
const std::string &s, std::string *existing)
327 if(
gates[idx].extra_len == s.size()) {
329 for(
unsigned long k=0; k<s.size(); ++k)
338 if(
gates[idx].extra_len > 0) {
347 gates[idx].extra_len=s.size();
355 return std::make_pair(0, 0);
372 for(
unsigned long start=
gates[idx].extra_idx, k=start, end=start+
gates[idx].extra_len; k<end; ++k)
397 const char *names[4] = {
"provsql_mapping.mmap",
"provsql_gates.mmap",
398 "provsql_wires.mmap",
"provsql_extra.mmap" };
401 const bool committed = (access(marker.c_str(), F_OK) == 0);
403 for(
const char *name: names) {
406 if(access(fresh.c_str(), F_OK) != 0)
409 rename(fresh.c_str(), target.c_str());
411 unlink(fresh.c_str());
415 unlink(marker.c_str());
477 const std::vector<pg_uuid_t> &roots,
bool dry_run,
482 auto before = circuit->
counts();
487 std::vector<bool> live;
488 unsigned long nb_live = circuit->
mark(roots, live);
500 const char *names[4] = {
"provsql_mapping.mmap",
"provsql_gates.mmap",
501 "provsql_wires.mmap",
"provsql_extra.mmap" };
502 std::string target[4], fresh[4];
503 for(
int i=0; i<4; ++i) {
506 unlink(fresh[i].c_str());
509 auto after = circuit->
sweepInto(live, fresh[0], fresh[1], fresh[2], fresh[3]);
522 int mfd = open(marker.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0600);
524 const char *reason = strerror(errno);
526 marker.c_str(), reason);
531 for(
int i=0; i<4; ++i)
532 if(rename(fresh[i].c_str(), target[i].c_str())) {
533 const char *reason = strerror(errno);
535 target[i].c_str(), reason);
538 unlink(marker.c_str());
541#ifdef PROVSQL_INPROCESS_STORE
554 const std::vector<pg_uuid_t> &roots, std::size_t budget)
560 const std::vector<FormulaRequest> &requests,
unsigned long cap,
561 unsigned long wide_cap)
564 requests, cap, wide_cap);
575#ifndef PROVSQL_INPROCESS_STORE
591 const std::vector<pg_uuid_t> &roots,
592 unsigned long budget,
char message_char)
595 std::vector<char> buf;
604 boost::iostreams::stream<
605 boost::iostreams::back_insert_device<std::vector<char>>> out(buf);
606 boost::archive::binary_oarchive oa(out);
613 if(rss > base_rss && rss - base_rss > budget)
624 std::vector<char>().swap(buf);
626 if(!
WRITEB(&size,
unsigned long) ||
628 provsql_error(
"Cannot write to pipe (message type %c)", message_char);
630 std::vector<char>().swap(buf);
638static void dispatch(
char c, Oid db_oid, Oid db_tablespace)
642 if(c==
'C' || c==
'G' || c==
'P' || c==
'I' || c==
'E')
650 unsigned nb_children;
655 std::vector<pg_uuid_t> children(nb_children);
656 for(
unsigned i=0; i<nb_children; ++i)
673 unsigned nb_children, info1, info2, len;
679 std::vector<pg_uuid_t> children(nb_children);
680 for(
unsigned i=0; i<nb_children; ++i)
683 if(!
READM(has_infos,
char) || !
READM(info1,
unsigned) || !
READM(info2,
unsigned)
684 || !
READM(len,
unsigned))
686 std::vector<char> data(len);
692 std::pair<unsigned, unsigned> existing{0, 0};
693 if(circuit->
setInfos(token, info1, info2, &existing)
695 provsql_warning(
"gate %s already records the annotation (%u, %u), not (%u, %u)",
696 uuid2string(token).c_str(), existing.first, existing.second,
700 std::string existing;
701 if(circuit->
setExtra(token, std::string(data.data(), len), &existing)
703 provsql_warning(
"gate %s already records the annotation \"%s\", not \"%s\"",
705 std::string(data.data(), len).c_str());
713 double prob, existing = 0.;
718 auto result = circuit->
setProb(token, prob, &existing);
719 char return_value =
static_cast<char>(result);
723 (!
WRITEB(&return_value,
char) || !
WRITEB(&existing,
double)))
724 provsql_error(
"Cannot write response to pipe (message type P)");
739 char has = circuit->
hasProb(token, &prob) ? 1 : 0;
742 provsql_error(
"Cannot write response to pipe (message type q)");
759 unsigned info1, info2;
760 std::pair<unsigned, unsigned> existing{0, 0};
761 if(!
READM(info1,
unsigned) || !
READM(info2,
unsigned))
763 if(circuit->
setInfos(token, info1, info2, &existing)
765 provsql_warning(
"gate %s already records the annotation (%u, %u), not (%u, %u)",
766 uuid2string(token).c_str(), existing.first, existing.second,
770 if(!
READM(len,
unsigned))
773 std::vector<char> data(len);
774 std::string existing;
777 if(circuit->
setExtra(token, std::string(data.data(), len), &existing)
779 provsql_warning(
"gate %s already records the annotation \"%s\", not \"%s\"",
781 std::string(data.data(), len).c_str());
797 provsql_error(
"Cannot write response to pipe (message type t)");
805 if(!
WRITEB(&nb,
unsigned long))
806 provsql_error(
"Cannot write response to pipe (message type n)");
818 unsigned nb_children = children.size();
819 if(!
WRITEB(&nb_children,
unsigned))
820 provsql_error(
"Cannot write response to pipe (message type c)");
823 provsql_error(
"Cannot write response to pipe (message type c)");
834 double prob = circuit->
getProb(token);
836 if(!
WRITEB(&prob,
double))
837 provsql_error(
"Cannot write response to pipe (message type p)");
848 auto infos = circuit->
getInfos(token);
850 if(!
WRITEB(&infos.first,
unsigned) || !
WRITEB(&infos.second,
unsigned))
851 provsql_error(
"Cannot write response to pipe (message type i)");
862 auto str = circuit->
getExtra(token);
863 unsigned len = str.size();
866 provsql_error(
"Cannot write response to pipe (message type e)");
873 unsigned long budget;
878#ifdef PROVSQL_INPROCESS_STORE
881 provsql_error(
"message type g is not used by the in-process store");
883 send_circuit(circuit, std::vector<pg_uuid_t>{token}, budget,
'g');
901 unsigned long nb_roots;
903 if(!
READM(dry_run,
char) || !
READM(nb_roots,
unsigned long))
906 std::vector<pg_uuid_t> roots(nb_roots);
907 for(
unsigned long i=0; i<nb_roots; ++i)
912 cleanupStore(db_oid, db_tablespace, roots, dry_run != 0, &res);
917 provsql_error(
"Cannot write response to pipe (message type X)");
931 provsql_error(
"Cannot write response to pipe (message type S)");
939 char unclean = chk.
unclean ? 1 : 0;
940 if(!
WRITEB(&unclean,
char)
948 provsql_error(
"Cannot write response to pipe (message type k)");
960 if(!
READM(nb_roots,
unsigned))
963 std::vector<pg_uuid_t> roots(nb_roots);
964 for(
unsigned i=0; i<nb_roots; ++i)
967 unsigned long budget;
968 if(!
READM(budget,
unsigned long))
971#ifdef PROVSQL_INPROCESS_STORE
974 provsql_error(
"message type j is not used by the in-process store");
984 unsigned long cap, wide_cap;
986 if(!
READM(cap,
unsigned long) || !
READM(wide_cap,
unsigned long)
987 || !
READM(nb,
unsigned))
989 std::vector<FormulaRequest> requests(nb);
990 for(
unsigned i = 0; i < nb; ++i)
992 || !
READM(requests[i].from,
unsigned long)
993 || !
READM(requests[i].count,
unsigned long))
996#ifdef PROVSQL_INPROCESS_STORE
997 provsql_error(
"message type F is not used by the in-process store");
999 std::vector<char> buf;
1001 boost::iostreams::stream<
1002 boost::iostreams::back_insert_device<std::vector<char>>> out(buf);
1003 boost::archive::binary_oarchive oa(out);
1009 unsigned long size = buf.size();
1035 dispatch(c, db_oid, db_tablespace);
1037 }
catch(
const std::exception &e) {
1040 what =
"unknown exception";
1046#ifndef PROVSQL_INPROCESS_STORE
1054 pfd.events = POLLIN;
1063 int r = poll(&pfd, 1,
1079 Oid db_oid, db_tablespace;
1080 if(!
READM(db_oid, Oid) || !
READM(db_tablespace, Oid))
1112 return mapping.uncleanShutdown() ||
gates.uncleanShutdown()
1113 ||
wires.uncleanShutdown() ||
extra.uncleanShutdown();
1124 std::vector<bool> referenced(c.
nb_gates,
false);
1125 for(
unsigned long k=0; k<
mapping.capacity(); ++k) {
1126 unsigned long v =
mapping.slotValue(k);
1132 referenced[v] =
true;
1134 for(
unsigned long i=0; i<c.
nb_gates; ++i) {
1148 std::vector<bool> &live)
const
1150 const unsigned long n =
gates.nbElements();
1151 live.assign(n,
false);
1152 unsigned long nb_live = 0;
1154 std::vector<unsigned long> stack;
1155 for(
const auto &r: roots) {
1160 stack.push_back(idx);
1164 while(!stack.empty()) {
1165 unsigned long idx = stack.back();
1175 stack.push_back(child);
1184 const std::vector<bool> &live,
1185 const std::string &mp,
const std::string &gp,
1186 const std::string &wp,
const std::string &ep)
const
1189 const unsigned long n =
gates.nbElements();
1195 unsigned long next = 0;
1196 for(
unsigned long i=0; i<n; ++i)
1210 for(
unsigned long i=0; i<n; ++i) {
1225 nwires.
add(
wires[old_children + c]);
1227 const unsigned long old_extra = gi.
extra_idx;
1242 if(legacy && gi.
prob == 1.
1250 for(
unsigned long k=0; k<
mapping.capacity(); ++k) {
1251 unsigned long v =
mapping.slotValue(k);
1278 return memcmp(&a, &b,
sizeof(
pg_uuid_t))<0;
1282 std::size_t budget)
const
1288 const std::vector<pg_uuid_t> &roots, std::size_t budget)
const
1298 auto check_budget = [&]() {
1299 if(++steps % 4096 == 0) {
1304 if(rss > base_rss && rss - base_rss > budget)
1323 std::priority_queue<gate_uuid, std::vector<gate_uuid>,
decltype(greater)>
1324 to_process(greater);
1325 for(
const auto &r : roots)
1329 std::vector<bool> processed;
1331 while(!to_process.empty()) {
1338 const std::size_t i =
static_cast<std::size_t
>(id);
1339 if(i < processed.size() && processed[i])
1341 if(i >= processed.size())
1342 processed.resize(std::max<std::size_t>(i + 1, 2 * processed.size()));
1343 processed[i] =
true;
1345 const unsigned long idx =
mapping[uuid];
1357 to_process.push(child);
1373 unsigned long idx)
const
1378 double prob =
probAt(idx);
1379 if(!std::isnan(prob))
1384 const unsigned info1 = absent ? 0 :
gates[idx].info1;
1385 const unsigned info2 = absent ? 0 :
gates[idx].info2;
1394 const unsigned info1 = absent ? 0 :
gates[idx].info1;
1395 const unsigned info2 = absent ? 0 :
gates[idx].info2;
1396 if(info1 != 0 || info2 != 0)
1417 const std::vector<FormulaRequest> &requests,
unsigned long cap,
1418 unsigned long wide_cap)
const
1426 std::unordered_map<unsigned long, unsigned long> size;
1432 auto size_of = [&](
unsigned long root) ->
unsigned long {
1435 auto it = size.find(root);
1436 if(it != size.end())
1438 std::unordered_map<unsigned long, bool> on_stack;
1439 std::vector<Frame> stack{{root, 0, 1}};
1440 on_stack[root] =
true;
1441 while(!stack.empty()) {
1442 Frame &f = stack.back();
1444 bool pushed =
false;
1448 while(f.k < gi.
nb_children && f.acc <= wide_cap) {
1453 else if(on_stack.count(c))
1456 auto ic = size.find(c);
1457 if(ic == size.end()) {
1458 stack.push_back({c, 0, 1});
1465 f.acc += s > cap ? 1 : s;
1470 const unsigned long done = std::min(f.acc, wide_cap + 1);
1472 on_stack.erase(f.idx);
1475 return size.at(root);
1478 std::unordered_set<unsigned long> stubbed;
1479 std::unordered_set<gate_uuid, gate_uuid_hash> included;
1480 auto stub = [&](
pg_uuid_t u,
unsigned long idx) {
1481 if(!stubbed.insert(idx).second)
1492 std::vector<std::pair<pg_uuid_t, bool> > todo{{u,
false}};
1493 while(!todo.empty()) {
1494 auto [v, whole] = todo.back();
1499 const unsigned long idx =
mapping[v];
1504 for(
unsigned long k = 0; k < gi.
nb_children; ++k) {
1506 const unsigned long wi =
mapping[w];
1508 if(!whole && wi !=
NOTHING && size_of(wi) > cap)
1511 todo.push_back({w, whole});
1516 for(
const auto &q : requests) {
1517 const unsigned long idx =
mapping[q.gate];
1531 for(
unsigned long k = q.from; k < q.from + q.count && k < gi.
nb_children;
1534 const unsigned long wi =
mapping[w];
1536 if(wi !=
NOTHING && size_of(wi) > cap)
gate_t
Strongly-typed gate identifier.
Out-of-line template method implementations for Circuit<gateType>.
Semiring-agnostic in-memory provenance circuit.
static std::map< Oid, Oid > circuit_tablespaces
The tablespace of each open circuit, to find its files again.
static constexpr const char * CLEANUP_SUFFIX
Suffix of the files a clean-up builds beside the live ones.
static void finishInterruptedCleanup(Oid db_oid, Oid db_tablespace)
Bring a database's store to a definite state before opening it.
static void cleanupStore(Oid db_oid, Oid db_tablespace, const std::vector< pg_uuid_t > &roots, bool dry_run, provsql_cleanup_result *out)
Rebuild a database's store, keeping only what roots reach.
static bool carriesProb(gate_type type)
Whether type is one of the gate kinds that carry a probability.
#define PROVSQL_FROM_SPOOL
static std::map< Oid, MMappedCircuit * > circuits
Per-database mmap-backed provenance circuits, keyed by database OID.
void destroy_provsql_mmap()
Unmap and close the mmap files.
void provsql_store_flush(void)
Force every open circuit to stable storage.
void provsql_mmap_dispatch(char c, Oid db_oid, Oid db_tablespace)
Serve one message of the store's protocol.
bool operator<(const pg_uuid_t a, const pg_uuid_t b)
Lexicographic less-than comparison for pg_uuid_t.
void provsql_mmap_main_loop()
Main processing loop of the mmap background worker.
static MMappedCircuit * getCircuit(Oid db_oid, Oid db_tablespace)
Return (creating lazily if needed) the circuit for db_oid.
void initialize_provsql_mmap()
Initialise the circuit store.
static bool store_dirty
Whether any circuit has been written to since the last flush.
static void send_circuit(const MMappedCircuit *circuit, const std::vector< pg_uuid_t > &roots, unsigned long budget, char message_char)
Answer a 'g' / 'j' request: the circuit reachable from roots, serialised, preceded by its size.
static constexpr const char * CLEANUP_MARKER
Marker file present only while a clean-up's rename sequence is in flight; see finishInterruptedCleanu...
static void closeDroppedCircuits()
Close the circuits of the databases dropped since they were opened.
static void dispatch(char c, Oid db_oid, Oid db_tablespace)
The body of provsql_mmap_dispatch, which may throw.
Persistent, mmap-backed storage for the full 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...
Thrown by MMappedCircuit::createGenericCircuit when the circuit it builds takes the process past the ...
Thrown by MMappedCircuit::createGenericCircuit when the statement that asked for the circuit is cance...
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
std::pair< gate_t, bool > findOrAddGate(const gate_uuid &u)
Return (or create) the gate associated with UUID u, and whether it was created.
gate_t getGate(const uuid &u)
Return (or create) the gate associated with UUID u.
void setInfos(gate_t g, unsigned info1, unsigned info2)
Set the integer annotation pair for gate g.
gate_t setGate(gate_type type) override
Allocate a new gate with type type and no UUID.
void setExtra(gate_t g, const std::string &ex)
Attach a string extra to gate g.
void setProb(gate_t g, double p)
Set the probability for gate g.
Persistent mmap-backed representation of the provenance circuit.
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.
@ Unchanged
The gate already held exactly this annotation.
@ Written
The gate had none and now holds the given annotation.
@ NoSuchGate
The token names no gate.
@ AlreadySet
The gate holds a different annotation; refused.
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.
std::pair< unsigned long, bool > publish(pg_uuid_t u, unsigned long value)
Insert UUID u with a caller-chosen value.
static constexpr unsigned long NOTHING
Sentinel returned by operator[]() when the UUID is not present.
void flush()
Force the backing file to stable storage (MappedRegion::flush()).
Append-only, mmap-backed vector of elements of type T.
void flush()
Force the backing file to stable storage (MappedRegion::flush()).
unsigned long nbElements() const
Return the number of elements currently stored.
void add(const T &value)
Append an element to the end of the vector.
std::size_t provsql_process_rss(pid_t pid)
The resident memory of process pid, in bytes, or 0 where the platform does not say.
Resident memory of a process, or of a process group.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
#define provsql_warning(fmt,...)
Emit a ProvSQL warning message (execution continues).
static constexpr unsigned long NOTHING
bool provsql_worker_spooled(void)
Whether store messages spooled during crash recovery remain to be applied (they come before the pipe)...
bool provsql_worker_buffered(void)
Whether the worker's read buffer holds unread bytes, which poll() cannot see.
bool provsql_store_cancel_requested(void)
Whether the circuit being built should be given up: in the worker, the backend that asked for it was ...
bool provsql_worker_from_spool
Whether the message being applied comes from the replay spool: it is not answered,...
Background worker and IPC primitives for mmap-backed circuit storage.
#define WRITEB_BYTES(ptr, n)
Write n reply bytes to the main-to-background pipe.
#define READM(var, type)
Read one value of type from the background-to-main pipe.
#define WRITEB(pvar, type)
Write one value of type to the main-to-background pipe.
#define PROVSQL_STORE_FLUSH_INTERVAL_MS
How long the worker waits after a write before forcing the store to stable storage.
#define READM_BYTES(ptr, n)
Read exactly n bytes of a request from the background-to-main pipe.
provsqlSharedState * provsql_shared_state
Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).
Shared-memory segment and inter-process pipe management.
@ gate_observe
Latent-variable observation (likelihood-weighting evidence): one wire → an observed bare gate_rv leaf...
@ gate_rv
Continuous random-variable leaf (extra encodes distribution).
@ gate_annotation
Transparent single-child wrapper carrying a query-level annotation in extra (inversion-free certifica...
@ gate_mobius
Signed Möbius combination: a MEASURE-only gate carrying one integer coefficient per child (in extra,...
@ gate_fixpoint
Component of the least solution of an equation system: one wire to a gate_fixsystem,...
@ gate_arith
n-ary arithmetic gate over scalar-valued children (info1 holds operator tag)
@ gate_assumed
Structural marker over a single child whose sub-circuit was computed under a Boolean-provenance assum...
string uuid2string(pg_uuid_t uuid)
Format a pg_uuid_t as a std::string.
C++ utility functions for UUID manipulation.
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.
A UUID as its 16 bytes, read as two big-endian words.
void toBytes(unsigned char *p) const
Write the 16 bytes of the UUID to p.
static gate_uuid fromBytes(const unsigned char *p)
The UUID whose 16 bytes start at p.
What provsql.circuit_cleanup() reports.
uint64 wires_before
Child wires before.
uint64 wires_after
Child wires kept.
uint64 extra_before
Annotation bytes before.
uint64 gates_after
Gate records kept.
uint64 extra_after
Annotation bytes kept.
uint64 gates_before
Gate records before.