Commit bbe72558 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c953e319
...@@ -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())
......
...@@ -87,6 +87,13 @@ func (δtail *ΔTail) Len() int { ...@@ -87,6 +87,13 @@ func (δtail *ΔTail) Len() int {
return len(δtail.tailv) return len(δtail.tailv)
} }
// Data returns slice with δtail data.
//
// The caller must not modify returned slice.
func (δtail *ΔTail) Data() /*readonly*/ []ΔRevEntry {
return δtail.tailv
}
// Head returns newest database state for which δtail has history coverage. // Head returns newest database state for which δtail has history coverage.
// //
// Head is ↑ on Append, in particular it does not ↓ on Forget even if δtail becomes empty. // Head is ↑ on Append, in particular it does not ↓ on Forget even if δtail becomes empty.
......
...@@ -61,6 +61,10 @@ func TestΔTail(t *testing.T) { ...@@ -61,6 +61,10 @@ func TestΔTail(t *testing.T) {
t.Fatalf("tailv:\nhave: %v\nwant: %v", δtail.tailv, tailv) t.Fatalf("tailv:\nhave: %v\nwant: %v", δtail.tailv, tailv)
} }
if d := δtail.Data(); !tailvEqual(d, tailv) {
t.Fatalf("Data():\nhave: %v\nwant: %v", d, tailv)
}
if l := δtail.Len(); l != len(tailv) { if l := δtail.Len(); l != len(tailv) {
t.Fatalf("Len() -> %d ; want %d", l, len(tailv)) t.Fatalf("Len() -> %d ; want %d", l, len(tailv))
} }
......
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