Commit bf411aa9 authored by Kirill Smelkov's avatar Kirill Smelkov

X zdata: Deduplicate zfile loading

parent aac37c11
......@@ -234,26 +234,15 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
txn.Abort()
}()
zconn, err := t.DB.Open(ctx, &zodb.ConnOptions{At: t.Head().At, NoPool: true}); X(err)
xzroot, err := zconn.Get(ctx, 0); X(err)
zroot := xzroot.(*zodb.Map)
err = zroot.PActivate(ctx); X(err)
zfile := zroot.Data["treegen/file"].(*ZBigFile)
zroot.PDeactivate()
zfile, blksize := t.XLoadZFile(ctx, zconn)
foid := zfile.POid()
err = zfile.PActivate(ctx); X(err)
blksize := zfile.blksize
blktabOid := zfile.blktab.POid()
if blktabOid != t.Root() {
t.Fatalf("BUG: zfile.blktab (%s) != treeroot (%s)", blktabOid, t.Root())
}
zfile.PDeactivate()
// update vδf + co for t1
vδf = append(vδf, &ΔFile{Rev: t1.At, Epoch: true})
vδE = append(vδE, _ΔFileEpoch{
Rev: t1.At,
oldRoot: zodb.InvalidOid,
newRoot: blktabOid,
newRoot: t.Root(),
newBlkSize: blksize,
oldTrackSetZBlk: nil,
})
......@@ -421,13 +410,13 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
if newEpoch {
δE := _ΔFileEpoch{Rev: commit.At}
if delfile {
δE.oldRoot = blktabOid
δE.oldRoot = t.Root()
δE.newRoot = zodb.InvalidOid
δE.newBlkSize = -1
// XXX oldBlkSize ?
} else {
δE.oldRoot = zodb.InvalidOid
δE.newRoot = blktabOid
δE.newRoot = t.Root()
δE.newBlkSize = blksize
// XXX oldBlkSize ?
}
......@@ -478,8 +467,8 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
for oid, zt := range δFtail.trackSetZBlk {
zblki := commit.ZBlkTab[oid]
for root, blocks := range zt.inroot {
if root != blktabOid {
t.Errorf(".trackSetZBlk: zblk %s points to unexpected blktab %s", zblki.Name, blktabOid)
if root != t.Root() {
t.Errorf(".trackSetZBlk: zblk %s points to unexpected blktab %s", zblki.Name, t.Root())
continue
}
......@@ -515,7 +504,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// verify δftail.root
δftail := δFtail.byFile[foid]
rootOK := blktabOid
rootOK := t.Root()
if delfile {
rootOK = zodb.InvalidOid
}
......@@ -627,25 +616,12 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
// load zfile via root['treegen/file']
// XXX dup
txn, ctx := transaction.New(context.Background())
defer func() {
txn.Abort()
}()
zconn, err := t.DB.Open(ctx, &zodb.ConnOptions{At: t.Head().At, NoPool: true}); X(err)
xzroot, err := zconn.Get(ctx, 0); X(err)
zroot := xzroot.(*zodb.Map)
err = zroot.PActivate(ctx); X(err)
zfile := zroot.Data["treegen/file"].(*ZBigFile)
zroot.PDeactivate()
// foid := zfile.POid()
err = zfile.PActivate(ctx); X(err)
// blksize := zfile.blksize
blktabOid := zfile.blktab.POid()
if blktabOid != t.Root() {
t.Fatalf("BUG: zfile.blktab (%s) != treeroot (%s)", blktabOid, t.Root())
}
zfile.PDeactivate()
zconn, err := t.DB.Open(ctx, &zodb.ConnOptions{At: t.Head().At}); X(err)
zfile, _ := t.XLoadZFile(ctx, zconn)
// XXX dup
xtrackBlk := func(blk int64) {
......@@ -721,6 +697,24 @@ func newT(t *testing.T) *T {
return &T{xbtreetest.NewT(t)}
}
// XLoadZFile loads zfile from root["treegen/file"]@head.
func (t *T) XLoadZFile(ctx context.Context, zconn *zodb.Connection) (zfile *ZBigFile, blksize int64) {
X := exc.Raiseif
xzroot, err := zconn.Get(ctx, 0); X(err)
zroot := xzroot.(*zodb.Map)
err = zroot.PActivate(ctx); X(err)
zfile = zroot.Data["treegen/file"].(*ZBigFile)
zroot.PDeactivate()
err = zfile.PActivate(ctx); X(err)
blksize = zfile.blksize
blktabOid := zfile.blktab.POid()
if blktabOid != t.Root() {
t.Fatalf("BUG: zfile.blktab (%s) != treeroot (%s)", blktabOid, t.Root())
}
zfile.PDeactivate()
return zfile, blksize
}
// δfstr/vδfstr convert δf/vδf to string taking symbolic at into account.
func (t *T) δfstr(δf *ΔFile) string {
s := fmt.Sprintf("@%s·%s", t.AtSymb(δf.Rev), δf.Blocks)
......
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