MCPcopy Create free account
hub / github.com/apache/impala / ReserveLocalBufferSpace

Method ReserveLocalBufferSpace

be/src/runtime/tmp-file-mgr.cc:565–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

563}
564
565Status TmpFileMgr::ReserveLocalBufferSpace(bool quick_return) {
566 int64_t file_size = GetRemoteTmpFileSize();
567
568 // The high water mark is used to record the total bytes which have been assigned, we
569 // can assume that all the assigned bytes will be finally returned to the pool.
570 // Before the high water mark reaches the bytes limit of the local buffer directory,
571 // the caller can gain space freely. But if the high water mark is over the bytes limit,
572 // the caller needs to gain space from the pool because all the available spaces are in
573 // the pool now.
574 TmpDir* dir = local_buff_dir_.get();
575 if (tmp_dirs_remote_ctrl_.local_buff_dir_bytes_high_water_mark_.Add(file_size)
576 > dir->bytes_limit_) {
577 tmp_dirs_remote_ctrl_.local_buff_dir_bytes_high_water_mark_.Add(-file_size);
578 } else {
579 GetLocalBufferDir()->bytes_used_metric_->Increment(file_size);
580 return Status::OK();
581 }
582
583 shared_ptr<TmpFile> tmp_file;
584 // If all of the space of the buffer directory has been assigned, gain a file which
585 // is available to be evicted from the TmpFileBufferPool. It can be a long wait if
586 // quick return is not set and there is no available file in the pool.
587 Status status = DequeueTmpFilesPool(&tmp_file, quick_return);
588 if (!status.ok()) {
589 DCHECK(tmp_file == nullptr);
590 return status;
591 }
592 // Evict the file to release the physical space.
593 // If error happens during eviction, we log an warning, and return status ok instead to
594 // keep the caller doing the writing since probably the physical file is already
595 // deleted.
596 status = TryEvictFile(tmp_file.get());
597 if (!status.ok()) {
598 LOG(WARNING) << "File Eviction Failed: " << tmp_file->GetWriteFile()->path();
599 }
600 return Status::OK();
601}
602
603TmpDir* TmpFileMgr::GetLocalBufferDir() const {
604 return local_buff_dir_.get();

Callers 2

AllocateRemoteSpaceMethod · 0.80

Calls 7

OKFunction · 0.85
pathMethod · 0.80
getMethod · 0.65
AddMethod · 0.45
IncrementMethod · 0.45
okMethod · 0.45
GetWriteFileMethod · 0.45

Tested by

no test coverage detected