store

package
v0.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2013 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var Permanent time.Time

Functions

func MaxVersion added in v0.3.0

func MaxVersion() int

MaxVersion returns the maximum compatible store version.

func MinVersion added in v0.3.0

func MinVersion() int

MinVersion returns the minimum compatible store version.

func RegisterCommandFactory added in v0.3.0

func RegisterCommandFactory(factory CommandFactory)

RegisterCommandFactory adds a command factory to the global registry.

func TTL added in v0.3.0

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

Convert string duration to time format

Types

type CommandFactory added in v0.3.0

type CommandFactory interface {
	Version() int
	CreateUpgradeCommand() raft.Command
	CreateSetCommand(key string, value string, expireTime time.Time) raft.Command
	CreateCreateCommand(key string, value string, expireTime time.Time, unique bool) raft.Command
	CreateUpdateCommand(key string, value string, expireTime time.Time) raft.Command
	CreateDeleteCommand(key string, 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 added in v0.3.0

func GetCommandFactory(version int) CommandFactory

GetCommandFactory retrieves a command factory for a given command version.

type Event added in v0.3.0

type Event struct {
	Action        string     `json:"action"`
	Key           string     `json:"key, omitempty"`
	Dir           bool       `json:"dir,omitempty"`
	PrevValue     string     `json:"prevValue,omitempty"`
	Value         string     `json:"value,omitempty"`
	KVPairs       kvPairs    `json:"kvs,omitempty"`
	Expiration    *time.Time `json:"expiration,omitempty"`
	TTL           int64      `json:"ttl,omitempty"` // Time to live in second
	ModifiedIndex uint64     `json:"modifiedIndex"`
}

func (*Event) Index added in v0.3.0

func (e *Event) Index() uint64

func (*Event) IsCreated added in v0.3.0

func (e *Event) IsCreated() bool

func (*Event) Response added in v0.3.0

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

Converts an event object into a response object.

type EventHistory added in v0.3.0

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

type KeyValuePair

type KeyValuePair struct {
	Key           string     `json:"key, omitempty"`
	Value         string     `json:"value,omitempty"`
	Dir           bool       `json:"dir,omitempty"`
	Expiration    *time.Time `json:"expiration,omitempty"`
	TTL           int64      `json:"ttl,omitempty"` // Time to live in second
	KVPairs       kvPairs    `json:"kvs,omitempty"`
	ModifiedIndex uint64     `json:"modifiedIndex,omitempty"`
}

When user list a directory, we add all the node into key-value pair slice

type Node

type Node struct {
	Path string

	CreateIndex   uint64
	ModifiedIndex uint64

	Parent *Node `json:"-"` // should not encode this field! avoid circular dependency.

	ExpireTime time.Time
	ACL        string
	Value      string           // for key-value pair
	Children   map[string]*Node // for directory
	// contains filtered or unexported fields
}

Node is the basic element in the store system. A key-value pair will have a string value A directory will have a children map

func (*Node) Add

func (n *Node) Add(child *Node) *etcdErr.Error

Add function adds a node to the receiver node. If the receiver is not a directory, a "Not A Directory" error will be returned. If there is a existing node with the same name under the directory, a "Already Exist" error will be returned

func (*Node) Clone

func (n *Node) Clone() *Node

Clone function clone the node recursively and return the new node. If the node is a directory, it will clone all the content under this directory. If the node is a key-value pair, it will clone the pair.

func (*Node) ExpirationAndTTL

func (n *Node) ExpirationAndTTL() (*time.Time, int64)

func (*Node) GetChild

func (n *Node) GetChild(name string) (*Node, *etcdErr.Error)

GetChild function returns the child node under the directory node. On success, it returns the file node

func (*Node) IsDir

func (n *Node) IsDir() bool

IsDir function checks whether the node is a directory. If the node is a directory, the function will return true. Otherwise the function will return false.

func (*Node) IsHidden

func (n *Node) IsHidden() bool

IsHidden function checks if the node is a hidden node. A hidden node will begin with '_' A hidden node will not be shown via get command under a directory For example if we have /foo/_hidden and /foo/notHidden, get "/foo" will only return /foo/notHidden

func (*Node) IsPermanent

func (n *Node) IsPermanent() bool

IsPermanent function checks if the node is a permanent one.

func (*Node) List

func (n *Node) List() ([]*Node, *etcdErr.Error)

List function return a slice of nodes under the receiver node. If the receiver node is not a directory, a "Not A Directory" error will be returned.

func (*Node) Pair

func (n *Node) Pair(recurisive, sorted bool) KeyValuePair

func (*Node) Read

func (n *Node) Read() (string, *etcdErr.Error)

Read function gets the value of the node. If the receiver node is not a key-value pair, a "Not A File" error will be returned.

func (*Node) Remove

func (n *Node) Remove(recursive bool, callback func(path string)) *etcdErr.Error

Remove function remove the node.

func (*Node) UpdateTTL

func (n *Node) UpdateTTL(expireTime time.Time)

func (*Node) Write

func (n *Node) Write(value string, index uint64) *etcdErr.Error

Write function set the value of the node to the given value. If the receiver node is a directory, a "Not A File" error will be returned.

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 added in v0.3.0

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 added in v0.3.0

func (s *Stats) Inc(field int)

func (*Stats) TotalReads added in v0.3.0

func (s *Stats) TotalReads() uint64

func (*Stats) TotalTranscations added in v0.3.0

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, value string, expireTime time.Time) (*Event, error)
	Update(nodePath string, newValue string, expireTime time.Time) (*Event, error)
	Create(nodePath string, value string, incrementalSuffix bool,
		expireTime time.Time) (*Event, error)
	CompareAndSwap(nodePath string, prevValue string, prevIndex uint64,
		value string, expireTime time.Time) (*Event, error)
	Delete(nodePath string, recursive 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 added in v0.3.0

func New() Store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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