clustersync

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package clustersync propagates admin configuration changes between gateway instances that share one database.

Admin-managed configuration is durable in the database but served from in-memory snapshots on each instance. Every successful admin write bumps a per-entity revision in the config_revisions table; every instance polls that tiny table and refreshes the snapshot of each entity whose revision moved. It needs nothing but the shared database, so it works the same on SQLite, PostgreSQL, and MongoDB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoDBStore

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

MongoDBStore keeps configuration revisions in MongoDB.

func NewMongoDBStore

func NewMongoDBStore(database *mongo.Database) (*MongoDBStore, error)

NewMongoDBStore uses the shared config_revisions collection.

func (*MongoDBStore) Bump

func (s *MongoDBStore) Bump(ctx context.Context, entity string) error

Bump increments entity's revision. $inc on an upsert keyed by _id is atomic on the document, so concurrent bumps never lose an increment.

func (*MongoDBStore) Revisions

func (s *MongoDBStore) Revisions(ctx context.Context) (map[string]int64, error)

Revisions returns every stored revision.

type SQLStore

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

SQLStore keeps configuration revisions in SQLite or PostgreSQL.

func NewSQLStore

func NewSQLStore(ctx context.Context, db sqlx.DB) (*SQLStore, error)

NewSQLStore initializes the shared config_revisions table.

func (*SQLStore) Bump

func (s *SQLStore) Bump(ctx context.Context, entity string) error

Bump increments entity's revision. The upsert is a single statement, so concurrent bumps from several instances never lose an increment.

func (*SQLStore) Revisions

func (s *SQLStore) Revisions(ctx context.Context) (map[string]int64, error)

Revisions returns every stored revision.

type Store

type Store interface {
	// Bump atomically increments the revision of entity, creating it at 1.
	Bump(ctx context.Context, entity string) error
	// Revisions returns the current revision of every entity bumped so far.
	Revisions(ctx context.Context) (map[string]int64, error)
}

Store persists one revision counter per entity in the shared database.

type Syncer

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

Syncer polls the revision table and refreshes changed entities.

func New

func New(ctx context.Context, shared storage.Storage) (*Syncer, error)

New opens the revision store on the shared storage connection. Call it before the services it refreshes load their snapshots: see NewSyncer.

func NewSyncer

func NewSyncer(ctx context.Context, store Store) (*Syncer, error)

NewSyncer records the current revisions as already applied. Taking them before the services load means a change made while they load is refreshed on the first tick, and nothing is refreshed needlessly at startup.

func (*Syncer) Close

func (s *Syncer) Close() error

Close stops polling and waits for a tick in progress to finish.

func (*Syncer) Entities

func (s *Syncer) Entities() []string

Entities lists the registered entities in refresh order.

func (*Syncer) Notifier

func (s *Syncer) Notifier(entity string) func(context.Context)

Notifier returns the function a service calls after each successful admin write of entity. A failed announcement is logged and retried on every tick until one succeeds, not returned: the write itself succeeded and this instance already serves it.

func (*Syncer) Register

func (s *Syncer) Register(entity string, refresh func(context.Context) error)

Register sets how entity's snapshot is reloaded when another instance (or this one) changes it. Entities refresh in registration order. Register every entity before Start.

func (*Syncer) Start

func (s *Syncer) Start(ctx context.Context)

Start polls until Close or until ctx ends. It does nothing while a poller runs; once ctx has ended, as when the server it was started for failed to start, a later Start polls again.

Jump to

Keyboard shortcuts

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