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

Function NewPool

IceFireDB-SQLite/pkg/mysql/client/pool.go:83–132  ·  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 {
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 pool.startNewConnections(pool.minAlive)
127 }
128
129 go pool.closeOldIdleConnections()
130
131 return pool
132}
133
134func (pool *Pool) GetStats(stats *ConnectionStats) {
135 pool.synchro.Lock()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected