cluster

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Mode    NodeMode
	Manager ClusterManager
	Tracer  opentracing.Tracer

	InsufficientShardsAvailable = NewError(http.StatusServiceUnavailable, errors.New("Insufficient shards available."))
)
View Source
var (
	ClusterName string

	GossipSettlePeriod time.Duration // if gossip not enabled, will be 0 regardless of config

)

Functions

func ConfigProcess

func ConfigProcess()

func ConfigSetup

func ConfigSetup()

func Init

func Init(name, version string, started time.Time, apiScheme string, apiPort int)

func MembersForSpeculativeQuery

func MembersForSpeculativeQuery() (map[int32][]Node, error)

MembersForSpeculativeQuery returns a prioritized list of nodes for each shard group keyed by the first (lowest) partition of their shard group

func Start

func Start()

func Stop

func Stop()

Types

type ClusterManager

type ClusterManager interface {
	IsPrimary() bool
	SetPrimary(bool)
	IsReady() bool
	SetReady()
	SetState(NodeState)
	ThisNode() Node
	MemberList(bool, bool) []Node
	Join([]string) (int, error)
	GetPartitions() []int32
	SetPartitions([]int32)
	SetPriority(int)
	Stop()
	Start()
}

type Error

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

func NewError

func NewError(code int, err error) *Error

func (*Error) Error

func (r *Error) Error() string

implement errors.Error interface

func (*Error) HTTPStatusCode added in v1.0.0

func (r *Error) HTTPStatusCode() int

implement response.Response

type HTTPNode

type HTTPNode struct {
	Name          string    `json:"name"`
	Version       string    `json:"version"`
	Primary       bool      `json:"primary"`
	PrimaryChange time.Time `json:"primaryChange"`
	Mode          NodeMode  `json:"mode"`
	State         NodeState `json:"state"`
	Priority      int       `json:"priority"`
	Started       time.Time `json:"started"`
	StateChange   time.Time `json:"stateChange"`
	Partitions    []int32   `json:"partitions"`
	ApiPort       int       `json:"apiPort"`
	ApiScheme     string    `json:"apiScheme"`
	Updated       time.Time `json:"updated"`
	RemoteAddr    string    `json:"remoteAddr"`
	// contains filtered or unexported fields
}

func (HTTPNode) GetName

func (n HTTPNode) GetName() string

func (HTTPNode) GetPartitions

func (n HTTPNode) GetPartitions() []int32

func (HTTPNode) GetPriority

func (n HTTPNode) GetPriority() int

func (HTTPNode) HasData added in v0.12.0

func (n HTTPNode) HasData() bool

func (HTTPNode) IsLocal

func (n HTTPNode) IsLocal() bool

func (HTTPNode) IsReady

func (n HTTPNode) IsReady() bool

func (HTTPNode) Post

func (n HTTPNode) Post(ctx context.Context, name, path string, body Traceable) (ret []byte, err error)

func (HTTPNode) PostRaw added in v1.0.0

func (n HTTPNode) PostRaw(ctx context.Context, name, path string, body Traceable) (io.ReadCloser, error)

func (HTTPNode) RemoteURL

func (n HTTPNode) RemoteURL() string

func (*HTTPNode) SetPartitions added in v0.12.0

func (n *HTTPNode) SetPartitions(part []int32)

SetPartitions sets the partitions that this node is handling

func (*HTTPNode) SetPrimary added in v0.12.0

func (n *HTTPNode) SetPrimary(primary bool) bool

SetPrimary sets the primary state of the node and returns whether it changed

func (*HTTPNode) SetPriority added in v0.12.0

func (n *HTTPNode) SetPriority(prio int) bool

SetPriority sets the priority of the node and returns whether it changed

func (*HTTPNode) SetState added in v0.12.0

func (n *HTTPNode) SetState(state NodeState) bool

SetState sets the state of the node and returns whether the state changed

type HTTPNodesByName

type HTTPNodesByName []HTTPNode

func (HTTPNodesByName) Len

func (n HTTPNodesByName) Len() int

func (HTTPNodesByName) Less

func (n HTTPNodesByName) Less(i, j int) bool

func (HTTPNodesByName) Swap

func (n HTTPNodesByName) Swap(i, j int)

type InvalidNodeModeErr added in v0.12.0

type InvalidNodeModeErr string

func (InvalidNodeModeErr) Error added in v0.12.0

func (e InvalidNodeModeErr) Error() string

type MemberlistManager

type MemberlistManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMemberlistManager

func NewMemberlistManager(thisNode HTTPNode) *MemberlistManager

func (*MemberlistManager) BroadcastUpdate

func (c *MemberlistManager) BroadcastUpdate()

func (*MemberlistManager) GetBroadcasts

func (c *MemberlistManager) GetBroadcasts(overhead, limit int) [][]byte

