Acquire lock on mmap/file if you are calling this
(p valuePointer, s *y.Slice)
| 217 | |
| 218 | // Acquire lock on mmap/file if you are calling this |
| 219 | func (lf *logFile) read(p valuePointer, s *y.Slice) (buf []byte, err error) { |
| 220 | var nbr int64 |
| 221 | offset := p.Offset |
| 222 | if lf.loadingMode == options.FileIO { |
| 223 | buf = s.Resize(int(p.Len)) |
| 224 | var n int |
| 225 | n, err = lf.fd.ReadAt(buf, int64(offset)) |
| 226 | nbr = int64(n) |
| 227 | } else { |
| 228 | // Do not convert size to uint32, because the lf.fmap can be of size |
| 229 | // 4GB, which overflows the uint32 during conversion to make the size 0, |
| 230 | // causing the read to fail with ErrEOF. See issue #585. |
| 231 | size := int64(len(lf.fmap)) |
| 232 | valsz := p.Len |
| 233 | lfsz := atomic.LoadUint32(&lf.size) |
| 234 | if int64(offset) >= size || int64(offset+valsz) > size || |
| 235 | // Ensure that the read is within the file's actual size. It might be possible that |
| 236 | // the offset+valsz length is beyond the file's actual size. This could happen when |
| 237 | // dropAll and iterations are running simultaneously. |
| 238 | int64(offset+valsz) > int64(lfsz) { |
| 239 | err = y.ErrEOF |
| 240 | } else { |
| 241 | buf = lf.fmap[offset : offset+valsz] |
| 242 | nbr = int64(valsz) |
| 243 | } |
| 244 | } |
| 245 | y.NumReads.Add(1) |
| 246 | y.NumBytesRead.Add(nbr) |
| 247 | return buf, err |
| 248 | } |
| 249 | |
| 250 | // generateIV will generate IV by appending given offset with the base IV. |
| 251 | func (lf *logFile) generateIV(offset uint32) []byte { |
no test coverage detected