coordinator

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateHeaderObject   = HeaderType('S')
	MessageHeaderObject = HeaderType('M')
	JobHeaderObject     = HeaderType('J')
)
View Source
const (
	PrimaryIndex   = IndexType(1)
	SecondaryIndex = IndexType(2)
)
View Source
const (
	OrderNone = Order(0)
	OrderAsc  = Order(1)
	OrderDesc = Order(2)
)

Order options.

View Source
const (
	CBOR = DocumentType(1)
)
View Source
const (
	Unknown = "unknown"
)
View Source
const (
	V1 = Version(1)
)

Variables

View Source
var (
	ErrInvalid      = errors.New("invalid")
	ErrNotExist     = errors.New("not exist")
	ErrNotSupported = errors.New("not supported")
	ErrNoMessage    = errors.New("no message")
)
View Source
var (
	StateObjectKeyHeader   = [2]byte{byte(StateHeaderObject), byte(byte(CBOR) | HeaderByteFromVersion(V1))}
	MessageObjectKeyHeader = [2]byte{byte(MessageHeaderObject), byte(byte(CBOR) | HeaderByteFromVersion(V1))}
	JobObjectKeyHeader     = [2]byte{byte(JobHeaderObject), byte(byte(CBOR) | HeaderByteFromVersion(V1))}
)
View Source
var NoLimit = int(0)

NoLimit represents a no limit option.

View Source
var NoOffset = uint(0)

NoOffset represents a no offset option.

Functions

func GetAllHeaderPrefixes added in v1.0.0

func GetAllHeaderPrefixes() [][]byte

GetAllHeaderPrefixes returns all header prefixes.

func HeaderByteFromVersion added in v1.0.0

func HeaderByteFromVersion(v Version) byte

func NewErrNotSupported added in v0.9.0

func NewErrNotSupported(v any) error

func NewErrObjectNotSupported added in v1.0.0

func NewErrObjectNotSupported(v any) error

func NewKeyNotExistError

func NewKeyNotExistError(v any) error

func TypeFromHeaderByte added in v1.0.0

func TypeFromHeaderByte(b byte) byte

Types

type Coordinator

type Coordinator interface {
	Store
	cluster.Node
	// SetNode sets the coordinator node.
	SetNode(node cluster.Node)
	// SetStateObject sets the state object for the specified key.
	SetStateObject(t StateType, obj Object) error
	// GetObject gets the object for the specified key and state type.
	GetStateObject(t StateType, key Key) (Object, error)
	// GetRangeObjects gets the result set for the specified key and state type.
	GetStateObjects(t StateType) (ResultSet, error)
	// PostMessage posts the specified message to the coordinator.
	PostMessage(msg Message) error
	// AddObserver adds the specified observer to the coordinator.
	AddObserver(observer Observer) error
}

Coordinator represents a coordination service.

type DocumentType added in v1.0.0

type DocumentType byte

DocumentType represents a document type.

type EventType

type EventType byte

EventType represents a coordinator event type.

const (
	// CreatedEvent represents a created event.
	CreatedEvent EventType = 'C'
	// UpdatedEvent represents a object updated event.
	UpdatedEvent EventType = 'U'
	// DeletedEvent represents a object deleted event.
	DeletedEvent EventType = 'O'
)

func (EventType) String added in v0.9.0

func (t EventType) String() string

String returns the string representation of the message event type.

type HeaderType added in v1.0.0

type HeaderType byte

func GetAllHeaderTypes added in v1.0.0

func GetAllHeaderTypes() []HeaderType

GetAllHeaderTypes returns all header types.

type IndexType added in v1.0.0

type IndexType byte

IndexType represents an index type.

type Key

type Key = document.Key

Key represents an unique key for a key-value object.

func NewKey

func NewKey() Key

NewKey returns a new blank key.

func NewKeyWith

func NewKeyWith(elems ...any) Key

NewKeyWith returns a new key from the specified key elements.

func NewMessageKeyWith added in v1.0.0

func NewMessageKeyWith(msg Message, clock cluster.Clock) Key

NewMessageKeyWith returns a new message key with the specified message.

func NewMessageScanKey added in v1.0.0

func NewMessageScanKey() Key

NewMessageScanKey returns a new scan message key to get the latest message clock.

func NewScanStateKeyWith added in v1.0.0

func NewScanStateKeyWith(t StateType) Key

