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

Method newConnectionProducer

IceFireDB-SQLite/pkg/mysql/client/pool.go:227–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

225}
226
227func (pool *Pool) newConnectionProducer() {
228 var connection Connection
229 var err error
230
231 for {
232 connection.conn = nil
233
234 pool.synchro.Lock()
235
236 connection = pool.getIdleConnectionUnsafe()
237 if connection.conn == nil {
238 if pool.synchro.stats.TotalCount >= pool.maxAlive {
239 // Can't create more connections
240 pool.synchro.Unlock()
241 time.Sleep(10 * time.Millisecond)
242 continue
243 }
244 pool.synchro.stats.TotalCount++ // "Reserving" new connection
245 }
246
247 pool.synchro.Unlock()
248
249 if connection.conn == nil {
250 connection, err = pool.createNewConnection()
251 if err != nil {
252 pool.synchro.Lock()
253 pool.synchro.stats.TotalCount-- // Bad luck, should try again
254 pool.synchro.Unlock()
255
256 time.Sleep(time.Duration(10+rand.Intn(90)) * time.Millisecond)
257 continue
258 }
259 }
260
261 pool.readyConnection <- connection
262 }
263}
264
265func (pool *Pool) createNewConnection() (Connection, error) {
266 var connection Connection

Callers 1

NewPoolFunction · 0.95

Calls 2

createNewConnectionMethod · 0.95

Tested by

no test coverage detected