topology

package
v0.0.0-...-8d4522d Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Server      sectionType = "Server"
	Clients     sectionType = "Clients"
	Memory      sectionType = "Memory"
	Persistence sectionType = "Persistence"
	Stats       sectionType = "Stats"
	Replication sectionType = "Replication"
	CPU         sectionType = "CPU"
	Cluster     sectionType = "Cluster"
	Keyspace    sectionType = "Keyspace"
)
View Source
const (
	VariantNCS = iota
	VariantRFC4122
	VariantMicrosoft
	VariantFuture
)

UUID layout variants.

Variables

View Source
var SUIDNil = &SUID{make([]byte, 16)}

The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.

View Source
var SuidToShortS = suidToShortS

Functions

func Equal

func Equal(u1 *SUID, u2 *SUID) bool

Equal returns true if u1 and u2 equals, otherwise returns false.

func TestSUID

func TestSUID()

Types

type Basic

type Basic interface {
	Run() Stop
}

Basic Run

type Mode

type Mode int
const (
	SingleMode Mode = iota
	SentinelMode
	ClusterMode

	MasterStr = `master`
	SlaveStr  = `slave`
)

type NodeInfo

type NodeInfo struct {
	Id     string `json:"node_id"`
	Addr   string `json:"node_addr"`
	Pass   string `json:"node_password"`
	Ver    string `json:"node_version"`
	Offset int64  `json:"node_offset"`

	IsMaster bool `json:"is_master"`
	// contains filtered or unexported fields
}

func CreateNodeInfo

func CreateNodeInfo(addr string, pass string) *NodeInfo

func (*NodeInfo) ExclusiveConn

func (n *NodeInfo) ExclusiveConn() (*client.Conn, string, string, error)

func (*NodeInfo) Stop

func (n *NodeInfo) Stop()

type NodeInfoGroup

type NodeInfoGroup struct {
	UUID string `json:"uuid"`
	// Index:0 is master node
	Members []*NodeInfo `json:"members_node"`
	// Group offset
	// In the process of switching,
	// If the value is greater than the offset value of the instance to be run, then the value is discarded,
	// And the full amount of data of the new instance is retrieved directly from -1
	// Otherwise it continues from the current offset.
	GroupOffset int64 `json:"group_offset"`
	// [{ip:port:runid}.String(),...]
	MemberIds []string `json:"member_ids"`
	// Node instance count
	MemberCnt int32 `json:"member_cnt"`
	// Identify current master run_id
	MasterId string
	// External incoming argsments address
	ArgumentAddrs []string
	// External incoming argsments password
	ArgumentPasswrod string
}

func CreateMSNodeGroup

func CreateMSNodeGroup(pass string, addrs ...string) *NodeInfoGroup

func CreateNodeInfoGroup

func CreateNodeInfoGroup() *NodeInfoGroup

func (*NodeInfoGroup) CloseAllMember

func (ns *NodeInfoGroup) CloseAllMember()

func (*NodeInfoGroup) Len

func (ns *NodeInfoGroup) Len() int

func (*NodeInfoGroup) Less

func (ns *NodeInfoGroup) Less(i, j int) bool

func (*NodeInfoGroup) Master

func (ns *NodeInfoGroup) Master() *NodeInfo

func (*NodeInfoGroup) Offset

func (ns *NodeInfoGroup) Offset() string

func (*NodeInfoGroup) Put

func (ns *NodeInfoGroup) Put(n *NodeInfo)

func (*NodeInfoGroup) Slaves

func (ns *NodeInfoGroup) Slaves() []*NodeInfo

func (*NodeInfoGroup) Swap

func (ns *NodeInfoGroup) Swap(i, j int)

func (*NodeInfoGroup) Update

func (ns *NodeInfoGroup) Update(offset int64)

type RedisCluster

type RedisCluster struct {
	// Multiple sets of msater slave information in one cluster
	Cluster map[string]*NodeInfoGroup `json:"cluster"`
}

func CreateRedisCluster

func CreateRedisCluster(pass string, addrss [][]string) *RedisCluster

func (*RedisCluster) Group

func (s *RedisCluster) Group(n *NodeInfo) *NodeInfoGroup

func (*RedisCluster) Increment

func (s *RedisCluster) Increment(n *NodeInfo, offset int64)

func (*RedisCluster) MarshalToWriter

func (s *RedisCluster) MarshalToWriter(dst io.Writer) error

masrshal