GetBroadcasts is called when user data messages can be broadcast. It can return a list of buffers to send. Each buffer should assume an overhead as provided with a limit on the total byte size allowed. The total byte size of the resulting data to send must not exceed the limit. Care should be taken that this method does not block, since doing so would block the entire UDP packet receive loop.

func (*MemberlistManager) GetPartitions

func (c *MemberlistManager) GetPartitions() []int32

get the partitions that this node is handling.

func (*MemberlistManager) IsPrimary

func (c *MemberlistManager) IsPrimary() bool

Returns true if the this node is a set as a primary node that should write data to cassandra.

func (*MemberlistManager) IsReady

func (c *MemberlistManager) IsReady() bool

Returns true if this node is a ready to accept requests from users.

func (*MemberlistManager) Join

func (c *MemberlistManager) Join(peers []string) (int, error)

func (*MemberlistManager) LocalState

func (c *MemberlistManager) LocalState(join bool) []byte

LocalState is used for a TCP Push/Pull. This is sent to the remote side in addition to the membership information. Any data can be sent here. See MergeRemoteState as well. The `join` boolean indicates this is for a join instead of a push/pull.

func (*MemberlistManager) MemberList

func (c *MemberlistManager) MemberList(isReady, hasData bool) []Node

func (*MemberlistManager) MergeRemoteState

func (c *MemberlistManager) MergeRemoteState(buf []byte, join bool)

func (*MemberlistManager) NodeMeta

func (c *MemberlistManager) NodeMeta(limit int) []byte

NodeMeta is used to retrieve meta-data about the current node when broadcasting an alive message. It's length is limited to the given byte size. This metadata is available in the HTTPNode structure.

func (*MemberlistManager) NotifyJoin

func (c *MemberlistManager) NotifyJoin(node *memberlist.Node)

func (*MemberlistManager) NotifyLeave

func (c *MemberlistManager) NotifyLeave(node *memberlist.Node)

func (*MemberlistManager) NotifyMsg

func (c *MemberlistManager) NotifyMsg(buf []byte)

NotifyMsg is called when a user-data message is received. Care should be taken that this method does not block, since doing so would block the entire UDP packet receive loop. Additionally, the byte slice may be modified after the call returns, so it should be copied if needed.

func (*MemberlistManager) NotifyUpdate

func (c *MemberlistManager) NotifyUpdate(node *memberlist.Node)

func (*MemberlistManager) SetPartitions

func (c *MemberlistManager) SetPartitions(part []int32)

set the partitions that this node is handling.

func (*MemberlistManager) SetPrimary

func (c *MemberlistManager) SetPrimary(primary bool)

SetPrimary sets the primary status of this node

func (*MemberlistManager) SetPriority

func (c *MemberlistManager) SetPriority(prio int)

set the priority of this node. lower values == higher priority

func (*MemberlistManager) SetReady

func (c *MemberlistManager) SetReady()

mark this node as ready to accept requests from users.

func (*MemberlistManager) SetState

func (c *MemberlistManager) SetState(state NodeState)

Set the state of this node.

func (*MemberlistManager) Start

func (c *MemberlistManager) Start()

func (*MemberlistManager) Stop

func (c *MemberlistManager) Stop()

func (*MemberlistManager) ThisNode

func (c *MemberlistManager) ThisNode() Node

type MockClusterManager

type MockClusterManager struct {
	Peers []*MockNode
	// contains filtered or unexported fields
}

func InitMock

func InitMock() *MockClusterManager

func (*MockClusterManager) GetPartitions

func (c *MockClusterManager) GetPartitions() []int32

func (*MockClusterManager) IsPrimary

func (c *MockClusterManager) IsPrimary() bool

func (*MockClusterManager) IsReady

func (c *MockClusterManager) IsReady() bool

func (*MockClusterManager) Join

func (c *MockClusterManager) Join(peers []string) (int, error)

func (*MockClusterManager) MemberList

func (c *MockClusterManager) MemberList(isReady, hasData bool) []Node

func (*MockClusterManager) SetPartitions

func (c *MockClusterManager) SetPartitions(partitions []int32)

func (*MockClusterManager) SetPrimary

func (c *MockClusterManager) SetPrimary(primary bool)

func (*MockClusterManager) SetPriority

func (c *MockClusterManager) SetPriority(prio int)

func (*MockClusterManager) SetReady

func (c *MockClusterManager) SetReady()

func (*MockClusterManager) SetReadyIn

func (c *MockClusterManager) SetReadyIn(t time.Duration)

func (*MockClusterManager) SetState

func (c *MockClusterManager) SetState(NodeState)

func (*MockClusterManager) Start

func (c *MockClusterManager) Start()

func (*MockClusterManager) Stop

