storeadapter

package module
v0.0.0-...-a491f03 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2014 License: Apache-2.0 Imports: 3 Imported by: 0

README

storeadapter

Build Status

Golang interface for ETCD/ZooKeeper style datastores

storeadapter

The storeadapter is an generalized client for connecting to a Zookeeper/ETCD-like high availability store. Writes are performed concurrently for optimal performance.

fakestoreadapter

Provides a fake in-memory implementation of the storeadapter to allow for unit tests that do not need to spin up a database.

workerpool

Provides a worker pool with a configurable pool size. Work scheduled on the pool will run concurrently, but no more poolSize workers can be running at any given moment.

storerunner

Brings up and manages the lifecycle of a live ETCD/ZooKeeper server cluster.

Documentation

Index

Constants

View Source
const (
	CreateEvent = EventType(iota)
	DeleteEvent
	ExpireEvent
	UpdateEvent
)

Variables

View Source
var (
	ErrorKeyNotFound         = errors.New("the requested key could not be found")
	ErrorNodeIsDirectory     = errors.New("node is a directory, not a leaf")
	ErrorNodeIsNotDirectory  = errors.New("node is a leaf, not a directory")
	ErrorTimeout             = errors.New("store request timed out")
	ErrorInvalidFormat       = errors.New("node has invalid format")
	ErrorInvalidTTL          = errors.New("got an invalid TTL")
	ErrorKeyExists           = errors.New("a node already exists at the requested key")
	ErrorKeyComparisonFailed = errors.New("node comparison failed")
)

Functions

This section is empty.

Types

type EventType

type EventType int

type StoreAdapter

type StoreAdapter interface {
	// Intiailize connection to server. For a store with no
	// persistent connection, this effectively just tests connectivity.
	Connect() error

	// Create a node and fail if it already exists.
	Create(StoreNode) error

	// Update a node and fail if it does not already exist.
	Update(StoreNode) error

	// CompareAndSwap a node and don't swap if the compare fails.
	CompareAndSwap(StoreNode, StoreNode) error
	CompareAndSwapByIndex(prevIndex uint64, newNode StoreNode) error

	// Set multiple nodes at once. If any of them fail,
	// it will return the first error.
	SetMulti(nodes []StoreNode) error

	// Retrieve a node from the store at the given key.
	// Returns an error if it does not exist.
	Get(key string) (StoreNode, error)

	// Recursively get the contents of a key.
	ListRecursively(key string) (StoreNode, error)

	// Delete a set of keys from the store. If any fail to be
	// deleted or don't actually exist, an error is returned.
	Delete(keys ...string) error

	// DeleteLeaves removes a set of empty directories and key-value pairs
	// from the store. If any fail to be deleted or don't actually exist,
	// an error is returned.
	DeleteLeaves(keys ...string) error

	// CompareAndDelete and don't delete if the compare fails.
	CompareAndDelete(StoreNode) error

	// Set the ttl on a directory
	UpdateDirTTL(key string, ttl uint64) error

	// Watch a given key recursively for changes. Events will come in on one channel, and watching will stop when a value is sent over the stop channel.
	//
	// Events may be missed, but the watcher will do its best to continue.
	//
	// Returns an error if the watcher cannot initially "attach" to the stream.
	//
	// Otherwise, the caller can assume that the watcher will continue attempting to stream events.
	Watch(key string) (events <-chan WatchEvent, stop chan<- bool, errors <-chan error)

	// Close any live persistent connection, and cleans up any running state.
	Disconnect() error

	// Create a node, keep it there, and send a notification when it is lost. Blocks until the node can be created.
	//
	// To release the node, send a channel value to the releaseNode channel, and read from the channel to ensure it's released.
	//
	// If the store times out, returns an error.
	MaintainNode(storeNode StoreNode) (lostNode <-chan bool, releaseNode chan chan bool, err error)
}

type StoreNode

type StoreNode struct {
	Key        string
	Value      []byte
	Dir        bool
	TTL        uint64
	ChildNodes []StoreNode
	Index      uint64
}

func (StoreNode) KeyComponents

func (self StoreNode) KeyComponents() []string

func (StoreNode) Lookup

func (self StoreNode) Lookup(childKey string) (StoreNode, bool)

type WatchEvent

type WatchEvent struct {
	Type     EventType
	Node     *StoreNode
	PrevNode *StoreNode
}

Jump to

Keyboard shortcuts

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