Commit 1ae40c93 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e7c831f2
...@@ -896,12 +896,14 @@ func (δBtail *ΔBtail) rebuild() (err error) { ...@@ -896,12 +896,14 @@ func (δBtail *ΔBtail) rebuild() (err error) {
for root, δtops := range δtopsByRoot { for root, δtops := range δtopsByRoot {
holeIdx := treeSetKey{SetKey{}} // XXX stub holeIdx := treeSetKey{SetKey{}} // XXX stub
// diff backwards curr -> prev // diff backwards curr -> prev
δT, err := treediff(ctx, root, δtops, δZTC, trackNew, holeIdx, zconnCurr, zconnPrev) δT, δtrack, err := treediff(ctx, root, δtops, δZTC, trackNew, holeIdx, zconnCurr, zconnPrev)
if err != nil { if err != nil {
return err return err
} }
tracef("-> root<%s> δkv*: %v\n", root, δT) tracef("-> root<%s> δkv*: %v δtrack*: %v\n", root, δT, δtrack)
trackNew.ApplyΔ(δ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
...@@ -1002,12 +1004,12 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) { ...@@ -1002,12 +1004,12 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
for root, δtops := range δtopsByRoot { for root, δtops := range δtopsByRoot {
holeIdx := δBtail.holeIdxByRoot[root] holeIdx := δBtail.holeIdxByRoot[root]
δT, err := treediff(ctx, root, δtops, δZTC, δBtail.trackIdx, holeIdx, zconnOld, zconnNew) δT, δtrack, err := treediff(ctx, root, δtops, δZTC, δBtail.trackIdx, holeIdx, zconnOld, zconnNew)
if err != nil { if err != nil {
return ΔB{}, err return ΔB{}, err
} }
tracef("\n-> root<%s> δkv: %v\n", root, δT) tracef("\n-> root<%s> δkv: %v δtrack: %v\n", root, δT, δtrack)
if len(δT) > 0 { // an object might be resaved without change if len(δT) > 0 { // an object might be resaved without change
δB.ByRoot[root] = δT δB.ByRoot[root] = δT
...@@ -1033,6 +1035,8 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) { ...@@ -1033,6 +1035,8 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
// XXX rebuild KVAtTail // XXX rebuild KVAtTail
// XXX rebuild lastRevOf // XXX rebuild lastRevOf
} }
δBtail.trackIdx.ApplyΔ(δtrack)
} }
return δB, nil return δB, nil
...@@ -1267,15 +1271,15 @@ func (rs rangeSplit) String() string { ...@@ -1267,15 +1271,15 @@ func (rs rangeSplit) String() string {
// treediff computes δT for tree specified by root in between old..new. // treediff computes δT/δtrack for tree/trackIdx specified by root in between old..new.
// //
// δtops is set of top nodes for changed subtrees. // δtops is set of top nodes for changed subtrees.
// δZTC is connected(δZ/T) - connected closure for subset of δZ(old..new) that // δZTC is connected(δZ/T) - connected closure for subset of δZ(old..new) that
// touches tracked nodes of T. // touches tracked nodes of T.
// //
// XXX trackIdx is updated // XXX holeIdx is updated XXX -> return similarly to δtrack
// XXX holeIdx is updated // XXX ^^^ -> but better kill holeIdx and do everything only via trackIdx
func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, trackIdx trackIndex, holeIdx treeSetKey, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) { func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, trackIdx trackIndex, holeIdx treeSetKey, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, δtrack *δtrackIndex, err error) {
defer xerr.Contextf(&err, "treediff %s..%s %s", zconnOld.At(), zconnNew.At(), root) defer xerr.Contextf(&err, "treediff %s..%s %s", zconnOld.At(), zconnNew.At(), root)
tracef("\ntreediff %s δtops: %v δZTC: %v\n", root, δtops, δZTC) tracef("\ntreediff %s δtops: %v δZTC: %v\n", root, δtops, δZTC)
...@@ -1289,12 +1293,12 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t ...@@ -1289,12 +1293,12 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
b, err2 := zgetNode(ctx, zconnNew, top) b, err2 := zgetNode(ctx, zconnNew, top)
err := xerr.Merge(err1, err2) err := xerr.Merge(err1, err2)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
δtop, δtrackTop, err := diffX(ctx, a, b, δZTC, trackIdx, holeIdx) δtop, δtrackTop, err := diffX(ctx, a, b, δZTC, trackIdx, holeIdx)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
// FIXME -> merge (VDEL vs add) // FIXME -> merge (VDEL vs add)
...@@ -1331,13 +1335,13 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t ...@@ -1331,13 +1335,13 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
} }
} }
*/ */
δtrack := &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}} δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}}
for _, δ := range δtrackv { for _, δ := range δtrackv {
δtrack.Update(δ) δtrack.Update(δ)
} }
trackIdx.ApplyΔ(δtrack) // trackIdx.ApplyΔ(δtrack)
return δT, nil return δT, δtrack, nil
} }
// diffX computes difference in between two revisions of a tree's subtree. // diffX computes difference in between two revisions of a tree's subtree.
......
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