settle

package
v0.30.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package settle coalesces the post-flight writes of many served requests into shared round trips on the post-flight store: a collector groups queued settles into batches, sent once full or a short delay after their first, and a few writers send each batch as one pipelined round trip.

Scope: queueing, batching, the full and closed queue fallbacks, resending a settle whose shared round trip failed in transport, and draining at close. Out of scope: what a settle writes; the limiter's commits and the key pool's success write queue themselves on the batch.

Expected kv ops per request: none of its own. A settle's writes ride a shared pipelined round trip, or one of their own when the queue is full or closed; a settle with nothing to write makes none and does not wait. One whose round trip failed in transport has its limit commits sent once more on their own; the key's success write is never resent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransportError

func TransportError(err error) bool

TransportError reports a command failure after which whether the command ran is unknown: the store took it and never answered, or the deadline ran out.

Types

type Config

type Config struct {
	// BatchSize is the most settles one round trip carries.
	BatchSize int
	// MaxDelay is how long the first settle of a batch waits for others; 0 sends what is already queued.
	MaxDelay time.Duration
	// QueueSize bounds the settles waiting for a writer; one that finds it full goes out on its own round trip.
	QueueSize int
	// PoolSize is the post-flight store's connection pool size; 0 if it has none.
	PoolSize int
}

Config sizes the queue. A QueueSize of 0 leaves it off: every settle goes out on a round trip of its own.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue coalesces settles. Concurrent calls are safe.

func New

func New(store kv.Store, cfg Config, log *slog.Logger) *Queue

New returns a queue sending batches on store, or nil when cfg.QueueSize is 0. Call Start before serving and Close at shutdown.

func (*Queue) Close

func (q *Queue) Close()

Close stops taking settles and waits for every queued and in-flight one to land, as long as the writers need to send them all with a resend each (drainTimeout). It logs how many it gave up on. Settle keeps working afterwards, on round trips of its own.

func (*Queue) NewBatch

func (q *Queue) NewBatch() *kv.Batch

NewBatch returns a batch for one settle's commands, on the store the queue sends to.

func (*Queue) Settle

func (q *Queue) Settle(ctx context.Context, b *kv.Batch, w Writes)

Settle sends the commands w queued on b, a batch from NewBatch, in a shared round trip and returns once they landed. A full or closed queue sends them on a round trip of their own; a settle that queued nothing returns at once. A caller that leaves first does not lose the settle: it still lands.

func (*Queue) Start

func (q *Queue) Start()

Start runs the collector and the writers until Close.

type Writes

type Writes interface {
	// TransportFailed reports whether a command failed in transport rather than with its own error reply: whether it ran is unknown.
	TransportFailed() bool
	// Finish reads the outcome once the batch has run.
	Finish(ctx context.Context)
	// Resend writes again, on a round trip of its own, what is safe to repeat: the limit commits, which the commit guard makes a no-op where the first send ran. A write that would apply twice is not sent again; Resend reads its first outcome instead.
	Resend(ctx context.Context)
}

Writes is one settle's commands queued on a batch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL