metrictank: github.com/grafana/metrictank/cluster Index | Files | Directories

package cluster

import "github.com/grafana/metrictank/cluster"

Index

Package Files

cluster.go config.go if.go manager.go mock.go node.go nodemode_string.go nodestate_string.go traceable.go

Variables

var (
    Mode    NodeMode
    Manager ClusterManager
    Tracer  opentracing.Tracer

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

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

)

func ConfigProcess Uses

func ConfigProcess()

func ConfigSetup Uses

func ConfigSetup()

func Init Uses

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

func MembersForSpeculativeQuery Uses

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 Uses

func Start()

func Stop Uses

func Stop()

type ClusterManager Uses

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 Uses

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

func NewError Uses

func NewError(code int, err error) *Error

func (*Error) Error Uses

func (r *Error) Error() string

implement errors.Error interface

func (*Error) HTTPStatusCode Uses

func (r *Error) HTTPStatusCode() int

implement response.Response

type HTTPNode Uses

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 Uses

func (n HTTPNode) GetName() string

func (HTTPNode) GetPartitions Uses

func (n HTTPNode) GetPartitions() []int32

func (HTTPNode) GetPriority Uses

func (n HTTPNode) GetPriority() int

func (HTTPNode) HasData Uses

func (n HTTPNode) HasData() bool

func (HTTPNode) IsLocal Uses

func (n HTTPNode) IsLocal() bool

func (HTTPNode) IsReady Uses

func (n HTTPNode) IsReady() bool

func (HTTPNode) Post Uses

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

func (HTTPNode) PostRaw Uses

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

func (HTTPNode) RemoteURL Uses

func (n HTTPNode) RemoteURL() string

func (*HTTPNode) SetPartitions Uses

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

SetPartitions sets the partitions that this node is handling

func (*HTTPNode) SetPrimary Uses

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

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

func (*HTTPNode) SetPriority Uses

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

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

func (*HTTPNode) SetState Uses

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

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

type HTTPNodesByName Uses

type HTTPNodesByName []HTTPNode

func (HTTPNodesByName) Len Uses

func (n HTTPNodesByName) Len() int

func (HTTPNodesByName) Less Uses

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

func (HTTPNodesByName) Swap Uses

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

type InvalidNodeModeErr Uses

type InvalidNodeModeErr string

func (InvalidNodeModeErr) Error Uses

func (e InvalidNodeModeErr) Error() string

type MemberlistManager Uses

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

func NewMemberlistManager Uses

func NewMemberlistManager(thisNode HTTPNode) *MemberlistManager

func (*MemberlistManager) BroadcastUpdate Uses

func (c *MemberlistManager) BroadcastUpdate()

func (*MemberlistManager) GetBroadcasts Uses

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 Uses

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

get the partitions that this node is handling.

func (*MemberlistManager) IsPrimary Uses

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 Uses

func (c *MemberlistManager) IsReady() bool

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

func (*MemberlistManager) Join Uses

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

func (*MemberlistManager) LocalState Uses

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 Uses

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

func (*MemberlistManager) MergeRemoteState Uses

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

func (*MemberlistManager) NodeMeta Uses

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 Uses

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

func (*MemberlistManager) NotifyLeave Uses

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

func (*MemberlistManager) NotifyMsg Uses

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 Uses

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

func (*MemberlistManager) SetPartitions Uses

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

set the partitions that this node is handling.

func (*MemberlistManager) SetPrimary Uses

func (c *MemberlistManager) SetPrimary(primary bool)

SetPrimary sets the primary status of this node

func (*MemberlistManager) SetPriority Uses

func (c *MemberlistManager) SetPriority(prio int)

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

func (*MemberlistManager) SetReady Uses

func (c *MemberlistManager) SetReady()

mark this node as ready to accept requests from users.

func (*MemberlistManager) SetState Uses

func (c *MemberlistManager) SetState(state NodeState)

Set the state of this node.

func (*MemberlistManager) Start Uses

func (c *MemberlistManager) Start()

func (*MemberlistManager) Stop Uses

func (c *MemberlistManager) Stop()

func (*MemberlistManager) ThisNode Uses

func (c *MemberlistManager) ThisNode() Node

type MockClusterManager Uses

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

func InitMock Uses

func InitMock() *MockClusterManager

func (*MockClusterManager) GetPartitions Uses

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

