store

package
v0.2.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 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 (
	UndefIndex = 0
	UndefTerm  = 0
)
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 TTL added in v0.2.0

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

Convert string duration to time format

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

type DeleteCommand struct {
	Key       string `json:"key"`
	Recursive bool   `json:"recursive"`
}

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"`
}

func (*Event) Response added in v0.2.0

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

Converts an event object into a response object.

type EventHistory added in v0.2.0

type EventHistory struct {
	Queue      eventQueue
	StartIndex uint64
	LastIndex  uint64
	LastTerm   uint64
	DupCnt     uint64 // help to compute the watching point with duplicated indexes in the queue
	// 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"`
	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

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) 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

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) IsExpired

func (n *Node) IsExpired() (bool, time.Duration)

IsExpired function checks if the node has been expired.

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, term 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 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) Inc added in v0.2.0

func (s *Stats) Inc(field int)

func (*Stats) TotalReads added in v0.2.0

func (s *Stats) TotalReads() uint64

func (*Stats) TotalWrites

func (s *Stats) TotalWrites() uint64

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
}

func New added in v0.2.0

func New() Store

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

Jump to

Keyboard shortcuts

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