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

Method getOldIdleConnections

IceFireDB-SQLProxy/pkg/mysql/client/pool.go:316–347  ·  view source on GitHub ↗
(dst []Connection)

Source from the content-addressed store, hash-verified

314}
315
316func (pool *Pool) getOldIdleConnections(dst []Connection) []Connection {
317 dst = dst[:0]
318
319 pool.synchro.Lock()
320
321 synchro := &pool.synchro
322
323 idleCnt := len(synchro.idleConnections)
324 checkBefore := pool.nowTs() - pool.idlePingTimeout
325
326 for i := idleCnt - 1; i >= 0; i-- {
327 if synchro.idleConnections[i].lastUseAt > checkBefore {
328 continue
329 }
330
331 dst = append(dst, synchro.idleConnections[i])
332
333 last := idleCnt - 1
334 if i < last {
335 // Removing an item from the middle of a slice
336 synchro.idleConnections[i], synchro.idleConnections[last] = synchro.idleConnections[last], synchro.idleConnections[i]
337 }
338
339 synchro.idleConnections[last].conn = nil
340 synchro.idleConnections = synchro.idleConnections[:last]
341 idleCnt--
342 }
343
344 pool.synchro.Unlock()
345
346 return dst
347}
348
349func (pool *Pool) recheckConnections(connections []Connection) {
350 const workerCnt = 2 // Heuristic :)

Callers 1

Calls 1

nowTsMethod · 0.95

Tested by

no test coverage detected