Documentation
¶
Overview ¶
Package postgres implements storage.Storage using PostgreSQL via pgx.
Index ¶
- Variables
- type Storage
- func (s *Storage) AcquireLock(ctx context.Context, key int64) (func(), error)
- func (s *Storage) ActivateSnapshot(ctx context.Context, collection, version string) error
- func (s *Storage) AppliedInstances(ctx context.Context, collection, version, status string) ([]string, error)
- func (s *Storage) CountApplied(ctx context.Context, collection, version string) (int, error)
- func (s *Storage) DeleteOldSnapshots(ctx context.Context, olderThan time.Time) (int, error)
- func (s *Storage) FailSnapshot(ctx context.Context, collection, version string) error
- func (s *Storage) GetActiveSnapshot(ctx context.Context, collection string) (*storage.Snapshot, error)
- func (s *Storage) GetActiveVersion(ctx context.Context, collection string) (string, error)
- func (s *Storage) GetSnapshot(ctx context.Context, collection, version string) (*storage.Snapshot, error)
- func (s *Storage) LogApply(ctx context.Context, instanceID, collection, version, status string) error
- func (s *Storage) Migrate(ctx context.Context) error
- func (s *Storage) ResetApplyLog(ctx context.Context, collection, version string) error
- func (s *Storage) SaveSnapshot(ctx context.Context, collection, version string, content []byte) error
Constants ¶
This section is empty.
Variables ¶
var MigrationSQL string
Functions ¶
This section is empty.
Types ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements storage.Storage using PostgreSQL.
func NewStorage ¶
NewStorage creates a new PostgreSQL-backed Storage.
func (*Storage) AcquireLock ¶
AcquireLock attempts to acquire a Postgres session-level advisory lock. Returns a release function if acquired. The caller must call release when done. Returns storage.ErrLockNotAcquired if the lock is already held by another session.
func (*Storage) ActivateSnapshot ¶
ActivateSnapshot marks the given snapshot as active and demotes any previously active snapshot for the same collection to inactive.
func (*Storage) AppliedInstances ¶ added in v1.1.0
func (s *Storage) AppliedInstances(ctx context.Context, collection, version, status string) ([]string, error)
AppliedInstances returns the instance IDs that logged the given status for (collection, version).
func (*Storage) CountApplied ¶
CountApplied returns the number of instances that successfully applied a version.
func (*Storage) DeleteOldSnapshots ¶ added in v1.1.0
DeleteOldSnapshots removes snapshots created before olderThan, except those in the 'active' status (which are preserved regardless of age so the cluster can always recover the current authoritative version).
In the same transaction, apply-log rows for the deleted snapshot versions are removed. Returns the number of snapshots deleted.
func (*Storage) FailSnapshot ¶
FailSnapshot marks a snapshot as failed.
func (*Storage) GetActiveSnapshot ¶
func (s *Storage) GetActiveSnapshot(ctx context.Context, collection string) (*storage.Snapshot, error)
GetActiveSnapshot returns the currently active snapshot for a collection.
func (*Storage) GetActiveVersion ¶ added in v1.2.0
GetActiveVersion returns just the version string of the active snapshot, without fetching the full content. Used by followers for cheap version comparison during self-heal checks.
func (*Storage) GetSnapshot ¶
func (s *Storage) GetSnapshot(ctx context.Context, collection, version string) (*storage.Snapshot, error)
GetSnapshot returns a specific snapshot by collection and version.
func (*Storage) LogApply ¶
func (s *Storage) LogApply(ctx context.Context, instanceID, collection, version, status string) error
LogApply records that an instance has applied (or failed to apply) a config version. Uses upsert so repeated calls are idempotent.
func (*Storage) ResetApplyLog ¶ added in v1.1.0
ResetApplyLog deletes all apply-log rows for (collection, version).