Commit 9d1dc98b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7981f7c1
......@@ -221,31 +221,42 @@ func (tidx trackIndex) gc1(oid zodb.Oid) {
}
delete(tidx, oid)
parent := t.parent
for parent != zodb.InvalidOid {
t := tidx[parent]
oid = t.parent
for oid != zodb.InvalidOid {
t := tidx[oid]
t.nchild--
if t.nchild > 0 {
if t.nchild > 0 || /* root node */t.parent == zodb.InvalidOid {
break
}
delete(tidx, parent)
parent = t.parent
delete(tidx, oid)
oid = t.parent
}
}
// ApplyΔ applies δ to trackIdx. XXX
func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
//fmt.Printf("\n\nApplyΔ\n")
//fmt.Printf("\ttidx: %v\n", tidx)
//fmt.Printf("\tDelLeaf: %v\n", δ.DelLeaf)
//fmt.Printf("\tAdd: %v\n", δ.Add)
//defer fmt.Printf("\n\t-> tidx: %v\n", tidx)
δnchild := map[zodb.Oid]int{}
// remove leafs and thier parents
for leaf := range δ.DelLeaf {
tidx.gc1(leaf)
t, present := tidx[leaf]
if !present {
continue // already not there
}
delete(tidx, leaf)
if t.parent != zodb.InvalidOid {
δnchild[t.parent] -= 1
}
}
// process adds
δnchild := map[zodb.Oid]int{}
for oid, δt := range δ.Add {
t, already := tidx[oid]
if already {
......@@ -262,14 +273,18 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
δnchild[t.parent] += 1 // remeber to nchild++ in parent
}
}
// perform scheduled δnchild adjustment
gcq := []zodb.Oid{}
for oid, δnc := range δnchild {
t := tidx[oid]
t := tidx[oid] // XXX t can be nil -> XXX no must be there as tidx is connected
t.nchild += δnc
if t.nchild == 0 {
if t.nchild == 0 && /* not root node */t.parent != zodb.InvalidOid {
gcq = append(gcq, oid)
}
}
// GC parents that became to have .nchild == 0
for _, oid := range gcq {
tidx.gc1(oid)
}
......@@ -842,10 +857,15 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
}
}
// adjust trackIdx
for _, δtrack := range δtrackv {
trackIdx.ApplyΔ(δtrack)
// adjust trackIdx by merge(δtrackTops)
δtrack := &δtrackIndex{DelLeaf: SetOid{}, Add: trackIndex{}}
for _, δ := range δtrackv {
δtrack.DelLeaf.Update(δ.DelLeaf)
for oid, t := range δ.Add {
δtrack.Add[oid] = t // XXX verify changes from 2 δtrackTops are consistent
}
}
trackIdx.ApplyΔ(δtrack)
return δT, nil
}
......@@ -1504,7 +1524,7 @@ func pop(nodeStk *[]*nodeInRange) *nodeInRange {
}
const debug = true
const debug = false
func tracef(format string, argv ...interface{}) {
if debug {
fmt.Printf(format, argv...)
......
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