Documentation ¶
Index ¶
- Constants
- Variables
- func GetAllHeaderPrefixes() [][]byte
- func HeaderByteFromVersion(v Version) byte
- func NewErrNotSupported(v any) error
- func NewErrObjectNotSupported(v any) error
- func NewKeyNotExistError(v any) error
- func TypeFromHeaderByte(b byte) byte
- type Coordinator
- type DocumentType
- type EventType
- type HeaderType
- type IndexType
- type Key
- type KeyCoder
- type KeyDecoder
- type KeyEncoder
- type KeyHeader
- type LimitOption
- type Message
- type MessageObject
- func (obj *MessageObject) Clock() cluster.Clock
- func (obj *MessageObject) Equals(other Message) bool
- func (obj *MessageObject) Event() EventType
- func (obj *MessageObject) From() cluster.Node
- func (obj *MessageObject) ID() uuid.UUID
- func (obj *MessageObject) Object() (any, error)
- func (obj *MessageObject) String() string
- func (obj *MessageObject) Type() MessageType
- func (obj *MessageObject) UnmarshalTo(to any) error
- type MessageType
- type Object
- type Observer
- type OffsetOption
- type Option
- type Order
- type OrderOption
- type ResultSet
- type StateType
- type Store
- type Transaction
- type Version
Constants ¶
const ( StateHeaderObject = HeaderType('S') MessageHeaderObject = HeaderType('M') JobHeaderObject = HeaderType('J') )
const ( PrimaryIndex = IndexType(1) SecondaryIndex = IndexType(2) )
const ( OrderNone = Order(0) OrderAsc = Order(1) OrderDesc = Order(2) )
Order options.
const (
CBOR = DocumentType(1)
)
const (
Unknown = "unknown"
)
const (
V1 = Version(1)
)
Variables ¶
var ( ErrInvalid = errors.New("invalid") ErrNotExist = errors.New("not exist") ErrNotSupported = errors.New("not supported") ErrNoMessage = errors.New("no message") )
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))} )
var NoLimit = int(0)
NoLimit represents a no limit option.
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 NewErrNotSupported ¶ added in v0.9.0
func NewErrObjectNotSupported ¶ added in v1.0.0
func NewKeyNotExistError ¶
func TypeFromHeaderByte ¶ added in v1.0.0
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 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 Key ¶
Key represents an unique key for a key-value object.
func NewKeyWith ¶
NewKeyWith returns a new key from the specified key elements.
func NewMessageKeyWith ¶ added in v1.0.0
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
NewScanStateKeyWith returns a new state key with the specified state type for the scan.
func NewStateKeyWith ¶ added in v1.0.0
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
NewKeyHeader creates a new key header from the specified bytes.
func (KeyHeader) DocumentType ¶ added in v1.0.0
func (header KeyHeader) DocumentType() DocumentType
DocumentType returns a document type.
func (KeyHeader) Type ¶ added in v1.0.0
func (header KeyHeader) Type() HeaderType
Type returns a header type.
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
NewObjectFrom creates a new object with the specified key and value.
func NewObjectWith ¶
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 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 )
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.