Commit f2b44b94 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6440a343
......@@ -398,11 +398,13 @@ func (S RangedKeySet) String() string {
}
func (r KeyRange) String() string {
hi := r.hi_
if hi < KeyMax {
hi += 1
var shi string
if r.hi_ == KeyMax {
shi = kstr(r.hi_) // ∞
} else {
shi = fmt.Sprintf("%d", r.hi_+1)
}
return fmt.Sprintf("[%s,%s)", kstr(r.lo), kstr(hi))
return fmt.Sprintf("[%s,%s)", kstr(r.lo), shi)
}
......
......@@ -467,16 +467,55 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
}
var ABoid zodb.Oid
var AB *Tree
if A != nil {
ABoid = A.POid()
AB = A
}
if B != nil {
ABoid = B.POid()
AB = B
}
// path prefix to A and B
ABpath := trackSet.Path(ABoid)
// key coverage for A and B
ABlo := KeyMin
ABhi_ := KeyMax
node := AB
ABcov:
for i := len(ABpath)-2; i >= 0; i-- {
xparent, err := node.PJar().Get(ctx, ABpath[i]); /*X*/if err != nil { return nil,nil,nil, err }
parent := xparent.(*Tree) // must succeed
// find node in parent children and constrain ABlo/ABhi accordingly
entryv := parent.Entryv()
for j, entry := range entryv {
if entry.Child() == node {
// parent.entry[j] points to node
// [i].Key ≤ [i].Child.*.Key < [i+1].Key
klo := entryv[j].Key()
khi_ := KeyMax
if j+1 < len(entryv) {
khi_ = entryv[j+1].Key() - 1
}
if klo > ABlo {
ABlo = klo
}
if khi_ < ABhi_ {
ABhi_ = khi_
}
node = parent
continue ABcov
}
}
panicf("BUG: T%s points to T%s as parent in trackSet, but not found in T%s children", node.POid(), parent.POid(), parent.POid())
}
if A == nil || B == nil {
// top of the subtree must stay in the tracking set even if the subtree is removed
// this way, if later, the subtree will be recreated, that change won't be missed
......@@ -496,11 +535,9 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
}
// initial split ranges for A and B
// FIXME walk till a from root to get more precise initial range
// XXX ^^^ get it from ABpath[-1].keyrange
prefix := ABpath[:len(ABpath)-1]
atop := &nodeInRange{prefix: prefix, lo: KeyMin, hi_: KeyMax, node: A} // [-∞, ∞)
btop := &nodeInRange{prefix: prefix, lo: KeyMin, hi_: KeyMax, node: B} // [-∞, ∞)
atop := &nodeInRange{prefix: prefix, lo: ABlo, hi_: ABhi_, node: A} // [-∞, ∞)
btop := &nodeInRange{prefix: prefix, lo: ABlo, hi_: ABhi_, node: B} // [-∞, ∞)
Av := rangeSplit{atop} // nodes expanded from A
Bv := rangeSplit{btop} // nodes expanded from B
......@@ -638,8 +675,13 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackSet PPTreeSubSet)
if nc := at.nchild; nc != 0 {
δtrack.δnchildNonLeafs[acOid] = nc
}
// XXX δtkeycov
// debugfDiff(" δtrack - %s %v\n", ar, ra.Path())
ar := KeyRange{ac.lo, ac.hi_}
bc := Bv.Get(ac.lo)
br := KeyRange{bc.lo, bc.hi_}
δtkeycovADel.AddRange(ar)
δtkeycovBAdd.AddRange(br)
debugfDiff(" δtrack - %s %v KKK\n", ar, apath)
debugfDiff(" δtrack + %s %v KKK\n", br, bpath)
}
continue
......@@ -940,11 +982,7 @@ func xidOf(obj zodb.IPersistent) string {
func (rn *nodeInRange) String() string {
done := " "; if rn.done { done = "*" }
hi := rn.hi_
if hi < KeyMax {
hi += 1
}
return fmt.Sprintf("%s[%s,%s)%s", done, kstr(rn.lo), kstr(hi), vnode(rn.node))
return fmt.Sprintf("%s%s%s", done, KeyRange{rn.lo, rn.hi_}, vnode(rn.node))
}
// push pushes element to node stack.
......
......@@ -1947,12 +1947,7 @@ func sortedKeys(kv map[Key]Δstring) []Key {
}
func (b *RBucket) String() string {
// XXX dup wrt nodeInRange.String
hi := b.hi_
if hi < KeyMax {
hi += 1
}
return fmt.Sprintf("[%s,%s)B%s{%s}", kstr(b.lo), kstr(hi), b.oid, kvtxt(b.kv))
return fmt.Sprintf("%sB%s{%s}", KeyRange{b.lo, b.hi_}, b.oid, kvtxt(b.kv))
}
......
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