Documentation ¶
Index ¶
- type ConnectionAllocFn
- type ConnectionKepper
- type DBPool
- func (s *DBPool) BuildHostOrder(key kr.ShardKey, targetSessionAttrs tsa.TSA) ([]config.Host, error)
- func (s *DBPool) ConnectionHost(clid uint, shardKey kr.ShardKey, host config.Host) (shard.Shard, error)
- func (s *DBPool) ConnectionWithTSA(clid uint, key kr.ShardKey, targetSessionAttrs tsa.TSA) (shard.Shard, error)
- func (s *DBPool) Discard(sh shard.Shard) error
- func (s *DBPool) ForEach(cb func(sh shard.Shardinfo) error) error
- func (s *DBPool) ForEachPool(cb func(pool Pool) error) error
- func (s *DBPool) Put(sh shard.Shard) error
- func (s *DBPool) SetRule(rule *config.BackendRule)
- func (s *DBPool) ShardMapping() map[string]*config.Shard
- func (s *DBPool) View() Statistics
- type MultiShardPool
- type Pool
- type PoolIterator
- type PoolView
- type Statistics
- type TsaKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionAllocFn ¶
type ConnectionKepper ¶
type DBPool ¶
type DBPool struct { Pool ShuffleHosts bool PreferAZ string // contains filtered or unexported fields }
func NewDBPool ¶
func NewDBPool(mapping map[string]*config.Shard, startupParams *startup.StartupParams, preferAZ string) *DBPool
NewDBPool creates a new DBPool instance with the given shard mapping. It uses the provided mapping to allocate shards based on the shard key, and initializes the necessary connections and configurations for each shard. The function returns a DBPool interface that can be used to interact with the pool.
Parameters:
- mapping: A map containing the shard mapping, where the key is the shard name and the value is a pointer to the corresponding Shard configuration.
- sp: A StartupParams
Returns:
- DBPool: A DBPool interface that represents the created pool.
func NewDBPoolFromMultiPool ¶
func NewDBPoolFromMultiPool(mapping map[string]*config.Shard, sp *startup.StartupParams, mp MultiShardPool, tsaRecheckDuration time.Duration) *DBPool
func (*DBPool) BuildHostOrder ¶
func (*DBPool) ConnectionHost ¶
func (s *DBPool) ConnectionHost(clid uint, shardKey kr.ShardKey, host config.Host) (shard.Shard, error)
ConnectionHost implements DBPool.
func (*DBPool) ConnectionWithTSA ¶
func (s *DBPool) ConnectionWithTSA(clid uint, key kr.ShardKey, targetSessionAttrs tsa.TSA) (shard.Shard, error)
Connection acquires a new instance connection for a client to a shard with target session attributes. It selects a shard host based on the target session attributes and returns a shard connection. If no connection can be established, it returns an error.
Parameters:
- clid: The client ID.
- key: The shard key.
- targetSessionAttrs: The target session attributes.
Returns:
- shard.Shard: The acquired shard connection.
- error: An error if the connection cannot be established.
TODO : unit tests
func (*DBPool) Discard ¶
Discard removes a shard from the instance pool. It returns an error if the removal fails.
Parameters: - sh: The shard to be removed from the pool.
Returns: - error: An error if the removal fails, nil otherwise.
func (*DBPool) ForEach ¶
ForEach iterates over each shard in the instance pool and calls the provided callback function. It returns an error if the callback function returns an error.
Parameters: - cb: The callback function to be called for each shard in the instance pool.
Returns: - error: An error if the callback function returns an error.
func (*DBPool) ForEachPool ¶
ForEachPool iterates over each pool in the instance pool and calls the provided callback function. It returns an error if the callback function returns an error.
Parameters: - cb: The callback function to be called for each pool in the instance pool.
Returns: - error: An error if the callback function returns an error.
func (*DBPool) Put ¶
Put puts a shard into the instance pool. It discards the shard if it is not synchronized or if it is not in idle transaction status. Otherwise, it puts the shard into the pool.
Parameters: - sh: The shard to be put into the pool.
Returns: - error: An error if the shard is discarded or if there is an error putting the shard into the pool.
TODO : unit tests
func (*DBPool) SetRule ¶
func (s *DBPool) SetRule(rule *config.BackendRule)
SetRule initializes the backend rule in the instance pool. It takes a pointer to a BackendRule as a parameter and saves it
Parameters:
- rule: A pointer to a BackendRule representing the backend rule to be initialized.
func (*DBPool) ShardMapping ¶
ShardMapping returns the shard mapping of the instance pool.
Returns:
- map[string]*config.Shard: The shard mapping of the instance pool.
func (*DBPool) View ¶
func (s *DBPool) View() Statistics
View implements DBPool. Subtle: this method shadows the method (Pool).View of InstancePoolImpl.Pool.
type MultiShardPool ¶
type MultiShardPool interface { ConnectionKepper shard.ShardIterator PoolIterator ConnectionHost(clid uint, shardKey kr.ShardKey, host config.Host) (shard.Shard, error) SetRule(rule *config.BackendRule) }
Host
func NewPool ¶
func NewPool(allocFn ConnectionAllocFn) MultiShardPool
NewPool creates a new MultiShardPool with the given connection allocation function. The connection allocation function allocFn is used to allocate connections for each shard. It returns a pointer to the created MultiShardPool.
Parameters:
- allocFn: The connection allocation function to be used for the MultiShardPool.
Returns:
- MultiShardPool: The created MultiShardPool.
type Pool ¶
type Pool interface { ConnectionKepper shard.ShardIterator Connection(clid uint, shardKey kr.ShardKey) (shard.Shard, error) }
dedicated host connection pool
func NewShardPool ¶
func NewShardPool(allocFn ConnectionAllocFn, host config.Host, beRule *config.BackendRule) Pool
NewShardPool creates a new instance of shardPool based on the provided ConnectionAllocFn, host, and BackendRule. It initializes the fields of shardPool with the corresponding values from the ConnectionAllocFn and BackendRule. It also initializes the queue with the ConnectionLimit.
Parameters:
- allocFn: The ConnectionAllocFn to be used for the shardPool.
- host: The host to be used for the shardPool.
- beRule: The BackendRule to be used for the shardPool.
Returns:
- Pool: The created instance of shardPool.
type PoolIterator ¶
type PoolView ¶
type PoolView struct { Id string DB string Usr string Host string Router string ConnCount int64 IdleConnCount int64 QueueSize int64 // contains filtered or unexported fields }
func NewPoolView ¶
NewPoolView creates a new instance of PoolView based on the provided PoolInfo. The PoolView is a dummy implementation of the Pool interface.
func (*PoolView) Connection ¶
func (*PoolView) View ¶
func (r *PoolView) View() Statistics