Documentation ¶
Overview ¶
一致性hash算法,初始化n个虚拟节点,然后将真实的服务器节点包装成虚拟节点,每个真实节点对应100个虚拟节点 根据虚拟节点获取提供服务的真实节点 ServerID_Index
Index ¶
- Constants
- Variables
- func DayTimeZero() int64
- func DayTimeZero2() int64
- func GenUID(serverID uint64) uint64
- func GetDiffDays(t1 int64, t2 int64) int
- func GetGUID() uint64
- func GetLocalIPV4() string
- func GoID() uint64
- func IsEmpty(value interface{}) bool
- func IsFloat(value interface{}) bool
- func IsInt(value interface{}) bool
- func IsMap(value interface{}) bool
- func IsNil(value interface{}) bool
- func IsSameDay(t1 int64, t2 int64) bool
- func IsSlice(value interface{}) bool
- func IsStruct(value interface{}) bool
- func IsUint(value interface{}) bool
- func MonthStartEnd() (int64, int64)
- func NewSnowFlake(node int64) *snowFlake
- func NewSpinLock() sync.Locker
- func Str2Time(timeStr string) (time.Time, error)
- func Str2UnixTime(timeStr string) (int64, error)
- func Time2Str(t int64) string
- func Time2TimeObj(t int64) time.Time
- func TimeMillisecond() int64
- func TimeSecond() int64
- func UniqID() string
- func WeekStartEnd() (int64, int64)
- func YeadAndWeek() (y, w int)
- type ConsistentHash
- type IObjPool
- type ObjPool
- type ObjService
- type Random
- type SortKeys
- type UniqueCode
- type VirtualNode
Constants ¶
View Source
const VNODE_NUMBER = 100
----------------------------------------------------------------------------------
Variables ¶
View Source
var ( // Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds Epoch int64 = 1288834974657 // NodeBits holds the number of bits to use for Node NodeBits uint8 = 10 // StepBits holds the number of bits to use for Step StepBits uint8 = 12 )
View Source
var File file
========================================================================
View Source
var (
Separator = string(filepath.Separator)
)
View Source
var SnowFlake *snowFlake
============================================================================
Functions ¶
func DayTimeZero2 ¶
func DayTimeZero2() int64
func GetLocalIPV4 ¶
func GetLocalIPV4() string
func IsFloat ¶
func IsFloat(value interface{}) bool
IsFloat checks whether `value` is type of float.
func IsSlice ¶
func IsSlice(value interface{}) bool
IsSlice checks whether `value` is type of slice.
func IsStruct ¶
func IsStruct(value interface{}) bool
IsStruct checks whether `value` is type of struct.
func NewSnowFlake ¶
func NewSnowFlake(node int64) *snowFlake
NewNode returns a new snowflake node that can be used to generate snowflake IDs
func NewSpinLock ¶
func YeadAndWeek ¶
func YeadAndWeek() (y, w int)
Types ¶
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
func NewConsistentHash ¶
func NewConsistentHash() *ConsistentHash
func (*ConsistentHash) Delete ¶
func (c *ConsistentHash) Delete(serverID int)
func (*ConsistentHash) Insert ¶
func (c *ConsistentHash) Insert(serverID int)
type ObjPool ¶
type ObjPool struct { New func() interface{} sync.RWMutex // contains filtered or unexported fields }
func NewObjPool ¶
type ObjService ¶
type ObjService struct {
// contains filtered or unexported fields
}
func NewObjService ¶
func NewObjService(rep interface{}) *ObjService
func (*ObjService) Call ¶
func (s *ObjService) Call(methodName string, args ...interface{})
type UniqueCode ¶
type UniqueCode struct {
// contains filtered or unexported fields
}
func NewUniqueCode ¶
func NewUniqueCode() *UniqueCode
func (*UniqueCode) NewUniqID ¶
func (u *UniqueCode) NewUniqID() string
type VirtualNode ¶
type VirtualNode struct {
// contains filtered or unexported fields
}
定义虚拟节点
func NewVNode ¶
func NewVNode(serverID int, index int) *VirtualNode
func (*VirtualNode) GetHash ¶
func (v *VirtualNode) GetHash() uint32
func (*VirtualNode) Index ¶
func (v *VirtualNode) Index() int
func (*VirtualNode) ServerID ¶
func (v *VirtualNode) ServerID() int
Click to show internal directories.
Click to hide internal directories.