Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: MIT Imports: 2 Imported by: 123

README

State Stores

State Stores provide a common way to interact with different data store implementations, and allow users to opt-in to advanced capabilities using defined metadata.

Currently supported state stores are:

  • AWS DynamoDB
  • Azure CosmosDB
  • Azure Table Storage
  • Cassandra
  • Cloud Firestore (Datastore mode)
  • CloudState
  • Couchbase
  • Etcd
  • HashiCorp Consul
  • Hazelcast
  • Memcached
  • MongoDB
  • Redis
  • SQL Server
  • Zookeeper
  • Cloud Firestore (Datastore mode)
  • Couchbase

Implementing a new State Store

A compliant state store needs to implement one or more interfaces: Store and TransactionalStore.

The interface for Store:

type Store interface {
	Init(metadata Metadata) error
	Delete(req *DeleteRequest) error
	BulkDelete(req []DeleteRequest) error
	Get(req *GetRequest) (*GetResponse, error)
	Set(req *SetRequest) error
	BulkSet(req []SetRequest) error
}

The interface for TransactionalStore:

type TransactionalStore interface {
	Init(metadata Metadata) error
	Multi(reqs []TransactionalRequest) error
}

See the documentation repo for examples.

Documentation

Index

Constants

View Source
const (
	FirstWrite  = "first-write"
	LastWrite   = "last-write"
	Strong      = "strong"
	Eventual    = "eventual"
	Exponential = "exponential"
	Linear      = "linear"
)

Variables

This section is empty.

Functions

func CheckDeleteRequestOptions

func CheckDeleteRequestOptions(req *DeleteRequest) error

CheckDeleteRequestOptions checks if delete request options use supported keywords

func CheckSetRequestOptions

func CheckSetRequestOptions(req *SetRequest) error

CheckSetRequestOptions checks if set request options use supported keywords

func DeleteWithRetries

func DeleteWithRetries(method func(req *DeleteRequest) error, req *DeleteRequest) error

DeleteWithRetries handles SetRequest with retries

func SetWithRetries

func SetWithRetries(method func(req *SetRequest) error, req *SetRequest) error

SetWithRetries handles SetRequest with retries

Types

type DeleteRequest

type DeleteRequest struct {
	Key      string            `json:"key"`
	ETag     string            `json:"etag,omitempty"`
	Metadata map[string]string `json:"metadata"`
	Options  DeleteStateOption `json:"options,omitempty"`
}

DeleteRequest is the object describing a delete state request

func (DeleteRequest) GetKey added in v0.2.0

func (r DeleteRequest) GetKey() string

Key gets the Key on a DeleteRequest

func (DeleteRequest) GetMetadata added in v0.2.0

func (r DeleteRequest) GetMetadata() map[string]string

Metadata gets the Metadata on a DeleteRequest

type DeleteStateOption

type DeleteStateOption struct {
	Concurrency string      `json:"concurrency,omitempty"` //"concurrency"
	Consistency string      `json:"consistency"`           //"eventual, strong"
	RetryPolicy RetryPolicy `json:"retryPolicy,omitempty"`
}

DeleteStateOption controls how a state store reacts to a delete request

type GetRequest

type GetRequest struct {
	Key      string            `json:"key"`
	Metadata map[string]string `json:"metadata"`
	Options  GetStateOption    `json:"options,omitempty"`
}

GetRequest is the object describing a state fetch request

type GetResponse

type GetResponse struct {
	Data     []byte            `json:"data"`
	ETag     string            `json:"etag,omitempty"`
	Metadata map[string]string `json:"metadata"`
}

GetResponse is the request object for getting state

type GetStateOption

type GetStateOption struct {
	Consistency string `json:"consistency"` //"eventual, strong"
}

GetStateOption controls how a state store reacts to a get request

type KeyInt added in v0.2.0

type KeyInt interface {
	GetKey() string
	GetMetadata() map[string]string
}

KeyInt is an interface that allows gets of the Key and Metadata inside requests

type Metadata

type Metadata struct {
	Properties map[string]string `json:"properties"`
}

Metadata contains a state store specific set of metadata properties

type OperationType

type OperationType string

OperationType describes a CRUD operation performed against a state store

const Delete OperationType = "delete"

Delete is a delete operation

const Upsert OperationType = "upsert"

Upsert is an update or create operation

type RetryPolicy

type RetryPolicy struct {
	Interval  time.Duration `json:"interval"`
	Threshold int           `json:"threshold"`
	Pattern   string        `json:"pattern,omitempty"` //linear, exponential
}

RetryPolicy describes how retries should be handled

type SetRequest

type SetRequest struct {
	Key      string            `json:"key"`
	Value    interface{}       `json:"value"`
	ETag     string            `json:"etag,omitempty"`
	Metadata map[string]string `json:"metadata"`
	Options  SetStateOption    `json:"options,omitempty"`
}

SetRequest is the object describing an upsert request

func (SetRequest) GetKey added in v0.2.0

func (r SetRequest) GetKey() string

Key gets the Key on a SetRequest

func (SetRequest) GetMetadata added in v0.2.0

func (r SetRequest) GetMetadata() map[string]string

Metadata gets the Key on a SetRequest

type SetStateOption

type SetStateOption struct {
	Concurrency string      `json:"concurrency,omitempty"` //first-write, last-write
	Consistency string      `json:"consistency"`           //"eventual, strong"
	RetryPolicy RetryPolicy `json:"retryPolicy,omitempty"`
}

SetStateOption controls how a state store reacts to a set request

type Store

type Store interface {
	Init(metadata Metadata) error
	Delete(req *DeleteRequest) error
	BulkDelete(req []DeleteRequest) error
	Get(req *GetRequest) (*GetResponse, error)
	Set(req *SetRequest) error
	BulkSet(req []SetRequest) error
}

Store is an interface to perform operations on store

type TransactionalRequest

type TransactionalRequest struct {
	Operation OperationType `json:"operation"`
	Request   interface{}   `json:"request"`
}

TransactionalRequest describes a transactional operation against a state store that comprises multiple types of operations The Request field is either a DeleteRequest or SetRequest

type TransactionalStore

type TransactionalStore interface {
	Init(metadata Metadata) error
	Multi(reqs []TransactionalRequest) error
}

TransactionalStore is an interface for initialization and support multiple transactional requests

Directories

Path Synopsis
aws
azure
gcp
hashicorp
Package zookeeper is a generated GoMock package.
Package zookeeper is a generated GoMock package.

Jump to

Keyboard shortcuts

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