m_etcd

package
v0.0.0-...-eab3a14 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

README

metafora etcd client

Testing

Testing the metafora etcd client requires that a new etcd instance be running. The etcd instances should be reachable via the connection described by the connection string localhost:5001,localhost:5002,localhost:5003 or a similar connection string should be exported as an environment variable ETCDCTL_PEERS. The environemnt variable ETCDTESTS must also be set to true, otherwise the tests will be skipped.

An example of running the integration tests is given in the command line below:

ETCDTESTS=1 IP="127.0.0.1" ETCDCTL_PEERS="$IP:5001,$IP:5002,$IP:5003"  go test -v

Documentation

Index

Constants

View Source
const (
	TasksPath    = "tasks"
	NodesPath    = "nodes"
	CommandsPath = "commands"
	MetadataKey  = "_metafora" // _{KEYs} are hidden files, so this will not trigger our watches
	OwnerMarker  = "owner"

	ForeverTTL = 0 //Ref: https://github.com/coreos/go-etcd/blob/e10c58ee110f54c2f385ac99764e8a7ca4cb13df/etcd/requests.go#L356

	//Etcd Error codes are passed directly through go-etcd from the http response,
	//So to find the error codes use this ref:
	//       https://github.com/coreos/etcd/blob/master/error/error.go#L67
	EcodeKeyNotFound  = 100
	EcodeNodeExist    = 105
	EcodeExpiredIndex = 401 // The event in requested index is outdated and cleared
)

Variables

View Source
var (
	ClaimTTL           uint64 = 120 // seconds
	DefaultNodePathTTL uint64 = 20  // seconds

)

Functions

func NewClient

func NewClient(namespace string, client *etcd.Client) metafora.Client

NewClient creates a new client using an etcd backend.

func NewEtcdCoordinator

func NewEtcdCoordinator(nodeID, namespace string, client *etcd.Client) metafora.Coordinator

NewEtcdCoordinator creates a new Metafora Coordinator implementation using etcd as the broker. If no node ID is specified, a unique one will be generated.

Coordinator methods will be called by the core Metafora Consumer. Calling Init, Close, etc. from your own code will lead to undefined behavior.

func NewFairBalancer

func NewFairBalancer(nodeid, namespace string, client *etcd.Client) metafora.Balancer

NewFairBalancer creates a new metafora.DefaultFairBalancer that uses etcd for counting tasks per node.

Types

type EtcdCoordinator

type EtcdCoordinator struct {
	Client *etcd.Client

	ClaimTTL uint64 // seconds

	NodeID string
	// contains filtered or unexported fields
}

func (*EtcdCoordinator) Claim

func (ec *EtcdCoordinator) Claim(taskID string) bool

Claim is called by the Consumer when a Balancer has determined that a task ID can be claimed. Claim returns false if another consumer has already claimed the ID.

func (*EtcdCoordinator) Close

func (ec *EtcdCoordinator) Close()

Close stops the coordinator and causes blocking Watch and Command methods to return zero values.

func (*EtcdCoordinator) Command

func (ec *EtcdCoordinator) Command() (metafora.Command, error)

Command blocks until a command for this node is received from the broker by the coordinator.

func (*EtcdCoordinator) Done

func (ec *EtcdCoordinator) Done(taskID string)

Done deletes the task.

func (*EtcdCoordinator) Init

Init is called once by the consumer to provide a Logger to Coordinator implementations.

func (*EtcdCoordinator) Release

func (ec *EtcdCoordinator) Release(taskID string)

Release deletes the claim file.

func (*EtcdCoordinator) Watch

func (ec *EtcdCoordinator) Watch() (taskID string, err error)

Watch will do a blocking etcd watch on taskPath until a claimable task is found or Close() is called.

Watch will return ("", nil) if the coordinator is closed.

Jump to

Keyboard shortcuts

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