Reads from byte offset 'offset' for 'bytes_to_read' bytes into 'buffer'. Returns true iff read succeeded. Returns false on error or if the file is already closed.
| 261 | // Returns true iff read succeeded. Returns false on error or if the file |
| 262 | // is already closed. |
| 263 | bool Read(int64_t offset, uint8_t* buffer, int64_t bytes_to_read) { |
| 264 | DCHECK_EQ(offset % PAGE_SIZE, 0); |
| 265 | // Hold the lock in shared mode to check if 'file_' is not closed already. |
| 266 | kudu::shared_lock<rw_spinlock> lock(lock_.get_lock()); |
| 267 | if (UNLIKELY(!file_)) return false; |
| 268 | DCHECK_LE(offset + bytes_to_read, current_offset_.Load()); |
| 269 | kudu::Status status = file_->Read(offset, Slice(buffer, bytes_to_read)); |
| 270 | if (UNLIKELY(!status.ok())) { |
| 271 | LOG(ERROR) << Substitute("Failed to read from $0 at offset $1 for $2 bytes: $3", |
| 272 | path_, offset, PrettyPrinter::PrintBytes(bytes_to_read), status.ToString()); |
| 273 | return false; |
| 274 | } |
| 275 | return true; |
| 276 | } |
| 277 | |
| 278 | // Writes 'buffer' of length 'buffer_len' into byte offset 'offset' in the file. |
| 279 | // Returns true iff write succeeded. Returns false on errors or if the file is |
no test coverage detected