swap

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 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 swap manages atomic state-table version pointers for backfill cutover.

The lambda-replay backfill pattern:

  1. Live pipeline writes to "<alias>_v<N>" (e.g. "page_views_v3").
  2. Backfill replay job runs into a fresh "<alias>_v<N+1>" — independent of live.
  3. When replay completes, the operator (or automation) calls Manager.SetActive to atomically advance the alias pointer.
  4. Query layer rolls / refreshes; clients now see results from v<N+1>.
  5. Old v<N> is dropped after a grace period.

The control table is a single DDB table holding one row per alias:

pk:    "<alias>"   (S)
ver:   <version>   (N)
at:    <unix-ms>   (N)  — last update timestamp

SetActive uses a conditional UpdateExpression so concurrent swap attempts can't regress (only ver > current-ver is accepted).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoActiveVersion = errors.New("swap: no active version for alias")

ErrNoActiveVersion is returned by GetActive when no pointer has been set yet for the alias.

View Source
var ErrVersionRegressed = errors.New("swap: cannot regress version")

ErrVersionRegressed is returned by SetActive when the requested version is not strictly greater than the current active version.

Functions

func CreateControlTable

func CreateControlTable(ctx context.Context, client *dynamodb.Client, controlTable string) error

CreateControlTable creates the control table with the schema expected by Manager. Production tables should be created via Terraform; this helper exists for tests and dev-loop convenience.

func TableName

func TableName(alias string, version int64) string

TableName renders "<alias>_v<version>" for state-table naming consistency.

Types

type Manager

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

Manager reads and writes version pointers in the control table.

func New

func New(client *dynamodb.Client, controlTable string) *Manager

New constructs a Manager. The control table must already exist; CreateControlTable is the convenience helper.

func (*Manager) GetActive

func (m *Manager) GetActive(ctx context.Context, alias string) (int64, error)

GetActive returns the current active version for alias. Returns ErrNoActiveVersion if none has been set.

func (*Manager) Resolve

func (m *Manager) Resolve(ctx context.Context, alias string) (string, error)

Resolve combines GetActive with TableName: returns "<alias>_v<active>" or, if no version has been set, "<alias>_v1" as the implicit-bootstrap convention.

func (*Manager) SetActive

func (m *Manager) SetActive(ctx context.Context, alias string, newVersion int64) error

SetActive atomically advances the alias pointer to newVersion. Refuses to regress — returns ErrVersionRegressed when newVersion is not strictly greater than the current version. The first SetActive call (no prior version) always succeeds.

Jump to

Keyboard shortcuts

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