Commit 46b78c5b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5eb50c5f
......@@ -46,6 +46,7 @@ type BucketEntry = btree.LOBucketEntry
type Key = int64
const KeyMax Key = math.MaxInt64
//const KeyMin Key = math.MinInt64
type Value = zodb.Oid // assumes key points to IPersistent
// deletion is represented as VDEL
const VDEL = zodb.InvalidOid
......@@ -299,6 +300,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
fmt.Printf("trackIdx: %v\n", δBtail.trackIdx)
// {} root -> {oid} changed under that root in tracked set
// XXX dumb -> rework to toposort and getting root from tops only
rootOf := func(node zodb.Oid) (root zodb.Oid, ok bool) {
track, ok := δBtail.trackIdx[node]
if !ok {
......@@ -503,8 +505,94 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, e
//
// [0].Key = -∞ ; always returned so
// [len(ev)].Key = +∞ ; should be assumed so
// a -> {aChildren} : ∈ δZTC
aChildren := map[zodb.Oid]Node{}
for _, __ := range av {
child := __.Child()
if δZTC.Has(child.POid() {
aChildren[child.POid()] = child // InvalidOid = embedded bucket
}
}
// -> "might be changed" subset of tracked keys
δtqkeys := SetKey{}
for achild := range aChildren {
track, ok := δBtail.trackIdx[achild]
if !ok {
panicf("node %s ∈ δZTC, but its track is ø", achild)
}
δtqkeys.Update(track.trackedKeys)
}
// b -> {bChildren} : coverage ∩ "might be changed" tracked keys
bChildren := map[zodb.Oid]Node{}
for i := range bv {
lo := bv[i].Key() // [lo, hi_] _not_ hi) not to overflow at ∞
hi_ := KeyMax
if i+1 < len(bv) {
hi_ = bv[i+1].Key() - 1
}
child := bv[i].Child()
// XXX dumb
for k := range δtqkeys {
if lo <= k && k <= hi_ {
bChildren[child.POid()] = child // InvalidOid = embedded bucket
break
}
}
}
// allChildren = aChildren ∪ bChildren
allChildren := SetOid{}
for c := range aChildren { allChildren.Add(c) }
for c := range bChildren { allChildren.Add(c) }
// go through all children that potentially can add to δ and process add/del/modify
for child := range allChildren { // XXX -> sorted?
ca := aChildren[child]
cb := bChildren[child]
δc, err := diffX(ctx, ca, cb, δZTC)
if err != nil {
return nil, err
}
// merge δ <- δc
for k, δv1 := range δ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
}
if δv.Old != δv.New {
δ[k] = δv
} else {
delete(δ, k)
}
}
}
/*
allChildren := SetOid{}
for _, __ := range av {
child := __.Child()
......@@ -564,7 +652,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, e
}
}
/*
/// *
// merge Tkdel <- δc
for k, v := range δc {
if v == VDEL {
......@@ -573,12 +661,13 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid) (δ map[Key]ΔValue, e
delete(Tkdel, k)
}
}
*/
//* /
// XXX process keys from δ outside of already tracked nodes
// XXX only deleted keys - no - delete can be from untracked
// node and on tracked it is seen as addition
}
*/
return δ, nil
}
......
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