globalconn

package
v1.1.0-beta.0...-a878e1f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	// IDPoolInvalidValue indicates invalid value from IDPool.
	IDPoolInvalidValue = math.MaxUint64
)
View Source
const LocalConnIDAllocator64TryCount = 10

LocalConnIDAllocator64TryCount is the try count of 64bits local connID allocation.

Variables

View Source
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) Cap

func (p *AutoIncPool) Cap() int

Cap implements IDPool interface.

func (*AutoIncPool) Get

func (p *AutoIncPool) Get() (id uint64, ok bool)

Get id by auto-increment.

func (*AutoIncPool) Init

func (p *AutoIncPool) Init(size uint64)

Init initiates AutoIncPool.

func (*AutoIncPool) InitExt

func (p *AutoIncPool) InitExt(size uint64, checkExisted bool, tryCnt int)

InitExt initiates AutoIncPool with more parameters.

func (*AutoIncPool) Len

func (p *AutoIncPool) Len() int

Len implements IDPool interface.

func (*AutoIncPool) Put

func (p *AutoIncPool) Put(id uint64) (ok bool)

Put id back to pool.

func (AutoIncPool) String

func (p AutoIncPool) String() string

String implements IDPool interface.

type GCID

type GCID struct {
	ServerID    uint64
	LocalConnID uint64
	Is64bits    bool
}

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

func ParseConnID(id uint64) (g GCID, isTruncated bool, err error)

ParseConnID parses an uint64 connection ID to GlobalConnID.

`isTruncated` indicates that older versions of the client truncated the 64-bit GlobalConnID to 32-bit.

func (*GCID) ToConnID

func (g *GCID) ToConnID() uint64

ToConnID returns the 64bits connection ID

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.

Jump to

Keyboard shortcuts

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