Commit 3563e821 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent cd9db582
...@@ -308,16 +308,28 @@ func (δBtail *ΔBtail) rebuildAll() (err error) { ...@@ -308,16 +308,28 @@ func (δBtail *ΔBtail) rebuildAll() (err error) {
tracefΔBtail("\nRebuildAll @%s..@%s trackNewRoots: %s\n", δBtail.Tail(), δBtail.Head(), δBtail.trackNewRoots) tracefΔBtail("\nRebuildAll @%s..@%s trackNewRoots: %s\n", δBtail.Tail(), δBtail.Head(), δBtail.trackNewRoots)
for root := range δBtail.trackNewRoots { for root := range δBtail.trackNewRoots {
delete(δBtail.trackNewRoots, root)
δBtail.rebuild1(root) δBtail.rebuild1(root)
} }
return nil return nil
} }
// rebuild1IfNeeded rebuilds ΔBtail for single root if that root needs rebuilding.
func (δBtail *ΔBtail) rebuild1IfNeeded(root zodb.Oid) error {
// XXX locking
_, ok := δBtail.trackNewRoots[root]
if !ok {
return nil
}
delete(δBtail.trackNewRoots, root)
return δBtail.rebuild1(root)
}
// rebuild1 rebuilds ΔBtail for single root. // rebuild1 rebuilds ΔBtail for single root.
func (δBtail *ΔBtail) rebuild1(root zodb.Oid) error { func (δBtail *ΔBtail) rebuild1(root zodb.Oid) error {
// XXX locking // XXX locking
delete(δBtail.trackNewRoots, root)
δTtail := δBtail.vδTbyRoot[root] // must be there δTtail := δBtail.vδTbyRoot[root] // must be there
δtrackSet, δrevSet, err := δTtail.rebuild(root, δBtail.δZtail, δBtail.db) δtrackSet, δrevSet, err := δTtail.rebuild(root, δBtail.δZtail, δBtail.db)
if err != nil { if err != nil {
...@@ -328,6 +340,7 @@ func (δBtail *ΔBtail) rebuild1(root zodb.Oid) error { ...@@ -328,6 +340,7 @@ func (δBtail *ΔBtail) rebuild1(root zodb.Oid) error {
return nil return nil
} }
// rebuild rebuilds ΔTtail taking trackNew requests into account. // rebuild rebuilds ΔTtail taking trackNew requests into account.
// //
// It returns: // It returns:
...@@ -338,7 +351,7 @@ func (δBtail *ΔBtail) rebuild1(root zodb.Oid) error { ...@@ -338,7 +351,7 @@ func (δBtail *ΔBtail) rebuild1(root zodb.Oid) error {
// //
// XXX place // XXX place
func (δTtail *ΔTtail) rebuild(root zodb.Oid, δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet blib.PPTreeSubSet, δrevSet setTid, err error) { func (δTtail *ΔTtail) rebuild(root zodb.Oid, δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet blib.PPTreeSubSet, δrevSet setTid, err error) {
defer xerr.Context(&err, "ΔTtail rebuild") defer xerr.Contextf(&err, "ΔTtail<%s> rebuild", root)
// XXX locking // XXX locking
tracefΔBtail("\nRebuild %s @%s .. @%s\n", root, δZtail.Tail(), δZtail.Head()) tracefΔBtail("\nRebuild %s @%s .. @%s\n", root, δZtail.Tail(), δZtail.Head())
...@@ -765,13 +778,18 @@ func (δBtail *ΔBtail) GetAt(ctx context.Context, root *Tree, key Key, at zodb. ...@@ -765,13 +778,18 @@ func (δBtail *ΔBtail) GetAt(ctx context.Context, root *Tree, key Key, at zodb.
// XXX key not tracked -> panic // XXX key not tracked -> panic
// XXX at not ∈ (tail, head] -> panic // XXX at not ∈ (tail, head] -> panic
// XXX dirty -> rebuild // XXX locking
rootAt := root.PJar().At() rootAt := root.PJar().At()
if rootAt != δBtail.Head() { if rootAt != δBtail.Head() {
panicf("δBtail: root.at (@%s) != head (@%s)", rootAt, δBtail.Head()) panicf("δBtail: root.at (@%s) != head (@%s)", rootAt, δBtail.Head())
} }
err = δBtail.rebuild1IfNeeded(root.POid())
if err != nil {
return
}
δTtail := δBtail.vδTbyRoot[root.POid()] δTtail := δBtail.vδTbyRoot[root.POid()]
if δTtail == nil { if δTtail == nil {
panicf("δBtail: root<%s> not tracked", root.POid()) panicf("δBtail: root<%s> not tracked", root.POid())
...@@ -842,7 +860,12 @@ func (δBtail *ΔBtail) GetAt(ctx context.Context, root *Tree, key Key, at zodb. ...@@ -842,7 +860,12 @@ func (δBtail *ΔBtail) GetAt(ctx context.Context, root *Tree, key Key, at zodb.
func (δBtail *ΔBtail) SliceByRootRev(root zodb.Oid, lo, hi zodb.Tid) /*readonly*/[]ΔTree { func (δBtail *ΔBtail) SliceByRootRev(root zodb.Oid, lo, hi zodb.Tid) /*readonly*/[]ΔTree {
xtail.AssertSlice(δBtail, lo, hi) xtail.AssertSlice(δBtail, lo, hi)
// XXX locking // XXX locking
// XXX rebuild
err := δBtail.rebuild1IfNeeded(root)
if err != nil {
panic(err) // XXX
}
δTtail, ok := δBtail.vδTbyRoot[root] δTtail, ok := δBtail.vδTbyRoot[root]
if !ok { if !ok {
return []ΔTree{} return []ΔTree{}
......
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