Commit 2799f995 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: DB.connv -> DB.pool

pool is a better name for "pool of unused connections" compared to connv.
parent 0806740d
...@@ -48,7 +48,9 @@ type DB struct { ...@@ -48,7 +48,9 @@ type DB struct {
stor IStorage stor IStorage
mu sync.Mutex mu sync.Mutex
connv []*Connection // order by ↑= .at
// pool of unused connections.
pool []*Connection // order by ↑= .at
// information about invalidations // information about invalidations
// XXX -> Storage. XXX or -> Cache? (so it is not duplicated many times for many DB case) // XXX -> Storage. XXX or -> Cache? (so it is not duplicated many times for many DB case)
...@@ -161,12 +163,12 @@ func (db *DB) get(at Tid) *Connection { ...@@ -161,12 +163,12 @@ func (db *DB) get(at Tid) *Connection {
db.mu.Lock() db.mu.Lock()
defer db.mu.Unlock() defer db.mu.Unlock()
l := len(db.connv) l := len(db.pool)
// find connv index corresponding to at: // find pool index corresponding to at:
// [i-1].at ≤ at < [i].at // [i-1].at ≤ at < [i].at
i := sort.Search(l, func(i int) bool { i := sort.Search(l, func(i int) bool {
return at < db.connv[i].at return at < db.pool[i].at
}) })
// search through window of X previous connections and find out the one // search through window of X previous connections and find out the one
...@@ -188,15 +190,15 @@ func (db *DB) get(at Tid) *Connection { ...@@ -188,15 +190,15 @@ func (db *DB) get(at Tid) *Connection {
// nothing found or too distant // nothing found or too distant
const Tnear = 10*time.Minute // XXX hardcoded const Tnear = 10*time.Minute // XXX hardcoded
if jδmin < 0 || tabs(δtid(at, db.connv[jδmin].at)) > Tnear { if jδmin < 0 || tabs(δtid(at, db.pool[jδmin].at)) > Tnear {
return newConnection(db, at) return newConnection(db, at)
} }
// reuse the connection // reuse the connection
conn := db.connv[jδmin] conn := db.pool[jδmin]
copy(db.connv[jδmin:], db.connv[jδmin+1:]) copy(db.pool[jδmin:], db.pool[jδmin+1:])
db.connv[l-1] = nil db.pool[l-1] = nil
db.connv = db.connv[:l-1] db.pool = db.pool[:l-1]
if conn.db != db { if conn.db != db {
panic("DB.get: foreign connection in the pool") panic("DB.get: foreign connection in the pool")
...@@ -223,16 +225,16 @@ func (db *DB) put(conn *Connection) { ...@@ -223,16 +225,16 @@ func (db *DB) put(conn *Connection) {
db.mu.Lock() db.mu.Lock()
defer db.mu.Unlock() defer db.mu.Unlock()
// XXX check if len(connv) > X, and drop conn if yes // XXX check if len(pool) > X, and drop conn if yes
// [i-1].at ≤ at < [i].at // [i-1].at ≤ at < [i].at
i := sort.Search(len(db.connv), func(i int) bool { i := sort.Search(len(db.pool), func(i int) bool {
return conn.at < db.connv[i].at return conn.at < db.pool[i].at
}) })
//db.connv = append(db.connv[:i], conn, db.connv[i:]...) //db.pool = append(db.pool[:i], conn, db.pool[i:]...)
db.connv = append(db.connv, nil) db.pool = append(db.pool, nil)
copy(db.connv[i+1:], db.connv[i:]) copy(db.pool[i+1:], db.pool[i:])
db.connv[i] = conn db.pool[i] = conn
// XXX GC too idle connections here? // XXX GC too idle connections here?
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment