Back to godoc.org

Package changeset

v0.0.0-...-9649366
Latest Go to latest

The highest tagged major version is .

Published: Nov 21, 2019 | License: Apache-2.0 | Module: github.com/chronosphereiox/m3

Index

Variables

var (
	// ErrAlreadyCommitted is returned when attempting to commit an already
	// committed ChangeSet
	ErrAlreadyCommitted = errors.New("change list already committed")

	// ErrCommitInProgress is returned when attempting to commit a change set
	// that is already being committed
	ErrCommitInProgress = errors.New("commit in progress")

	// ErrChangeSetClosed is returned when attempting to make a change to a
	// closed (committed / commit in progress) ChangeSet
	ErrChangeSetClosed = errors.New("change set closed")

	// ErrUnknownVersion is returned when attempting to commit a change for
	// a version that doesn't exist
	ErrUnknownVersion = errors.New("unknown version")
)

type ApplyFn

type ApplyFn func(config, changes proto.Message) error

An ApplyFn applies a set of changes to a configuration, resulting in a new configuration

type ChangeFn

type ChangeFn func(config, changes proto.Message) error

A ChangeFn adds a change to an existing set of changes

type Manager

type Manager interface {
	// Change creates a new change against the latest configuration, adding it
	// to the set of pending changes for that configuration
	Change(change ChangeFn) error

	// GetPendingChanges gets the latest uncommitted changes
	GetPendingChanges() (int, proto.Message, proto.Message, error)

	// Commit commits the specified ChangeSet, transforming the configuration on
	// which they are based into a new configuration, and storing that new
	// configuration as a next versions. Ensures that changes are applied as a
	// batch, are not applied more than once, and that new changes are not
	// started while a commit is underway
	Commit(version int, apply ApplyFn) error
}

A Manager manages sets of changes in a version friendly manager. Changes to a given version of a configuration object are stored under <key>/_changes/<version>. Multiple changes can be added, then committed all at once. Committing transforms the configuration according to the changes, then writes the configuration back. CAS operations are used to ensure that commits are not applied more than once, and to avoid conflicts on the change object itself.

func NewManager

func NewManager(opts ManagerOptions) (Manager, error)

NewManager creates a new change list Manager

type ManagerOptions

type ManagerOptions interface {
	// KV is the KVStore holding the configuration
	SetKV(kv kv.Store) ManagerOptions
	KV() kv.Store

	// ConfigKey is the key holding the configuration object
	SetConfigKey(key string) ManagerOptions
	ConfigKey() string

	// Logger is the logger to use
	SetLogger(logger *zap.Logger) ManagerOptions
	Logger() *zap.Logger

	// ConfigType is a proto.Message defining the structure of the configuration
	// object.  Clones of this proto will be used to unmarshal configuration
	// instances
	SetConfigType(config proto.Message) ManagerOptions
	ConfigType() proto.Message

	// ChangesType is a proto.Message defining the structure of the changes
	// object.  Clones of this protol will be used to unmarshal change list
	// instances.
	SetChangesType(changes proto.Message) ManagerOptions
	ChangesType() proto.Message

	// Validate validates the options
	Validate() error
}

ManagerOptions are options used in creating a new ChangeSet Manager

func NewManagerOptions

func NewManagerOptions() ManagerOptions

NewManagerOptions creates an empty ManagerOptions

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier