Documentation ¶
Overview ¶
Package redisclusterutil implements some protocol level details of cluster specification.
It could be used independently from rediscluster package.
Index ¶
- Constants
- func BatchKey(reqs []redis.Request) (string, bool)
- func BatchSlot(reqs []redis.Request) (uint16, bool)
- func CRC16(buf []byte) uint16
- func ParseMasterOnly(resp interface{}) (set map[uint16]struct{}, valid bool, err error)
- func ReqSlot(req redis.Request) (uint16, bool)
- func RequestMasterOnly(c redis.Sender, key string) (set map[uint16]struct{}, valid bool, err error)
- func Resolve(addr string) (string, error)
- func SetMasterOnly(c redis.Sender, key string, slots []uint16) error
- func Slot(key string) uint16
- func UnsetMasterOnly(c redis.Sender, key string, slots []uint16) error
- type InstanceInfo
- type InstanceInfos
- func (iis InstanceInfos) CollectAddressesAndMigrations(addrs map[string]struct{}, migrating map[uint16]struct{})
- func (iis InstanceInfos) HashSum() uint64
- func (iis InstanceInfos) Hosts() []string
- func (iis InstanceInfos) MergeWith(other InstanceInfos) InstanceInfos
- func (iis InstanceInfos) MySelf() *InstanceInfo
- func (iis InstanceInfos) SlotsRanges() []SlotsRange
- type SlotMigration
- type SlotMoving
- type SlotsRange
Constants ¶
const MasterOnlyKey = "CLUSTER_SELF:MASTER_ONLY"
MasterOnlyKey is a key of redis's SET which contains slots number. Cluster connector's main loop will switch these slots to MasterOnly mode on configuration refreshing. When slot migrates, slave redis instance behaves stupidly: they do not know about migration, and therefore they doesn't response with "ASKING" error for migrated key, and doesn't response to "ASKING" command on new shard. MasterOnlyKey is used within custom cluster migration utility to correctly migrate slot.
const NumSlots = 16384
NumSlots is the number of slots keys are sharded into in a redis cluster
Variables ¶
This section is empty.
Functions ¶
func BatchSlot ¶
BatchSlot returns slot common for all requests in batch (if there is such common slot).
func CRC16 ¶
CRC16 returns checksum for a given set of bytes based on the crc algorithm defined for hashing redis keys in a cluster setup
func ParseMasterOnly ¶
ParseMasterOnly parses content of MasterOnlyKey.
func RequestMasterOnly ¶
RequestMasterOnly fetches content of key as a int set, and returns it as a map. If key is empty (""), then MasterOnlyKey is used.
func SetMasterOnly ¶
SetMasterOnly sets MasterOnlyKey to contain specified slots. It is used before slot migration.
Types ¶
type InstanceInfo ¶
type InstanceInfo struct { Uuid string Addr string IP string Port int Port2 int Fail bool MySelf bool // NoAddr means that node were missed due to misconfiguration. // More probably, redis instance with other UUID were started on the same port. NoAddr bool SlaveOf string Slots [][2]uint16 Migrating []SlotMigration }
InstanceInfo represents line of CLUSTER NODES result.
func (*InstanceInfo) AddrValid ¶ added in v0.9.3
func (ii *InstanceInfo) AddrValid() bool
AddrValid returns true if instance is successfully configure. Note that it could differ from HasAddr in some corner cases.
func (*InstanceInfo) HasAddr ¶
func (ii *InstanceInfo) HasAddr() bool
HasAddr returns true if it is addressless instance (replaced with instance with other UUID), it will have no port
func (*InstanceInfo) IsMaster ¶
func (ii *InstanceInfo) IsMaster() bool
IsMaster returns if this instance is master
type InstanceInfos ¶
type InstanceInfos []InstanceInfo
InstanceInfos represents CLUSTER NODES result
func ParseClusterNodes ¶
func ParseClusterNodes(res interface{}) (InstanceInfos, error)
ParseClusterNodes parses result of CLUSTER NODES command.
func (InstanceInfos) CollectAddressesAndMigrations ¶
func (iis InstanceInfos) CollectAddressesAndMigrations(addrs map[string]struct{}, migrating map[uint16]struct{})
CollectAddressesAndMigrations collects all node's addresses and all slot migrations.
func (InstanceInfos) HashSum ¶
func (iis InstanceInfos) HashSum() uint64
HashSum calculates signature of cluster configuration. It assumes, configuration were sorted in some way. If configuration fetched from all hosts has same signature, then cluster is in stable state.
func (InstanceInfos) Hosts ¶
func (iis InstanceInfos) Hosts() []string
Hosts returns set of instance addresses.
func (InstanceInfos) MergeWith ¶
func (iis InstanceInfos) MergeWith(other InstanceInfos) InstanceInfos
MergeWith merges sorted cluster information, giving preference to myself lines. It could be used to obtain "union of all cluster configuration visions" in custom tools managing cluster.
func (InstanceInfos) MySelf ¶
func (iis InstanceInfos) MySelf() *InstanceInfo
MySelf returns info line for the host information were collected from.
func (InstanceInfos) SlotsRanges ¶
func (iis InstanceInfos) SlotsRanges() []SlotsRange
SlotsRanges returns sorted SlotsRange-s made from slots information of cluster configuration.
type SlotMigration ¶
type SlotMigration struct { Number uint16 Moving SlotMoving Peer string }
SlotMigration represents one migrating slot.
type SlotMoving ¶
type SlotMoving byte
SlotMoving is a flag about direction of slot migration.
const ( // SlotMigrating indicates slot is migrating from this instance. SlotMigrating SlotMoving = 1 // SlotImporting indicates slot is importing into this instance. SlotImporting SlotMoving = 2 )
type SlotsRange ¶
type SlotsRange struct { From int To int Addrs []string // addresses of hosts hosting this range of slots. First address is a master, and other are slaves. }
SlotsRange represents slice of slots
func ParseSlotsInfo ¶
func ParseSlotsInfo(res interface{}) ([]SlotsRange, error)
ParseSlotsInfo parses result of CLUSTER SLOTS command