Commit 4f04dc6b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5af13240
......@@ -829,86 +829,6 @@ func (δBtail *ΔBtail) GetAt(root zodb.Oid, key Key, at zodb.Tid) (value Value,
return value, rev, valueExact, revExact, nil
}
// XXX kill
// Get returns root[key] as of @at database state plus revision that changed it.
//
// if revExact=False - rev is upper estimate for the revision.
//
// key must be tracked
// at must ∈ (tail, head]
//
// XXX root -> Oid ?
func (δBtail *ΔBtail) XXGetAt(ctx context.Context, root *Tree, key Key, at zodb.Tid) (value Value, ok bool, rev zodb.Tid, revExact bool, err error) {
rootOid := root.POid()
defer xerr.Contextf(&err, "δBtail: root<%s>: get %d @%s", rootOid, key, at)
// XXX key not tracked -> panic
// XXX at not ∈ (tail, head] -> panic
// XXX locking
rootAt := root.PJar().At()
if rootAt != δBtail.Head() {
panicf("δBtail: root.at (@%s) != head (@%s)", rootAt, δBtail.Head())
}
err = δBtail.rebuild1IfNeeded(rootOid)
if err != nil {
return
}
δTtail := δBtail.vδTbyRoot[rootOid]
if δTtail == nil {
panicf("δBtail: root<%s> not tracked", rootOid)
}
// XXX -> index lastXXXOf(key) | linear scan ↓ looking for change <= at
rev = δBtail.Tail()
revExact = false
for i := len(δTtail.vδT)-1; i >= 0; i-- {
δT := δTtail.vδT[i]
δvalue, ok_ := δT.ΔKV[key]
if ok_ {
ok = true
if δT.Rev > at {
value = δvalue.Old
} else {
value = δvalue.New
rev = δT.Rev
revExact = true
break
}
}
}
// key was found in δT ∈ δTtail
if ok {
if value == VDEL {
ok = false
}
return
}
// δBtail[key] is not present - key was not changing in (tail, head].
// since at ∈ (tail, head] as the result we can use @rev[key] for any
// rev ∈ (tail, head].
//
// XXX can we avoid requiring live root? (think again afresh)
// XXX -> move handling of "key not in δBtail -> to δFtail.LastBlkRev"
xvalue, ok, err := root.Get(ctx, key)
if !ok {
value = VDEL
}
if err != nil || !ok {
return
}
value, err = vOid(xvalue)
if err != nil {
ok = false
return
}
return
}
// XXX don't need
//func (δBtail *ΔBtail) SliceByRev(lo, hi zodb.Tid) /*readonly*/ []ΔB {
......
......@@ -840,129 +840,6 @@ func (δFtail *ΔFtail) _BlkRevAt(ctx context.Context, zf *ZBigFile, blk int64,
}
// XXX kill
// LastBlkRev returns last revision that changed file[blk] as of @at database state.
//
// if exact=False - what is returned is only an upper bound for last block revision.
//
// zf must be from @head.
// at must ∈ (tail, head]
// blk must be tracked
//
// XXX +ctx, error rebuild []δF here
func (δFtail *ΔFtail) __LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64, at zodb.Tid) (_ zodb.Tid, exact bool) {
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)
//fmt.Printf("\nblkrev #%d @%s\n", blk, at)
// XXX assert at ∈ (tail, head]
// XXX assert zf.at == head (!)
// XXX locking
δftail, err := δFtail.rebuildIfNeeded(zf.POid())
if err != nil {
return zodb.InvalidTid, false, err
}
// find epoch that covers at and associated blktab root/object
vδE := δftail.vδE
//fmt.Printf(" vδE: %v\n", vδE)
l := len(vδE)
i := sort.Search(l, func(i int) bool {
return at < vδE[i].Rev
})
// vδE[i] is next epoch
// vδE[i-1] is epoch that covers at
// root
var root zodb.Oid
var rootObj *btree.LOBTree
if i == l {
// XXX can use δftail.root instead of activate/deactivate zfile
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
epoch = δFtail.Tail()
} else {
epoch = vδE[i].Rev
}
//fmt.Printf(" epoch: @%s root: %s\n", epoch, root)
// get to rootObj (NOTE @head, because it is ΔBtail.GetAt requirement) XXX
if rootObj == nil && root != xbtree.VDEL {
zconn := zf.PJar()
xrootObj, err := zconn.Get(ctx, root)
if err != nil {
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))
}
}
// XXX take epochs into account
var zblkOid zodb.Oid
var tabRev zodb.Tid
var tabRevExact, ok bool
if rootObj != nil {
zblkOid, ok, tabRev, tabRevExact, err = δFtail.δBtail.XXGetAt(ctx, rootObj, blk, at)
//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 {
tabRev = epoch
tabRevExact = true
}
// block was removed
if !ok {
return tabRev, tabRevExact, nil
}
// blktab[blk] was changed to point to a zblk @rev.
// blk revision is max rev and when zblk changed last in (rev, at] range.
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, nil
} else {
return tabRev, tabRevExact, nil
}
}
// ----------------------------------------
......
......@@ -864,7 +864,6 @@ retry:
zhead := head.zconn
bfdir := head.bfdir
oldHead := zhead.At()
// invalidate kernel cache for data in changed files
// NOTE no δFmu lock needed because zhead is WLocked
......@@ -914,7 +913,7 @@ retry:
for blk := range δfile.Blocks {
blk := blk
wg.Go(func(ctx context.Context) error {
return file.invalidateBlk(ctx, blk, oldHead)
return file.invalidateBlk(ctx, blk)
})
}
}
......@@ -1046,7 +1045,7 @@ func (head *Head) zheadWait(ctx context.Context, at zodb.Tid) (err error) {
//
// see "4.4) for all file/blk to in invalidate we do"
// called with zheadMu wlocked.
func (f *BigFile) invalidateBlk(ctx context.Context, blk int64, oldHead zodb.Tid) (err error) {
func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) (err error) {
defer xerr.Contextf(&err, "%s: invalidate blk #%d:", f.path(), blk)
fsconn := gfsconn
......@@ -1088,8 +1087,7 @@ func (f *BigFile) invalidateBlk(ctx context.Context, blk int64, oldHead zodb.Tid
func() {
// store retrieved data back to OS cache for file @<rev>/file[blk]
δFtail := f.head.bfdir.δFtail
// blkrev, _ := δFtail.BlkRevAt(ctx, f.zfile, blk, f.head.zconn.At())
blkrev, _ := δFtail.BlkRevAt(ctx, f.zfile, blk, oldHead)
blkrev, _ := δFtail.BlkRevAt(ctx, f.zfile, blk, f.head.zconn.At())
frev, funlock, err := groot.lockRevFile(blkrev, f.zfile.POid())
if err != nil {
log.Errorf("BUG: %s: invalidate blk #%d: %s (ignoring, but reading @revX/bigfile will be slow)", f.path(), blk, 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