Commit d1f63f32 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3597e916
...@@ -52,7 +52,7 @@ type DB struct { ...@@ -52,7 +52,7 @@ type DB struct {
// δtail of database changes for invalidations // δtail of database changes for invalidations
// min(rev) = min(conn.at) for all conn ∈ db (opened and in the pool) // min(rev) = min(conn.at) for all conn ∈ db (opened and in the pool)
δtail ΔTail // [](rev↑, []oid) δtail *ΔTail // [](rev↑, []oid)
// openers waiting for δtail.Head to become covering their at. // openers waiting for δtail.Head to become covering their at.
δwait map[δwaiter]struct{} // set{(at, ready)} XXX -> set_δwaiter? δwait map[δwaiter]struct{} // set{(at, ready)} XXX -> set_δwaiter?
...@@ -69,7 +69,11 @@ type δwaiter struct { ...@@ -69,7 +69,11 @@ type δwaiter struct {
// NewDB creates new database handle. // NewDB creates new database handle.
func NewDB(stor IStorage) *DB { func NewDB(stor IStorage) *DB {
// XXX db options? // XXX db options?
db := &DB{stor: stor} db := &DB{
stor: stor,
δtail: NewΔTail(),
δwait: make(map[δwaiter]struct{}),
}
watchq := make(chan CommitEvent) watchq := make(chan CommitEvent)
stor.AddWatch(watchq) stor.AddWatch(watchq)
// XXX DelWatch? in db.Close() ? // XXX DelWatch? in db.Close() ?
......
...@@ -19,18 +19,18 @@ ...@@ -19,18 +19,18 @@
package zodb package zodb
// XXX do we really need ΔTail to be exported from zodb?
// (other users are low level caches + maybe ZEO/NEO -> zplumbing? but then import cycle)
import ( import (
"fmt" "fmt"
) )
// XXX do we really need ΔTail to be exported from zodb?
// (other users are low level caches + maybe ZEO/NEO -> zplumbing? but then import cycle)
// ΔTail represents tail of revisional changes. // ΔTail represents tail of revisional changes.
// //
// It semantically consists of // It semantically consists of
// //
// [](rev↑, []id) // [](rev↑, []id) XXX + head?
// //
// and index // and index
// //
...@@ -43,10 +43,10 @@ import ( ...@@ -43,10 +43,10 @@ import (
// //
// It provides operations to // It provides operations to
// //
// - XXX Head
// - append information to the tail about next revision, // - append information to the tail about next revision,
// - forget information in the tail past specified revision, and // - forget information in the tail past specified revision, and
// - query the tail about what is last revision that changed an id. // - query the tail about what is last revision that changed an id.
// - query the tail about what head/tail XXX?
// //
// ΔTail is safe to access for multiple-readers / single writer. // ΔTail is safe to access for multiple-readers / single writer.
// //
...@@ -55,6 +55,7 @@ import ( ...@@ -55,6 +55,7 @@ import (
// oid - ZODB object identifier, when ΔTail represents changes to ZODB objects, // oid - ZODB object identifier, when ΔTail represents changes to ZODB objects,
// #blk - file block number, when ΔTail represents changes to a file. // #blk - file block number, when ΔTail represents changes to a file.
type ΔTail struct { type ΔTail struct {
head Tid
tailv []δRevEntry tailv []δRevEntry
lastRevOf map[Oid]Tid // index for LastRevOf queries lastRevOf map[Oid]Tid // index for LastRevOf queries
...@@ -73,9 +74,12 @@ func NewΔTail() *ΔTail { ...@@ -73,9 +74,12 @@ func NewΔTail() *ΔTail {
return &ΔTail{lastRevOf: make(map[Oid]Tid)} return &ΔTail{lastRevOf: make(map[Oid]Tid)}
} }
// XXX + .Head() -> max(rev) XXX or 0 if len(tailv) == 0? // Head returns database state starting from which δtail has history coverage. XXX
//
// For newly created ΔTail Head returns 0.
// Head is ↑, in particular it does not go back to 0 when δtail becomes empty.
func (δtail *ΔTail) Head() Tid { func (δtail *ΔTail) Head() Tid {
panic("TODO") return δtail.head
} }
// XXX add way to extend coverage without appending changed data? (i.e. if a // XXX add way to extend coverage without appending changed data? (i.e. if a
...@@ -86,13 +90,11 @@ func (δtail *ΔTail) Head() Tid { ...@@ -86,13 +90,11 @@ func (δtail *ΔTail) Head() Tid {
// rev must be ↑. // rev must be ↑.
func (δtail *ΔTail) Append(rev Tid, changev []Oid) { func (δtail *ΔTail) Append(rev Tid, changev []Oid) {
// check rev↑ // check rev↑
// XXX better also check even when δtail is ø (after forget) if δtail.head >= rev {
if l := len(δtail.tailv); l > 0 { panic(fmt.Sprintf("δtail.Append: rev not ↑: %s -> %s", δtail.head, rev))
if revPrev := δtail.tailv[l-1].rev; revPrev >= rev {
panic(fmt.Sprintf("δtail.Append: rev not ↑: %s -> %s", revPrev, rev))
}
} }
δtail.head = rev
δtail.tailv = append(δtail.tailv, δRevEntry{rev, changev}) δtail.tailv = append(δtail.tailv, δRevEntry{rev, changev})
for _, id := range changev { for _, id := range changev {
δtail.lastRevOf[id] = rev δtail.lastRevOf[id] = rev
......
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