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 ¶
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 ¶
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 ¶
NewBatch returns a batch for one settle's commands, on the store the queue sends to.
func (*Queue) Settle ¶
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.
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.