Commit 5dc77419 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ee9904c6
...@@ -91,20 +91,22 @@ import ( ...@@ -91,20 +91,22 @@ import (
type Tree = btree.LOBTree type Tree = btree.LOBTree
type Bucket = btree.LOBucket type Bucket = btree.LOBucket
type Node = btree.LONode type Node = btree.LONode
type TreeEntry = btree.LOEntry type TreeEntry = btree.LOEntry
type BucketEntry = btree.LOBucketEntry type BucketEntry = btree.LOBucketEntry
type Key = int64 type Key = int64
const KeyMax Key = math.MaxInt64 const KeyMax Key = math.MaxInt64
const KeyMin Key = math.MinInt64 const KeyMin Key = math.MinInt64
type Value = zodb.Oid // assumes key points to IPersistent
type Value = zodb.Oid // assumes value is persistent reference
// deletion is represented as VDEL // deletion is represented as VDEL
const VDEL = zodb.InvalidOid const VDEL = zodb.InvalidOid
type Oid = zodb.Oid type Oid = zodb.Oid
type SetKey = SetI64 type SetKey = SetI64
// ΔValue represents change in value. // ΔValue represents change in value.
type ΔValue struct { type ΔValue struct {
Old Value Old Value
...@@ -160,9 +162,8 @@ type ΔBtail struct { ...@@ -160,9 +162,8 @@ type ΔBtail struct {
// includes all changed objects, not only tracked ones. // includes all changed objects, not only tracked ones.
δZtail *zodb.ΔTail δZtail *zodb.ΔTail
// XXX vvv keys keys ∈ tracket -> keys ∈ kadj[tracket] ? // XXX vvv keys keys ∈ tracked -> keys ∈ kadj[tracket] ?
// δRtail []ΔRoots // which BTree were changed; Noted only by keys ∈ tracket subset // δRtail []ΔRoots // which BTree were changed; Noted only by keys ∈ tracket subset
// byRoot map[*Tree]*ΔTtail // root -> k/v change history; only for keys ∈ tracket subset
byRoot map[zodb.Oid]*ΔTtail // {} root -> [] k/v change history; only for keys ∈ tracket subset byRoot map[zodb.Oid]*ΔTtail // {} root -> [] k/v change history; only for keys ∈ tracket subset
// XXX or ask client to provide db on every call? // XXX or ask client to provide db on every call?
...@@ -333,9 +334,9 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node, flags Track ...@@ -333,9 +334,9 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node, flags Track
// taken into account. In other words a tree history will assuredly include // taken into account. In other words a tree history will assuredly include
// only those keys, that correspond to tracked subset of δZ. // only those keys, that correspond to tracked subset of δZ.
// //
// δZ should include all objects changed by ZODB transaction. // δZ must include all objects changed by ZODB transaction.
// //
// XXX optionally accept zconnOld/zconnNew from client // TODO optionally accept zconnOld/zconnNew from client
func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) { func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
headOld := δBtail.Head() headOld := δBtail.Head()
defer xerr.Contextf(&err, "ΔBtail update %s -> %s", headOld, δZ.Tid) defer xerr.Contextf(&err, "ΔBtail update %s -> %s", headOld, δZ.Tid)
...@@ -387,7 +388,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) { ...@@ -387,7 +388,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
// δZConnectTracked computes connected closure of δZ/T. // δZConnectTracked computes connected closure of δZ/T.
// //
// δZ - all changes in a ZODB transaction. // δZ - all changes in a ZODB transaction.
// δZ/T - subset of those changes intersection with tracking set. // δZ/T - subset of those changes intersecting with tracking set.
// δZ/TC - connected closure for δZ/T // δZ/TC - connected closure for δZ/T
// //
// for example for e.g. t₀->t₁->b₂ if δZ/T={t₀ b₂} -> δZ/TC=δZ/T+{t₁} // for example for e.g. t₀->t₁->b₂ if δZ/T={t₀ b₂} -> δZ/TC=δZ/T+{t₁}
...@@ -534,7 +535,7 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) { ...@@ -534,7 +535,7 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) {
// GetToLeaf returns leaf node corresponding to key k. // GetToLeaf returns leaf node corresponding to key k.
// //
// Leaf is usually bucket node, but, in the sole single case of empty tree, can be that root tree node. // Leaf is usually bucket node, but, in the sole single case of empty tree, can be that root tree node.
// GetToLeaf expands step-by-step every tree from where it has to traverse to next depth level. // GetToLeaf expands step-by-step every tree through which it has to traverse to next depth level.
// //
// XXX also return path? // XXX also return path?
func (prs *rangeSplit) GetToLeaf(ctx context.Context, k Key) (rnode *nodeInRange, ok bool, err error) { func (prs *rangeSplit) GetToLeaf(ctx context.Context, k Key) (rnode *nodeInRange, ok bool, err error) {
...@@ -593,7 +594,6 @@ func (rs rangeSplit) String() string { ...@@ -593,7 +594,6 @@ func (rs rangeSplit) String() string {
// 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, 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)
// XXX zconnX -> a, b ?
tracef("treediff %s δtops: %v δZTC: %v\n", root, δtops, δZTC) tracef("treediff %s δtops: %v δZTC: %v\n", root, δtops, δZTC)
defer tracef("\n") defer tracef("\n")
...@@ -716,14 +716,14 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -716,14 +716,14 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
err = atree.PActivate(ctx); if err != nil { return nil, err} err = atree.PActivate(ctx); if err != nil { return nil, err}
defer atree.PDeactivate() defer atree.PDeactivate()
// empty tree - do not expand into bucket - only process tracked holes
if len(atree.Entryv()) == 0 { if len(atree.Entryv()) == 0 {
// empty tree - do not expand into bucket - only process tracked holes
// XXX dup wrt bucket processing? // XXX dup wrt bucket processing?
δA := map[Key]ΔValue{}
track, ok := trackIdx[atree.POid()] track, ok := trackIdx[atree.POid()]
if !ok { if !ok {
panicf("%s ∈ δZTC, but ∉ trackIdx", vnode(atree)) panicf("%s ∈ δZTC, but ∉ trackIdx", vnode(atree))
} }
δA := map[Key]ΔValue{}
for k := range track.holes { for k := range track.holes {
δA[k] = ΔValue{VDEL, VDEL} // ø->ø indicates hole δA[k] = ΔValue{VDEL, VDEL} // ø->ø indicates hole
} }
...@@ -744,6 +744,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -744,6 +744,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
continue continue
} }
// normal tree - expand till buckets
children := av.Expand(arn) children := av.Expand(arn)
for _, rchild := range children { for _, rchild := range children {
coid := rchild.node.POid() coid := rchild.node.POid()
...@@ -810,7 +811,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid] ...@@ -810,7 +811,7 @@ func diffT(ctx context.Context, a, b *Tree, δZTC SetOid, trackIdx map[zodb.Oid]
} }
// B queue // B queue
// expand keys in new δA -> in B till buckets; // expand keys from new δA -> in B till buckets;
// process B buckets that cover new keys into δ+ // process B buckets that cover new keys into δ+
Aqueue = SetKey{} Aqueue = SetKey{}
for k := range Bqueue { for k := range Bqueue {
......
...@@ -387,8 +387,6 @@ func xwalkDFS(ctx context.Context, lo, hi Key, ztree *Tree, bvisit func(*RBucket ...@@ -387,8 +387,6 @@ func xwalkDFS(ctx context.Context, lo, hi Key, ztree *Tree, bvisit func(*RBucket
bvisit(&RBucket{xlo, xhi, bkv}) bvisit(&RBucket{xlo, xhi, bkv})
} }
} }
// XGetδKV translates {k -> δ<oid>} to {k -> δ(ZBlk(oid).data)} according to db@at1..at2 snapshots. // XGetδKV translates {k -> δ<oid>} to {k -> δ(ZBlk(oid).data)} according to db@at1..at2 snapshots.
...@@ -505,23 +503,6 @@ func xverifyΔBTail(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, a ...@@ -505,23 +503,6 @@ func xverifyΔBTail(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, a
adj := SetKey{}; adj.Update(adj1); adj.Update(adj2) adj := SetKey{}; adj.Update(adj1); adj.Update(adj2)
kadj[k] = adj kadj[k] = adj
/*
for k_ := range xkv1.Get(k1).kv {
adj.Add(k_)
for k__ := range xkv2.Get(k_).kv {
adj.Add(k__)
}
}
for k_ := range xkv2.Get(k2).kv {
adj.Add(k_)
for k__ := range xkv1.Get(k_).kv {
adj.Add(k__)
}
}
kadj[k] = adj
*/
} }
if kadjOK != nil && !reflect.DeepEqual(kadj, kadjOK) { if kadjOK != nil && !reflect.DeepEqual(kadj, kadjOK) {
......
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