Skip to content

Pipelines & Events Reference

VirtualDB's extension model is built on two primitives.

A pipeline is an ordered sequence of named points. When something happens — a query arrives, rows are fetched, a transaction commits — VirtualDB runs the corresponding pipeline. Handlers registered at a point are called in priority order and can inspect or modify the data passing through.

An event is a fire-and-forget notification emitted after a pipeline completes. Events are for observation, not transformation — subscribe to an event when you need to react to something without blocking the path that triggered it.

Pipelines

vdb.context.create

Fired once at startup, before any connections are accepted. Used to initialize the global context shared across all sessions.

PointDescription
vdb.context.create.build_contextAllocates the initial global context object.
vdb.context.create.contributeAllows handlers to add values to the context.
vdb.context.create.sealSeals the context — no further contributions accepted.
vdb.context.create.emitFires startup-time events.

vdb.server.start

Fired after the global context is sealed, just before the server binds its port.

PointDescription
vdb.server.start.build_contextBuilds the context for the start sequence.
vdb.server.start.configureApplies final server configuration.
vdb.server.start.launchStarts the server and binds the TCP listener.
vdb.server.start.emitEmits the server-started notification.

vdb.server.stop

Fired when VirtualDB receives a shutdown signal (SIGTERM or SIGINT).

PointDescription
vdb.server.stop.build_contextBuilds the context for the stop sequence.
vdb.server.stop.drainWaits for in-flight requests to complete.
vdb.server.stop.haltCloses the listener and terminates the server.
vdb.server.stop.emitEmits vdb.server.stopped.

vdb.connection.opened

Fired after a client completes the MySQL authentication handshake.

PointDescription
vdb.connection.opened.build_contextBuilds the per-connection context with the authenticated user and remote address.
vdb.connection.opened.acceptGate point — a handler that returns an error refuses the connection.
vdb.connection.opened.trackRegisters the connection in VirtualDB's connection state map.
vdb.connection.opened.emitEmits vdb.connection.opened.

vdb.connection.closed

Fired when a client disconnects, regardless of the reason.

PointDescription
vdb.connection.closed.build_contextBuilds the context for the teardown sequence.
vdb.connection.closed.cleanupDiscards any in-progress transaction delta for this connection.
vdb.connection.closed.releaseRemoves the connection from the state map.
vdb.connection.closed.emitEmits vdb.connection.closed.

vdb.transaction.begin

Fired when a transaction starts, whether via an explicit BEGIN or implicitly in autocommit mode.

PointDescription
vdb.transaction.begin.build_contextBuilds the context, including whether the transaction is read-only.
vdb.transaction.begin.authorizeGate point — a handler that returns an error refuses the transaction.
vdb.transaction.begin.emitEmits vdb.transaction.started.

vdb.transaction.commit

Fired when a transaction is committed.

PointDescription
vdb.transaction.commit.build_contextBuilds the context for the commit sequence.
vdb.transaction.commit.applyMerges the transaction's private delta into the live process delta.
vdb.transaction.commit.emitEmits vdb.transaction.committed.

vdb.transaction.rollback

Fired when a transaction is rolled back, fully or to a named savepoint.

PointDescription
vdb.transaction.rollback.build_contextBuilds the context, including the savepoint name (empty string for a full rollback).
vdb.transaction.rollback.applyDiscards the transaction's private delta.
vdb.transaction.rollback.emitEmits vdb.transaction.rolledback.

vdb.query.received

Fired when a SQL statement arrives, before the SQL engine executes it. This is the primary interception point for query rewriting.

PointDescription
vdb.query.received.build_contextBuilds the context with the raw SQL string and current database name.
vdb.query.received.interceptTransformation point. A handler may return a modified SQL string; VirtualDB executes the replacement.
vdb.query.received.emitNo event here — vdb.query.completed is emitted after execution.

vdb.records.source

Fired after rows are fetched from the source database, before the delta overlay is applied.

PointDescription
vdb.records.source.build_contextBuilds the context with the table name and the raw record slice.
vdb.records.source.transformTransformation point. Handlers may add, remove, or modify rows. The built-in delta overlay runs here at priority 10.
vdb.records.source.emitNotifies subscribers that source records are available.

Priority and the delta overlay

Handlers registered at vdb.records.source.transform with priority < 10 see raw source rows before the delta is applied. Handlers with priority > 10 see the merged rows after the overlay. See Plugins for more.


vdb.records.merged

Fired after the delta has been overlaid on source rows, producing the final result set. This is the last opportunity to modify rows before they reach the client.

PointDescription
vdb.records.merged.build_contextBuilds the context with the post-merge record slice.
vdb.records.merged.transformTransformation point. Handlers may make final adjustments to outgoing rows.
vdb.records.merged.emitNotifies subscribers that the merged records are ready.

vdb.write.insert

Fired once per row when an INSERT is processed.

PointDescription
vdb.write.insert.build_contextBuilds the context with the table name and the new row.
vdb.write.insert.applyRecords the row as a new insert in the delta. Handlers may modify the record.
vdb.write.insert.emitEmits vdb.record.inserted.

vdb.write.update

Fired once per row when an UPDATE is processed.

PointDescription
vdb.write.update.build_contextBuilds the context with the table name and both the old and new row.
vdb.write.update.applyRecords the update overlay in the delta. Handlers may modify the new row before it is stored.
vdb.write.update.emitEmits vdb.record.updated.

vdb.write.delete

Fired once per row when a DELETE is processed.

PointDescription
vdb.write.delete.build_contextBuilds the context with the table name and the deleted row.
vdb.write.delete.applyRecords a tombstone in the delta, removing any prior overlay for the same row.
vdb.write.delete.emitEmits vdb.record.deleted.

Events

Events are emitted after their corresponding pipeline completes. Subscribe to observe state changes without blocking the request path.

EventEmitted when
vdb.server.stoppedThe server has fully shut down and the port has been released.
vdb.connection.openedA client connection has been accepted and is being tracked.
vdb.connection.closedA client connection has been released.
vdb.transaction.startedA transaction has been authorized and begun.
vdb.transaction.committedA transaction has committed and its delta merged into the live store.
vdb.transaction.rolledbackA transaction has been rolled back (full or to a savepoint).
vdb.query.completedA query has finished. Payload includes the SQL string, rows affected, and any error.
vdb.record.insertedA row has been stored in the delta as an insert.
vdb.record.updatedAn update overlay has been recorded in the delta.
vdb.record.deletedA tombstone has been recorded in the delta.
vdb.schema.loadedSchema metadata for a table has been loaded from the source. Payload includes the table name, columns, and primary key.
vdb.schema.invalidatedSchema metadata for a table has been invalidated and will reload on next access.

Handler priorities

When multiple handlers are registered at the same pipeline point, they run in ascending priority order — lower numbers run first. Priorities do not need to be unique or contiguous.

Plugin-declared pipelines and events

Plugins are not limited to the built-in pipelines. A plugin may declare its own pipelines and events in its declare notification, making them available for other plugins to attach to. See Plugins for details.

  • Plugins — writing a plugin and the JSON-RPC protocol
  • How It Works — the delta model and query lifecycle

Released under the Elastic License 2.0.