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

Method ReadFromCache

be/src/runtime/io/scan-range.cc:621–678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619}
620
621Status ScanRange::ReadFromCache(
622 const unique_lock<mutex>& reader_lock, bool* read_succeeded) {
623 DCHECK(reader_lock.mutex() == &reader_->lock_ && reader_lock.owns_lock());
624 DCHECK(UseHdfsCache());
625 DCHECK_EQ(bytes_read_, 0);
626 *read_succeeded = false;
627 Status status = file_reader_->Open();
628 if (!status.ok()) return status;
629
630 // Check cancel status.
631 {
632 unique_lock<mutex> lock(lock_);
633 RETURN_IF_ERROR(cancel_status_);
634 }
635
636 file_reader_->CachedFile(&cache_.data, &cache_.len);
637 // Data was not cached, caller will fall back to normal read path.
638 if (cache_.data == nullptr) {
639 VLOG_QUERY << "Cache read failed for scan range: " << DebugString()
640 << ". Switching to disk read path.";
641 // Clean up the scan range state before re-issuing it.
642 file_reader_->Close();
643 return Status::OK();
644 }
645 // A partial read can happen when files are truncated.
646 // TODO: If HDFS ever supports partially cached blocks, we'll have to distinguish
647 // between errors and partially cached blocks here.
648 if (cache_.len < len()) {
649 VLOG_QUERY << "Error reading file from HDFS cache: " << file_ << ". Expected "
650 << len() << " bytes, but read " << cache_.len << ". Switching to disk read path.";
651 // Null out the cache buffer to avoid any interactions when this falls
652 // back to the regular read path.
653 cache_.len = 0;
654 cache_.data = nullptr;
655 // Close the scan range. 'read_succeeded' is still false, so the caller will fall back
656 // to non-cached read of this scan range.
657 file_reader_->Close();
658 return Status::OK();
659 }
660
661 *read_succeeded = true;
662 // If there are sub-ranges, then we need to memcpy() them from the cached buffer.
663 if (HasSubRanges()) return Status::OK();
664
665 DCHECK(!buffer_manager_->is_client_buffer());
666 buffer_manager_->set_cached_buffer();
667 bytes_read_ = cache_.len;
668
669 // Create a single buffer desc for the entire scan range and enqueue that.
670 // The memory is owned by the HDFS java client, not the Impala backend.
671 unique_ptr<BufferDescriptor> desc = unique_ptr<BufferDescriptor>(new BufferDescriptor(
672 this, cache_.data, 0));
673 desc->len_ = cache_.len;
674 desc->eosr_ = true;
675 EnqueueReadyBuffer(move(desc));
676 COUNTER_ADD_IF_NOT_NULL(reader_->bytes_read_counter_, cache_.len);
677 return Status::OK();
678}

Callers 1

TryReadFromCacheMethod · 0.80

Calls 11

OKFunction · 0.85
moveFunction · 0.85
owns_lockMethod · 0.80
set_cached_bufferMethod · 0.80
DebugStringFunction · 0.50
mutexMethod · 0.45
OpenMethod · 0.45
okMethod · 0.45
CachedFileMethod · 0.45
CloseMethod · 0.45
is_client_bufferMethod · 0.45

Tested by

no test coverage detected