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

OperationReturnsSummary
Database.ReactorsStatusdocumentdatabase.reactors_status() returns an owned object document describing the live mutation runtime.
Database.ReactorsSyncnonedatabase.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.
go54B
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

StatusWhen
StatusUnavailablethe database does not enable the reactors plugin
StatusClosedthe database is closed
StatusOutOfMemorynative memory is exhausted

Examples

Describe the live mutation runtime

go157B
if err := db.ReactorsSync(5 * time.Second); err != nil {
	return err
}

result, err := db.ReactorsStatus()
if err != nil {
	return err
}
defer result.Close()
Result / 68B
{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_wait argument 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_wait passes first, and closed when the database closes.
go60B
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

ParameterTypeOwnershipDefaultMeaning
maxWaittime.DurationValueRequiredThe maximum wait for the next event, as a native duration.

Errors

StatusWhen
StatusInvalidArgumentmax_wait is negative
StatusFaileda live mutation failure stands. reactors_status describes it
StatusTimeoutmax_wait passed first
StatusUnavailablethe database does not enable the reactors plugin
StatusClosedthe database is closed

Examples

Wait until live mutations caught up

go157B
if err := db.ReactorsSync(5 * time.Second); err != nil {
	return err
}

result, err := db.ReactorsStatus()
if err != nil {
	return err
}
defer result.Close()
Result / 68B
{enabled  true
 cursor   4
 head     4
 pending  false
 reactors []}

C exports: stardust_db_reactors_sync