MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / NewPool

Function NewPool

IceFireDB-SQLProxy/pkg/mysql/client/pool.go:83–134  ·  view source on GitHub ↗

NewPool initializes new connection pool and uses params: addr, user, password, dbName and options. minAlive specifies the minimum number of open connections that the pool will try to maintain. maxAlive specifies the maximum number of open connections (for internal reasons, may be greater by 1

(
	logFunc LogFunc,
	minAlive int,
	maxAlive int,
	maxIdle int,
	addr string,
	user string,
	password string,
	dbName string,
	options ...func(conn *Conn),
)

Source from the content-addressed store, hash-verified

81// (for internal reasons, may be greater by 1 inside newConnectionProducer).
82// maxIdle specifies the maximum number of idle connections (see DefaultIdleTimeout).
83func NewPool(
84 logFunc LogFunc,
85 minAlive int,
86 maxAlive int,
87 maxIdle int,
88 addr string,
89 user string,
90 password string,
91 dbName string,
92 options ...func(conn *Conn),
93) (*Pool, error) {
94 if minAlive > maxAlive {
95 minAlive = maxAlive
96 }
97 if maxIdle > maxAlive {
98 maxIdle = maxAlive
99 }
100 if maxIdle <= minAlive {
101 maxIdle = minAlive
102 }
103
104 pool := &Pool{
105 logFunc: logFunc,
106 minAlive: minAlive,
107 maxAlive: maxAlive,
108 maxIdle: maxIdle,
109
110 idleCloseTimeout: Timestamp(math.Ceil(DefaultIdleTimeout.Seconds())),
111 idlePingTimeout: Timestamp(math.Ceil(MaxIdleTimeoutWithoutPing.Seconds())),
112
113 connect: func() (*Conn, error) {
114 return Connect(addr, user, password, dbName, options...)
115 },
116
117 readyConnection: make(chan Connection),
118 }
119
120 pool.synchro.idleConnections = make([]Connection, 0, pool.maxIdle)
121
122 go pool.newConnectionProducer()
123
124 if pool.minAlive > 0 {
125 pool.logFunc(`Pool: Setup %d new connections (minimal pool size)...`, pool.minAlive)
126 if err := pool.startNewConnections(pool.minAlive); err != nil {
127 return nil, err
128 }
129 }
130
131 go pool.closeOldIdleConnections()
132
133 return pool, nil
134}
135
136func (pool *Pool) GetStats(stats *ConnectionStats) {
137 pool.synchro.Lock()

Callers 2

initClientPoolMethod · 0.92
NewMySQLProxyFunction · 0.92

Calls 5

newConnectionProducerMethod · 0.95
startNewConnectionsMethod · 0.95
TimestampTypeAlias · 0.70
ConnectFunction · 0.70

Tested by

no test coverage detected