NewScanStateKeyWith returns a new state key with the specified state type for the scan.

func NewStateKeyWith added in v1.0.0

func NewStateKeyWith(t StateType, elems ...any) Key

NewStateKey returns a new state key.

type KeyCoder added in v1.0.0

type KeyCoder interface {
	KeyDecoder
	KeyEncoder
}

A KeyCoder includes key decoder and encoder interfaces.

type KeyDecoder added in v1.0.0

type KeyDecoder interface {
	// DecodeKey returns the decoded key from the specified bytes if available, otherwise returns an error.
	DecodeKey([]byte) (Key, error)
}

An KeyDecoder decodes the specified bytes.

type KeyEncoder added in v1.0.0

type KeyEncoder interface {
	// EncodeKey returns the encoded bytes from the specified key if available, otherwise returns an error.
	EncodeKey(Key) ([]byte, error)
}

An KeyEncoder encodes the specified key.

type KeyHeader added in v1.0.0

type KeyHeader [2]byte

KeyHeader represents a header for all keys.

func NewKeyHeaderFrom added in v1.0.0

func NewKeyHeaderFrom(b []byte) KeyHeader

NewKeyHeader creates a new key header from the specified bytes.

func (KeyHeader) Bytes added in v1.0.0

func (header KeyHeader) Bytes() []byte

Bytes returns a byte array.

func (KeyHeader) DocumentType added in v1.0.0

func (header KeyHeader) DocumentType() DocumentType

DocumentType returns a document type.

func (KeyHeader) IndexType added in v1.0.0

func (header KeyHeader) IndexType() IndexType

IndexType returns an index type.

func (KeyHeader) String added in v1.0.0

func (header KeyHeader) String() string

String returns a string.

func (KeyHeader) Type added in v1.0.0

func (header KeyHeader) Type() HeaderType

Type returns a header type.

func (KeyHeader) Version added in v1.0.0

func (header KeyHeader) Version() Version

Version returns a version.

type LimitOption added in v1.0.0

type LimitOption struct {
	Limit int
}

LimitOption represents a limit option.

func NewLimitOption added in v1.0.0

func NewLimitOption(limit int) *LimitOption

NewLimitOption returns a new limit option.

type Message

type Message interface {
	// Clock returns the message clock.
	Clock() cluster.Clock
	// From returns the destination node of the message.
	From() cluster.Node
	// Type returns the message type.
	Type() MessageType
	// Event returns the message event type.
	Event() EventType
	// Object returns the object of the message.
	Object() (any, error)
	// UnmarshalTo unmarshals the object value to the specified object.
	UnmarshalTo(to any) error
	// Equals returns true if the message is equal to the specified event.
	Equals(Message) bool
	// String returns the string representation of the message.
	String() string
}

Message represents a coordinator event.

func NewMessageFrom added in v1.0.0

func NewMessageFrom(obj *MessageObject) Message

NewMessageFrom returns a new message with the specified message object.

func NewMessageWith

func NewMessageWith(t MessageType, e EventType, obj any) (Message, error)

NewMessageWith returns a new message with the specified type and object.

type MessageObject added in v1.0.0

type MessageObject struct {
	FromID      uuid.UUID
	FromCluster string
	FromHost    string
	MsgClock    uint64
	MsgType     byte
	EvtType     byte
	EncBytes    []byte
}

MessageObject represents a message object.

func NewMessageObject added in v1.0.0

func NewMessageObject() *MessageObject

NewMessageObject returns a new empty message.

func NewMessageObjectWith added in v1.0.0

func NewMessageObjectWith(msg Message, node cluster.Node, clock cluster.Clock) (*MessageObject, error)

NewMessageObjectWith returns a new message value with the specified message.

func (*MessageObject) Clock added in v1.0.0

func (obj *MessageObject) Clock() cluster.Clock

Clock returns the message clock.

func (*MessageObject) Equals added in v1.0.0

func (obj *MessageObject) Equals(other Message) bool

Equals returns true if the message is equal to the specified message.

func (*MessageObject) Event added in v1.0.0

func (obj *MessageObject) Event() EventType

EventType returns the message event type.

func (*MessageObject) From added in v1.0.0

func (obj *MessageObject) From() cluster.Node

From returns the destination node of the message.

func (*MessageObject) ID added in v1.0.0

func (obj *MessageObject) ID() uuid.UUID

ID returns the message ID.

func (*MessageObject) Object added in v1.0.0

