metadata

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleMaster = "master"
	RoleSlave  = "slave"
)
View Source
const (
	MinSlotID = 0
	MaxSlotID = 16383
)

Variables

View Source
var (
	ErrEntryNoExists           = errors.New("the entry does not exist")
	ErrEntryExisted            = errors.New("the entry already existed")
	ErrIndexOutOfRange         = errors.New("index out of range")
	ErrShardNoMatchPromoteNode = errors.New("no match promote node in shard")
	ErrShardNoReplica          = errors.New("no replica in shard")
)
View Source
var ErrSlotOutOfRange = errors.New("slot id was out of range, should be between 0 and 16383")
View Source
var (
	NodeIdLen = 40
)

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	Name    string        `json:"name"`
	Version int64         `json:"version"`
	Shards  []Shard       `json:"shards"`
	Config  ClusterConfig `json:"config"`
}

func ParseCluster

func ParseCluster(clusterStr string) (*Cluster, error)

ParseCluster will parse the cluster string into cluster topology.

func (*Cluster) CheckOverlap

func (cluster *Cluster) CheckOverlap(slotRange *SlotRange) error

func (*Cluster) ToSlotString

func (cluster *Cluster) ToSlotString() (string, error)

type ClusterConfig

type ClusterConfig struct {
	Name              string `json:"name"`
	HeartBeatInterval uint64 `json:"heartbeat_interval"`
	HeartBeatRetries  uint64 `json:"heartbeat_retries"`
}

type NodeInfo

type NodeInfo struct {
	ID        string `json:"id" validate:"required"`
	Addr      string `json:"addr" validate:"required"`
	Role      string `json:"role" validate:"required"`
	Password  string `json:"password"`
	CreatedAt int64  `json:"created_at"`
}

func (*NodeInfo) IsMaster

func (nodeInfo *NodeInfo) IsMaster() bool

func (*NodeInfo) Validate

func (nodeInfo *NodeInfo) Validate() error

type Shard

type Shard struct {
	Nodes         []NodeInfo  `json:"nodes"`
	SlotRanges    []SlotRange `json:"slot_ranges"`
	ImportSlot    int         `json:"import_slot"`
	MigratingSlot int         `json:"migrating_slot"`
}

func NewShard

func NewShard() *Shard

func (*Shard) HasOverlap

func (shard *Shard) HasOverlap(slotRange *SlotRange) bool

func (*Shard) ToSlotsString

func (shard *Shard) ToSlotsString() (string, error)

type Shards

type Shards []Shard

func (Shards) Len

func (s Shards) Len() int

func (Shards) Less

func (s Shards) Less(i, j int) bool

func (Shards) Swap

func (s Shards) Swap(i, j int)

type SlotRange

type SlotRange struct {
	Start int `json:"start"`
	Stop  int `json:"stop"`
}

func MergeSlotRanges

func MergeSlotRanges(source []SlotRange, target []SlotRange) []SlotRange

func NewSlotRange

func NewSlotRange(start, stop int) (*SlotRange, error)

func ParseSlotRange

func ParseSlotRange(s string) (*SlotRange, error)

func RemoveSlotRanges

func RemoveSlotRanges(source []SlotRange, target []SlotRange) []SlotRange

func SpiltSlotRange

func SpiltSlotRange(number int) []SlotRange

func (*SlotRange) HasOverlap

func (slotRange *SlotRange) HasOverlap(that *SlotRange) bool

func (*SlotRange) MarshalJSON

func (slotRange *SlotRange) MarshalJSON() ([]byte, error)

func (*SlotRange) String

func (slotRange *SlotRange) String() string

func (*SlotRange) UnmarshalJSON

func (slotRange *SlotRange) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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