Commit 2d71c2ed authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 80bdf7e4
......@@ -126,7 +126,7 @@ type ΔValue struct {
//
// δB:
// .rev↑
// {} root -> {}(key, value) XXX value -> δvalue
// {} root -> {}(key, δvalue) XXX was value
//
// and atTail keeps set of k/v @tail for keys changed in (tail, head]
//
......@@ -167,24 +167,26 @@ type ΔBtail struct {
// δRtail []ΔRoots // which BTree were changed; Noted only by 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?
// handle to make connections to access database.
// TODO allow client to optionally provide zconnOld/zconnNew on e.g. Update()
db *zodb.DB // to open connections to load new/old tree|buckets
// 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
// XXX -> parentIdx
// XXX -> parentIdx map[zodb.Oid]zodb.Oid ?
trackIdx map[zodb.Oid]nodeTrack
// XXX tracked holes
holeIdx treeSetKey
// tracked objects that are not yet taken into account in current δBtail
trackNew SetOid
// // tracked objects that are not yet taken into account in current δBtail
// trackNew SetOid
}
// XXX place
// nodeTrack represents tracking information about a node.
// XXX kill (parentIdx is just {} oid -> oid)
type nodeTrack struct {
parent zodb.Oid // parent node | InvalidOid for root
/*
......@@ -283,7 +285,7 @@ func (δBtail *ΔBtail) Tail() zodb.Tid { return δBtail.δZtail.Tail() }
// path[0] signifies tree root.
// All path elements must be Tree except last one which must be Bucket.
//
// XXX δBtail is rebuild to also include keys corresponding to added nodes.
// δBtail will also track all keys corresponding to added bucket nodes. XXX
//
// XXX objects in path must be with .PJar().At() == .head
// XXX path -> []oid ?
......@@ -393,7 +395,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
}
// open ZODB connections corresponding to "old" and "new" states
// TODO caller should provide one of those (probably new)
// TODO caller should provide one of those (probably new) as usually it has it
txn, ctx := transaction.New(context.TODO()) // XXX
defer txn.Abort()
zconnOld, err := δBtail.db.Open(ctx, &zodb.ConnOptions{At: headOld})
......
......@@ -18,7 +18,7 @@
// See https://www.nexedi.com/licensing for rationale and options.
package main
// tests for δbtail.go
// XXX doc (2 ways of testing: explicit + allstructs), treegen py helper
// Adjacency matrix
......@@ -272,6 +272,7 @@ func (tg *AllStructsSrv) AllStructs(kv1, kv2 map[Key]string, maxdepth, maxsplit,
// RBucket represents Bucket node covering [lo, hi) key range in its Tree.
type RBucket struct {
// XXX +oid, +parent (RTree)
lo, hi Key
kv map[Key]string // bucket's k->v; values were ZBlk objects whose data is loaded instead.
}
......@@ -433,8 +434,6 @@ func xzgetBlkData(ctx context.Context, zconn *zodb.Connection, zblkOid zodb.Oid)
// kadjOK may be optionally provided. if kadjOK != nil computed adjacency
// matrix is verified against it.
func xverifyΔBTail(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, at1, at2 zodb.Tid, xkv1, xkv2 RBucketSet, δZ *zodb.EventCommit, kadjOK map[Key]SetKey) {
d12 := kvdiff(xkvFlatten(xkv1), xkvFlatten(xkv2))
// verify transition at1->at2 for all initial states of tracked {keys} from kv1 + kv2 + ∞
allKeys := SetKey{}; allKeys.Add(kInf) // ∞ simulating ZBigFile.Size() query
maxk1 := -kInf; maxk2 := -kInf
......@@ -460,7 +459,7 @@ func xverifyΔBTail(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, a
k1 := k
k2 := k
if k == kInf {
if k == kInf { // XXX not needed? - kill?
k1 = maxk1
k2 = maxk2
}
......@@ -470,8 +469,8 @@ func xverifyΔBTail(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, a
//tracef("\n")
for len(q1) > 0 || len(q2) > 0 {
//fmt.Printf("q1: %v\n", q1)
//fmt.Printf("q2: %v\n", q2)
//tracef("q1: %v\n", q1)
//tracef("q2: %v\n", q2)
if l1 := len(q1); l1 > 0 {
k1 = q1[l1-1]; q1 = q1[:l1-1]
if !adj1.Has(k1) {
......@@ -517,16 +516,19 @@ func xverifyΔBTail(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, a
keys.Add(allKeyv[idx])
}
xverifyΔBTail1(t, subj, db, treeRoot, at1,at2, d12, δZ, keys, kadj)
xverifyΔBTail1(t, subj, db, treeRoot, at1,at2, xkv1,xkv2, δZ, keys, kadj)
}
}
// xverifyΔBTail1 verifies how ΔBTail handles ZODB update at1->at2 from initial
// tracked state defined by initialTrackedKeys.
func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, at1,at2 zodb.Tid, d12 map[Key]Δstring, δZ *zodb.EventCommit, initialTrackedKeys SetKey, kadj map[Key]SetKey) {
// XXX initialTrackedKeys -> tracked1 ?
func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid, at1,at2 zodb.Tid, xkv1,xkv2 RBucketSet, δZ *zodb.EventCommit, initialTrackedKeys SetKey, kadj map[Key]SetKey) {
X := exc.Raiseif
tracef("\n>>> Track=%s\n", initialTrackedKeys)
d12 := kvdiff(xkvFlatten(xkv1), xkvFlatten(xkv2))
var kadjTracked SetKey = nil
var δT, δTok map[Key]Δstring = nil, nil
......@@ -599,7 +601,25 @@ func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid,
}
}
// XXX verify δbtail index consistency against @at1
// XXX verify δbtail trackIdx against @at1
// holes1 = tracked1 \ kv1
holes1 := SetKey{}
for k := range initialTrackedKeys {
if k == kInf {
continue // ∞ is translated to maxk1 XXX
}
_, keyin1 := xkv1.Get(k).kv[k]
if !keyin1 {
holes1.Add(k)
}
}
/*
if !reflect.DeepEqual(holes1, δbtail.holeIdx.SetKey) {
badf("δbtail.holeIdx1 wrong ; holeIdx=%v holeIdxOK=%v", δbtail.holeIdx, holes1)
}
*/
// XXX verify δbtail holeIdx against @at1
// δB <- δZ
δB, err := δbtail.Update(δZ); X(err)
......@@ -608,6 +628,19 @@ func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid,
return
}
// holes2 = tracked2 \ kv2 ( = kadj[tracked1] \ kv2)
holes2 := SetKey{}
for k := range kadjTracked {
if k == kInf {
continue // ∞ is translated to maxk2
}
_, keyin2 := xkv2.Get(k).kv[k]
if !keyin2 {
holes2.Add(k)
}
}
// XXX verify
// XXX verify δbtail index consistency against @at2
// XXX verify that removed keys remain in trackedIdx (holes), so that e.g.
// track [k]; k:a->b; k:b->ø; k:ø->c is not missed
......
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