Commit 4224b580 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: DB: preserve δtail not to go down to ø slice on seldom commits

If we use only the rule that we keep last 10 minutes of database
history, and commits come less often than that - e.g. once per 30
minutes, on every new commit we'll be throwing away all δtail data,
which would result on completely throwing away live cache on every
DB.Open .

Add another rule to cover seldom updates spectrum so that we never throw
till empty δtail and keep at least 10 elements in δtail queue. This will
make sure that live cache is preserved even when updates to database are
seldom to come.

Tests pending...
parent 8ee32480
...@@ -103,12 +103,16 @@ type DB struct { ...@@ -103,12 +103,16 @@ type DB struct {
// FIXME for now we just fix // FIXME for now we just fix
// //
// Tδkeep = 10min // Tδkeep = 10min
// δkeep = 10
// //
// and keep δtail coverage for Tδkeep time // and keep δtail coverage for Tδkeep time, with ensuring that we keep
// at least δkeep entries not to loose cache on very seldom commits:
// //
// timelen(δtail) = Tδkeep // timelen(δtail) = Tδkeep
// len(δtail) ≥ δkeep
δtail *ΔTail // [](rev↑, []oid) δtail *ΔTail // [](rev↑, []oid)
tδkeep time.Duration tδkeep time.Duration
δkeep int
// waiters for δtail.Head to become ≥ their at. // waiters for δtail.Head to become ≥ their at.
hwait map[hwaiter]struct{} // set{(at, ready)} hwait map[hwaiter]struct{} // set{(at, ready)}
...@@ -130,6 +134,7 @@ func NewDB(stor IStorage) *DB { ...@@ -130,6 +134,7 @@ func NewDB(stor IStorage) *DB {
hwait: make(map[hwaiter]struct{}), hwait: make(map[hwaiter]struct{}),
tδkeep: 10*time.Minute, // see δtail discussion tδkeep: 10*time.Minute, // see δtail discussion
δkeep: 10, // ---- // ----
} }
at0 := stor.AddWatch(db.watchq) at0 := stor.AddWatch(db.watchq)
...@@ -261,9 +266,25 @@ func (db *DB) watcher() (err error) { ...@@ -261,9 +266,25 @@ func (db *DB) watcher() (err error) {
// forget older δtail entries // forget older δtail entries
tcut := db.δtail.Head().Time().Add(-db.tδkeep) tcut := db.δtail.Head().Time().Add(-db.tδkeep)
δcut := TidFromTime(tcut) δcut := TidFromTime(tcut) // cut by δTkeep rule
//fmt.Printf("db: watcher: δtail: = (%s, %s]\n", db.δtail.Tail(), db.δtail.Head()) //fmt.Printf("db: watcher: δtail: = (%s, %s]\n", db.δtail.Tail(), db.δtail.Head())
//fmt.Printf("db: watcher: forget <= %s\n", δcut) //fmt.Printf("db: watcher: forget <= %s\n", δcut)
// take db.δkeep into account, so that we preserve len(δtail) ≥ δkeep
δtail := db.δtail.Data()
rcut := δcut // cut by δkeep rule
if l := len(δtail); l > db.δkeep {
rcut = δtail[l-db.δkeep-1].Rev
rcut -= 1 // ForgetPast forgets by ≤
} else {
rcut = 0 // keep everything
}
if rcut < δcut {
//fmt.Printf("db: watcher: forget %s -> %s (seldom commits)\n", δcut, rcut)
δcut = rcut
}
db.δtail.ForgetPast(δcut) db.δtail.ForgetPast(δcut)
//fmt.Printf("db: watcher: δtail: -> (%s, %s]\n", db.δtail.Tail(), db.δtail.Head()) //fmt.Printf("db: watcher: δtail: -> (%s, %s]\n", db.δtail.Tail(), db.δtail.Head())
......
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