Commit e2614eb3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 231a8e52
...@@ -210,20 +210,17 @@ type δtrackIndex struct { ...@@ -210,20 +210,17 @@ type δtrackIndex struct {
Add trackIndex Add trackIndex
} }
// ApplyΔ applies δ to trackIdx. XXX // gc1 garbage-collects oid and cleans up its parent down-up.
func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) { func (tidx trackIndex) gc1(oid zodb.Oid) {
fmt.Printf("\n\nApplyΔ\n") t, present := tidx[oid]
fmt.Printf("\tDelLeaf: %v\n", δ.DelLeaf)
fmt.Printf("\tAdd: %v\n", δ.Add)
// remove leafs and thier parents
for leaf := range δ.DelLeaf {
t, present := tidx[leaf]
if !present { if !present {
continue // leaf already not there return // already not there
}
if t.nchild != 0 {
panicf("gc %v (nchild != 0)", t)
} }
delete(tidx, leaf) delete(tidx, oid)
parent := t.parent parent := t.parent
for parent != zodb.InvalidOid { for parent != zodb.InvalidOid {
t := tidx[parent] t := tidx[parent]
...@@ -234,6 +231,17 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) { ...@@ -234,6 +231,17 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
delete(tidx, parent) delete(tidx, parent)
parent = t.parent parent = t.parent
} }
}
// ApplyΔ applies δ to trackIdx. XXX
func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
fmt.Printf("\n\nApplyΔ\n")
fmt.Printf("\tDelLeaf: %v\n", δ.DelLeaf)
fmt.Printf("\tAdd: %v\n", δ.Add)
// remove leafs and thier parents
for leaf := range δ.DelLeaf {
tidx.gc1(leaf)
} }
// process adds // process adds
...@@ -254,9 +262,16 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) { ...@@ -254,9 +262,16 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
δnchild[t.parent] += 1 // remeber to nchild++ in parent δnchild[t.parent] += 1 // remeber to nchild++ in parent
} }
} }
gcq := []zodb.Oid{}
for parent, δnc := range δnchild { for parent, δnc := range δnchild {
tidx[parent].nchild += δnc t := tidx[parent]
// XXX .nchild == 0 - remove ? t.nchild += δnc
if t.nchild == 0 {
gcq = append(gcq, t.parent)
}
}
for _, oid := range gcq {
tidx.gc1(oid)
} }
} }
......
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