store

package
v0.1.1-0...-fe2d1c1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PERMANENT = time.Unix(0, 0)

Functions

func CheckKeyword

func CheckKeyword(key string) bool

CheckKeyword will check if the key contains the keyword. For now, we only check for prefix.

func GenKeys

func GenKeys(num int, depth int) []string

GenKeys randomly generate num of keys with max depth

Types

type EtcdStats

type EtcdStats struct {
	// Number of get requests
	Gets uint64 `json:"gets"`

	// Number of sets requests
	Sets uint64 `json:"sets"`

	// Number of delete requests
	Deletes uint64 `json:"deletes"`

	// Number of testAndSet requests
	TestAndSets uint64 `json:"testAndSets"`
}

type Keyword

type Keyword string

func (Keyword) Error

func (e Keyword) Error() string

type ListNode

type ListNode struct {
	Key   string
	Value string
	Type  string
}

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 NotFile

type NotFile string

func (NotFile) Error

func (e NotFile) Error() string

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

func CreateStore(max int) *Store

Create a new stroe Arguement max is the max number of response we want to record

func (*Store) AddWatcher

func (s *Store) AddWatcher(prefix string, watcher *Watcher, sinceIndex uint64) error

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

func (s *Store) Delete(key string, index uint64) ([]byte, error)

func (*Store) Get

func (s *Store) Get(key string) ([]byte, error)

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

func (s *Store) RawGet(key string) ([]*Response, error)

func (*Store) Recovery

func (s *Store) Recovery(state []byte) error

Recovery the state of the stroage system from a previous state

func (*Store) Save

func (s *Store) Save() ([]byte, error)

Save the current state of the storage system

func (*Store) Set

func (s *Store) Set(key string, value string, expireTime time.Time, index uint64) ([]byte, error)

func (*Store) SetMessager

func (s *Store) SetMessager(messager chan<- string)

Set the messager of the store

func (*Store) Stats

func (s *Store) Stats() []byte

Stats returns the basic statistics information of etcd storage since its recent start

func (*Store) TestAndSet

func (s *Store) TestAndSet(key string, prevValue string, value string, expireTime time.Time, index uint64) ([]byte, error)

Set the value of the key to the value if the given prevValue is equal to the value of the key

func (*Store) TotalWrites

func (s *Store) TotalWrites() uint64

TotalWrites returns the total write operations It helps with snapshot

type TestFail

type TestFail string

func (TestFail) Error

func (e TestFail) Error() string

type Watcher

type Watcher struct {
	C chan *Response
}

Currently watcher only contains a response channel

func NewWatcher

func NewWatcher() *Watcher

Create a new watcher

type WatcherHub

type WatcherHub struct {
	// contains filtered or unexported fields
}

WatcherHub is where the client register its watcher

Jump to

Keyboard shortcuts

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