zkcluster

package
v0.0.0-...-a11d02e Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2015 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

zkcluster - A connector for a zookeeper assisted redis cluster. It reads cluster configurations and shard status from zookeeper servers. It has a checker implementation which could be run separately. Multiple checkers are also possible and they would automatically elect a leader and make quorum-like decisions.

Index

Constants

View Source
const (
	ZK_ROOT       = "/goreclusters"
	DEF_FLAGS     = int32(0)
	EPH_SEQ_FLAGS = zk.FlagEphemeral | zk.FlagSequence
)

Variables

View Source
var (
	DEF_ACL = zk.WorldACL(zk.PermAll)
)

Functions

This section is empty.

Types

type ZKChecker

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

Healthchecker implementation of the zookeeper assisted redis cluster. It checks the status of redis instances and record them to the zookeeper. ZKCluster would watch that information and update its status. ZKChecker also supports quorum-like decisions with an automatic leader election. The leader gathers votes from all checkers to change status. Once the majority(even would be ignored) has an opposite state, a status change happens. Only the leader can gather votes, open the ballot box and update the status. If the leader lost a connection to the zookeeper, another one would take the leader automatically.

func NewZKChecker

func NewZKChecker(options *ZKCheckerOptions) (*ZKChecker, error)

Return a new checker instance.

func (*ZKChecker) Shutdown

func (c *ZKChecker) Shutdown()

Dispose the checker.

func (*ZKChecker) Start

func (c *ZKChecker) Start() error

Start the checker.

func (*ZKChecker) Stop

func (c *ZKChecker) Stop()

Stop the checker.

type ZKCheckerOptions

type ZKCheckerOptions struct {
	ZKServers   []string
	ZKTimeout   time.Duration
	Clustername string
	Nworker     int
	Interval    time.Duration
	Threshold   time.Duration
}

Options for ZKChecker

type ZKCluster

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

Connector implementation for the zookeeper assisted redis cluster. It reads cluster configurations and shard status from zookeeper servers. It also has roles of NodeReader, RingBuilder and HealthChecker which Cluster interface requires.

func NewZKCluster

func NewZKCluster(servers []string, clustername string, timeout time.Duration) (*ZKCluster, error)

Return a new ZKCluster instance.

func (*ZKCluster) BuildRing

func (c *ZKCluster) BuildRing(shards []Shard) *HashRing

ZK assisted RingBuilder implementation. The ring type or the parameters might be designated via the zookeeper.

func (*ZKCluster) Connect

func (c *ZKCluster) Connect(key []byte) (*redis.Client, func(), int64, error)

Locate and connect to an appropriate redis instance with a key.

func (*ZKCluster) ReadNodes

func (c *ZKCluster) ReadNodes() []Shard

ZK assisted NodeReader implementation.

func (*ZKCluster) Shutdown

func (c *ZKCluster) Shutdown()

Dispose the connector.

func (*ZKCluster) Start

func (c *ZKCluster) Start(shards []Shard) <-chan ShardStatus

ZK assisted HealthChecker implementation.

func (*ZKCluster) Stop

func (c *ZKCluster) Stop()

ZK assisted HealthChecker implementation.

type ZKClusterInfo

type ZKClusterInfo struct {
	Name    string
	Version int64
	Options ZKClusterOptions
	Shards  []Shard
}

Cluster information stored on the zookeeper.

type ZKClusterOptions

type ZKClusterOptions struct {
	FailoverEnabled bool
	RingType        string
	RingParams      string
}

Cluster options stored on the zookeeper.

type ZKConnector

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

Connector interface to zookeeper servers.

func NewZKConnector

func NewZKConnector(servers []string, timeout time.Duration) (*ZKConnector, error)

func (*ZKConnector) GetCluster

func (zc *ZKConnector) GetCluster(name string) (*ZKClusterInfo, error)

func (*ZKConnector) GetClusters

func (zc *ZKConnector) GetClusters() ([]*ZKClusterInfo, error)

func (*ZKConnector) Shutdown

func (zc *ZKConnector) Shutdown()

type ZKManager

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

The manager of cluster information on the zookeeper.

func NewZKManager

func NewZKManager(servers []string, timeout time.Duration) (*ZKManager, error)

Return a new manager instance.

func (*ZKManager) CreateCluster

func (zm *ZKManager) CreateCluster(cluster *ZKClusterInfo) error

Create a new cluster information with given option onto the zookeeper.

func (*ZKManager) DeleteCluster

func (zm *ZKManager) DeleteCluster(name string) error

Delete the cluster.

func (*ZKManager) Shutdown

func (zm *ZKManager) Shutdown()

Dispose the manager instance.

func (*ZKManager) UpdateCluster

func (zm *ZKManager) UpdateCluster(cluster *ZKClusterInfo) error

Update a cluster information.

Jump to

Keyboard shortcuts

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