| 2311 | } |
| 2312 | |
| 2313 | Status TmpFileBufferPool::EnqueueWriteRange(io::WriteRange* range, TmpFile* tmp_file) { |
| 2314 | Status status = Status::OK(); |
| 2315 | { |
| 2316 | unique_lock<mutex> write_range_list_lock(lock_); |
| 2317 | DCHECK(range != nullptr); |
| 2318 | DCHECK(range->disk_file() != nullptr); |
| 2319 | DCHECK(range->io_ctx() != nullptr); |
| 2320 | if (range->disk_file()->IsSpaceReserved()) { |
| 2321 | // If the space is reserved, send the range to the DiskQueue. |
| 2322 | return range->io_ctx()->AddWriteRange(range); |
| 2323 | } else if (range->io_ctx()->IsCancelled()) { |
| 2324 | // If the io_ctx is cancelled, nofity the caller to cancel the query. |
| 2325 | return TMP_FILE_BUFFER_POOL_CONTEXT_CANCELLED; |
| 2326 | } else { |
| 2327 | io_ctx_to_file_set_map_[range->io_ctx()].insert(range->disk_file()); |
| 2328 | write_ranges_to_add_[range->disk_file()].emplace_back(range); |
| 2329 | } |
| 2330 | // Put the first range of a file to the queue for waiting for the available space, |
| 2331 | // the ranges in the queue would be popped one by one, when the space is reserved, |
| 2332 | // all ranges of the file are added to the DiskQueue by io_ctx. |
| 2333 | if (range->offset() == 0) { |
| 2334 | write_ranges_.emplace_back(range); |
| 2335 | DCHECK(tmp_file != nullptr); |
| 2336 | write_ranges_iterator_[range] = |
| 2337 | std::make_pair(prev(write_ranges_.cend()), tmp_file); |
| 2338 | } |
| 2339 | } |
| 2340 | work_available_.NotifyAll(); |
| 2341 | return status; |
| 2342 | } |
| 2343 | |
| 2344 | void TmpFileBufferPool::RemoveWriteRangesInternal( |
| 2345 | RequestContext* io_ctx, vector<TmpFileMgr::WriteDoneCallback>* write_callbacks) { |
no test coverage detected