cluster

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 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 cluster keeps state that lives in memory consistent across API replicas. Today that is the generated GraphQL schema: when one replica changes a collection, every other replica must rebuild its schema.

Index

Constants

View Source
const (
	// DefaultChannel carries "something changed" notifications.
	DefaultChannel = "gohead:schema:changed"
	// DefaultVersionKey is a counter bumped on every change. Replicas poll it
	// so that a notification missed during a Redis disconnect is not lost.
	DefaultVersionKey = "gohead:schema:version"
	// DefaultPollInterval bounds how stale a replica can get when pub/sub
	// messages are lost.
	DefaultPollInterval = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*SchemaSync)

Option customizes a SchemaSync (mainly for tests).

func WithKeys

func WithKeys(channel, versionKey string) Option

WithKeys changes the channel and version key names.

func WithPollInterval

func WithPollInterval(d time.Duration) Option

WithPollInterval changes how often the version key is checked.

type SchemaSync

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

SchemaSync broadcasts schema changes between replicas. A nil Redis client makes it a no-op, which is correct for a single replica.

func NewSchemaSync

func NewSchemaSync(rdb *redis.Client, opts ...Option) *SchemaSync

NewSchemaSync returns a SchemaSync using rdb (which may be nil).

func (*SchemaSync) InstanceID

func (s *SchemaSync) InstanceID() string

InstanceID identifies this replica in notifications.

func (*SchemaSync) Notify

func (s *SchemaSync) Notify(ctx context.Context) error

Notify tells the other replicas that the schema changed. The caller is expected to have rebuilt its own schema already. If Redis is unreachable, the announcement is retried by Run until it succeeds, so a change made during an outage still reaches the other replicas.

func (*SchemaSync) Run

func (s *SchemaSync) Run(ctx context.Context, reload func() error)

Run listens for changes made by other replicas and calls reload for each, until ctx is cancelled. It also polls the version key, so a replica that missed a message (Redis restart, network blip) catches up within one poll interval. Run returns immediately when there is no Redis client.

Jump to

Keyboard shortcuts

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