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

.

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