Commit eb715051 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 73501d87
...@@ -282,12 +282,6 @@ type nodeTrack struct { ...@@ -282,12 +282,6 @@ type nodeTrack struct {
// //
// XXX place // XXX place
type δtrackIndex struct { type δtrackIndex struct {
/*
// set of leaf nodes to remove. After leafs are removed, their parents
// are automatically cleaned down-up. Removals are processed before
// adds (see below).
DelLeaf SetOid
*/
Del trackIndex Del trackIndex
Add trackIndex Add trackIndex
δnchildNonLeafs map[zodb.Oid]int δnchildNonLeafs map[zodb.Oid]int
...@@ -397,42 +391,20 @@ func (A trackIndex) DifferenceInplace(B trackIndex) { ...@@ -397,42 +391,20 @@ func (A trackIndex) DifferenceInplace(B trackIndex) {
B.verify() B.verify()
defer A.verify() defer A.verify()
// δnchild := map[zodb.Oid]int{}
A.xDifferenceInplace(B) A.xDifferenceInplace(B)
// A.fixup(δnchild)
} }
//func (A trackIndex) xDifferenceInplace(B trackIndex, δnchild map[zodb.Oid]int) {
func (A trackIndex) xDifferenceInplace(B trackIndex) { func (A trackIndex) xDifferenceInplace(B trackIndex) {
if debugPPSet { if debugPPSet {
fmt.Printf("\n\n xDifferenceInplace:\n") fmt.Printf("\n\n xDifferenceInplace:\n")
fmt.Printf(" a: %s\n", A) fmt.Printf(" a: %s\n", A)
fmt.Printf(" b: %s\n", B) fmt.Printf(" b: %s\n", B)
// fmt.Printf(" δ: %v\n", δnchild) defer fmt.Printf(" ->d: %s\n", A)
defer func() {
fmt.Printf(" ->d: %s\n", A)
// fmt.Printf(" ->δ: %v\n", δnchild)
}()
} }
δnchild := map[zodb.Oid]int{} δnchild := map[zodb.Oid]int{}
/* XXX kill // remove B.leafs and their parents
// remove (A^B).leafs and thier parents
// we have to start (A^B).leafs - not from B.leafs - because B can
// contain non-leaf to remove from A, with that non-leaf having
// children in B, that are not present in A:
//
// c c
// | |
// 11 11
// | |
// 14 14
// | \
// 15 16
AB := B.Intersect(A)
*/
// remove B.leafs and thier parents
for oid, t2 := range B { for oid, t2 := range B {
if t2.nchild != 0 { if t2.nchild != 0 {
continue // not a leaf continue // not a leaf
...@@ -453,7 +425,6 @@ func (A trackIndex) xDifferenceInplace(B trackIndex) { ...@@ -453,7 +425,6 @@ func (A trackIndex) xDifferenceInplace(B trackIndex) {
} }
delete(A, oid) delete(A, oid)
// XXX + return A.nchild in removedNonLeafs {} oid -> nchild ? (probably no)
if t.parent != zodb.InvalidOid { if t.parent != zodb.InvalidOid {
δnchild[t.parent] -= 1 δnchild[t.parent] -= 1
} }
...@@ -462,17 +433,12 @@ func (A trackIndex) xDifferenceInplace(B trackIndex) { ...@@ -462,17 +433,12 @@ func (A trackIndex) xDifferenceInplace(B trackIndex) {
A.fixup(δnchild) A.fixup(δnchild)
} }
//func (A trackIndex) xUnionInplace(B trackIndex, δnchild map[zodb.Oid]int) {
func (A trackIndex) xUnionInplace(B trackIndex) { func (A trackIndex) xUnionInplace(B trackIndex) {
if debugPPSet { if debugPPSet {
fmt.Printf("\n\n xUnionInplace:\n") fmt.Printf("\n\n xUnionInplace:\n")
fmt.Printf(" a: %s\n", A) fmt.Printf(" a: %s\n", A)
fmt.Printf(" b: %s\n", B) fmt.Printf(" b: %s\n", B)
// fmt.Printf(" δ: %v\n", δnchild) defer fmt.Printf(" ->u: %s\n", A)
defer func() {
fmt.Printf(" ->u: %s\n", A)
// fmt.Printf(" ->δ: %v\n", δnchild)
}()
} }
δnchild := map[zodb.Oid]int{} δnchild := map[zodb.Oid]int{}
...@@ -482,7 +448,7 @@ func (A trackIndex) xUnionInplace(B trackIndex) { ...@@ -482,7 +448,7 @@ func (A trackIndex) xUnionInplace(B trackIndex) {
if !already { if !already {
t = &nodeTrack{parent: t2.parent, nchild: 0} t = &nodeTrack{parent: t2.parent, nchild: 0}
A[oid] = t A[oid] = t
// remeber to nchild++ in parent // remember to nchild++ in parent
if t.parent != zodb.InvalidOid { if t.parent != zodb.InvalidOid {
δnchild[t.parent] += 1 δnchild[t.parent] += 1
} }
...@@ -537,35 +503,7 @@ func (A trackIndex) UnionInplace(B trackIndex) { ...@@ -537,35 +503,7 @@ func (A trackIndex) UnionInplace(B trackIndex) {
B.verify() B.verify()
defer A.verify() defer A.verify()
// δnchild := map[zodb.Oid]int{}
A.xUnionInplace(B) A.xUnionInplace(B)
// A.fixup(δnchild)
/*
for oid, t2 := range B {
t, already := A[oid]
if !already {
t = &nodeTrack{parent: t2.parent, nchild: t2.nchild}
A[oid] = t
} else {
if t2.parent != t.parent {
// XXX or verify this at Track time and require
// that update is passed only entries with the
// same .parent? (then it would be ok to panic here)
// XXX -> error (e.g. due to corrupt data in ZODB)
panicf("node %s is reachable from multiple parents: %s %s",
oid, t.parent, t2.parent)
}
t.nchild += t2.nchild
if t.parent != zodb.InvalidOid {
// this node is already present in both trees
// compensate for that in its parent (which must be present)
A[t.parent].nchild--
}
}
}
*/
} }
// ApplyΔ applies δ to trackIdx. XXX // ApplyΔ applies δ to trackIdx. XXX
...@@ -756,7 +694,7 @@ func (δBtail *ΔBtail) holeIdxFor(root zodb.Oid) treeSetKey { ...@@ -756,7 +694,7 @@ func (δBtail *ΔBtail) holeIdxFor(root zodb.Oid) treeSetKey {
return holeIdx return holeIdx
} }
// Path returns path leading to node speficied by oid. // Path returns path leading to node specified by oid.
// //
// The node must be in the set. // The node must be in the set.
// XXX place // XXX place
...@@ -1329,20 +1267,10 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t ...@@ -1329,20 +1267,10 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
} }
// adjust trackIdx by merge(δtrackTops) // 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
}
}
*/
δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}} δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}}
for _, δ := range δtrackv { for _, δ := range δtrackv {
δtrack.Update(δ) δtrack.Update(δ)
} }
// trackIdx.ApplyΔ(δtrack)
return δT, δtrack, nil return δT, δtrack, nil
} }
...@@ -1416,7 +1344,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h ...@@ -1416,7 +1344,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
if B == nil { panic("B is nil") } if B == nil { panic("B is nil") }
δ = map[Key]ΔValue{} δ = map[Key]ΔValue{}
// δtrack = &δtrackIndex{DelLeaf: SetOid{}, Add: trackIndex{}}
δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}} δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}}
defer tracef(" -> δ: %v\n", δ) defer tracef(" -> δ: %v\n", δ)
...@@ -1454,10 +1381,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h ...@@ -1454,10 +1381,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
} }
// {} oid -> parent for all nodes in Bv: current and previously expanded - up till top B // {} oid -> parent for all nodes in Bv: current and previously expanded - up till top B
// XXX
// XXX requires A.oid == B.oid // XXX requires A.oid == B.oid
// XXX -> trackIndex
// BtrackIdx := map[zodb.Oid]nodeTrack{B.POid(): nodeTrack{parent: trackIdx[B.POid()].parent}}
BtrackIdx := trackIndex{} BtrackIdx := trackIndex{}
BtrackIdx.AddPath(trackIdx.Path(B.POid())) BtrackIdx.AddPath(trackIdx.Path(B.POid()))
...@@ -1482,7 +1406,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h ...@@ -1482,7 +1406,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
// a is bucket -> δ- // a is bucket -> δ-
δA, err := diffB(ctx, a, nil); /*X*/if err != nil { return nil,nil, err } δA, err := diffB(ctx, a, nil); /*X*/if err != nil { return nil,nil, err }
err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil, err } err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil, err }
// δtrack.DelLeaf.Add(a.POid())
δtrack.Del.AddPath(ra.Path()) δtrack.Del.AddPath(ra.Path())
// Bkqueue <- δA // Bkqueue <- δA
...@@ -1540,7 +1463,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h ...@@ -1540,7 +1463,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
bchildren := Bv.Expand(blo) bchildren := Bv.Expand(blo)
for _, bc := range bchildren { for _, bc := range bchildren {
bcOid := bc.node.POid() bcOid := bc.node.POid()
// BtrackIdx[bcOid] = nodeTrack{parent: blo.node.POid()}
BtrackIdx.AddPath(bc.Path()) BtrackIdx.AddPath(bc.Path())
if acOid == bcOid { if acOid == bcOid {
found = true found = true
...@@ -1566,22 +1488,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h ...@@ -1566,22 +1488,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
} }
} }
/* XXX kill
oid := acOid
for oid != zodb.InvalidOid {
told := trackIdx[oid]
tnew, ok := BtrackIdx[oid]
if !ok {
break
}
if told == nil || (told.parent != tnew.parent) {
δtrack.Add.AddPath(BtrackIdx.Path(oid))
}
oid = tnew.parent
}
*/
continue continue
} }
} }
...@@ -1665,7 +1571,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h ...@@ -1665,7 +1571,6 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
// δ <- δA // δ <- δA
err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil, err } err = δMerge(δ, δA); /*X*/if err != nil { return nil,nil, err }
// δtrack.DelLeaf.Add(a.node.POid())
δtrack.Del.AddPath(a.Path()) δtrack.Del.AddPath(a.Path())
// Bkqueue <- δA // Bkqueue <- δA
......
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