Documentation ¶
Index ¶
- Constants
- Variables
- func MaxVersion() int
- func MinVersion() int
- func RegisterCommandFactory(factory CommandFactory)
- func TTL(duration string) (time.Time, error)
- type CommandFactory
- type Event
- type EventHistory
- type KeyValuePair
- type Node
- func (n *Node) Add(child *Node) *etcdErr.Error
- func (n *Node) Clone() *Node
- func (n *Node) ExpirationAndTTL() (*time.Time, int64)
- func (n *Node) GetChild(name string) (*Node, *etcdErr.Error)
- func (n *Node) IsDir() bool
- func (n *Node) IsHidden() bool
- func (n *Node) IsPermanent() bool
- func (n *Node) List() ([]*Node, *etcdErr.Error)
- func (n *Node) Pair(recurisive, sorted bool) KeyValuePair
- func (n *Node) Read() (string, *etcdErr.Error)
- func (n *Node) Remove(recursive bool, callback func(path string)) *etcdErr.Error
- func (n *Node) UpdateTTL(expireTime time.Time)
- func (n *Node) Write(value string, index uint64) *etcdErr.Error
- type Response
- type Stats
- type Store
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
Functions ¶
func MaxVersion ¶ added in v0.2.0
func MaxVersion() int
MaxVersion returns the maximum compatible store version.
func MinVersion ¶ added in v0.2.0
func MinVersion() int
MinVersion returns the minimum compatible store version.
func RegisterCommandFactory ¶ added in v0.2.0
func RegisterCommandFactory(factory CommandFactory)
RegisterCommandFactory adds a command factory to the global registry.
Types ¶
type CommandFactory ¶ added in v0.2.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.2.0
func GetCommandFactory(version int) CommandFactory
GetCommandFactory retrieves a command factory for a given command version.
type Event ¶ added in v0.2.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"` }
type EventHistory ¶ added in v0.2.0
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 ¶
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 ¶
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) GetChild ¶
GetChild function returns the child node under the directory node. On success, it returns the file node
func (*Node) IsDir ¶
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 ¶
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 ¶
IsPermanent function checks if the node is a permanent one.
func (*Node) List ¶
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 ¶
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.
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.2.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) TotalReads ¶ added in v0.2.0
func (*Stats) TotalTranscations ¶ added in v0.2.0
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) }