Documentation ¶
Index ¶
- Constants
- Variables
- type Allocator
- type AutoIncPool
- func (p *AutoIncPool) Cap() int
- func (p *AutoIncPool) Get() (id uint64, ok bool)
- func (p *AutoIncPool) Init(size uint64)
- func (p *AutoIncPool) InitExt(size uint64, checkExisted bool, tryCnt int)
- func (p *AutoIncPool) Len() int
- func (p *AutoIncPool) Put(id uint64) (ok bool)
- func (p AutoIncPool) String() string
- type GCID
- type GlobalAllocator
- type IDPool
- type LockFreeCircularPool
- func (p *LockFreeCircularPool) Cap() int
- func (p *LockFreeCircularPool) Get() (val uint64, ok bool)
- func (p *LockFreeCircularPool) Init(size uint64)
- func (p *LockFreeCircularPool) InitExt(size uint32, fillCount uint32)
- func (p *LockFreeCircularPool) InitForTest(head uint32, fillCount uint32)
- func (p *LockFreeCircularPool) Len() int
- func (p *LockFreeCircularPool) Put(val uint64) (ok bool)
- func (p *LockFreeCircularPool) String() string
- type SimpleAllocator
Constants ¶
const ( // MaxServerID64 is maximum serverID for 64bits global connection ID. MaxServerID64 = 1<<22 - 1 // LocalConnIDBits64 is the number of bits of localConnID for 64bits global connection ID. LocalConnIDBits64 = 40 // MaxLocalConnID64 is maximum localConnID for 64bits global connection ID. MaxLocalConnID64 = 1<<LocalConnIDBits64 - 1 // ReservedCount is the count of reserved connection IDs for internal processes. ReservedCount = 200 )
const ( // IDPoolInvalidValue indicates invalid value from IDPool. IDPoolInvalidValue = math.MaxUint64 )
const LocalConnIDAllocator64TryCount = 10
LocalConnIDAllocator64TryCount is the try count of 64bits local connID allocation.
Variables ¶
var ( // ServerIDBits32 is the number of bits of serverID for 32bits global connection ID. ServerIDBits32 uint = 11 // MaxServerID32 is maximum serverID for 32bits global connection ID. MaxServerID32 uint64 = 1<<ServerIDBits32 - 1 // LocalConnIDBits32 is the number of bits of localConnID for 32bits global connection ID. LocalConnIDBits32 uint = 20 // MaxLocalConnID32 is maximum localConnID for 32bits global connection ID. MaxLocalConnID32 uint64 = 1<<LocalConnIDBits32 - 1 )
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator interface { // NextID returns next connection ID. NextID() uint64 // Release releases connection ID to allocator. Release(connectionID uint64) // GetReservedConnID returns reserved connection ID. GetReservedConnID(reservedNo uint64) uint64 }
Allocator allocates global connection IDs.
type AutoIncPool ¶
type AutoIncPool struct {
// contains filtered or unexported fields
}
AutoIncPool simply do auto-increment to allocate ID. Wrapping will happen.
func (*AutoIncPool) Get ¶
func (p *AutoIncPool) Get() (id uint64, ok bool)
Get id by auto-increment.
func (*AutoIncPool) InitExt ¶
func (p *AutoIncPool) InitExt(size uint64, checkExisted bool, tryCnt int)
InitExt initiates AutoIncPool with more parameters.
func (AutoIncPool) String ¶
func (p AutoIncPool) String() string
String implements IDPool interface.
type GCID ¶
GCID is the Global Connection ID, providing UNIQUE connection IDs across the whole TiDB cluster. Used when GlobalKill feature is enable. See https://github.com/pingcap/tidb/blob/master/docs/design/2020-06-01-global-kill.md 32 bits version:
31 21 20 1 0 +--------+------------------+------+ |serverID| local connID |markup| | (11b) | (20b) | =0 | +--------+------------------+------+
64 bits version:
63 62 41 40 1 0 +--+---------------------+--------------------------------------+------+ | | serverID | local connID |markup| |=0| (22b) | (40b) | =1 | +--+---------------------+--------------------------------------+------+
NOTE: 1. `serverId“ in 64 bits version can be less than 2^11. This will happen when the 32 bits local connID has been used up, while `serverID` stay unchanged. 2. The local connID of a 32 bits GCID can be the same with another 64 bits GCID. This will not violate the uniqueness of GCID.
func ParseConnID ¶
ParseConnID parses an uint64 connection ID to GlobalConnID.
`isTruncated` indicates that older versions of the client truncated the 64-bit GlobalConnID to 32-bit.
type GlobalAllocator ¶
type GlobalAllocator struct {
// contains filtered or unexported fields
}
GlobalAllocator is global connection ID allocator.
func NewGlobalAllocator ¶
func NewGlobalAllocator(serverIDGetter serverIDGetterFn, enable32Bits bool) *GlobalAllocator
NewGlobalAllocator creates a GlobalAllocator.
func (*GlobalAllocator) Allocate ¶
func (g *GlobalAllocator) Allocate() GCID
Allocate allocates a new global connection ID.
func (*GlobalAllocator) GetReservedConnID ¶
func (g *GlobalAllocator) GetReservedConnID(reservedNo uint64) uint64
GetReservedConnID implements ConnIDAllocator interface.
func (*GlobalAllocator) NextID ¶
func (g *GlobalAllocator) NextID() uint64
NextID returns next connection ID.
func (*GlobalAllocator) Release ¶
func (g *GlobalAllocator) Release(connectionID uint64)
Release releases connectionID to pool.
type IDPool ¶
type IDPool interface { fmt.Stringer // Init initiates pool. Init(size uint64) // Len returns length of available id's in pool. // Note that Len() would return -1 when this method is NOT supported. Len() int // Cap returns the capacity of pool. Cap() int // Put puts value to pool. "ok" is false when pool is full. Put(val uint64) (ok bool) // Get gets value from pool. "ok" is false when pool is empty. Get() (val uint64, ok bool) }
IDPool is the pool allocating & deallocating IDs.
type LockFreeCircularPool ¶
type LockFreeCircularPool struct {
// contains filtered or unexported fields
}
LockFreeCircularPool is a lock-free circular implementation of IDPool. Note that to reduce memory usage, LockFreeCircularPool supports 32bits IDs ONLY.
func (*LockFreeCircularPool) Cap ¶
func (p *LockFreeCircularPool) Cap() int
Cap implements IDPool interface.
func (*LockFreeCircularPool) Get ¶
func (p *LockFreeCircularPool) Get() (val uint64, ok bool)
Get implements IDPool interface.
func (*LockFreeCircularPool) Init ¶
func (p *LockFreeCircularPool) Init(size uint64)
Init implements IDPool interface.
func (*LockFreeCircularPool) InitExt ¶
func (p *LockFreeCircularPool) InitExt(size uint32, fillCount uint32)
InitExt initializes LockFreeCircularPool with more parameters. fillCount: fills pool with [1, min(fillCount, 1<<(sizeInBits-1)]. Pass "math.MaxUint32" to fulfill the pool.
func (*LockFreeCircularPool) InitForTest ¶
func (p *LockFreeCircularPool) InitForTest(head uint32, fillCount uint32)
InitForTest used to unit test overflow of head & tail.
func (*LockFreeCircularPool) Len ¶
func (p *LockFreeCircularPool) Len() int
Len implements IDPool interface.
func (*LockFreeCircularPool) Put ¶
func (p *LockFreeCircularPool) Put(val uint64) (ok bool)
Put implements IDPool interface.
func (*LockFreeCircularPool) String ¶
func (p *LockFreeCircularPool) String() string
String implements IDPool interface. Notice: NOT thread safe.
type SimpleAllocator ¶
type SimpleAllocator struct {
// contains filtered or unexported fields
}
SimpleAllocator is a simple connection id allocator used when GlobalKill feature is disable.
func NewSimpleAllocator ¶
func NewSimpleAllocator() *SimpleAllocator
NewSimpleAllocator creates a new SimpleAllocator.
func (*SimpleAllocator) GetReservedConnID ¶
func (*SimpleAllocator) GetReservedConnID(reservedNo uint64) uint64
GetReservedConnID implements ConnIDAllocator interface.
func (*SimpleAllocator) NextID ¶
func (a *SimpleAllocator) NextID() uint64
NextID implements ConnIDAllocator interface.
func (*SimpleAllocator) Release ¶
func (a *SimpleAllocator) Release(id uint64)
Release implements ConnIDAllocator interface.