| 541 | } |
| 542 | |
| 543 | Status TmpFileMgr::TryEvictFile(TmpFile* tmp_file) { |
| 544 | DCHECK(tmp_file != nullptr); |
| 545 | if (tmp_file->disk_type() == io::DiskFileType::DUMMY) return Status::OK(); |
| 546 | |
| 547 | TmpFileRemote* tmp_file_remote = static_cast<TmpFileRemote*>(tmp_file); |
| 548 | DiskFile* buffer_file = tmp_file_remote->DiskBufferFile(); |
| 549 | |
| 550 | // Remove the buffer of the TmpFile. |
| 551 | // After deletion of the buffer, if the TmpFile doesn't exist in the remote file system |
| 552 | // either, that means the TmpFile shared pointer can be removed from the TmpFileMgr, |
| 553 | // because in this case, the physical file is considered no longer in the system. |
| 554 | // Hold the unique locks of the files during the deletion. |
| 555 | Status status = Status::OK(); |
| 556 | { |
| 557 | unique_lock<shared_mutex> buffer_lock(buffer_file->physical_file_lock_); |
| 558 | if (buffer_file->GetFileStatus() == io::DiskFileStatus::PERSISTED) { |
| 559 | status = buffer_file->Delete(buffer_lock); |
| 560 | } |
| 561 | } |
| 562 | return status; |
| 563 | } |
| 564 | |
| 565 | Status TmpFileMgr::ReserveLocalBufferSpace(bool quick_return) { |
| 566 | int64_t file_size = GetRemoteTmpFileSize(); |