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

.

parent f9c29c14
......@@ -538,14 +538,21 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
//
// XXX +ctx, error rebuild []δF here
func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64, at zodb.Tid) (_ zodb.Tid, exact bool) {
//defer xerr.Contextf(&err, "") // XXX text
rev, exact, err := δFtail._LastBlkRev(ctx, zf, blk, at)
if err != nil {
panic(err) // XXX
}
return rev, exact
}
func (δFtail *ΔFtail) _LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64, at zodb.Tid) (_ zodb.Tid, exact bool, err error) {
defer xerr.Contextf(&err, "blkrev f<%s> #%d @%s", zf.POid(), blk, at)
// XXX locking
// XXX rebuild
δftail := δFtail.byFile[zf.POid()]
// find epoch that covers at
// find epoch that covers at and associated blktab root/object
vδE := δftail.vδE
l := len(vδE)
i := sort.Search(l, func(i int) bool {
......@@ -553,13 +560,30 @@ func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64,
})
// vδE[i] is next epoch
// vδE[i-1] is epoch that covers at
// root
var root zodb.Oid
var epoch zodb.Tid
var rootObj *btree.LOBTree
if i == l {
root = zf.blktab // XXX activate
err := zf.PActivate(ctx)
if err != nil {
// file deleted
if xzodb.IsErrNoData(err) {
root = xbtree.VDEL
} else {
return zodb.InvalidTid, false, err
}
} else {
rootObj = zf.blktab
root = rootObj.POid()
zf.PDeactivate()
}
} else {
root = vδE[i].oldRoot
}
// epoch
var epoch zodb.Tid
i--
if i < 0 {
// i<0 - first epoch (no explicit start) - use δFtail.tail as lo
......@@ -568,26 +592,31 @@ func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64,
epoch = vδE[i].Rev
}
//root := δftail.root // XXX handle epochs
err := zf.PActivate(ctx)
// get to rootObj (NOTE @head, because it is ΔBtail.GetAt requirement)
if rootObj == nil && root != xbtree.VDEL {
zconn := zf.PJar()
xrootObj, err := zconn.Get(ctx, root)
if err != nil {
// file deleted
if xzodb.IsErrNoData(err) {
return δFtail.Tail(), false // FIXME tail -> epoch(at)
return zodb.InvalidTid, false, err
}
var ok bool
rootObj, ok = xrootObj.(*btree.LOBTree)
if !ok {
return zodb.InvalidTid, false, fmt.Errorf("blktab: expect LOBTree; got %s", xzodb.TypeOf(xrootObj))
}
panic(err) // XXX
}
defer zf.PDeactivate()
// XXX take epochs into account
// XXX tabRev -> treeRev ?
//zblkOid, ok, tabRev, tabRevExact, err := δFtail.δBtail.GetAt(ctx, root, blk, at)
zblkOid, ok, tabRev, tabRevExact, err := δFtail.δBtail.GetAt(ctx, zf.blktab, blk, at)
var zblkOid zodb.Oid
var tabRev zodb.Tid
var tabRevExact, ok bool
if rootObj != nil {
zblkOid, ok, tabRev, tabRevExact, err = δFtail.δBtail.GetAt(ctx, rootObj, blk, at)
//fmt.Printf("GetAt #%d @%s -> %s, %v, @%s, %v\n", blk, at, zblkOid, ok, tabRev, tabRevExact)
if err != nil {
panic(err) // XXX
return zodb.InvalidTid, false, err
}
}
if tabRev < epoch {
......@@ -595,9 +624,8 @@ func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64,
}
// block was removed
// XXX or not in tracked set?
if !ok {
return tabRev, tabRevExact
return tabRev, tabRevExact, nil
}
// blktab[blk] was changed to point to a zblk @rev.
......@@ -605,9 +633,9 @@ func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64,
zblkRev, zblkRevExact := δFtail.δBtail.ΔZtail().LastRevOf(zblkOid, at)
//fmt.Printf("ZRevOf %s @%s -> @%s, %v\n", zblkOid, at, zblkRev, zblkRevExact)
if zblkRev > tabRev {
return zblkRev, zblkRevExact
return zblkRev, zblkRevExact, nil
} else {
return tabRev, tabRevExact
return tabRev, tabRevExact, nil
}
}
......
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