Commit 00e14419 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 94389dd3
...@@ -1156,27 +1156,19 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) error { ...@@ -1156,27 +1156,19 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) error {
// noone was loading - we became reponsible to load this block // noone was loading - we became reponsible to load this block
zbf := f.zbf zbf := f.zbf
blkdata, treepath, err := zbf.LoadBlk(ctx, blk) // XXX -> +blkrevmax1 blkdata, treepath, blkpathRevMax, err := zbf.LoadBlk(ctx, blk)
loading.blkdata = blkdata loading.blkdata = blkdata
loading.err = err loading.err = err
close(loading.ready) close(loading.ready)
_ = treepath // XXX locking
/* _ = treepath // TODO -> btreeMap
blkrevmax := zodb.Tid(0)
for __, node := range treepath {
node.PActivate() // XXX err
blkrevmax = max(_, node.PSerial())
node.PDeactivate()
}
*/
// XXX before loading.ready? // XXX before loading.ready?
blkrevmax2, _ := f.δFtail.LastRevOf(blk, zbf.PJar().At()) blkrevmax, _ := f.δFtail.LastRevOf(blk, zbf.PJar().At())
//revmax := min(blkrevmax1, blkrevmax2) if blkpathRevMax < blkrevmax {
revmax := blkrevmax2 blkrevmax = blkpathRevMax
_ = revmax }
/* /*
// XXX remmapping - only if head.rev == 0 // XXX remmapping - only if head.rev == 0
......
...@@ -440,44 +440,49 @@ func (bf *zBigFileState) PySetState(pystate interface{}) (err error) { ...@@ -440,44 +440,49 @@ func (bf *zBigFileState) PySetState(pystate interface{}) (err error) {
// LoadBlk loads data for file block #blk. // LoadBlk loads data for file block #blk.
// //
// it also returns BTree path in .blktab for loaded block. // it also returns:
//
// - BTree path in .blktab for loaded block,
// - maximum revision of nodes in the BTree path.
// //
// XXX better load into user-provided buf? // XXX better load into user-provided buf?
func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath []zodb.IPersistent, err error) { func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath []zodb.IPersistent, pathRevMax zodb.Tid, err error) {
defer xerr.Contextf(&err, "bigfile %s: loadblk %d", bf.POid(), blk) defer xerr.Contextf(&err, "bigfile %s: loadblk %d", bf.POid(), blk)
err = bf.PActivate(ctx) err = bf.PActivate(ctx)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, 0, err
} }
defer bf.PDeactivate() defer bf.PDeactivate()
// XXX -> GetTo(callback(node) - use node.PSerial to build maxrev + treepath) pathRevMax = 0
xzblk, ok, treev, bucket, err := bf.blktab.GetTo(ctx, blk) xzblk, ok, err := bf.blktab.GetTo(ctx, blk, func(node zodb.IPersistent) {
if err != nil { treePath = append(treePath, node)
return nil, nil, err rev := node.PSerial()
if rev > pathRevMax {
pathRevMax = rev
} }
for _, tree := range treev { })
treePath = append(treePath, tree) if err != nil {
return nil, nil, 0, err
} }
treePath = append(treePath, bucket)
if !ok { if !ok {
return make([]byte, bf.blksize), treePath, nil return make([]byte, bf.blksize), treePath, pathRevMax, nil
} }
zblk, ok := xzblk.(zBlk) zblk, ok := xzblk.(zBlk)
if !ok { if !ok {
return nil, nil, fmt.Errorf("expect ZBlk*; got %s", typeOf(xzblk)) return nil, nil, 0, fmt.Errorf("expect ZBlk*; got %s", typeOf(xzblk))
} }
blkdata, err := zblk.loadBlkData(ctx) blkdata, err := zblk.loadBlkData(ctx)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, 0, err
} }
l := int64(len(blkdata)) l := int64(len(blkdata))
if l > bf.blksize { if l > bf.blksize {
return nil, nil, fmt.Errorf("invalid blk: size = %d (> blksize = %d)", l, bf.blksize) return nil, nil, 0, fmt.Errorf("invalid blk: size = %d (> blksize = %d)", l, bf.blksize)
} }
// append trailing \0 to data to reach .blksize // append trailing \0 to data to reach .blksize
...@@ -490,7 +495,7 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath ...@@ -490,7 +495,7 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath
zblk.bindZFile(bf, blk) zblk.bindZFile(bf, blk)
//log.Printf("ZBigFile.loadblk(%d) -> %dB", blk, len(blkdata)) //log.Printf("ZBigFile.loadblk(%d) -> %dB", blk, len(blkdata))
return blkdata, treePath, nil return blkdata, treePath, pathRevMax, nil
} }
// Size returns whole file size. // Size returns whole file size.
......
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