84#define PROVSQL_STORE_FLUSH_INTERVAL_MS 200
151 unsigned nb_children,
165 unsigned nb_children,
167 bool has_infos,
unsigned info1,
168 unsigned info2,
const char *extra);
234 unsigned *nb_children_out,
238#ifdef PROVSQL_INPROCESS_STORE
247bool provsql_inproc_send(
const char *buf,
size_t len);
254extern size_t buffercap;
256void provsql_buffer_ensure(
size_t need);
258#define READM(var, type) provsql_fifo_pop (&provsql_shared_state->req, &(var), sizeof(type))
259#define READB(var, type) provsql_fifo_pop (&provsql_shared_state->resp, &(var), sizeof(type))
260#define WRITEB(pvar, type) provsql_fifo_push(&provsql_shared_state->resp, (pvar), sizeof(type))
261#define WRITEM(pvar, type) provsql_fifo_push(&provsql_shared_state->req, (pvar), sizeof(type))
263#define READB_BYTES(ptr, n) provsql_fifo_pop (&provsql_shared_state->resp, (ptr), (n))
264#define READM_BYTES(ptr, n) provsql_fifo_pop (&provsql_shared_state->req, (ptr), (n))
265#define WRITEB_BYTES(ptr, n) provsql_fifo_push(&provsql_shared_state->resp, (ptr), (n))
267#define STARTWRITEM() (bufferpos=0)
268#define ADDWRITEM(pvar, type) (provsql_buffer_ensure(bufferpos+sizeof(type)), memcpy(buffer+bufferpos, pvar, sizeof(type)), bufferpos+=sizeof(type))
269#define SENDWRITEM() provsql_inproc_send(buffer, bufferpos)
277extern char buffer[PIPE_BUF];
292#define READM(var, type) provsql_worker_read(&var, sizeof(type))
294#define READB(var, type) (read(provsql_shared_state->pipembr, &var, sizeof(type))==(ssize_t)sizeof(type))
296#define WRITEB(pvar, type) (write(provsql_shared_state->pipembw, pvar, sizeof(type))!=-1)
298#define WRITEM(pvar, type) (write(provsql_shared_state->pipebmw, pvar, sizeof(type))!=-1)
301#define READB_BYTES(ptr, n) provsql_read_all(provsql_shared_state->pipembr, (ptr), (n))
303#define READM_BYTES(ptr, n) provsql_worker_read((ptr), (n))
305#define WRITEB_BYTES(ptr, n) (write(provsql_shared_state->pipembw, (ptr), (n))!=-1)
308#define STARTWRITEM() (bufferpos=0)
310#define ADDWRITEM(pvar, type) (memcpy(buffer+bufferpos, pvar, sizeof(type)), bufferpos+=sizeof(type))
312#define SENDWRITEM() (write(provsql_shared_state->pipebmw, buffer, bufferpos)!=-1)
325#define ADDWRITEDB() (ADDWRITEM(&MyDatabaseId, Oid), ADDWRITEM(&MyDatabaseTableSpace, Oid))
Build-configuration switches shared across the C and C++ sources.
char buffer[PIPE_BUF]
Shared write buffer used with STARTWRITEM / ADDWRITEM / SENDWRITEM.
unsigned bufferpos
Current write position within buffer.
void initialize_provsql_mmap(void)
Initialise the circuit store.
bool provsql_store_written(void)
Whether this transaction has written to the circuit store.
void provsql_internal_create_gate(const pg_uuid_t *token, gate_type type, unsigned nb_children, const pg_uuid_t *children_data)
Create a gate from in-extension C/C++ code (cache + worker IPC).
void provsql_internal_create_gate_with(const pg_uuid_t *token, gate_type type, unsigned nb_children, const pg_uuid_t *children, bool has_infos, unsigned info1, unsigned info2, const char *extra)
Create a gate together with its infos and its text, in one message that is not answered.
void provsql_store_note_write(void)
Note that this transaction has written to the circuit store.
provsql_set_prob_result
Outcome of a probability write, mirroring MMappedCircuit::SetProbResult across the IPC boundary.
@ PROVSQL_SET_PROB_NOT_PROB_GATE
The gate carries no probability.
@ PROVSQL_SET_PROB_WRITTEN
Written; undo on rollback.
@ PROVSQL_SET_PROB_ALREADY_SET
Holds a different value; refused.
@ PROVSQL_SET_PROB_UNCHANGED
Already held exactly this value.
void provsql_mmap_worker(Datum)
Entry point for the ProvSQL mmap background worker.
bool provsql_read_all(int fd, void *dst, size_t n)
Read exactly n bytes from fd into dst; false on EOF/error.
void destroy_provsql_mmap(void)
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)
Handle a single IPC message: read its payload and write its reply.
gate_type provsql_fetch_gate(const pg_uuid_t *token, unsigned *nb_children_out, pg_uuid_t **children_out)
Fetch a gate's type and children, cache-first with a worker round-trip (and cache fill) on a miss.
void provsql_circuit_cleanup_request(bool dry_run, const pg_uuid_t *roots, int64 nb_roots, provsql_cleanup_result *out)
Ask the worker to rebuild this database's store, keeping only what roots reach.
bool provsql_worker_buffered(void)
Whether the worker's read buffer holds unread bytes, which poll() cannot see.
bool provsql_worker_read(void *dst, size_t n)
The worker's buffered read of the request pipe: what the pipe holds is read in one call,...
provsql_set_prob_result provsql_internal_set_prob(const pg_uuid_t *token, double prob, double *existing)
Write a gate's probability from in-extension C/C++ code.
bool provsql_internal_get_prob_written(const pg_uuid_t *token, double *prob)
Report whether a probability has been written on a gate.
void provsql_internal_clear_prob(const pg_uuid_t *token)
Drop a gate's probability, leaving it as it was before anyone wrote one.
void provsql_mmap_main_loop(void)
Main processing loop of the mmap background worker.
void RegisterProvSQLMMapWorker(void)
Register the ProvSQL mmap background worker with PostgreSQL.
Core types, constants, and utilities shared across ProvSQL.
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.