Back to godoc.org
go.etcd.io/etcd / store

Package store

v0.2.0
Latest Go to latest

The latest major version is .

Published: Dec 23, 2013 | License: Apache-2.0 | Module: go.etcd.io/etcd

Index

Constants

const (
	Get            = "get"
	Create         = "create"
	Set            = "set"
	Update         = "update"
	Delete         = "delete"
	CompareAndSwap = "compareAndSwap"
	Expire         = "expire"
)
const (
	SetSuccess = iota
	SetFail
	DeleteSuccess
	DeleteFail
	CreateSuccess
	CreateFail
	UpdateSuccess
	UpdateFail
	CompareAndSwapSuccess
	CompareAndSwapFail
	GetSuccess
	GetFail
	ExpireCount
)

Variables

var Permanent time.Time

func MaxVersion

func MaxVersion() int

MaxVersion returns the maximum compatible store version.

func MinVersion

func MinVersion() int

MinVersion returns the minimum compatible store version.

func RegisterCommandFactory

func RegisterCommandFactory(factory CommandFactory)

RegisterCommandFactory adds a command factory to the global registry.

func TTL

func TTL(duration string) (time.Time, error)

Convert string duration to time format

type CommandFactory

type CommandFactory interface {
	Version() int
	CreateUpgradeCommand() raft.Command
	CreateSetCommand(key string, dir bool, value string, expireTime time.Time) raft.Command
	CreateCreateCommand(key string, dir bool, value string, expireTime time.Time, unique bool) raft.Command
	CreateUpdateCommand(key string, value string, expireTime time.Time) raft.Command
	CreateDeleteCommand(key string, dir, recursive bool) raft.Command
	CreateCompareAndSwapCommand(key string, value string, prevValue string,
		prevIndex uint64, expireTime time.Time) raft.Command
	CreateSyncCommand(now time.Time) raft.Command
}

The CommandFactory provides a way to create different types of commands depending on the current version of the store.

func GetCommandFactory

func GetCommandFactory(version int) CommandFactory

GetCommandFactory retrieves a command factory for a given command version.

type Event

type Event struct {
	Action string      `json:"action"`
	Node   *NodeExtern `json:"node,omitempty"`
}

func (*Event) Index

func (e *Event) Index() uint64

func (*Event) IsCreated

func (e *Event) IsCreated() bool

func (*Event) Response

func (event *Event) Response(currentIndex uint64) interface{}

Converts an event object into a response object.

type EventHistory

type EventHistory struct {
	Queue      eventQueue
	StartIndex uint64
	LastIndex  uint64
	// contains filtered or unexported fields
}

type NodeExtern

type NodeExtern struct {
	Key           string      `json:"key, omitempty"`
	PrevValue     string      `json:"-"`
	Value         string      `json:"value,omitempty"`
	Dir           bool        `json:"dir,omitempty"`
	Expiration    *time.Time  `json:"expiration,omitempty"`
	TTL           int64       `json:"ttl,omitempty"`
	Nodes         NodeExterns `json:"nodes,omitempty"`
	ModifiedIndex uint64      `json:"modifiedIndex,omitempty"`
	CreatedIndex  uint64      `json:"createdIndex,omitempty"`
}

NodeExtern is the external representation of the internal node with additional fields PrevValue is the previous value of the node TTL is time to live in second

type NodeExterns

type NodeExterns []NodeExtern

func (NodeExterns) Len

func (ns NodeExterns) Len() int

interfaces for sorting

func (NodeExterns) Less

func (ns NodeExterns) Less(i, j int) bool

func (NodeExterns) Swap

func (ns NodeExterns) Swap(i, j int)

type Response

type Response struct {
	Action    string `json:"action"`
	Key       string `json:"key"`
	Dir       bool   `json:"dir,omitempty"`
	PrevValue string `json:"prevValue,omitempty"`
	Value     string `json:"value,omitempty"`

	// If the key did not exist before the action,
	// this field should be set to true
	NewKey bool `json:"newKey,omitempty"`

	Expiration *time.Time `json:"expiration,omitempty"`

	// Time to live in second
	TTL int64 `json:"ttl,omitempty"`

	// The command index of the raft machine when the command is executed
	Index uint64 `json:"index"`
}

The response from the store to the user who issue a command

type Stats

type Stats struct {

	// Number of get requests
	GetSuccess uint64 `json:"getsSuccess"`
	GetFail    uint64 `json:"getsFail"`

	// Number of sets requests
	SetSuccess uint64 `json:"setsSuccess"`
	SetFail    uint64 `json:"setsFail"`

	// Number of delete requests
	DeleteSuccess uint64 `json:"deleteSuccess"`
	DeleteFail    uint64 `json:"deleteFail"`

	// Number of update requests
	UpdateSuccess uint64 `json:"updateSuccess"`
	UpdateFail    uint64 `json:"updateFail"`

	// Number of create requests
	CreateSuccess uint64 `json:"createSuccess"`
	CreateFail    uint64 `json:"createFail"`

	// Number of testAndSet requests
	CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"`
	CompareAndSwapFail    uint64 `json:"compareAndSwapFail"`

	ExpireCount uint64 `json:"expireCount"`

	Watchers uint64 `json:"watchers"`
}

func (*Stats) Inc

func (s *Stats) Inc(field int)

func (*Stats) TotalReads

func (s *Stats) TotalReads() uint64

func (*Stats) TotalTranscations

func (s *Stats) TotalTranscations() uint64

type Store

type Store interface {
	Version() int
	CommandFactory() CommandFactory
	Index() uint64

	Get(nodePath string, recursive, sorted bool) (*Event, error)
	Set(nodePath string, dir bool, value string, expireTime time.Time) (*Event, error)
	Update(nodePath string, newValue string, expireTime time.Time) (*Event, error)
	Create(nodePath string, dir bool, value string, unique bool,
		expireTime time.Time) (*Event, error)
	CompareAndSwap(nodePath string, prevValue string, prevIndex uint64,
		value string, expireTime time.Time) (*Event, error)
	Delete(nodePath string, recursive, dir bool) (*Event, error)
	Watch(prefix string, recursive bool, sinceIndex uint64) (<-chan *Event, error)

	Save() ([]byte, error)
	Recovery(state []byte) error

	TotalTransactions() uint64
	JsonStats() []byte
	DeleteExpiredKeys(cutoff time.Time)
}

func New

func New() Store

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