Commit 670bd87a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 841d1a73
...@@ -455,7 +455,9 @@ func (conn *Connection) resyncAndDBUnlock(txn transaction.Transaction, at Tid) { ...@@ -455,7 +455,9 @@ func (conn *Connection) resyncAndDBUnlock(txn transaction.Transaction, at Tid) {
return return
} }
// get returns connection from db pool most close to at with conn.at ∈ (atMin, at]. // get returns connection from db pool most close to at with conn.at ∈ [atMin, at].
//
// XXX recheck [atMin or (atMin
// //
// if there is no such connection in the pool - nil is returned. // if there is no such connection in the pool - nil is returned.
// must be called with db.mu locked. // must be called with db.mu locked.
...@@ -469,30 +471,31 @@ func (db *DB) get(atMin, at Tid) *Connection { ...@@ -469,30 +471,31 @@ func (db *DB) get(atMin, at Tid) *Connection {
}) })
// search through window of X previous connections and find out the one // search through window of X previous connections and find out the one
// with minimal distance to get to state @at. If all connections are too // with minimal distance to get to state @at that fits into requested range.
// distant - create connection anew. // XXX no -> nil
// //
// XXX search not only previous, but future too? (we can get back to // XXX search not only previous, but future too? (we can get back to
// past by invalidating what was later changed) (but likely it will // past by invalidating what was later changed) (but likely it will
// hurt by destroying cache of more recent connection) // hurt by destroying cache of more recent connection).
const X = 10 // XXX hardcoded const X = 10 // XXX search window size: hardcoded
jδmin := -1 jδmin := -1
for j := i - X; j < i; j++ { for j := i - X; j < i; j++ {
if j < 0 { if j < 0 {
continue continue
} }
if db.pool[j].at < atMin {
continue
}
// TODO search for max N(live) - N(live, that will need to be invalidated) // TODO search for max N(live) - N(live, that will need to be invalidated)
jδmin = j // XXX stub (using rightmost j) jδmin = j // XXX stub (using rightmost j)
} }
// nothing found or too distant // nothing found
const Tnear = 10*time.Minute // XXX hardcoded if jδmin < 0 {
if jδmin < 0 || tabs(δtid(at, db.pool[jδmin].at)) > Tnear { return nil
return newConnection(db, at) // XXX no -> nil
} }
// reuse the connection // found - reuse the connection
conn := db.pool[jδmin] conn := db.pool[jδmin]
copy(db.pool[jδmin:], db.pool[jδmin+1:]) copy(db.pool[jδmin:], db.pool[jδmin+1:])
db.pool[l-1] = nil db.pool[l-1] = nil
...@@ -505,10 +508,6 @@ func (db *DB) get(atMin, at Tid) *Connection { ...@@ -505,10 +508,6 @@ func (db *DB) get(atMin, at Tid) *Connection {
panic("DB.get: live connection in the pool") panic("DB.get: live connection in the pool")
} }
if conn.at != at {
panic("DB.get: TODO: invalidations") // XXX
}
return conn return conn
} }
......
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