Documentation ¶
Index ¶
- Constants
- Variables
- func TTL(duration string) (time.Time, error)
- type CompareAndSwapCommand
- type CreateCommand
- type DeleteCommand
- 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) Expire()
- func (n *Node) GetChild(name string) (*Node, *etcdErr.Error)
- func (n *Node) IsDir() bool
- func (n *Node) IsExpired() (bool, time.Duration)
- 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, term uint64) *etcdErr.Error
- type Response
- type SetCommand
- type Stats
- type Store
- type UpdateCommand
Constants ¶
const ( Get = "get" Create = "create" Set = "set" Update = "update" Delete = "delete" CompareAndSwap = "compareAndSwap" Expire = "expire" )
const ( UndefIndex = 0 UndefTerm = 0 )
const ( SetSuccess = iota SetFail DeleteSuccess DeleteFail CreateSuccess CreateFail UpdateSuccess UpdateFail CompareAndSwapSuccess CompareAndSwapFail GetSuccess GetFail ExpireCount )
Variables ¶
var (
Permanent time.Time
)
Functions ¶
Types ¶
type CompareAndSwapCommand ¶
type CompareAndSwapCommand struct { Key string `json:"key"` Value string `json:"value"` ExpireTime time.Time `json:"expireTime"` PrevValue string `json: prevValue` PrevIndex uint64 `json: prevIndex` }
The CompareAndSwap performs a conditional update on a key in the store.
func (*CompareAndSwapCommand) Apply ¶
func (c *CompareAndSwapCommand) Apply(server raft.Server) (interface{}, error)
Set the key-value pair if the current value of the key equals to the given prevValue
func (*CompareAndSwapCommand) CommandName ¶
func (c *CompareAndSwapCommand) CommandName() string
The name of the testAndSet command in the log
type CreateCommand ¶
type CreateCommand struct { Key string `json:"key"` Value string `json:"value"` ExpireTime time.Time `json:"expireTime"` Unique bool `json:"unique"` }
Create command
func (*CreateCommand) Apply ¶
func (c *CreateCommand) Apply(server raft.Server) (interface{}, error)
Create node
func (*CreateCommand) CommandName ¶
func (c *CreateCommand) CommandName() string
The name of the create command in the log
type DeleteCommand ¶
The DeleteCommand removes a key from the Store.
func (*DeleteCommand) Apply ¶
func (c *DeleteCommand) Apply(server raft.Server) (interface{}, error)
Delete the key
func (*DeleteCommand) CommandName ¶
func (c *DeleteCommand) CommandName() string
The name of the delete command in the log
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 // The command index of the raft machine when the command is executed Index uint64 `json:"index"` Term uint64 `json:"term"` }
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"` KVPairs kvPairs `json:"kvs,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 CreateTerm uint64 ModifiedIndex uint64 ModifiedTerm uint64 Parent *Node `json:"-"` // should not encode this field! avoid cyclical 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) Expire ¶
func (n *Node) Expire()
Expire function will test if the node is expired. if the node is already expired, delete the node and return. if the node is permanent (this shouldn't happen), return at once. else wait for a period time, then remove the node. and notify the watchhub.
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 SetCommand ¶
type SetCommand struct { Key string `json:"key"` Value string `json:"value"` ExpireTime time.Time `json:"expireTime"` }
Create command
func (*SetCommand) Apply ¶
func (c *SetCommand) Apply(server raft.Server) (interface{}, error)
Create node
func (*SetCommand) CommandName ¶
func (c *SetCommand) CommandName() string
The name of the create command in the log
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) TotalWrites ¶
type Store ¶
type Store interface { Get(nodePath string, recursive, sorted bool, index uint64, term uint64) (*Event, error) Set(nodePath string, value string, expireTime time.Time, index uint64, term uint64) (*Event, error) Update(nodePath string, newValue string, expireTime time.Time, index uint64, term uint64) (*Event, error) Create(nodePath string, value string, incrementalSuffix bool, expireTime time.Time, index uint64, term uint64) (*Event, error) CompareAndSwap(nodePath string, prevValue string, prevIndex uint64, value string, expireTime time.Time, index uint64, term uint64) (*Event, error) Delete(nodePath string, recursive bool, index uint64, term uint64) (*Event, error) Watch(prefix string, recursive bool, sinceIndex uint64, index uint64, term uint64) (<-chan *Event, error) Save() ([]byte, error) Recovery(state []byte) error JsonStats() []byte }
type UpdateCommand ¶
type UpdateCommand struct { Key string `json:"key"` Value string `json:"value"` ExpireTime time.Time `json:"expireTime"` }
Update command
func (*UpdateCommand) Apply ¶
func (c *UpdateCommand) Apply(server raft.Server) (interface{}, error)
Create node
func (*UpdateCommand) CommandName ¶
func (c *UpdateCommand) CommandName() string
The name of the update command in the log