Reactors
The reactors plugin runs live mutations.
A live mutation is a stored mutation definition with live true and an optional integer priority.
These operations belong to the plugin, not to the core.
They work only on a database that enables the reactors plugin at open, and report the unavailable status otherwise.
The plugins option selects the enabled plugins. An absent list enables every included plugin.
Store live mutations with patch_definition under the mutations kind.
After each commit, the plugin runs a round: every live mutation evaluates its query as of that transaction, and their patches commit together as one output transaction.
Mutations explains rounds, chains and failures.
Operations
| Operation | Returns | Summary |
|---|---|---|
| Database.ReactorsStatus | document | database.reactors_status() returns an owned object document describing the live mutation runtime. |
| Database.ReactorsSync | none | database.reactors_sync(max_wait) waits until live mutations processed every transaction committed before the call. |
Database.ReactorsStatus
database.reactors_status() returns an owned object document describing the live mutation runtime.
database.reactors_status() describes the live mutation runtime.
- It is a reactors plugin operation: the database must enable the reactors plugin at open, otherwise the call reports unavailable.
- A live mutation is a stored mutation definition with live true and an optional integer priority.
- The owned object has enabled, cursor (the last processed source transaction), head, pending (transactions await a round), reactors (id, name, priority and sinceTx of each live mutation) and, while one stands, failure (sourceTx, code, reactors and path).
After each commit, every live mutation evaluates its query as of that transaction, and their patches commit together as one output transaction.
- When two patches write different values to one path, the higher priority wins.
- Equal priorities fail with code Reactor_Conflict.
- The combined patch must satisfy the scoped schemas of every contributing live mutation.
- A schema rejection records Schema_Validation and commits no output.
- A failure keeps the cursor before its source until a live mutation definition changes.
func (d *Database) ReactorsStatus() (*Document, error)- Concurrency: Other calls can overlap this call, except the release of a handle that this call uses.
- Ownership: The caller owns the returned handle and releases it.
Errors
| Status | When |
|---|---|
StatusUnavailable | the database does not enable the reactors plugin |
StatusClosed | the database is closed |
StatusOutOfMemory | native memory is exhausted |
Examples
Describe the live mutation runtime
if err := db.ReactorsSync(5 * time.Second); err != nil {
return err
}
result, err := db.ReactorsStatus()
if err != nil {
return err
}
defer result.Close(){enabled true
cursor 4
head 4
pending false
reactors []}C exports: stardust_db_reactors_status, stardust_result_take_document, stardust_result_error, stardust_result_release
Database.ReactorsSync
database.reactors_sync(max_wait) waits until live mutations processed every transaction committed before the call.
- It is a reactors plugin operation: the database must enable the reactors plugin at open, otherwise the call reports unavailable.
- The
max_waitargument uses the host duration type. - Zero checks once.
- A representable negative wait reports
invalid_argument. - It reports failed while a live mutation failure stands, timeout when
max_waitpasses first, and closed when the database closes.
func (d *Database) ReactorsSync(maxWait time.Duration) error- Concurrency: Other calls can overlap this call, except the release of a handle that this call uses.
Parameters
| Parameter | Type | Ownership | Default | Meaning |
|---|---|---|---|---|
maxWait | time.Duration | Value | Required | The maximum wait for the next event, as a native duration. |
Errors
| Status | When |
|---|---|
StatusInvalidArgument | max_wait is negative |
StatusFailed | a live mutation failure stands. reactors_status describes it |
StatusTimeout | max_wait passed first |
StatusUnavailable | the database does not enable the reactors plugin |
StatusClosed | the database is closed |
Examples
Wait until live mutations caught up
if err := db.ReactorsSync(5 * time.Second); err != nil {
return err
}
result, err := db.ReactorsStatus()
if err != nil {
return err
}
defer result.Close(){enabled true
cursor 4
head 4
pending false
reactors []}C exports: stardust_db_reactors_sync