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