Commit c9f93cf0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9ac61959
...@@ -313,7 +313,7 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P ...@@ -313,7 +313,7 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
// go backwards and merge vδT <- treediff(lo..hi/trackNew) // go backwards and merge vδT <- treediff(lo..hi/trackNew)
vδZ := δZtail.Data() vδZ := δZtail.Data()
vδtrack := []*ΔPPTreeSubSet{} // vδtrack := []*ΔPPTreeSubSet{}
for i := len(vδZ)-1; i>=0; i-- { for i := len(vδZ)-1; i>=0; i-- {
δZ := vδZ[i] δZ := vδZ[i]
...@@ -326,6 +326,19 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P ...@@ -326,6 +326,19 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
atPrev = δZtail.Tail() atPrev = δZtail.Tail()
} }
δtrackNew, δtkeycov, err := δTtail.rebuild1(atPrev, δZ, trackNew, db)
if err != nil {
return nil, err
}
trackNew.ApplyΔ(δtrackNew)
// FIXME use δtkeycov to recompute track coverage
_ = δtkeycov
// XXX update .KVAtTail, .lastRevOf
/*
δZTC, δtopsByRoot := δZConnectTracked(δZ.Changev, trackNew) δZTC, δtopsByRoot := δZConnectTracked(δZ.Changev, trackNew)
debugfΔBtail("\n rebuild @%s <- @%s\n", atPrev, δZ.Rev) debugfΔBtail("\n rebuild @%s <- @%s\n", atPrev, δZ.Rev)
...@@ -362,21 +375,12 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P ...@@ -362,21 +375,12 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
debugfΔBtail(" -> root<%s> δkv*: %v δtrack*: %v\n", root, δT, δtrack) debugfΔBtail(" -> root<%s> δkv*: %v δtrack*: %v\n", root, δT, δtrack)
trackNew.ApplyΔ(δtrack) trackNew.ApplyΔ(δtrack)
vδtrack = append([]*ΔPPTreeSubSet{δtrack}, vδtrack...) // vδtrack = append([]*ΔPPTreeSubSet{δtrack}, vδtrack...)
if len(δT) == 0 { // an object might be resaved without change if len(δT) == 0 { // an object might be resaved without change
continue continue
} }
/* XXX kill
δTtail, ok := δBtail.vδTbyRoot[root]
if !ok {
// this root was not tracked before -> create δTtail for it with empty changes
δTtail = newΔTtail()
δBtail.vδTbyRoot[root] = δTtail
}
*/
// δTtail.vδT <- merge δT* // δTtail.vδT <- merge δT*
l := len(δTtail.vδT) l := len(δTtail.vδT)
j := sort.Search(l, func(k int) bool { j := sort.Search(l, func(k int) bool {
...@@ -391,7 +395,6 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P ...@@ -391,7 +395,6 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
} }
δTcurr := δTtail.vδT[j] δTcurr := δTtail.vδT[j]
for k, δv := range δT { for k, δv := range δT {
// the diff was backward; δTtail entries are with diff forward // the diff was backward; δTtail entries are with diff forward
δv.New, δv.Old = δv.Old, δv.New δv.New, δv.Old = δv.Old, δv.New
...@@ -408,6 +411,7 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P ...@@ -408,6 +411,7 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
// XXX update .KVAtTail, .lastRevOf // XXX update .KVAtTail, .lastRevOf
} }
*/
} }
/* /*
...@@ -422,6 +426,96 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P ...@@ -422,6 +426,96 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
return δtrackSet, nil return δtrackSet, nil
} }
// rebuild1 rebuilds δT for single δZ.
//
// δtrackNew/δtkeycov represents how trackNew changes when going from atPrev <- δZ.Rev .
func (δTtail *ΔTtail) rebuild1(atPrev zodb.Tid, δZ zodb.ΔRevEntry, trackNew PPTreeSubSet, db *zodb.DB) (δtrackNew *ΔPPTreeSubSet, δtkeycov *RangedKeySet, err error) {
defer xerr.Contextf(&err, "rebuild1 %s<-%s", atPrev, δZ.Rev)
debugfΔBtail("\n rebuild1 @%s <- @%s\n", atPrev, δZ.Rev)
debugfΔBtail(" δZ:\t%v\n", δZ.Changev)
debugfΔBtail(" trackNew: %v\n", trackNew)
defer func() {
debugfΔBtail("-> δtrackNew: %v\n", δtrackNew)
debugfΔBtail("-> δtkeycov: %v\n", δtkeycov)
debugfΔBtail("\n\n")
}()
δZTC, δtopsByRoot := δZConnectTracked(δZ.Changev, trackNew)
// skip opening DB connections if there is no change to this tree
if len(δtopsByRoot) == 0 {
return nil, nil, nil
}
if len(δtopsByRoot) != 1 {
panicf("BUG: δtopsByRoot has > 1 entries: %v\ntrackNew: %v\nδZ: %v", δtopsByRoot, trackNew, δZ)
}
var root zodb.Oid
var δtops SetOid
for root_, δtops_ := range δtopsByRoot {
root = root_
δtops = δtops_
}
// open ZODB connection corresponding to "current" and "prev" states
txn, ctx := transaction.New(context.TODO()) // XXX
defer txn.Abort()
zconnPrev, err := db.Open(ctx, &zodb.ConnOptions{At: atPrev})
if err != nil {
return nil, nil, err
}
zconnCurr, err := db.Open(ctx, &zodb.ConnOptions{At: δZ.Rev})
if err != nil {
return nil, nil, err
}
// diff backwards curr -> prev
δT, δtrack, δtkeycov, err := treediff(ctx, root, δtops, δZTC, trackNew, zconnCurr, zconnPrev)
if err != nil {
return nil, nil, err
}
debugfΔBtail(" -> root<%s> δkv*: %v δtrack*: %v δtkeycov*: %v\n", root, δT, δtrack, δtkeycov)
if len(δT) == 0 { // an object might be resaved without change
return δtrack, δtkeycov, nil
}
// δTtail.vδT <- merge δT*
l := len(δTtail.vδT)
j := sort.Search(l, func(k int) bool {
return δZ.Rev <= δTtail.vδT[k].Rev
})
if j == l || δTtail.vδT[j].Rev != δZ.Rev {
δTcurr := ΔTree{Rev: δZ.Rev, ΔKV: map[Key]ΔValue{}}
// insert(@j, δTcurr)
δTtail.vδT = append(δTtail.vδT[:j],
append([]ΔTree{δTcurr},
δTtail.vδT[j:]...)...)
}
δTcurr := δTtail.vδT[j]
for k, δv := range δT {
// the diff was backward; δTtail entries are with diff forward
δv.New, δv.Old = δv.Old, δv.New
δv_, already := δTcurr.ΔKV[k]
if already {
if δv != δv_ {
panicf("[%v] inconsistent δv:\nδTcurr: %v\nδT: %v", k, δTcurr, δT)
}
} else {
δTcurr.ΔKV[k] = δv
}
}
// XXX update .KVAtTail, .lastRevOf (here?)
return δtrack, δtkeycov, nil
}
// Update updates δB with per-object level ZODB changes. // Update updates δB with per-object level ZODB changes.
// //
// Only those objects from δZ that belong to tracked set are guaranteed to be // Only those objects from δZ that belong to tracked set are guaranteed to be
...@@ -524,6 +618,7 @@ if XXX_killWhenRebuildWorks { ...@@ -524,6 +618,7 @@ if XXX_killWhenRebuildWorks {
δTKeyCov.ByRoot[root] = δtkeycov δTKeyCov.ByRoot[root] = δtkeycov
// XXX if δtkeycov != ø -> rebuild δTtail // XXX if δtkeycov != ø -> rebuild δTtail
// XXX here? or in the caller?
} }
return δB, δTKeyCov, nil return δB, δTKeyCov, nil
......
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