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 ¶
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 WithPollInterval ¶
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.