Commit 08472be4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 361d0d20
......@@ -259,6 +259,7 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node, flags Track
oid, track.parent, parent)
}
if track.trackedKeys != nil { // root always covers [-∞, ∞)
// XXX add all keys of leaf bucket XXX for bucket _and_ back for parents
track.trackedKeys.Add(key)
}
parent = oid
......@@ -351,7 +352,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
}
for root, δZT := range δZByRoot {
δT, err := treediff(ctx, root, δZT, zconnOld, zconnNew)
δT, err := treediff(ctx, root, δZT, δBtail.trackIdx, zconnOld, zconnNew)
if err != nil {
return ΔB{}, err
}
......@@ -386,7 +387,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
//
// XXX only for tracked
// δZT is δZ/T - subset of δZ(old..new) that touches tracked nodes of T.
func treediff(ctx context.Context, root zodb.Oid, δZT SetOid, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) {
func treediff(ctx context.Context, root zodb.Oid, δZT SetOid, trackIdx map[zodb.Oid]nodeTrack, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) {
defer xerr.Contextf(&err, "treediff %s..%s %s", zconnOld.At(), zconnNew.At(), root)
// XXX zconnX -> a, b ?
......@@ -406,7 +407,7 @@ func treediff(ctx context.Context, root zodb.Oid, δZT SetOid, zconnOld, zconnNe
return nil, err
}
δtop, err := diffX(ctx, a, b, δZTC)
δtop, err := diffX(ctx, a, b, δZTC, trackIdx)
if err != nil {
return nil, err
}
......@@ -431,7 +432,7 @@ func treediff(ctx context.Context, root zodb.Oid, δZT SetOid, zconnOld, zconnNe
// δZTC is connected set of objects covering δZT (objects changed in this tree in old..new).
//
// a/b can be nil; a=nil means addition, b=nil means deletion.
func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]ΔValue, err error) {
func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack) (δ map[Key]ΔValue, err error) {
if a==nil && b==nil {
panic("BUG: both a & b == nil")
}
......@@ -466,7 +467,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]ΔValue, er
}
if isT {
return diffT(ctx, aT, bT, δZTC)
return diffT(ctx, aT, bT, δZTC, trackIdx)
} else {
return diffB(ctx, aB, bB)
}
......@@ -476,7 +477,9 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid) (δ map[Key]ΔValue, er
//
// a, b point to top of the subtree @old and @new revisions.
// δZTC is connected set of objects covering δZT (objects changed in this tree in old..new).
func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, err error) {
//
// XXX trackIdx -> just pass δBtail?
func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack) (δ map[Key]ΔValue, err error) {
fmt.Printf(" T %s %s\n", xidOf(a), xidOf(b))
defer xerr.Contextf(&err, "diffT %s %s", xidOf(a), xidOf(b))
......@@ -518,7 +521,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, e
// -> "might be changed" subset of tracked keys
δtqkeys := SetKey{}
for achild := range aChildren {
track, ok := δBtail.trackIdx[achild]
track, ok := trackIdx[achild]
if !ok {
panicf("node %s ∈ δZTC, but its track is ø", achild)
}
......@@ -554,7 +557,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, e
ca := aChildren[child]
cb := bChildren[child]
δc, err := diffX(ctx, ca, cb, δZTC)
δc, err := diffX(ctx, ca, cb, δZTC, trackIdx)
if err != nil {
return nil, err
}
......@@ -590,6 +593,33 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, e
delete(δ, k)
}
}
// update δc -> tracked keys
// ca = nil -> add cb to tracked
// cb = nil -> remove ca from tracked
// (their siblings must be already processed by diffX call)
if ca == nil {
trackIdx[child] = nodeTrack{parent: b.POid(), trackedKeys: SetKey{}}
}
if cb == nil {
delete(trackIdx, child) // XXX remove keys from parent?
} else {
trackedKeys := trackIdx[child].trackedKeys
for k, δv := range δc {
switch {
case δv.Old == VDEL:
trackedKeys.Add(k)
case δv.New == VDEL:
trackedKeys.Add(k)
// k v1->v2 no change in key
}
}
}
}
/*
......
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