pool

package
v0.0.0-...-e11fe06 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: PostgreSQL Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionAllocFn

type ConnectionAllocFn func(shardKey kr.ShardKey, host config.Host, rule *config.BackendRule) (shard.Shard, error)

type ConnectionKepper

type ConnectionKepper interface {
	Put(host shard.Shard) error
	Discard(sh shard.Shard) error
	View() Statistics
}

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 (s *DBPool) BuildHostOrder(key kr.ShardKey, targetSessionAttrs tsa.TSA) ([]config.Host, error)

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

func (s *DBPool) Discard(sh shard.Shard) error

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

func (s *DBPool) ForEach(cb func(sh shard.Shardinfo) error) error

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

func (s *DBPool) ForEachPool(cb func(pool Pool) error) error

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

func (s *DBPool) Put(sh shard.Shard) error

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

func (s *DBPool) ShardMapping() map[string]*config.Shard

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 PoolIterator interface {
	ForEachPool(cb func(p Pool) error) error
}

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

func NewPoolView(info *protos.PoolInfo) *PoolView

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 (r *PoolView) Connection(clid uint, shardKey kr.ShardKey) (shard.Shard, error)

func (*PoolView) Discard

func (r *PoolView) Discard(sh shard.Shard) error

func (*PoolView) ForEach

func (r *PoolView) ForEach(cb func(p shard.Shardinfo) error) error

func (*PoolView) Put

func (r *PoolView) Put(host shard.Shard) error

func (*PoolView) View

func (r *PoolView) View() Statistics

type Statistics

type Statistics struct {
	DB                string
	Usr               string
	Hostname          string
	RouterName        string
	UsedConnections   int
	IdleConnections   int
	QueueResidualSize int
}

type TsaKey

type TsaKey struct {
	Tsa  tsa.TSA
	Host string
	AZ   string
}

Jump to

Keyboard shortcuts

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