wire

package
v0.0.0-...-406b1e7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(metaStruct meta.Struct, existing any, diff Diff, validate ValidateFn) (any, error)

Decode deserializes a database update by applying the difference to the existing entity.

Returns nil if there are no effective changes. Otherwise, returns a modified copy of the existing entity or a new entity if existing is nil. Const fields can only be modified when existing is nil.

If a validate function is specified, it is called for every modified field; it should return an error if changing the field is not allowed.

Types

type ActiveObject

type ActiveObject struct {
	Kind  string
	TS    time.Time // last updated
	Props Diff
}

ActiveObject is a record in the hot start file representing an object in the active set

type ActiveSetHeader

type ActiveSetHeader struct {
	Version  int
	Position Position
}

ActiveSetHeader is the header of the hot start file

type Changes

type Changes map[string]KindChanges // kind -> ID -> diff

Changes is a set of diffs organized by kind and ID

func (Changes) Clone

func (c Changes) Clone() Changes

Clone returns a deep copy of the Changes

func (Changes) MarshalLogObject

func (c Changes) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of Changes with zap.Object

func (Changes) Optimize

func (c Changes) Optimize()

Optimize removes empty diffs and maps from the changes

type Diff

type Diff map[string]json.RawMessage

A Diff represents a patch to an entity. It is a mapping from a field name to its new value (serialized as JSON).

func Encode

func Encode(metaStruct meta.Struct, before, after any, validate ValidateFn) (Diff, error)

Encode serializes a database update by encoding the difference between two entities, the first of which can be nil.

Returns nil if there is no difference.

If a validate function is specified, it is called for every modified field; it should return an error if changing the field is not allowed.

func (Diff) Clone

func (d Diff) Clone() Diff

Clone returns a deep copy of the Diff

func (Diff) MarshalLogObject

func (d Diff) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of Diff with zap.Object

type ErrMismatch

type ErrMismatch string

ErrMismatch is an error type for fatal problems: * database version mismatch * position continuity broken

const ErrContinuityBroken ErrMismatch = "continuity broken"

ErrContinuityBroken is an ErrMismatch error that happens when a client tries to resume reading transactions from a position that is no longer valid

func ErrVersionMismatch

func ErrVersionMismatch(expected, actual int) ErrMismatch

ErrVersionMismatch returns an ErrMismatch error for the situation when the database version doesn't match the expectation

func (ErrMismatch) Error

func (err ErrMismatch) Error() string

func (ErrMismatch) ExitCode

func (ErrMismatch) ExitCode() int

ExitCode fulfils run.WithExitCode.

ErrMismatch is expected during database maintenance such as a version upgrade. To distinguish is from other errors, it causes the process to exit with code 100.

type Filter

type Filter map[string][]string

Filter describes a filter for relevant kinds and property names.

The map has an entry for each kind, with the kind name as key and the list of relevant property names as value.

A nil value of a map entry means all properties of the kind are relevant.

A nil value of the map itself means all properties of all kinds are relevant.

type IncomingTransaction

type IncomingTransaction struct {
	Transaction
	Position Position
}

IncomingTransaction is a transaction annotated by its position. Wire format only.

func (IncomingTransaction) MarshalLogObject

func (txn IncomingTransaction) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of IncomingTransaction with zap.Object

type KindChanges

type KindChanges map[string]Diff // ID -> diff

KindChanges is a set of diffs organized by ID, for a single kind

func (KindChanges) Clone

func (kc KindChanges) Clone() KindChanges

Clone returns a deep copy of the KindChanges

func (KindChanges) MarshalLogArray

func (kc KindChanges) MarshalLogArray(e zapcore.ArrayEncoder) error

MarshalLogArray implements zapcore.ArrayMarshaler to allow logging of KindChanges with zap.Object

func (KindChanges) Optimize

func (kc KindChanges) Optimize()

Optimize removes empty diffs from the KindChanges

type Manifest

type Manifest struct {
	Version int
	Topic   string

	Maintenance bool `json:",omitempty"` // If true, only maintenance tools are allowed to touch the database

	Audit json.RawMessage `json:",omitempty"` // extra metadata; exact format decoupled from Limestone
}

Manifest describes where the transaction log is stored

func (Manifest) MarshalLogObject

func (m Manifest) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of Manifest with zap.Object

type Notification

type Notification struct {
	// Reports a fatal error. The server disconnects immediately after.
	Err ErrMismatch `json:",omitempty"`

	// An incoming transaction
	Txn *IncomingTransaction `json:",omitempty"`

	// The hot end of the stream has been reached
	Hot bool `json:",omitempty"`
}

Notification is a packet sent from server to client

If more than one of the properties are present, the packet is equivalent to several packets containing one each, in the order in which they are declared below.

func (Notification) MarshalLogObject

func (n Notification) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of Notification with zap.Object

type Position

type Position string

A Position is an opaque token that can be used to resume reading from a known location

const Beginning Position = ""

Beginning is the Position value that means to read from the beginning of the history

type Request

type Request struct {
	Version int
	Last    Position
	Filter  Filter
	Compact bool // OK to collapse series of transactions and strip events
}

A Request is sent from client to server as the mandatory first WS message

type Source

type Source struct {
	Producer meta.Producer `json:",omitempty"` // Generic service name
	Instance string        `json:",omitempty"` // Optional string that makes the pair unique (e.g. shard ID)
}

Source describes the submitter of a database update

func (Source) MarshalLogObject

func (s Source) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of Source with zap.Object

type Transaction

type Transaction struct {
	// Timestamp override
	//
	// When submitting new transactions, leave empty.
	// When reading, assume out-of-band message timestamp if empty.
	// When converting history, set to original transaction timestamp.
	//
	// If set, must precede out-of-band message timestamp.
	// Must be monotonic.
	TS *time.Time `json:",omitempty"`

	Source  Source `json:",omitempty"`
	Session int64  `json:",omitempty"` // for echo cancellation

	Changes Changes

	Audit json.RawMessage `json:",omitempty"` // remote IP, session ID etc; exact format decoupled from Limestone
}

Transaction is a storage and wire representation of a Limestone transaction

func (Transaction) MarshalLogObject

func (txn Transaction) MarshalLogObject(e zapcore.ObjectEncoder) error

MarshalLogObject implements zapcore.ObjectMarshaler to allow logging of Transaction with zap.Object

type ValidateFn

type ValidateFn func(index int, before, after reflect.Value) error

A ValidateFn receives the index of a field within meta.Struct.Fields along with its old and new values, and has a chance to fail encoding or decoding by returning an error. When creating a new entity, before is a reflection of the zero value of the field type.

Jump to

Keyboard shortcuts

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