Documentation
¶
Overview ¶
Package writecoordinator serialises all SQLite write operations through a single goroutine, eliminating concurrent write contention on the primary instance and providing a natural chokepoint for metrics and backpressure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDraining = errors.New("writecoordinator: draining for primary handover, not accepting writes")
ErrDraining is returned by Submit once Drain has been called: the coordinator no longer accepts writes because the primary is handing over.
Functions ¶
This section is empty.
Types ¶
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator serialises all write operations through a single background goroutine, satisfying the dbproxy.WriteSubmitter interface.
func New ¶
New creates a Coordinator and starts the serialisation goroutine. queueSize specifies the job-channel buffer; values <= 0 default to 256.
func (*Coordinator) Drain ¶ added in v0.710.6
func (c *Coordinator) Drain(ctx context.Context) error
Drain stops accepting new writes (Submit returns ErrDraining from now on) and waits until every job already queued has been executed, or ctx expires. It is the first step of a primary's ordered handover: the writes secondaries already forwarded are applied before the lock is released, so the next primary never races them. It does not stop the coordinator; call Shutdown afterwards. Safe to call more than once and after Shutdown.
A Submit that passed the draining check just before Drain was called may still enqueue behind the barrier; that caller is unblocked with an error by the subsequent Shutdown, like any write pending at shutdown.
func (*Coordinator) Metrics ¶
func (c *Coordinator) Metrics() CoordinatorMetrics
Metrics returns a consistent snapshot of coordinator statistics.
func (*Coordinator) SetPublisher ¶
func (c *Coordinator) SetPublisher(pub changepub.Publisher)
SetPublisher attaches a change-event publisher to the coordinator. Must be called before the first Submit; not safe for concurrent use.
func (*Coordinator) Shutdown ¶
func (c *Coordinator) Shutdown()
Shutdown stops the coordinator gracefully. In-flight jobs that have already been dequeued will still complete; pending jobs that are still in the channel will have their callers unblocked via the done signal.
func (*Coordinator) Submit ¶
func (c *Coordinator) Submit(ctx context.Context, req dbproxy.WriteRequest) (json.RawMessage, error)
Submit enqueues a write job and blocks until the result is available or the caller's context is cancelled. It satisfies dbproxy.WriteSubmitter.
type CoordinatorMetrics ¶
type CoordinatorMetrics struct {
Accepted uint64
Completed uint64
Failed uint64
QueueDepth int
MaxQueue int
}
CoordinatorMetrics holds a consistent snapshot of coordinator statistics.
type WriteJob ¶
type WriteJob struct {
// contains filtered or unexported fields
}
WriteJob is a single write request queued for serialised execution.
type WriteResult ¶
type WriteResult struct {
Result json.RawMessage
Error error
}
WriteResult is the outcome of a serialised write operation.