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