segmentstore

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 20 Imported by: ? modules, 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 segmentstore tells the relay which kinds of connection of the bootstrap file can serve segments, and in which modes. It is the only place of the relay that names the kinds of store: the reconcile engine asks the flagruntime.SegmentStores it returns and never looks at a kind.

Nothing is opened here. A kind is described by the type that serves it (redissegment.Provider for redis, valkeysegment.Provider for valkey); the types are only inspected for the segment interfaces they implement, so a store that gains a mode is seen without a change to this package.

Index

Constants

View Source
const (
	DefaultDialBound = 5 * time.Second
	DefaultReadBound = 3 * time.Second
)

DefaultDialBound is the bound of one dial when timeouts.connect is unset: the default dial timeout of go-redis and valkey-go. DefaultReadBound is the default read timeout of go-redis.

View Source
const DefaultRetryInterval = time.Second

DefaultRetryInterval is how often a connection that is needed and not connected is dialled again.

Variables

View Source
var (

	// ErrNotConnected is the error of a lookup on a connection that is not connected yet: the lookups stay Unknown
	// and the segments answer STORE_ERROR until the connection is up.
	ErrNotConnected = errors.New("the segment store is not connected")
	// ErrUnknownConnection is returned by Bind for a name that is not a connection of the bootstrap file.
	ErrUnknownConnection = errors.New("not a connection of the bootstrap file")
	// ErrCannotServe is returned by Bind for a connection whose kind cannot serve segments.
	ErrCannotServe = errors.New("the connection cannot serve segments")
)

Functions

func New

New describes the connections of a bootstrap configuration: every connection by name, with its kind and, for a kind that serves segments, the type that serves it. A configuration without connections gives an empty table.

func RedisOptions

RedisOptions is the go-redis option of a connection: the addresses, the credentials, TLS and the timeouts. The relay and the segment tool of the CLI dial with it.

func ValkeyClientOption

func ValkeyClientOption(
	conn *bootstrap.ValkeyConnection,
	secrets bootstrap.LoadOptions,
) (valkey.ClientOption, time.Duration, error)

ValkeyClientOption is the valkey-go option of a connection: the address, the credentials, TLS and the timeouts. The relay and the segment tool of the CLI dial with it. The second result is the lookup timeout of the connection.

Types

type ConnectionState

type ConnectionState struct {
	// Name is the name in the bootstrap file.
	Name string `json:"name"`
	// Kind is the type of the connection.
	Kind string `json:"kind"`
	// State is "idle" (no segment uses it), "connecting", "connected", "error" (the last dial failed) or "closed"
	// (after Shutdown).
	State string `json:"state"`
	// FirstDialPending is true while the connection is needed, the dial loop runs and its first dial has no outcome
	// yet (neither a client nor an error). The readiness waits for it; it is not part of the JSON.
	FirstDialPending bool `json:"-"`
}

ConnectionState is what /info and the metrics tell of one connection.

type Connections

type Connections struct {
	flagruntime.StoreTable
	// contains filtered or unexported fields
}

Connections owns the stores of the process: one client for each connection of the bootstrap file that a valid dynamic definition uses, dialled when it is first needed, by the loop of Connections.Run, and closed by Connections.Shutdown. A store that is down never stops the relay: its segments answer not a member, STORE_ERROR, until it is back. It is a flagruntime.SegmentStores and a flagruntime.SegmentBinder.

func NewConnections

func NewConnections(cfg *bootstrap.Config, opts Options) *Connections

NewConnections describes the connections of the bootstrap file and prepares their dialers. It opens nothing.

func (*Connections) Bind

func (c *Connections) Bind(
	connection string, missing segment.MissingKey, defs []flagruntime.BoundDefinition,
) (*flagruntime.Binding, error)

Bind implements flagruntime.SegmentBinder. It marks the connection as needed and returns at once: the lookups are answered when the connection is up.

func (*Connections) Run

func (c *Connections) Run(ctx context.Context)

Run dials the connections that are needed and not connected, now and every retry interval, until ctx ends. It is owned by the run context of the relay.

func (*Connections) Shutdown

func (c *Connections) Shutdown(_ context.Context) error

Shutdown closes the clients. It is called with a fresh context, after the loops ended; a connection that is being dialled when it is called is closed as soon as the dial returns.

func (*Connections) States

func (c *Connections) States() []ConnectionState

States returns the state of each connection that can serve segments, sorted by name.

type Dialer

type Dialer func(ctx context.Context) (Handle, error)

Dialer connects one connection. It must honour the context.

type Handle

type Handle interface {
	// Bind returns the binding of the definitions, with a missing key read as missing says.
	Bind(missing segment.MissingKey, defs []flagruntime.BoundDefinition) (*flagruntime.Binding, error)
	// Close closes the client.
	Close() error
}

Handle is a connected store: the client of one connection, shared by every generation. It binds the definitions of a generation to a provider that reads through the client; closing the provider of a generation never closes it.

type Options

type Options struct {
	// Logger receives the connect and the failure of a connection. Nil discards.
	Logger *slog.Logger
	// Dialers replaces the dialer of a connection by name (a test, an embedder); a connection without one is
	// dialled by the kind it names.
	Dialers map[string]Dialer
	// Timer replaces the timer of the wait for a first dial ([time.After] when nil); a test drives it. The wait is
	// bounded by the lookupTimeout of the connection and by the context of the lookup.
	Timer func(time.Duration) <-chan time.Time
	// Secrets reads the secrets and the files of the connections.
	Secrets bootstrap.LoadOptions
	// RetryInterval is how often the connections that are needed and down are dialled. Zero means
	// [DefaultRetryInterval].
	RetryInterval time.Duration
}

Options configure Connections.

Jump to

Keyboard shortcuts

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