Documentation
¶
Index ¶
- Constants
- func RegisterLocator(builder Builder)
- type Builder
- type StaticLocator
- func (s *StaticLocator) All() []*SupernodeGroup
- func (s *StaticLocator) Get() *Supernode
- func (s *StaticLocator) GetGroup(name string) *SupernodeGroup
- func (s *StaticLocator) Next() *Supernode
- func (s *StaticLocator) Refresh() bool
- func (s *StaticLocator) Report(node string, metrics *SupernodeMetrics)
- func (s *StaticLocator) Select(key interface{}) *Supernode
- func (s *StaticLocator) Size() int
- func (s *StaticLocator) String() string
- type SuperNodeEvent
- type Supernode
- type SupernodeGroup
- type SupernodeLocator
- type SupernodeMetrics
Constants ¶
const ( // GroupDefaultName indicates all the supernodes in this group are set as // default value. It's only used when the supernode list from configuration // or CLI is empty. GroupDefaultName = "default" // GroupConfigName indicates all the supernodes in this group come from // configuration or CLI. GroupConfigName = "config" )
Variables ¶
This section is empty.
Functions ¶
func RegisterLocator ¶
func RegisterLocator(builder Builder)
RegisterLocator provides a way for users to customize SupernodeLocator. This function should be invoked before CreateLocator.
Types ¶
type Builder ¶
type Builder func(cfg *config.Config) SupernodeLocator
Builder defines the constructor of SupernodeLocator.
var DefaultBuilder Builder = func(cfg *config.Config) SupernodeLocator { if cfg == nil || len(cfg.Nodes) == 0 { return NewStaticLocator(GroupDefaultName, config.GetDefaultSupernodesValue()) } locator, _ := NewStaticLocatorFromStr(GroupConfigName, cfg.Nodes) return locator }
DefaultBuilder returns a supernode locator with default value when supernodes in the config file is empty.
type StaticLocator ¶
type StaticLocator struct { Group *SupernodeGroup // contains filtered or unexported fields }
StaticLocator uses the nodes passed from configuration or CLI.
func NewStaticLocator ¶
func NewStaticLocator(groupName string, nodes []*config.NodeWeight) *StaticLocator
NewStaticLocator constructs StaticLocator which uses the nodes passed from configuration or CLI.
func NewStaticLocatorFromStr ¶
func NewStaticLocatorFromStr(groupName string, nodes []string) (*StaticLocator, error)
NewStaticLocatorFromStr constructs StaticLocator from string list. The format of nodes is: ip:port=weight
func (*StaticLocator) All ¶
func (s *StaticLocator) All() []*SupernodeGroup
All returns all the supernodes.
func (*StaticLocator) Get ¶
func (s *StaticLocator) Get() *Supernode
Get returns the current selected supernode, it should be idempotent. It should return nil before first calling the Next method.
func (*StaticLocator) GetGroup ¶
func (s *StaticLocator) GetGroup(name string) *SupernodeGroup
GetGroup returns the group with the giving name.
func (*StaticLocator) Next ¶
func (s *StaticLocator) Next() *Supernode
Next chooses the next available supernode for retrying or other purpose. The current supernode should be set as this result.
func (*StaticLocator) Refresh ¶
func (s *StaticLocator) Refresh() bool
Refresh refreshes all the supernodes.
func (*StaticLocator) Report ¶
func (s *StaticLocator) Report(node string, metrics *SupernodeMetrics)
Report records the metrics of the current supernode in order to choose a more appropriate supernode for the next time if necessary.
func (*StaticLocator) Select ¶
func (s *StaticLocator) Select(key interface{}) *Supernode
Select chooses a supernode based on the giving key. It should not affect the result of method 'Get()'.
func (*StaticLocator) Size ¶
func (s *StaticLocator) Size() int
Size returns the number of all supernodes.
func (*StaticLocator) String ¶
func (s *StaticLocator) String() string
type SuperNodeEvent ¶
type SuperNodeEvent struct {
// contains filtered or unexported fields
}
func NewDisableEvent ¶
func NewDisableEvent(node string) *SuperNodeEvent
func NewEnableEvent ¶
func NewEnableEvent(node string) *SuperNodeEvent
type Supernode ¶
type Supernode struct { Schema string IP string Port int Weight int GroupName string Metrics *SupernodeMetrics }
Supernode holds the basic information of supernodes.
type SupernodeGroup ¶
type SupernodeGroup struct { Name string Nodes []*Supernode // Infos stores other information that user can customized. Infos map[string]string }
SupernodeGroup groups supernodes which have same attributes. For example, we can group supernodes by region, business, version and so on. The implementation of SupernodeLocator can select a supernode based on the group.
func (*SupernodeGroup) GetNode ¶
func (sg *SupernodeGroup) GetNode(idx int) *Supernode
GetNode return the node with the giving index.
type SupernodeLocator ¶
type SupernodeLocator interface { // Get returns the current selected supernode, it should be idempotent. // It should return nil before first calling the Next method. Get() *Supernode // Next chooses the next available supernode for retrying or other // purpose. The current supernode should be set as this result. Next() *Supernode // Select chooses a supernode based on the giving key. // It should not affect the result of method 'Get()'. Select(key interface{}) *Supernode // GetGroup returns the group with the giving name. GetGroup(name string) *SupernodeGroup // All returns all the supernodes. All() []*SupernodeGroup // Size returns the number of all supernodes. Size() int // Report records the metrics of the current supernode in order to choose a // more appropriate supernode for the next time if necessary. Report(node string, metrics *SupernodeMetrics) // Refresh refreshes all the supernodes. Refresh() bool }
SupernodeLocator defines the way how to get available supernodes. Developers can implement their own locator more flexibly , not just get the supernode list from configuration or CLI.
func CreateLocator ¶
func CreateLocator(cfg *config.Config) SupernodeLocator
CreateLocator creates a supernode locator with the giving config.
func NewHashCirclerLocator ¶
type SupernodeMetrics ¶
type SupernodeMetrics struct {
Metrics map[string]interface{}
}
SupernodeMetrics holds metrics used for the locator to choose supernode.