Commit c919bfee authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ccac4d70
......@@ -27,6 +27,10 @@ package xbtree
//go:generate ../../gen-set xbtree Object interface{} zset_object.go
import (
"context"
"fmt"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/btree"
)
......@@ -260,12 +264,15 @@ func (btail *ΔTail) ForgetPast(revCut zodb.Tid) {
//
// XXX at must ∈ (tail, head] XXX [tail ?
// XXX key must be tracked
func (δΒtail *ΔTail) Get(root *Tree, key Key, at zodb.Tid) (value Value, ok bool, rev zodb.Tid, revExact bool) {
func (δΒtail *ΔTail) Get(ctx context.Context, root *Tree, key Key, at zodb.Tid) (value Value, ok bool, rev zodb.Tid, revExact bool, err error) {
defer xerr.Contextf(&err, "δBtail: root<%s>: get %s @%s", root.POid(), key, at)
// XXX key not tracked -> panic
// XXX at not ∈ (tail, head] -> panic
// XXX handle deletion
// FIXME stub -> that only ZBlk.rev is used
return @head, rev=.Tail(), revExact=false
//return @head, rev=.Tail(), revExact=false
// XXX dirty -> rebuild
......@@ -286,15 +293,34 @@ func (δΒtail *ΔTail) Get(root *Tree, key Key, at zodb.Tid) (value Value, ok b
}
}
// found key in history tail
// key was found in δT ∈ δTtail
if ok {
return
}
// key not in history tail
value, ok = δTtail.KVAtTail[key]
// key not in history tail.
// either use @tail[key], if it is present, or @head[key]
rev = δΒtail.Tail()
revExact = false
value, ok = δTtail.KVAtTail[key]
if ok {
return
}
// @tail[key] is not present - key was not changing in (tail, head].
// since at ∈ (tail, head] we can use @head[key] as the result
xvalue, ok, err := root.Get(ctx, key)
if err != nil {
return
}
v, ok := xvalue.(zodb.IPersistent)
if !ok {
err = fmt.Errorf("got %T; expect ZODB persistent reference", xvalue)
return
}
value = v.POid()
ok = true
return
}
......
......@@ -940,7 +940,7 @@ func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) (err error) {
if int64(len(blkdata)) == blksize {
func() {
// store retrieved data back to OS cache for file @<rev>/file[blk]
blkrev, _ := f.LastBlkRev(blk, f.head.zconn.At())
blkrev, _ := f.LastBlkRev(ctx, blk, f.head.zconn.At())
frev, frelease, err := groot.mkrevfile(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)
......@@ -1190,7 +1190,7 @@ func (f *BigFile) updateWatchers(ctx context.Context, blk int64, treepath []btre
// if blkrev is rough estimation and that upper bound is > w.at
// we have to recompute ~exact file[blk] revision @head.
if blkrevRough {
blkrev, _ = f.LastBlkRev(blk, f.head.zconn.At())
blkrev, _ = f.LastBlkRev(ctx, blk, f.head.zconn.At())
blkrevRough = false
if blkrev <= w.at {
......@@ -1204,7 +1204,7 @@ func (f *BigFile) updateWatchers(ctx context.Context, blk int64, treepath []btre
// and most of them would be on different w.at - cache of the file will
// be lost. Via pinning to particular block revision, we make sure the
// revision to pin is the same on all clients, and so file cache is shared.
pinrev, _ := w.file.LastBlkRev(blk, w.at) // XXX move into go?
pinrev, _ := w.file.LastBlkRev(ctx, blk, w.at) // XXX move into go?
wg.Go(func() error {
// XXX close watcher on any error
......
......@@ -20,6 +20,8 @@
package main
import (
"context"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/btree"
......@@ -156,11 +158,16 @@ func (δFtail *ΔFtail) ForgetPast(revCut zodb.Tid) {
// blk must be tracked
//
// XXX +ctx, error rebuild []δF here
func (f *BigFile) LastBlkRev(blk int64, at zodb.Tid) (_ zodb.Tid, exact bool) {
func (f *BigFile) LastBlkRev(ctx context.Context, blk int64, at zodb.Tid) (_ zodb.Tid, exact bool) {
//defer xerr.Contextf(&err, "") // XXX text
δFtail := f.head.bfdir.δFtail
// XXX tabRev -> treeRev ?
zblkOid, ok, tabRev, tabRevExact := δFtail.δBtail.Get(f.zfile.blktab, blk, at)
zblkOid, ok, tabRev, tabRevExact, err := δFtail.δBtail.Get(ctx, f.zfile.blktab, blk, at)
if err != nil {
panic(err)
}
// block was removed
// XXX or not in tracked set?
......
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