Commit 0700f488 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 82fd3e37
...@@ -762,7 +762,14 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -762,7 +762,14 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
aq = append(aq, rchild) aq = append(aq, rchild)
case *Bucket: case *Bucket:
// XXX δ += -[k]v -[k]ø (for tracked DEL) // XXX also -[k]ø (for tracked DEL)
δA, err := diffB(ctx, rchild.node.(*Bucket), nil)
if err != nil {
return nil, err
}
// XXX δ <- δA
// XXX AKeysDone <- δA
} }
} }
} }
...@@ -777,11 +784,14 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -777,11 +784,14 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
bv = rangeSplit{btop} bv = rangeSplit{btop}
} }
for k := range Bkeysq { for k := range Bkeysq {
BKeysDone.Add(k)
bbucket, ok, err := bv.GetToBucket(ctx, k) bbucket, ok, err := bv.GetToBucket(ctx, k)
if !ok { if !ok {
continue // key not covered continue // key not covered
} }
// XXX check bucket for already "done" (i.e. taken into account)
bbucket.node.(*Bucket) bbucket.node.(*Bucket)
δB, err := diffB(ctx, nil, bbucket.node.(*Bucket)) δB, err := diffB(ctx, nil, bbucket.node.(*Bucket))
if err != nil { if err != nil {
...@@ -790,7 +800,9 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -790,7 +800,9 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
// XXX δ <- δB // XXX δ <- δB
for k, δv := range δ { for k, δv := range δ {
// if !AKeysDone.Has(k) {
Akeysq.Add(k)
}
} }
} }
...@@ -869,37 +881,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -869,37 +881,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
} }
// merge δ <- δc // merge δ <- δc
for k, δv1 := range δc { δmergeInto(δ, δc)
δv2, already := δ[k]
if !already {
δ[k] = δv1
continue
}
// both δ and δc has [k] - it can be that key
// entry migrated from one bucket into another.
if !( (δv2.New == VDEL && δv1.Old == VDEL) ||
(δv2.Old == VDEL && δv1.New == VDEL) ) {
return nil, fmt.Errorf("BUG or btree corrupt: [%v] has " +
"duplicate entries: %v, %v", k, δv1, δv2)
}
δv := ΔValue{}
if δv1.New == VDEL {
δv.Old = δv1.Old
δv.New = δv2.New
} else {
δv.Old = δv2.Old
δv.New = δv1.New
}
fmt.Printf(" [%v] merge %s %s -> %s\n", k, δv1, δv2, δv)
if δv.Old != δv.New {
δ[k] = δv
} else {
delete(δ, k)
}
}
// update δc -> tracked keys // update δc -> tracked keys
...@@ -933,6 +915,44 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -933,6 +915,44 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
} }
// δmergeInto merges changes from δ2 into δ.
// Usually δ is total-building δ, while δ2 is diff from comparing some subnodes.
func δmergeInto(δ, δ2 map[Key]ΔValue) {
// merge δ <- δ2
for k, δv2 := range δ2 {
δv1, already := δ[k]
if !already {
δ[k] = δv2
continue
}
// both δ and δ2 has [k] - it can be that key
// entry migrated from one bucket into another.
if !( (δv1.New == VDEL && δv2.Old == VDEL) ||
(δv1.Old == VDEL && δv2.New == VDEL) ) {
return nil, fmt.Errorf("BUG or btree corrupt: [%v] has " +
"duplicate entries: %v, %v", k, δv1, δv2)
}
δv := ΔValue{}
if δv2.New == VDEL {
δv.Old = δv2.Old
δv.New = δv1.New
} else {
δv.Old = δv1.Old
δv.New = δv2.New
}
fmt.Printf(" [%v] merge %s %s -> %s\n", k, δv1, δv2, δv)
if δv.Old != δv.New {
δ[k] = δv
} else {
delete(δ, k)
}
}
}
func __diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack) (δ map[Key]ΔValue, err error) { func __diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack) (δ map[Key]ΔValue, err error) {
fmt.Printf(" T %s %s\n", xidOf(a), xidOf(b)) fmt.Printf(" T %s %s\n", xidOf(a), xidOf(b))
......
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