| 258 | } |
| 259 | |
| 260 | Status WriteRange::DoWrite() { |
| 261 | Status ret_status = Status::OK(); |
| 262 | Status close_status = Status::OK(); |
| 263 | DiskQueue* queue = io_ctx_->parent_->disk_queues_[disk_id_]; |
| 264 | int64_t written_bytes = 0; |
| 265 | FileWriter* file_writer = disk_file_->GetFileWriter(); |
| 266 | /// DoWrite is used for Spilling. |
| 267 | /// For spilling to local, we will open and close the file handle for |
| 268 | /// each write range, which is the WriteOne() function, since it could |
| 269 | /// be a random write in each file. |
| 270 | /// For spilling to remote, we will keep the file handle open, until the |
| 271 | /// write range is the last one of the file to do the sequential write. |
| 272 | if (disk_file_->disk_type() == DiskFileType::LOCAL) { |
| 273 | return file_writer->WriteOne(this); |
| 274 | } |
| 275 | { |
| 276 | ScopedHistogramTimer write_timer(queue->write_latency()); |
| 277 | shared_lock<shared_mutex> lock(disk_file_->physical_file_lock_); |
| 278 | ret_status = file_writer->Open(); |
| 279 | if (!ret_status.ok()) return DoWriteEnd(queue, ret_status); |
| 280 | ret_status = file_writer->Write(this, &written_bytes); |
| 281 | disk_file_->UpdateReadBufferMetaDataIfNeeded(written_bytes - len_); |
| 282 | int64_t actual_file_size = disk_file_->actual_file_size(); |
| 283 | // actual_file_size is only set once, otherwise it is 0 by default. If it is still |
| 284 | // not set, it is impossible to be full. |
| 285 | if (actual_file_size != 0) { |
| 286 | DCHECK_LE(written_bytes, disk_file_->actual_file_size()); |
| 287 | is_full_ = written_bytes == actual_file_size; |
| 288 | } else { |
| 289 | // If the actual size hasn't been set, the written bytes must be less than the |
| 290 | // default file size. |
| 291 | DCHECK_LT(written_bytes, disk_file_->file_size()); |
| 292 | } |
| 293 | if (is_full_) close_status = file_writer->Close(); |
| 294 | if (ret_status.ok() && !close_status.ok()) ret_status = close_status; |
| 295 | if (ret_status.ok() && is_full_) { |
| 296 | // If the file is full, the file handle should be closed, |
| 297 | // so set the file to persisted status. |
| 298 | disk_file_->SetStatus(io::DiskFileStatus::PERSISTED); |
| 299 | } |
| 300 | } |
| 301 | return DoWriteEnd(queue, ret_status); |
| 302 | } |
| 303 | |
| 304 | Status WriteRange::DoWriteEnd(DiskQueue* queue, const Status& ret_status) { |
| 305 | if (ret_status.ok()) { |
no test coverage detected