Commit 8672b6d8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3c69ff8d
...@@ -172,7 +172,7 @@ func δZConnectTracked(δZv []zodb.Oid, T blib.PPTreeSubSet) (δZTC setOid, δto ...@@ -172,7 +172,7 @@ func δZConnectTracked(δZv []zodb.Oid, T blib.PPTreeSubSet) (δZTC setOid, δto
// nodeInRange represents a Node coming under [lo, hi_] key range in its tree. // nodeInRange represents a Node coming under [lo, hi_] key range in its tree.
type nodeInRange struct { type nodeInRange struct {
prefix []zodb.Oid // path to this node goes via this objects prefix []zodb.Oid // path to this node goes via this objects
lo, hi_ Key // [lo, hi_] NOTE _not_ hi) not to overflow at ∞ XXX -> keycov KeyRange? keycov blib.KeyRange
node Node node Node
done bool // whether this node was already taken into account while computing diff done bool // whether this node was already taken into account while computing diff
} }
...@@ -210,14 +210,14 @@ func (rs rangeSplit) Get(k Key) *nodeInRange { ...@@ -210,14 +210,14 @@ func (rs rangeSplit) Get(k Key) *nodeInRange {
// Get_ returns node covering key k. // Get_ returns node covering key k.
func (rs rangeSplit) Get_(k Key) (rnode *nodeInRange, ok bool) { func (rs rangeSplit) Get_(k Key) (rnode *nodeInRange, ok bool) {
i := sort.Search(len(rs), func(i int) bool { i := sort.Search(len(rs), func(i int) bool {
return k <= rs[i].hi_ return k <= rs[i].keycov.Hi_
}) })
if i == len(rs) { if i == len(rs) {
return nil, false // key not covered return nil, false // key not covered
} }
rn := rs[i] rn := rs[i]
if !(rn.lo <= k && k <= rn.hi_) { if !rn.keycov.Has(k) {
panicf("BUG: get(%v) -> %s; coverage: %s", k, rn, rs) panicf("BUG: get(%v) -> %s; coverage: %s", k, rn, rs)
} }
...@@ -234,7 +234,7 @@ func (rs rangeSplit) Get_(k Key) (rnode *nodeInRange, ok bool) { ...@@ -234,7 +234,7 @@ func (rs rangeSplit) Get_(k Key) (rnode *nodeInRange, ok bool) {
func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) { func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) {
rs := *prs rs := *prs
i := sort.Search(len(rs), func(i int) bool { i := sort.Search(len(rs), func(i int) bool {
return rnode.hi_ <= rs[i].hi_ return rnode.keycov.Hi_ <= rs[i].keycov.Hi_
}) })
if i == len(rs) || rs[i] != rnode { if i == len(rs) || rs[i] != rnode {
panicf("%s not in rangeSplit; coverage: %s", rnode, rs) panicf("%s not in rangeSplit; coverage: %s", rnode, rs)
...@@ -248,19 +248,18 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) { ...@@ -248,19 +248,18 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) {
treev := tree.Entryv() treev := tree.Entryv()
children = make(rangeSplit, 0, len(treev)+1) children = make(rangeSplit, 0, len(treev)+1)
for i := range treev { for i := range treev {
lo := rnode.lo lo := rnode.keycov.Lo
if i > 0 { if i > 0 {
lo = treev[i].Key() lo = treev[i].Key()
} }
hi_ := rnode.hi_ hi_ := rnode.keycov.Hi_
if i < len(treev)-1 { if i < len(treev)-1 {
hi_ = treev[i+1].Key()-1 // NOTE -1 because it is hi_] not hi) hi_ = treev[i+1].Key()-1 // NOTE -1 because it is hi_] not hi)
} }
children = append(children, &nodeInRange{ children = append(children, &nodeInRange{
prefix: rnode.Path(), prefix: rnode.Path(),
lo: lo, keycov: blib.KeyRange{lo, hi_},
hi_: hi_,
node: treev[i].Child(), node: treev[i].Child(),
}) })
} }
...@@ -558,9 +557,10 @@ ABcov: ...@@ -558,9 +557,10 @@ ABcov:
} }
// initial split ranges for A and B // initial split ranges for A and B
ABcov := blib.KeyRange{ABlo, ABhi_}
prefix := ABpath[:len(ABpath)-1] prefix := ABpath[:len(ABpath)-1]
atop := &nodeInRange{prefix: prefix, lo: ABlo, hi_: ABhi_, node: A} // [-∞, ∞) atop := &nodeInRange{prefix: prefix, keycov: ABcov, node: A}
btop := &nodeInRange{prefix: prefix, lo: ABlo, hi_: ABhi_, node: B} // [-∞, ∞) btop := &nodeInRange{prefix: prefix, keycov: ABcov, node: B}
Av := rangeSplit{atop} // nodes expanded from A Av := rangeSplit{atop} // nodes expanded from A
Bv := rangeSplit{btop} // nodes expanded from B Bv := rangeSplit{btop} // nodes expanded from B
...@@ -621,23 +621,21 @@ ABcov: ...@@ -621,23 +621,21 @@ ABcov:
// a is bucket -> δ- // a is bucket -> δ-
δA, err := diffB(ctx, a, nil); /*X*/if err != nil { return nil,nil,nil, err } δA, err := diffB(ctx, a, nil); /*X*/if err != nil { return nil,nil,nil, err }
err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil,nil, err } err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil,nil, err }
ar := blib.KeyRange{ra.lo, ra.hi_}
δtrack.Del.AddPath(ra.Path()) δtrack.Del.AddPath(ra.Path())
δtkeycovADel.AddRange(ar) δtkeycovADel.AddRange(ra.keycov)
debugfDiff(" δtrack - %s %v\n", ar, ra.Path()) debugfDiff(" δtrack - %s %v\n", ra.keycov, ra.Path())
// Bkqueue <- ra.range // Bkqueue <- ra.range
Bktodo(ar) Bktodo(ra.keycov)
ra.done = true ra.done = true
case *Tree: case *Tree:
// empty tree - queue holes covered by it // empty tree - queue holes covered by it
if len(a.Entryv()) == 0 { if len(a.Entryv()) == 0 {
ar := blib.KeyRange{ra.lo, ra.hi_}
δtrack.Del.AddPath(ra.Path()) δtrack.Del.AddPath(ra.Path())
δtkeycovADel.AddRange(ar) δtkeycovADel.AddRange(ra.keycov)
debugfDiff(" δtrack - %s %v\n", ar, ra.Path()) debugfDiff(" δtrack - %s %v\n", ra.keycov, ra.Path())
Bktodo(ar) Bktodo(ra.keycov)
continue continue
} }
...@@ -660,8 +658,8 @@ ABcov: ...@@ -660,8 +658,8 @@ ABcov:
bc, found := BnodeIdx[acOid] bc, found := BnodeIdx[acOid]
if !found { if !found {
for { for {
blo := Bv.Get(ac.lo) blo := Bv.Get(ac.keycov.Lo)
bhi_ := Bv.Get(ac.hi_) bhi_ := Bv.Get(ac.keycov.Hi_)
if blo != bhi_ { if blo != bhi_ {
break break
} }
...@@ -692,9 +690,7 @@ ABcov: ...@@ -692,9 +690,7 @@ ABcov:
} }
if found { if found {
// ac can be skipped if key coverage stays the same // ac can be skipped if key coverage stays the same
ar := blib.KeyRange{ac.lo, ac.hi_} if ac.keycov == bc.keycov {
br := blib.KeyRange{bc.lo, bc.hi_}
if ar == br {
// adjust trackSet since path to the node could have changed // adjust trackSet since path to the node could have changed
apath := ac.Path() apath := ac.Path()
bpath := bc.Path() bpath := bc.Path()
...@@ -759,23 +755,22 @@ ABcov: ...@@ -759,23 +755,22 @@ ABcov:
// δ <- δB // δ <- δB
err = δMerge(δ, δB); /*X*/if err != nil { return nil,nil,nil, err } err = δMerge(δ, δB); /*X*/if err != nil { return nil,nil,nil, err }
br := blib.KeyRange{b.lo, b.hi_}
δtrack.Add.AddPath(b.Path()) δtrack.Add.AddPath(b.Path())
δtkeycovBAdd.AddRange(br) δtkeycovBAdd.AddRange(b.keycov)
debugfDiff(" δtrack + %s %v\n", br, b.Path()) debugfDiff(" δtrack + %s %v\n", b.keycov, b.Path())
// Akqueue <- δB // Akqueue <- δB
Bkdone.AddRange(br) Bkdone.AddRange(b.keycov)
Aktodo(br) Aktodo(b.keycov)
b.done = true b.done = true
} }
// continue with next right bucket until r coverage is complete // continue with next right bucket until r coverage is complete
if r.Hi_ <= b.hi_ { if r.Hi_ <= b.keycov.Hi_ {
break break
} }
lo = b.hi_ + 1 lo = b.keycov.Hi_ + 1
} }
} }
Bkqueue.Clear() Bkqueue.Clear()
...@@ -799,27 +794,26 @@ ABcov: ...@@ -799,27 +794,26 @@ ABcov:
err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil,nil, err } err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil,nil, err }
δtrack.Del.AddPath(a.Path()) δtrack.Del.AddPath(a.Path())
// NOTE adjust δtkeycovADel only if a was originally tracked // NOTE adjust δtkeycovADel only if a was originally tracked
ar := blib.KeyRange{a.lo, a.hi_}
_, tracked := trackSet[a.node.POid()] _, tracked := trackSet[a.node.POid()]
if tracked { if tracked {
δtkeycovADel.AddRange(ar) δtkeycovADel.AddRange(a.keycov)
debugfDiff(" δtrack - %s %v\n", ar, a.Path()) debugfDiff(" δtrack - %s %v\n", a.keycov, a.Path())
} else { } else {
debugfDiff(" δtrack - [) %v\n", a.Path()) debugfDiff(" δtrack - [) %v\n", a.Path())
} }
// Bkqueue <- a.range // Bkqueue <- a.range
Akdone.AddRange(ar) Akdone.AddRange(a.keycov)
Bktodo(ar) Bktodo(a.keycov)
a.done = true a.done = true
} }
// continue with next right bucket until r coverage is complete // continue with next right bucket until r coverage is complete
if r.Hi_ <= a.hi_ { if r.Hi_ <= a.keycov.Hi_ {
break break
} }
lo = a.hi_ + 1 lo = a.keycov.Hi_ + 1
} }
} }
Akqueue.Clear() Akqueue.Clear()
...@@ -1010,7 +1004,7 @@ func xidOf(obj zodb.IPersistent) string { ...@@ -1010,7 +1004,7 @@ func xidOf(obj zodb.IPersistent) string {
func (rn *nodeInRange) String() string { func (rn *nodeInRange) String() string {
done := " "; if rn.done { done = "*" } done := " "; if rn.done { done = "*" }
return fmt.Sprintf("%s%s%s", done, blib.KeyRange{rn.lo, rn.hi_}, vnode(rn.node)) return fmt.Sprintf("%s%s%s", done, rn.keycov, vnode(rn.node))
} }
// push pushes element to node stack. // push pushes element to node stack.
......
...@@ -428,7 +428,7 @@ func widenTrackNew(trackNew blib.PPTreeSubSet, δtkeycov *blib.RangedKeySet, roo ...@@ -428,7 +428,7 @@ func widenTrackNew(trackNew blib.PPTreeSubSet, δtkeycov *blib.RangedKeySet, roo
} }
tree := xtree.(*Tree) // must succeed XXX better explicit panic? tree := xtree.(*Tree) // must succeed XXX better explicit panic?
top := &nodeInRange{prefix: nil, lo: KeyMin, hi_: KeyMax, node: tree} top := &nodeInRange{prefix: nil, keycov: blib.KeyRange{KeyMin, KeyMax}, node: tree}
V := rangeSplit{top} V := rangeSplit{top}
for _, r := range δtkeycov.AllRanges() { for _, r := range δtkeycov.AllRanges() {
lo := r.Lo lo := r.Lo
...@@ -437,10 +437,10 @@ func widenTrackNew(trackNew blib.PPTreeSubSet, δtkeycov *blib.RangedKeySet, roo ...@@ -437,10 +437,10 @@ func widenTrackNew(trackNew blib.PPTreeSubSet, δtkeycov *blib.RangedKeySet, roo
trackNew.AddPath(b.Path()) trackNew.AddPath(b.Path())
// continue with next right bucket until r coverage is complete // continue with next right bucket until r coverage is complete
if r.Hi_ <= b.hi_ { if r.Hi_ <= b.keycov.Hi_ {
break break
} }
lo = b.hi_ + 1 lo = b.keycov.Hi_ + 1
} }
} }
return nil return 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