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,
241 unsigned *info1,
unsigned *info2);
249#ifdef PROVSQL_INPROCESS_STORE
258bool provsql_inproc_send(
const char *buf,
size_t len);
265extern size_t buffercap;
267void provsql_buffer_ensure(
size_t need);
269#define READM(var, type) provsql_fifo_pop (&provsql_shared_state->req, &(var), sizeof(type))
270#define READB(var, type) provsql_fifo_pop (&provsql_shared_state->resp, &(var), sizeof(type))
271#define WRITEB(pvar, type) provsql_fifo_push(&provsql_shared_state->resp, (pvar), sizeof(type))
272#define WRITEM(pvar, type) provsql_fifo_push(&provsql_shared_state->req, (pvar), sizeof(type))
274#define READB_BYTES(ptr, n) provsql_fifo_pop (&provsql_shared_state->resp, (ptr), (n))
275#define READM_BYTES(ptr, n) provsql_fifo_pop (&provsql_shared_state->req, (ptr), (n))
276#define WRITEB_BYTES(ptr, n) provsql_fifo_push(&provsql_shared_state->resp, (ptr), (n))
278#define STARTWRITEM() (bufferpos=0)
279#define ADDWRITEM(pvar, type) (provsql_buffer_ensure(bufferpos+sizeof(type)), memcpy(buffer+bufferpos, pvar, sizeof(type)), bufferpos+=sizeof(type))
280#define SENDWRITEM() provsql_inproc_send(buffer, bufferpos)
313extern char buffer[PIPE_BUF];
334#define PROVSQL_REPLAY_SPOOL "global/provsql_replay_spool"
340#define READM(var, type) provsql_worker_read(&var, sizeof(type))
342#define READB(var, type) provsql_read_all(provsql_shared_state->pipembr, &var, sizeof(type))
344#define WRITEB(pvar, type) provsql_write_all(provsql_shared_state->pipembw, pvar, sizeof(type))
346#define WRITEM(pvar, type) provsql_write_all(provsql_shared_state->pipebmw, pvar, sizeof(type))
349#define READB_BYTES(ptr, n) provsql_read_all(provsql_shared_state->pipembr, (ptr), (n))
351#define READM_BYTES(ptr, n) provsql_worker_read((ptr), (n))
353#define WRITEB_BYTES(ptr, n) provsql_write_all(provsql_shared_state->pipembw, (ptr), (n))
356#define STARTWRITEM() (bufferpos=0)
358#define ADDWRITEM(pvar, type) (memcpy(buffer+bufferpos, pvar, sizeof(type)), bufferpos+=sizeof(type))
360#define SENDWRITEM() provsql_write_all(provsql_shared_state->pipebmw, buffer, bufferpos)
373#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.
bool provsql_worker_from_spool
Whether the message being applied comes from the replay spool: it is not answered,...
bool provsql_write_all(int fd, const void *src, size_t n)
Write the n bytes of src to fd, however many write calls it takes; false on error.
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_request_start(void)
Start a request that may keep the worker busy (the building of a circuit): no cancel is pending for i...
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.
void provsql_replay_spool_close(void)
Sync and close the replay spool at the end of WAL replay (the resource manager's cleanup).
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.
bool provsql_worker_spooled(void)
Whether store messages spooled during crash recovery remain to be applied (they come before the pipe)...
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_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_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 provsql_internal_get_infos(const pg_uuid_t *token, unsigned *info1, unsigned *info2)
Read a gate's info1 and info2, through the worker.
bool provsql_wait_reply(void)
Wait, under the store lock, until the worker's reply to this backend's request can be read.
char * provsql_internal_get_extra(const pg_uuid_t *token)
Read a gate's extra text, through the worker; palloc'd.
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.