segmentstore

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 16 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 owns the stores of the dynamic segments of the relay: the connections of the bootstrap file that can serve segments, how and when each is dialled, and what the segments see while one is down. It is core: it knows no client library and no kind of store by name.

A kind of store is a Kind, an adapter in its own package (`redisdial`, `valkeydial`); the relay passes the kinds it serves in Options.Kinds. A kind states the segment.StoreCapabilities of its provider package, and a Plan for each connection: its dialer and its bounds. This package holds what all kinds share: the table of connections, the lookup by name, one client for each connection, the dial loop, the states, the logs and the shutdown.

Nothing is opened until a generation binds a connection.

Index

Constants

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")
	// ErrUnavailable is wrapped by the error of a dial that did not end within its bound: the store did not answer in
	// time, like a store that cannot be reached.
	ErrUnavailable = errors.New("segment store unavailable")
)
View Source
var ErrDuplicateKind = errors.New("two kinds of segment store have the same type")

ErrDuplicateKind is returned by NewKinds for two kinds of the same type: the list of kinds is written once, by the program that wires the relay, so a type twice is a mistake of the program.

Functions

func New

func New(cfg *bootstrap.Config, kinds Kinds) flagruntime.StoreTable

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

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. Nil options are the zero Options.

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 Env added in v1.5.0

type Env struct {
	// Tracing are the OpenTelemetry providers that the client is built with; the zero value is tracing off.
	Tracing tracing.Providers
	// Secrets reads the secrets and the files of the connection.
	Secrets bootstrap.LoadOptions
}

Env is what the process gives every kind to build its clients with.

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 Kind added in v1.5.0

type Kind interface {
	// Type is the type of the connections of the kind in the bootstrap file ("redis").
	Type() string
	// Capabilities is what the store of the kind serves, as its provider package states it.
	Capabilities() segment.StoreCapabilities
	// Plan says how to connect conn, a connection of this Type. It opens nothing: the dialer of the plan does, when
	// the connection is first needed.
	Plan(conn *bootstrap.Connection, env Env) Plan
}

Kind is the adapter of one kind of connection (redis, valkey): the port of this package. It is the only thing that knows the client library of the kind. The relay is given the kinds it serves as a value (Options.Kinds, made by NewKinds); a kind that is not given cannot serve segments. A new kind is one package that implements Kind and one entry in that list.

type Kinds added in v1.5.0

type Kinds map[string]Kind

Kinds are the kinds of store that the relay serves, by their type.

func NewKinds added in v1.5.0

func NewKinds(kinds ...Kind) (Kinds, error)

NewKinds returns the kinds by type. Two kinds of one type are an error that names the type.

type Options

type Options struct {
	Tracing       *tracing.Providers
	Logger        *slog.Logger
	Dialers       map[string]Dialer
	Timer         func(time.Duration) <-chan time.Time
	Kinds         Kinds
	Secrets       bootstrap.LoadOptions
	RetryInterval time.Duration
}

Options configure Connections.

type Plan added in v1.5.0

type Plan struct {
	// Dial connects the connection. Nil means that the connection cannot be dialled.
	Dial Dialer
	// DialBound ends a dial attempt that does not return. Zero means [dialkit.DefaultDialBound].
	DialBound time.Duration
	// LookupBound is the lookupTimeout of the connection: the wait of a lookup for the first dial. Zero means
	// [bootstrap.DefaultLookupTimeout].
	LookupBound time.Duration
}

Plan is how one connection is connected and bounded.

Directories

Path Synopsis
Package dialkit is what the dial packages of the kinds of segment store share: the TLS configuration of a connection, the class of a failed dial, and the bounds and timeouts of a connection.
Package dialkit is what the dial packages of the kinds of segment store share: the TLS configuration of a connection, the class of a failed dial, and the bounds and timeouts of a connection.
Package dialtest is the test support of the kinds of segment store (`segmentstore.Kind`): a loopback store that speaks enough RESP for go-redis and valkey-go, and the cases that every kind must pass, run by the tests of each kind (`redisdial`, `valkeydial`) in its own package, so that each is measured by its own tests.
Package dialtest is the test support of the kinds of segment store (`segmentstore.Kind`): a loopback store that speaks enough RESP for go-redis and valkey-go, and the cases that every kind must pass, run by the tests of each kind (`redisdial`, `valkeydial`) in its own package, so that each is measured by its own tests.
Package redisdial is the go-redis adapter of the segment store port: the segmentstore.Kind of the connections of type redis.
Package redisdial is the go-redis adapter of the segment store port: the segmentstore.Kind of the connections of type redis.
Package valkeydial is the valkey-go adapter of the segment store port: the segmentstore.Kind of the connections of type valkey.
Package valkeydial is the valkey-go adapter of the segment store port: the segmentstore.Kind of the connections of type valkey.

Jump to

Keyboard shortcuts

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