Commit e7e8600f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 27b8b378
......@@ -169,11 +169,14 @@ type ΔBtail struct {
// XXX or ask client to provide db on every call?
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.
// trackIdx describes @head state
trackIdx map[zodb.Oid]nodeTrack
// XXX tracked holes
holeIdx treeSetKey
// tracked objects that are not yet taken into account in current δBtail
trackNew SetOid
}
......@@ -186,6 +189,25 @@ type nodeTrack struct {
// 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.
type ΔB struct {
Rev zodb.Tid
......@@ -370,7 +392,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
}
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 {
return ΔB{}, err
}
......@@ -603,7 +625,7 @@ func (rs rangeSplit) String() string {
// δtops is set of top nodes for changed subtrees.
// δZTC is connected(δZ/T) - connected closure for subset of δZ(old..new) that
// 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)
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
return nil, err
}
δtop, err := diffX(ctx, a, b, δZTC, trackIdx)
δtop, err := diffX(ctx, a, b, δZTC, trackIdx, holeIdx)
if err != nil {
return nil, err
}
......@@ -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).
//
// 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 {
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
}
if isT {
return diffT(ctx, aT, bT, δZTC, trackIdx)
return diffT(ctx, aT, bT, δZTC, trackIdx, holeIdx)
} else {
return diffB(ctx, aB, bB)
}
......@@ -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).
//
// 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))
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]
}
}
// 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) {
Bkqueue.Add(k)
}
......@@ -882,7 +904,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
}
}
// 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_) {
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