Documentation
¶
Index ¶
- Variables
- func CheckKeyword(key string) bool
- func GenKeys(num int, depth int) []string
- type EtcdStats
- type Keyword
- type ListNode
- type Node
- type NotFile
- type NotFoundError
- type Response
- type Store
- func (s *Store) AddWatcher(prefix string, watcher *Watcher, sinceIndex uint64) error
- func (s *Store) Delete(key string, index uint64) ([]byte, error)
- func (s *Store) Get(key string) ([]byte, error)
- func (s *Store) RawGet(key string) ([]*Response, error)
- func (s *Store) Recovery(state []byte) error
- func (s *Store) Save() ([]byte, error)
- func (s *Store) Set(key string, value string, expireTime time.Time, index uint64) ([]byte, error)
- func (s *Store) SetMessager(messager chan<- string)
- func (s *Store) Stats() []byte
- func (s *Store) TestAndSet(key string, prevValue string, value string, expireTime time.Time, index uint64) ([]byte, error)
- type TestFail
- type Watcher
- type WatcherHub
Constants ¶
This section is empty.
Variables ¶
var PERMANENT = time.Unix(0, 0)
Functions ¶
func CheckKeyword ¶
CheckKeyword will check if the key contains the keyword. For now, we only check for prefix.
Types ¶
type ListNode ¶
A listNode represent the simplest Key-Value pair with its type It is only used when do list opeartion We want to have a file system like store, thus we distingush "file" and "directory"
type Node ¶
type Node struct {
// The string value of the node
Value string `json:"value"`
// If the node is a permanent one the ExprieTime will be Unix(0,0)
// Otherwise after the expireTime, the node will be deleted
ExpireTime time.Time `json:"expireTime"`
// contains filtered or unexported fields
}
A Node represents a Value in the Key-Value pair in the store It has its value, expire time and a channel used to update the expire time (since we do countdown in a go routine, we need to communicate with it via channel)
type NotFoundError ¶
type NotFoundError string
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
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 Store ¶
type Store struct {
// key-value store structure
Tree *tree
// A map to keep the recent response to the clients
ResponseMap map[string]*Response
// The max number of the recent responses we can record
ResponseMaxSize int
// The current number of the recent responses we have recorded
ResponseCurrSize uint
// The index of the first recent responses we have
ResponseStartIndex uint64
// Current index of the raft machine
Index uint64
// Basic statistics information of etcd storage
BasicStats EtcdStats
// contains filtered or unexported fields
}
The main struct of the Key-Value store
func CreateStore ¶
Create a new stroe Arguement max is the max number of response we want to record
func (*Store) AddWatcher ¶
Add a channel to the watchHub. The watchHub will send response to the channel when any key under the prefix changes [since the sinceIndex if given]
func (*Store) Get ¶
Get all the items under key If key is a file return the file If key is a directory reuturn an array of files
func (*Store) SetMessager ¶
Set the messager of the store
type Watcher ¶
type Watcher struct {
C chan *Response
}
Currently watcher only contains a response channel
type WatcherHub ¶
type WatcherHub struct {
// contains filtered or unexported fields
}
WatcherHub is where the client register its watcher