56 for(
const auto &c: children)
68 return gates[idx].type;
73 std::vector<pg_uuid_t> result;
78 result.push_back(
wires[k]);
101 return gates[idx].prob;
108 gates[idx].info1=info1;
109 gates[idx].info2=info2;
120 gates[idx].extra_len=s.size();
128 return std::make_pair(0, 0);
141 for(
unsigned long start=
gates[idx].extra_idx, k=start, end=start+
gates[idx].extra_len; k<end; ++k)
152 while(
READM(c,
char)) {
158 unsigned nb_children;
163 std::vector<pg_uuid_t> children(nb_children);
164 for(
unsigned i=0; i<nb_children; ++i)
181 char return_value = ok?
static_cast<char>(1):0;
183 if(!
WRITEB(&return_value,
char))
184 provsql_error(
"Cannot write response to pipe (message type P)");
191 unsigned info1, info2;
209 char *data =
new char[len];
229 provsql_error(
"Cannot write response to pipe (message type t)");
237 if(!
WRITEB(&nb,
unsigned long))
238 provsql_error(
"Cannot write response to pipe (message type n)");
250 unsigned nb_children = children.size();
251 if(!
WRITEB(&nb_children,
unsigned))
252 provsql_error(
"Cannot write response to pipe (message type c)");
255 provsql_error(
"Cannot write response to pipe (message type c)");
268 if(!
WRITEB(&prob,
double))
269 provsql_error(
"Cannot write response to pipe (message type p)");
282 if(!
WRITEB(&infos.first,
unsigned) || !
WRITEB(&infos.second,
unsigned))
283 provsql_error(
"Cannot write response to pipe (message type i)");
295 unsigned len = str.size();
298 provsql_error(
"Cannot write response to pipe (message type e)");
309 std::stringstream ss;
310 boost::archive::binary_oarchive oa(ss);
313 ss.seekg(0, std::ios::end);
314 unsigned long size = ss.tellg();
315 ss.seekg(0, std::ios::beg);
346 return memcmp(&a, &b,
sizeof(
pg_uuid_t))<0;
351 std::set<pg_uuid_t> to_process, processed;
352 to_process.insert(token);
356 while(!to_process.empty()) {
358 to_process.erase(to_process.begin());
359 processed.insert(uuid);
365 if(!std::isnan(prob))
369 for(
unsigned i=0; i<children.size(); ++i) {
373 if(processed.find(children[i])==processed.end())
374 to_process.insert(children[i]);
gate_t
Strongly-typed gate identifier.
Out-of-line template method implementations for Circuit<gateType>.
Semiring-agnostic in-memory provenance circuit.
GenericCircuit createGenericCircuit(pg_uuid_t token)
Build an in-memory GenericCircuit rooted at token.
void destroy_provsql_mmap()
Unmap and close the mmap files.
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 * circuit
Singleton pointer to the process-wide mmap-backed provenance circuit.
void initialize_provsql_mmap()
Open (or create) the mmap files and initialise the circuit store.
Persistent, mmap-backed storage for the full provenance circuit.
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
gate_t getGate(const uuid &u)
Return (or create) the gate associated with UUID u.
In-memory provenance circuit with semiring-generic evaluation.
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.
void setExtra(pg_uuid_t token, const std::string &s)
Attach a variable-length string annotation to a gate.
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.
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.
gate_type getGateType(pg_uuid_t token) const
Return the type of the gate identified by token.
void sync()
Flush all backing files to disk with msync().
bool setProb(pg_uuid_t token, double prob)
Set the probability associated with a gate.
MMappedVector< char > extra
Variable-length string data.
double getProb(pg_uuid_t token) const
Return the probability stored for 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.
MMappedVector< GateInformation > gates
Gate metadata array.
MMappedVector< pg_uuid_t > wires
Flattened child UUID array.
void setInfos(pg_uuid_t token, unsigned info1, unsigned info2)
Update the info1 / info2 annotations of a gate.
std::pair< unsigned, unsigned > getInfos(pg_uuid_t token) const
Return the info1 / info2 pair for the gate token.
std::pair< unsigned long, bool > add(pg_uuid_t u)
Insert UUID u, assigning it the next available integer.
void sync()
Flush dirty pages to the backing file with msync().
static constexpr unsigned long NOTHING
Sentinel returned by operator[]() when the UUID is not present.
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.
void sync()
Flush dirty pages to the backing file with msync().
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
Background worker and IPC primitives for mmap-backed circuit storage.
#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.
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_type
Possible gate type in the provenance circuit.
@ gate_update
Update operation.
@ gate_eq
Equijoin gate (for where provenance)
@ gate_value
Scalar value (for aggregate provenance)
@ gate_mulinput
Multivalued input (for Boolean provenance)
@ gate_agg
Aggregation operator (for aggregate provenance)
@ gate_project
Project gate (for where provenance)
@ gate_invalid
Invalid gate type.
@ gate_cmp
Currently unused, meant for comparison of aggregate values.
@ gate_input
Input (variable) gate of the circuit.
string uuid2string(pg_uuid_t uuid)
Format a pg_uuid_t as a std::string.
C++ utility functions for UUID manipulation.
long pipebmr
Background-to-main pipe: read end (worker reads)
long pipembw
Main-to-background pipe: write end (backend writes)