func (*MockClusterManager) IsPrimary Uses

func (c *MockClusterManager) IsPrimary() bool

func (*MockClusterManager) IsReady Uses

func (c *MockClusterManager) IsReady() bool

func (*MockClusterManager) Join Uses

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

func (*MockClusterManager) MemberList Uses

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

func (*MockClusterManager) SetPartitions Uses

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

func (*MockClusterManager) SetPrimary Uses

func (c *MockClusterManager) SetPrimary(primary bool)

func (*MockClusterManager) SetPriority Uses

func (c *MockClusterManager) SetPriority(prio int)

func (*MockClusterManager) SetReady Uses

func (c *MockClusterManager) SetReady()

func (*MockClusterManager) SetReadyIn Uses

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

func (*MockClusterManager) SetState Uses

func (c *MockClusterManager) SetState(NodeState)

func (*MockClusterManager) Start Uses

func (c *MockClusterManager) Start()

func (*MockClusterManager) Stop Uses

func (c *MockClusterManager) Stop()

func (*MockClusterManager) ThisNode Uses

func (c *MockClusterManager) ThisNode() Node

type MockNode Uses

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

func NewMockNode Uses

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

func (*MockNode) GetName Uses

func (n *MockNode) GetName() string

func (*MockNode) GetPartitions Uses

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

func (*MockNode) GetPriority Uses

func (n *MockNode) GetPriority() int

func (*MockNode) HasData Uses

func (n *MockNode) HasData() bool

func (*MockNode) IsLocal Uses

func (n *MockNode) IsLocal() bool

func (*MockNode) IsReady Uses

func (n *MockNode) IsReady() bool

func (MockNode) Post Uses

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

func (MockNode) PostRaw Uses

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

type Node Uses

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 Uses

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 Uses

type NodeMode uint8

go:generate stringer -type=NodeMode -trimprefix=Mode

const (
    ModeShard NodeMode = iota
    ModeDev
    ModeQuery
)

func NodeModeFromString Uses

func NodeModeFromString(mode string) (NodeMode, error)

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

func (NodeMode) MarshalJSON Uses

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

MarshalJSON marshals a NodeMode

func (NodeMode) String Uses

func (i NodeMode) String() string

func (*NodeMode) UnmarshalJSON Uses

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

UnmarshalJSON unmashals a NodeMode

type NodeState Uses

type NodeState int

go:generate stringer -type=NodeState

const (
    NodeNotReady NodeState = iota
    NodeReady
    NodeUnreachable
)

func NodeStateFromString Uses

func NodeStateFromString(s string) NodeState

func (NodeState) MarshalJSON Uses

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

func (NodeState) String Uses

func (i NodeState) String() string

func (*NodeState) UnmarshalJSON Uses

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 Uses

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

func NewSingleNodeManager Uses

func NewSingleNodeManager(thisNode HTTPNode) *SingleNodeManager

func (*SingleNodeManager) GetPartitions Uses

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

get the partitions that this node is handling.

func (*SingleNodeManager) IsPrimary Uses

func (m *SingleNodeManager) IsPrimary() bool

func (*SingleNodeManager) IsReady Uses

func (m *SingleNodeManager) IsReady() bool

func (*SingleNodeManager) Join Uses

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

func (*SingleNodeManager) MemberList Uses

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

func (*SingleNodeManager) SetPartitions Uses

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

set the partitions that this node is handling.

func (*SingleNodeManager) SetPrimary Uses

func (m *SingleNodeManager) SetPrimary(primary bool)

func (*SingleNodeManager) SetPriority Uses

func (m *SingleNodeManager) SetPriority(prio int)

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

func (*SingleNodeManager) SetReady Uses

func (m *SingleNodeManager) SetReady()

func (*SingleNodeManager) SetState Uses

func (m *SingleNodeManager) SetState(state NodeState)

func (*SingleNodeManager) Start Uses

func (m *SingleNodeManager) Start()

func (*SingleNodeManager) Stop Uses

func (m *SingleNodeManager) Stop()

func (*SingleNodeManager) ThisNode Uses

func (m *SingleNodeManager) ThisNode() Node

type Traceable Uses

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

Directories

PathSynopsis
partitioner

Package cluster imports 29 packages (graph) and is imported by 27 packages. Updated 2020-03-30. Refresh now. Tools for package owners.