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

X rebuild: tests: Don't access ZODB in xtrackKeys

Use preloaded data, similarly to previous commit.

95s -> 82s.
parent 8f6e2b1e
...@@ -285,6 +285,17 @@ type RBucket struct { ...@@ -285,6 +285,17 @@ type RBucket struct {
kv map[Key]string // bucket's k->v; values were ZBlk objects whose data is loaded instead. kv map[Key]string // bucket's k->v; values were ZBlk objects whose data is loaded instead.
} }
// Path returns path to this bucket from tree root.
func (rb *RBucket) Path() []zodb.Oid {
path := []zodb.Oid{rb.oid}
p := rb.parent
for p != nil {
path = append([]zodb.Oid{p.oid}, path...)
p = p.parent
}
return path
}
// RBucketSet represents set of buckets covering whole [-∞,∞) range. // RBucketSet represents set of buckets covering whole [-∞,∞) range.
type RBucketSet []*RBucket // k↑ type RBucketSet []*RBucket // k↑
...@@ -728,7 +739,7 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod ...@@ -728,7 +739,7 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
// δbtail @at1 with initial tracked set // δbtail @at1 with initial tracked set
δbtail := NewΔBtail(t1.at, db) δbtail := NewΔBtail(t1.at, db)
xtrackKeys(δbtail, treeRoot, initialTrackedKeys) xtrackKeys(δbtail, t1, initialTrackedKeys)
// TrackedδZ = Tracked ^ δZ (i.e. a tracked node has changed, or its coverage was changed) // TrackedδZ = Tracked ^ δZ (i.e. a tracked node has changed, or its coverage was changed)
TrackedδZ = SetKey{} TrackedδZ = SetKey{}
...@@ -1153,7 +1164,7 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, δbtail *ΔBtail, tj *tTreeCommit, ...@@ -1153,7 +1164,7 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, δbtail *ΔBtail, tj *tTreeCommit,
ø := PPTreeSubSet{} ø := PPTreeSubSet{}
// Track(keys) // Track(keys)
xtrackKeys(δbtail, treeRoot, keys) xtrackKeys(δbtail, tj, keys)
subj := fmt.Sprintf("@%s: after Track%v", xat[tj.at], keys) subj := fmt.Sprintf("@%s: after Track%v", xat[tj.at], keys)
δbtail.assertTrack(t, subj, trackSet, trackNew) δbtail.assertTrack(t, subj, trackSet, trackNew)
...@@ -1221,36 +1232,26 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *tTreeCommit, ...@@ -1221,36 +1232,26 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *tTreeCommit,
// xtrackKeys issues δbtail.Track requests for tree[keys]. // xtrackKeys issues δbtail.Track requests for tree[keys].
// XXX place // XXX place
func xtrackKeys(δbtail *ΔBtail, treeRoot zodb.Oid, keys SetKey) { func xtrackKeys(δbtail *ΔBtail, t *tTreeCommit, keys SetKey) {
X := exc.Raiseif X := exc.Raiseif
head := δbtail.Head()
txn, ctx := transaction.New(context.Background()) if head != t.at {
defer txn.Abort() panicf("BUG: δbtail.head: %s ; t.at: %s", head, t.at)
zconn, err := δbtail.db.Open(ctx, &zodb.ConnOptions{At: δbtail.Head()}); X(err)
xtree, err := zgetNodeOrNil(ctx, zconn, treeRoot); X(err)
var ztree *Tree // = nil if treeRoot was deleted
if xtree != nil {
ztree = xtree.(*Tree)
} }
for k := range keys { for k := range keys {
if ztree != nil { // NOTE: if tree is deleted - the following adds it to tracked
_, _, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err) // set with every key being a hole. This aligns with the
err = δbtail.Track(k, path); X(err) // following situation
} else { //
// if treeRoot is deleted - add it to tracked set with every key // T1 -> ø -> T2
// being a hole. This aligns with the following situation //
// // where after T1->ø, even though the tree becomes deleted, its root
// T1 -> ø -> T2 // continues to be tracked and all keys migrate to holes in the
// // tracking set. By aligning initial state to the same as after
// where after T1->ø, even though the tree becomes deleted, its root // T1->ø, we test what will happen on ø->T2.
// continues to be tracked and all keys migrate to holes in the b := t.xkv.Get(k)
// tracking set. By aligning initial state to the same as after err := δbtail.track(k, b.Path()); X(err)
// T1->ø, we test what will happen on ø->T2.
err = δbtail.track(k, []zodb.Oid{treeRoot}); X(err)
}
} }
} }
......
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