Documentation ¶
Index ¶
- Constants
- type AutoIncPool
- type IDPool
- type LockFreeCircularPool
- func (p *LockFreeCircularPool) Get() (val uint64, ok bool)
- func (p *LockFreeCircularPool) Init(sizeInBits uint32)
- func (p *LockFreeCircularPool) InitExt(sizeInBits 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
Constants ¶
const ( // MaxServerID32 is maximum serverID for 32bits global connection ID. MaxServerID32 = 1<<11 - 1 // LocalConnIDBits32 is the number of bits of localConnID for 32bits global connection ID. LocalConnIDBits32 = 20 // MaxLocalConnID32 is maximum localConnID for 32bits global connection ID. MaxLocalConnID32 = 1<<LocalConnIDBits32 - 1 // 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 )
GlobalConnID 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 | +--+---------------------+--------------------------------------+------+
const ( // IDPoolInvalidValue indicates invalid value from IDPool. IDPoolInvalidValue = math.MaxUint64 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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) Init ¶
func (p *AutoIncPool) Init(sizeInBits uint32)
Init initiates AutoIncPool.
func (*AutoIncPool) InitExt ¶
func (p *AutoIncPool) InitExt(sizeInBits uint32, checkExisted bool, tryCnt int)
InitExt initiates AutoIncPool with more parameters.
func (AutoIncPool) String ¶
func (p AutoIncPool) String() string
String implements IDPool interface.
type IDPool ¶
type IDPool interface { fmt.Stringer // Init initiates pool. Init(sizeInBits uint32) // Len returns length of available id's in pool. // Note that Len() would return -1 when this method is NOT supported. Len() 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) Get ¶
func (p *LockFreeCircularPool) Get() (val uint64, ok bool)
Get implements IDPool interface.
func (*LockFreeCircularPool) Init ¶
func (p *LockFreeCircularPool) Init(sizeInBits uint32)
Init implements IDPool interface.
func (*LockFreeCircularPool) InitExt ¶
func (p *LockFreeCircularPool) InitExt(sizeInBits 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.