func (obj *MessageObject) Object() (any, error)

Object returns the object of the message.

func (*MessageObject) String added in v1.0.0

func (obj *MessageObject) String() string

String returns the string representation of the message.

func (*MessageObject) Type added in v1.0.0

func (obj *MessageObject) Type() MessageType

Type returns the message type.

func (*MessageObject) UnmarshalTo added in v1.0.0

func (obj *MessageObject) UnmarshalTo(to any) error

UnmarshalTo unmarshals the object value to the specified object.

type MessageType

type MessageType byte

MessageType represents a coordinator message type.

const (
	// ObjectMessage represents a object message type.
	ObjectMessage MessageType = 'O'
	// DatabaseMessage represents a database message type.
	DatabaseMessage MessageType = 'D'
	// CollectionMessage represents a schema message type.
	CollectionMessage MessageType = 'C'
	// UserMessage represents a user message type.
	UserMessage MessageType = 'U'
)

func (MessageType) String added in v1.0.0

func (t MessageType) String() string

String returns the string representation of the message type.

type Object

type Object interface {
	// Key returns the object key.
	Key() Key
	// Bytes returns the encoded object value.
	Bytes() []byte
	// Unmarshal unmarshals the object value to the specified object.
	Unmarshal(toj any) error
	// Equals returns true if the object is equal to the specified object.
	Equals(Object) bool
	// String returns the string representation.
	String() string
}

Object represents a key-value object.

func NewObjectFrom added in v1.0.0

func NewObjectFrom(key Key, val any) (Object, error)

NewObjectFrom creates a new object with the specified key and value.

func NewObjectWith

func NewObjectWith(key Key, bytes []byte) Object

NewObjectWith creates a new object with the specified key and value.

type Observer

type Observer interface {
	// OnMessageReceived is called when a message is received.
	OnMessageReceived(msg Message)
}

Observer is an interface to receive a message.

type OffsetOption added in v1.0.0

type OffsetOption struct {
	Offset uint
}

OffsetOption represents an offset option.

func NewOffsetOption added in v1.0.0

func NewOffsetOption(offset uint) *OffsetOption

NewLimitOption returns a new offset option.

type Option added in v1.0.0

type Option = any

Option represents a option.

type Order added in v1.0.0

type Order = int

Order represents a order.

type OrderOption added in v1.0.0

type OrderOption struct {
	Order Order
}

OrderOption represents a order option.

func NewOrderOptionWith added in v1.0.0

func NewOrderOptionWith(order Order) *OrderOption

NewOrderOptionWith returns a new order option.

type ResultSet

type ResultSet interface {
	// Next moves the cursor forward next object from its current position.
	Next() bool
	// Object returns an object in the current position.
	Object() Object
	// Object returns all objects in the result set.
	Objects() []Object
}

ResultSet represents a result set which includes range operation results.

type StateType added in v1.0.0

type StateType uint8

StateType is a type of the state object.

const (
	// NodeState represents a node state type.
	NodeState StateType = 1
)

func (StateType) String added in v1.0.0

func (t StateType) String() string

String returns a string representation of the state type.

type Store added in v1.0.0

type Store interface {
	// SetKeyCoder sets the key coder.
	SetKeyCoder(coder KeyCoder)
	// DecodeKey returns the decoded key from the specified bytes if available, otherwise returns an error.
	DecodeKey([]byte) (Key, error)
	// EncodeKey returns the encoded bytes from the specified key if available, otherwise returns an error.
	EncodeKey(Key) ([]byte, error)
	// Transact begin a new transaction.
	Transact() (Transaction, error)
}

Store represents a coordination store inteface.

type Transaction

type Transaction interface {
	// Set sets the object for the specified key.
	Set(obj Object) error
	// Get gets the object for the specified key.
	Get(key Key) (Object, error)
	// GetRange gets the result set for the specified key.
	GetRange(key Key, opts ...Option) (ResultSet, error)
	// Remove removes the object for the specified key.
	Remove(key Key) error
	// Commit commits this transaction.
	Commit() error
	// Cancel cancels this transaction.
	Cancel() error
	// Truncate removes all objects.
	Truncate() error
}

Transaction represents a transaction interface.

type Version added in v1.0.0

type Version byte

Version represents a version.

func VertionFromHeaderByte added in v1.0.0

func VertionFromHeaderByte(b byte) Version

Jump to

Keyboard shortcuts

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