| 90 | |
| 91 | template <typename OutputType, typename Deserializer> |
| 92 | Status BlobReader<OutputType, Deserializer>::Load(io::RequestContext* request_context, |
| 93 | MemTracker* mem_tracker, ObjectPool* obj_pool, const std::string& path, |
| 94 | int64_t content_offset, int64_t content_length, OutputType* output) { |
| 95 | DCHECK(request_context != nullptr); |
| 96 | DCHECK(mem_tracker != nullptr); |
| 97 | DCHECK(obj_pool != nullptr); |
| 98 | DCHECK(output != nullptr); |
| 99 | |
| 100 | // Allocate buffer for reading the blob |
| 101 | ScopedBuffer buffer(mem_tracker); |
| 102 | if (!buffer.TryAllocate(content_length)) { |
| 103 | return Status(strings::Substitute( |
| 104 | "Could not allocate buffer of $0 bytes for blob file '$1'.", |
| 105 | content_length, path)); |
| 106 | } |
| 107 | |
| 108 | // Get HDFS connection |
| 109 | io::ScanRange::FileInfo file_info; |
| 110 | file_info.mtime = 1; |
| 111 | RETURN_IF_ERROR(HdfsFsCache::instance()->GetConnection( |
| 112 | path, &file_info.fs, &fs_cache_)); |
| 113 | file_info.filename = path.c_str(); |
| 114 | |
| 115 | // Create scan range for the blob content |
| 116 | io::ScanRange* scan_range = io::ScanRange::AllocateScanRange(obj_pool, file_info, |
| 117 | content_length, content_offset, {}, nullptr, -1, false, |
| 118 | io::BufferOpts::ReadInto(buffer.buffer(), buffer.Size(), |
| 119 | io::BufferOpts::USE_DATA_CACHE)); |
| 120 | |
| 121 | // Read the blob data |
| 122 | std::unique_ptr<io::BufferDescriptor> io_buffer; |
| 123 | bool needs_buffers; |
| 124 | RETURN_IF_ERROR(request_context->StartScanRange(scan_range, &needs_buffers)); |
| 125 | DCHECK(!needs_buffers) << "Already provided a buffer"; |
| 126 | RETURN_IF_ERROR(scan_range->GetNext(&io_buffer)); |
| 127 | scan_range->ReturnBuffer(std::move(io_buffer)); |
| 128 | |
| 129 | return Deserializer::Deserialize(buffer.buffer(), content_length, output); |
| 130 | } |
| 131 | |
| 132 | /// Size of the blob header (length + magic) for deletion vector blobs |
| 133 | static constexpr int DELETION_VECTOR_BLOB_HEADER_SIZE = 8; |
no test coverage detected