Commit 51fb2628 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a6760d8f
......@@ -184,8 +184,9 @@ type ΔBtail struct {
// XXX place
// nodeTrack represents tracking information about a node.
type nodeTrack struct {
parent zodb.Oid // parent node | InvalidOid for root
trackedKeys SetKey // keys tracked under this node; nil for root XXX only !empty root
parent zodb.Oid // parent node | InvalidOid for root
holes SetKey // missing keys tracked under this node XXX nil for root(?) XXX only !empty root
trackedKeys SetKey // XXX kill
}
// ΔB represents a change in BTrees space.
......@@ -306,7 +307,7 @@ func (δBtail *ΔBtail) Track(ctx context.Context, key Key, keyPresent bool, pat
// XXX check for InvalidOid (e.g. T/B1:a with bucket not having its own oid.
track, oldTrack = δBtail.trackIdx[oid]
if !oldTrack {
track = nodeTrack{parent: parent, trackedKeys: SetKey{}}
track = nodeTrack{parent: parent, holes: SetKey{}, trackedKeys: SetKey{}}
δBtail.trackIdx[oid] = track
// XXX .trackNew += oid
}
......@@ -321,6 +322,17 @@ func (δBtail *ΔBtail) Track(ctx context.Context, key Key, keyPresent bool, pat
parent = oid
}
// remember tracked holes in trackIdx
if !keyPresent {
if leafBucket != nil {
track.holes.Add(key)
} else {
// empty tree
rootTrack := δBtail.trackIdx[root] // must succeed
rootTrack.holes.Add(key)
}
}
// tracked += all keys of leaf bucket for every node up to the root
fmt.Printf(" oldTrack: %v leafBucket: %v\n", oldTrack, leafBucket)
if !oldTrack && leafBucket != nil {
......@@ -360,6 +372,7 @@ func (δBtail *ΔBtail) Track(ctx context.Context, key Key, keyPresent bool, pat
}
}
_, ok := δBtail.byRoot[root]
if !ok {
δBtail.byRoot[root] = newΔTtail()
......@@ -558,6 +571,7 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) {
// [len(ev)].Key = +∞ ; should be assumed so
tree := rnode.node.(*Tree)
treev := tree.Entryv()
fmt.Printf("E treev: %v\n", treev)
children = make(rangeSplit, 0, len(treev)+1)
for i := range treev {
lo := rnode.lo
......@@ -572,6 +586,8 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) {
children = append(children, &nodeInRange{lo, hi_, treev[i].Child()})
}
fmt.Printf("E children: %s\n", children)
// del[i]; insert(@i, children)
*prs = append(rs[:i], append(children, rs[i+1:]...)...)
return children
......@@ -739,9 +755,11 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
// initial phase: expand changed nodes in a till buckets;
// XXX changed buckets -> δ-
if a != nil { // XXX kill (always !nil) ?
fmt.Println("ZZZ")
// XXX maybe walk till a from root to get more precise initial range?
atop := &nodeInRange{lo: KeyMin, hi_: KeyMax, node: a} // [-∞, ∞)
av = rangeSplit{atop}
fmt.Printf("X av: %s\n", av)
aq := []*nodeInRange{atop} // stack
for len(aq) > 0 {
l := len(aq)
......@@ -750,6 +768,8 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
defer arn.node.PDeactivate()
children := av.Expand(arn)
fmt.Printf("Y children: %s\n", children)
fmt.Printf("Y av: %s\n", av)
for _, rchild := range children {
coid := rchild.node.POid()
if !( δZTC.Has(coid) ||
......@@ -758,16 +778,23 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
continue
}
switch rchild.node.(type) {
switch node := rchild.node.(type) {
case *Tree:
aq = append(aq, rchild)
case *Bucket:
// XXX also -[k]ø (for tracked DEL)
δA, err := diffB(ctx, rchild.node.(*Bucket), nil)
δA, err := diffB(ctx, node, nil)
if err != nil {
return nil, err
}
// also -[k]ø (for tracked holes)
track, ok := trackIdx[node.POid()]
if !ok {
panicf("%s ∈ δZTC, but ∉ trackIdx", vnode(node))
}
for k := range track.holes {
δA[k] = ΔValue{VDEL, VDEL} // ø->ø indicates hole
}
// δ <- δA
err = δMerge(δ, δA)
......@@ -1386,5 +1413,5 @@ func (rn nodeInRange) String() string {
}
func (track nodeTrack) String() string {
return fmt.Sprintf("{p%s k%s}", track.parent, track.trackedKeys)
return fmt.Sprintf("{p%s h%s k%s}", track.parent, track.holes, track.trackedKeys)
}
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