func (*RedisCluster) Offset

func (s *RedisCluster) Offset(n *NodeInfo) string

func (*RedisCluster) Run

func (s *RedisCluster) Run() Stop

func (*RedisCluster) Topology

func (s *RedisCluster) Topology() *ToplogyMapped

type RedisSentinel

type RedisSentinel struct {
	*NodeInfoGroup `json:"sentinel"`
}

func CreateRedisSentinel

func CreateRedisSentinel(pass string, addrs ...string) *RedisSentinel

func (*RedisSentinel) Group

func (s *RedisSentinel) Group(n *NodeInfo) *NodeInfoGroup

func (*RedisSentinel) Increment

func (s *RedisSentinel) Increment(n *NodeInfo, offset int64)

func (*RedisSentinel) MarshalToWriter

func (s *RedisSentinel) MarshalToWriter(dst io.Writer) error

func (*RedisSentinel) Offset

func (s *RedisSentinel) Offset(n *NodeInfo) string

func (*RedisSentinel) Run

func (s *RedisSentinel) Run() Stop

func (*RedisSentinel) Topology

func (s *RedisSentinel) Topology() *ToplogyMapped

type RedisSingle

type RedisSingle struct {
	*NodeInfoGroup `json:"single"`
}

redis single or master->slave architectural model

func CreateRedisSingle

func CreateRedisSingle(pass string, addrs ...string) *RedisSingle

func (*RedisSingle) Group

func (s *RedisSingle) Group(n *NodeInfo) *NodeInfoGroup

func (*RedisSingle) Increment

func (s *RedisSingle) Increment(n *NodeInfo, offset int64)

func (*RedisSingle) MarshalToWriter

func (r *RedisSingle) MarshalToWriter(dst io.Writer) error

func (*RedisSingle) Offset

func (s *RedisSingle) Offset(n *NodeInfo) string

func (*RedisSingle) Run

func (r *RedisSingle) Run() Stop

func (*RedisSingle) Topology

func (r *RedisSingle) Topology() *ToplogyMapped

type SUID

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

UUID representation compliant with specification described in RFC 4122.

func NewSUID

func NewSUID() *SUID

NewV1 returns UUID based on current timestamp and MAC address.

func WrapSUID

func WrapSUID(_buf []byte) *SUID

func (*SUID) Bytes

func (u *SUID) Bytes() []byte

Bytes returns bytes slice representation of UUID.

func (*SUID) SetVariant

func (this *SUID) SetVariant()

SetVariant sets variant bits as described in RFC 4122.

func (*SUID) SetVersion

func (this *SUID) SetVersion(v byte)

SetVersion sets version bits.

func (*SUID) String

func (this *SUID) String() string

func (*SUID) StringFull

func (u *SUID) StringFull() string

Returns canonical string representation of UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

func (*SUID) Variant

func (u *SUID) Variant() uint

Variant returns UUID layout variant.

func (*SUID) Version

func (u *SUID) Version() uint

Version returns algorithm version used to generate UUID.

type StateEvent

type StateEvent struct {
	StateType
	Error error
	Name  string
	Data  string
}

type StateType

type StateType int
const (
	// node runing
	RUNING StateType = iota
	// During sent stop state
	STOPPED
	// Call node.collect timeout with 1 second
	TIMEOUT
	// Unexpected error occurred
	BROKEN
)

type Stop

type Stop func() error

service stop handle

type ToplogyMapped

type ToplogyMapped map[*NodeInfo][]*NodeInfo

func (*ToplogyMapped) Compares

func (t *ToplogyMapped) Compares(cur *ToplogyMapped) (
	newNodes []*NodeInfo,
	oldNodes []*NodeInfo,
	hasChanged bool,
)

type Topologist

type Topologist interface {
	// Get redis real server topology
	Topology() *ToplogyMapped
	// Increment offset
	Increment(*NodeInfo, int64)
	// Group get current node groupAddr
	Group(*NodeInfo) *NodeInfoGroup
	// Offset get the string of offset
	Offset(*NodeInfo) string
	// marshal
	MarshalToWriter(io.Writer) error
	// The implementor needs to implement Basic interface template
	// Return the service callback method
	Basic
}

func NewTopologyist

func NewTopologyist(mode Mode, pass string, addrs ...string) (t Topologist, err error)

func UnmarshalFromBytes

func UnmarshalFromBytes(mode Mode, p []byte) (Topologist, error)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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