Commit e7e8600f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 27b8b378
...@@ -169,11 +169,14 @@ type ΔBtail struct { ...@@ -169,11 +169,14 @@ type ΔBtail struct {
// XXX or ask client to provide db on every call? // XXX or ask client to provide db on every call?
db *zodb.DB // to open connections to load new/old tree|buckets db *zodb.DB // to open connections to load new/old tree|buckets
// tracked nodes index: node -> parent + accessed holes under this node // tracked nodes index: node -> parent + accessed holes under this node XXX -> holeIdx
// we only allow single parent/root case and report "tree corrupt" otherwise. // we only allow single parent/root case and report "tree corrupt" otherwise.
// trackIdx describes @head state // trackIdx describes @head state
trackIdx map[zodb.Oid]nodeTrack trackIdx map[zodb.Oid]nodeTrack
// XXX tracked holes
holeIdx treeSetKey
// tracked objects that are not yet taken into account in current δBtail // tracked objects that are not yet taken into account in current δBtail
trackNew SetOid trackNew SetOid
} }
...@@ -186,6 +189,25 @@ type nodeTrack struct { ...@@ -186,6 +189,25 @@ type nodeTrack struct {
// XXX move holes into separate ΔBtail..holeIdx // XXX move holes into separate ΔBtail..holeIdx
} }
// treeSetKey represents ordered set of keys.
// it can be point-queried and range-accessed.
// TODO -> btree
type treeSetKey struct {
SetKey
}
// InRange returns
func (hi treeSetKey) GetInRange(lo, hi_ Key) SetKey {
// FIXME dumb O(n) -> TODO use cznic/b
ret := SetKey{}
for k := range hi.SetKey {
if lo <= k && k <= hi_ {
ret.Add(k)
}
}
return ret
}
// ΔB represents a change in BTrees space. // ΔB represents a change in BTrees space.
type ΔB struct { type ΔB struct {
Rev zodb.Tid Rev zodb.Tid
...@@ -370,7 +392,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) { ...@@ -370,7 +392,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
} }
for root, δtops := range δtopsByRoot { for root, δtops := range δtopsByRoot {
δT, err := treediff(ctx, root, δtops, δZTC, δBtail.trackIdx, zconnOld, zconnNew) δT, err := treediff(ctx, root, δtops, δZTC, δBtail.trackIdx, δBtail.holeIdx, zconnOld, zconnNew)
if err != nil { if err != nil {
return ΔB{}, err return ΔB{}, err
} }
...@@ -603,7 +625,7 @@ func (rs rangeSplit) String() string { ...@@ -603,7 +625,7 @@ func (rs rangeSplit) String() string {
// δtops is set of top nodes for changed subtrees. // δtops is set of top nodes for changed subtrees.
// δZTC is connected(δZ/T) - connected closure for subset of δZ(old..new) that // δZTC is connected(δZ/T) - connected closure for subset of δZ(old..new) that
// touches tracked nodes of T. // touches tracked nodes of T.
func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) { func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack, holeIdx treeSetKey, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) {
defer xerr.Contextf(&err, "treediff %s..%s %s", zconnOld.At(), zconnNew.At(), root) defer xerr.Contextf(&err, "treediff %s..%s %s", zconnOld.At(), zconnNew.At(), root)
tracef("treediff %s δtops: %v δZTC: %v\n", root, δtops, δZTC) tracef("treediff %s δtops: %v δZTC: %v\n", root, δtops, δZTC)
...@@ -619,7 +641,7 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t ...@@ -619,7 +641,7 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
return nil, err return nil, err
} }
δtop, err := diffX(ctx, a, b, δZTC, trackIdx) δtop, err := diffX(ctx, a, b, δZTC, trackIdx, holeIdx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -646,7 +668,7 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t ...@@ -646,7 +668,7 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
// δZTC is connected set of objects covering δZT (objects changed in this tree in old..new). // δZTC is connected set of objects covering δZT (objects changed in this tree in old..new).
// //
// a/b can be nil; a=nil means addition, b=nil means deletion. // a/b can be nil; a=nil means addition, b=nil means deletion.
func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack) (δ map[Key]ΔValue, err error) { func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]nodeTrack, holeIdx treeSetKey) (δ map[Key]ΔValue, err error) {
if a==nil && b==nil { if a==nil && b==nil {
panic("BUG: both a & b == nil") panic("BUG: both a & b == nil")
} }
...@@ -681,7 +703,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]n ...@@ -681,7 +703,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]n
} }
if isT { if isT {
return diffT(ctx, aT, bT, δZTC, trackIdx) return diffT(ctx, aT, bT, δZTC, trackIdx, holeIdx)
} else { } else {
return diffB(ctx, aB, bB) return diffB(ctx, aB, bB)
} }
...@@ -693,7 +715,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]n ...@@ -693,7 +715,7 @@ func diffX(ctx context.Context, a, b Node, δZTC SetOid, trackIdx map[zodb.Oid]n
// δZTC is connected set of objects covering δZT (objects changed in this tree in old..new). // δZTC is connected set of objects covering δZT (objects changed in this tree in old..new).
// //
// XXX trackIdx -> just pass δBtail? // XXX trackIdx -> just pass δBtail?
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, holeIdx treeSetKey) (δ map[Key]ΔValue, err error) {
tracef(" diffT %s %s\n", xidOf(A), xidOf(B)) tracef(" diffT %s %s\n", xidOf(A), xidOf(B))
defer xerr.Contextf(&err, "diffT %s %s", xidOf(A), xidOf(B)) defer xerr.Contextf(&err, "diffT %s %s", xidOf(A), xidOf(B))
...@@ -748,7 +770,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -748,7 +770,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
} }
} }
// Bkqueue <- holes(ra.range) // Bkqueue <- holes(ra.range)
for k := range holeIdx.InRange(ra.lo, ra.hi_) { for k := range holeIdx.GetInRange(ra.lo, ra.hi_) {
if !Bkdone.Has(k) { if !Bkdone.Has(k) {
Bkqueue.Add(k) Bkqueue.Add(k)
} }
...@@ -882,7 +904,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -882,7 +904,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
} }
} }
// Bkqueue <- holes(a.range) // Bkqueue <- holes(a.range)
for k_ := range holeIdx.InRange(a.lo, a.hi_) { for k_ := range holeIdx.GetInRange(a.lo, a.hi_) {
if !Bkdone.Has(k_) { if !Bkdone.Has(k_) {
Bkqueue.Add(k_) Bkqueue.Add(k_)
} }
......
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