sync

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package sync provides source/target synchronization with conflict policies. The memory engine is suitable for demos and tests; production adapters supply cursors over their own stores.

Index

Constants

View Source
const DefaultMaxKeys = 4096

DefaultMaxKeys bounds in-memory demo stores.

Variables

View Source
var (
	ErrInvalidArg    = errors.New("sync: invalid argument")
	ErrConflict      = errors.New("sync: conflict")
	ErrManual        = errors.New("sync: manual resolution required")
	ErrNotFound      = errors.New("sync: not found")
	ErrBoundExceeded = errors.New("sync: bound exceeded")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Policy    ConflictPolicy
	MaxManual int // bound queued manual keys (0 = 256)
}

Config configures an Engine.

type ConflictPolicy

type ConflictPolicy string

ConflictPolicy selects how source/target disagreements are resolved.

const (
	PreferSource ConflictPolicy = "prefer-source"
	PreferTarget ConflictPolicy = "prefer-target"
	PreferLatest ConflictPolicy = "prefer-latest"
	Manual       ConflictPolicy = "manual"
	Reject       ConflictPolicy = "reject"
)

type Cursor

type Cursor struct {
	Position string
	Updated  time.Time
}

Cursor tracks progress through a source.

type Engine

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

Engine runs sync passes.

func New

func New(cfg Config) (*Engine, error)

New creates a sync engine.

func (*Engine) Cursor

func (e *Engine) Cursor() Cursor

Cursor returns the current cursor.

func (*Engine) ManualKeys

func (e *Engine) ManualKeys() []string

ManualKeys returns keys awaiting operator resolution.

func (*Engine) Sync

func (e *Engine) Sync(ctx context.Context, src Source, dst Target, limit int) (Result, error)

Sync pulls from source and applies to target per policy.

type MemoryStore

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

MemoryStore is an in-process Source and Target for demos/tests.

func NewMemoryStore

func NewMemoryStore(max int) *MemoryStore

NewMemoryStore creates a bounded memory store.

func (*MemoryStore) Get

func (m *MemoryStore) Get(_ context.Context, key string) (Record, bool, error)

Get returns a record.

func (*MemoryStore) Len

func (m *MemoryStore) Len() int

Len returns entry count.

func (*MemoryStore) Next

func (m *MemoryStore) Next(_ context.Context, cur Cursor, limit int) ([]Record, Cursor, error)

Next implements Source by scanning keys after cursor position.

func (*MemoryStore) Put

func (m *MemoryStore) Put(_ context.Context, rec Record) error

Put upserts a record.

type Record

type Record struct {
	Key       string
	Value     string
	UpdatedAt time.Time
	Version   uint64
}

Record is a syncable item (no secret values).

type Result

type Result struct {
	Applied   int      `json:"applied"`
	Skipped   int      `json:"skipped"`
	Rejected  int      `json:"rejected"`
	Manual    []string `json:"manual,omitempty"`
	Cursor    Cursor   `json:"cursor"`
	Conflicts int      `json:"conflicts"`
}

Result summarizes one Sync pass.

type Source

type Source interface {
	Next(ctx context.Context, cur Cursor, limit int) ([]Record, Cursor, error)
}

Source reads records after a cursor.

type Target

type Target interface {
	Get(ctx context.Context, key string) (Record, bool, error)
	Put(ctx context.Context, rec Record) error
}

Target applies records and reports existing values for conflict checks.

Jump to

Keyboard shortcuts

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