Writes 'buffer' of length 'buffer_len' into byte offset 'offset' in the file. Returns true iff write succeeded. Returns false on errors or if the file is already closed.
| 279 | // Returns true iff write succeeded. Returns false on errors or if the file is |
| 280 | // already closed. |
| 281 | bool Write(int64_t offset, const uint8_t* buffer, int64_t buffer_len) { |
| 282 | DCHECK_EQ(offset % PAGE_SIZE, 0); |
| 283 | DCHECK_LE(offset, current_offset_.Load()); |
| 284 | if (UNLIKELY(readonly_.Load())) return false; |
| 285 | // Hold the lock in shared mode to check if 'file_' is not closed already. |
| 286 | kudu::shared_lock<rw_spinlock> lock(lock_.get_lock()); |
| 287 | if (UNLIKELY(!file_ || readonly_.Load())) return false; |
| 288 | DCHECK_LE(offset + buffer_len, current_offset_.Load()); |
| 289 | kudu::Status status = file_->Write(offset, Slice(buffer, buffer_len)); |
| 290 | if (UNLIKELY(!status.ok())) { |
| 291 | LOG(ERROR) << Substitute("Failed to write to $0 at offset $1 for $2 bytes: $3", |
| 292 | path_, offset, PrettyPrinter::PrintBytes(buffer_len), status.ToString()); |
| 293 | return false; |
| 294 | } |
| 295 | return true; |
| 296 | } |
| 297 | |
| 298 | void PunchHole(int64_t offset, int64_t hole_size) { |
| 299 | DCHECK_EQ(offset % PAGE_SIZE, 0); |
no test coverage detected