func (c *MockClusterManager) Stop()

func (*MockClusterManager) ThisNode

func (c *MockClusterManager) ThisNode() Node

type MockNode

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

func NewMockNode

func NewMockNode(isLocal bool, name string, partitions []int32, postResponse []byte) *MockNode

func (*MockNode) GetName

func (n *MockNode) GetName() string

func (*MockNode) GetPartitions

func (n *MockNode) GetPartitions() []int32

func (*MockNode) GetPriority

func (n *MockNode) GetPriority() int

func (*MockNode) HasData added in v0.12.0

func (n *MockNode) HasData() bool

func (*MockNode) IsLocal

func (n *MockNode) IsLocal() bool

func (*MockNode) IsReady

func (n *MockNode) IsReady() bool

func (MockNode) Post

func (n MockNode) Post(ctx context.Context, name, path string, body Traceable) ([]byte, error)

func (MockNode) PostRaw added in v1.0.0

func (n MockNode) PostRaw(ctx context.Context, name, path string, body Traceable) (io.ReadCloser, error)

type Node

type Node interface {
	IsLocal() bool
	IsReady() bool
	GetPartitions() []int32
	GetPriority() int
	HasData() bool
	Post(context.Context, string, string, Traceable) ([]byte, error)
	PostRaw(ctx context.Context, name, path string, body Traceable) (io.ReadCloser, error)
	GetName() string
}

func MembersForQuery

func MembersForQuery() ([]Node, error)

MembersForQuery returns the list of nodes to broadcast requests to If partitions are assigned to nodes in groups (a[0,1], b[0,1], c[2,3], d[2,3] as opposed to a[0,1], b[0,2], c[1,3], d[2,3]), only 1 member per partition is returned. The nodes are selected based on priority, preferring thisNode if it has the lowest prio, otherwise using a random selection from all nodes with the lowest prio.

type NodeMode added in v0.12.0

type NodeMode uint8
const (
	ModeShard NodeMode = iota
	ModeDev
	ModeQuery
)

func NodeModeFromString added in v0.12.0

func NodeModeFromString(mode string) (NodeMode, error)

capitalized form is what stringer (.String()) generates and is used for json serialization

func (NodeMode) MarshalJSON added in v0.12.0

func (n NodeMode) MarshalJSON() ([]byte, error)

MarshalJSON marshals a NodeMode

func (NodeMode) String added in v0.12.0

func (i NodeMode) String() string

func (*NodeMode) UnmarshalJSON added in v0.12.0

func (n *NodeMode) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a NodeMode

type NodeState

type NodeState int
const (
	NodeNotReady NodeState = iota
	NodeReady
	NodeUnreachable
)

func NodeStateFromString

func NodeStateFromString(s string) NodeState

func (NodeState) MarshalJSON

func (n NodeState) MarshalJSON() ([]byte, error)

func (NodeState) String

func (i NodeState) String() string

func (*NodeState) UnmarshalJSON

func (n *NodeState) UnmarshalJSON(data []byte) error

UnmarshalJSON supports unmarshalling according to the older integer based, as well as the new string based, representation

type SingleNodeManager

type SingleNodeManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSingleNodeManager

func NewSingleNodeManager(thisNode HTTPNode) *SingleNodeManager

func (*SingleNodeManager) GetPartitions

func (m *SingleNodeManager) GetPartitions() []int32

get the partitions that this node is handling.

func (*SingleNodeManager) IsPrimary

func (m *SingleNodeManager) IsPrimary() bool

func (*SingleNodeManager) IsReady

func (m *SingleNodeManager) IsReady() bool

func (*SingleNodeManager) Join

func (m *SingleNodeManager) Join(peers []string) (int, error)

func (*SingleNodeManager) MemberList

func (m *SingleNodeManager) MemberList(isReady, hasData bool) []Node

func (*SingleNodeManager) SetPartitions

func (m *SingleNodeManager) SetPartitions(part []int32)

set the partitions that this node is handling.

func (*SingleNodeManager) SetPrimary

func (m *SingleNodeManager) SetPrimary(primary bool)

func (*SingleNodeManager) SetPriority

func (m *SingleNodeManager) SetPriority(prio int)

set the priority of this node. lower values == higher priority

func (*SingleNodeManager) SetReady

func (m *SingleNodeManager) SetReady()

func (*SingleNodeManager) SetState

func (m *SingleNodeManager) SetState(state NodeState)

func (*SingleNodeManager) Start

func (m *SingleNodeManager) Start()

func (*SingleNodeManager) Stop

func (m *SingleNodeManager) Stop()

func (*SingleNodeManager) ThisNode

func (m *SingleNodeManager) ThisNode() Node

type Traceable

type Traceable interface {
	Trace(span opentracing.Span)
	TraceDebug(span opentracing.Span)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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