Commit 29c9f13d authored by Kirill Smelkov's avatar Kirill Smelkov

X readBlk: Fix thinko in aready case

We were checking for `loading.err != nil` as the indication for success
and it should have been `err == nil`. The symphoms of the bug were that
\0 instead of data were read sometimes:

	wcfs: 2018/10/11 19:18:12 < 22: i7.READ {Fh 0 [2097152 +131072)  L 0 RDONLY,0x8000}                             <-- NOTE

	I1011 19:18:12.556125    6330 wcfs.go:538] readBlk #1 dest[0:+2097152]
	I1011 19:18:12.556361    6330 wcfs.go:538] readBlk #1 dest[0:+2097152]
	wcfs: 2018/10/11 19:18:12 ZBlk0.PySetState #11
	wcfs: 2018/10/11 19:18:12 ZBigFile.loadblk(1) -> 2097152B

	wcfs: 2018/10/11 19:18:12 > 22:     OK,  131072B data "\x00\x00\x00\x00\x00\x00\x00\x00"...                     <-- XXX not "hello world"

	wcfs: 2018/10/11 19:18:12 < 24: i7.READ {Fh 0 [2359296 +131072)  L 0 RDONLY,0x8000}
	wcfs: 2018/10/11 19:18:12 > 23:     OK,  131072B data "\x00\x00\x00\x00\x00\x00\x00\x00"...
	wcfs: 2018/10/11 19:18:12 > 0:     NOTIFY_STORE_CACHE, {i7 [2097152 +2097152)} 2097152B data "hello wo"...      <-- NOTE
parent d58c71e8
...@@ -522,7 +522,7 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus ...@@ -522,7 +522,7 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus
if re := end % zbf.blksize; re != 0 { if re := end % zbf.blksize; re != 0 {
aend += zbf.blksize - re aend += zbf.blksize - re
} }
dest = make([]byte, aend - aoff) // ~> [off:aend] in file dest = make([]byte, aend - aoff) // ~> [aoff:aend) in file
// XXX better ctx = transaction.PutIntoContext(ctx, txn) // XXX better ctx = transaction.PutIntoContext(ctx, txn)
ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx) ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx)
...@@ -535,6 +535,7 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus ...@@ -535,6 +535,7 @@ func (bfdata *BigFileData) Read(_ nodefs.File, dest []byte, off int64, fctx *fus
blk := blkoff / zbf.blksize blk := blkoff / zbf.blksize
wg.Go(func() error { wg.Go(func() error {
δ := blkoff-aoff // blk position in dest δ := blkoff-aoff // blk position in dest
log.Infof("readBlk #%d dest[%d:+%d]", blk, δ, zbf.blksize)
return bfdata.readBlk(ctx, blk, dest[δ:δ+zbf.blksize]) return bfdata.readBlk(ctx, blk, dest[δ:δ+zbf.blksize])
}) })
} }
...@@ -572,7 +573,7 @@ func (bfdata *BigFileData) readBlk(ctx context.Context, blk int64, dest []byte) ...@@ -572,7 +573,7 @@ func (bfdata *BigFileData) readBlk(ctx context.Context, blk int64, dest []byte)
return ctx.Err() return ctx.Err()
case <-loading.ready: case <-loading.ready:
if loading.err != nil { if loading.err == nil {
copy(dest, loading.blkdata) copy(dest, loading.blkdata)
} }
return loading.err return loading.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