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

Method getOldIdleConnections

IceFireDB-SQLite/pkg/mysql/client/pool.go:314–345  ·  view source on GitHub ↗
(dst []Connection)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

nowTsMethod · 0.95

Tested by

no test coverage detected