| 92 | std::unique_ptr<SeekableInputStream> BufferedInput::enqueue( |
| 93 | Region region, |
| 94 | const dwio::common::StreamIdentifier* /*si*/) { |
| 95 | if (region.length == 0) { |
| 96 | return std::make_unique<SeekableArrayInputStream>( |
| 97 | static_cast<const char*>(nullptr), 0); |
| 98 | } |
| 99 | |
| 100 | // if the region is already in buffer - such as metadata |
| 101 | auto ret = readBuffer(region.offset, region.length); |
| 102 | if (ret) { |
| 103 | return ret; |
| 104 | } |
| 105 | |
| 106 | // push to region pool and give the caller the callback |
| 107 | regions_.push_back(region); |
| 108 | return std::make_unique<SeekableArrayInputStream>( |
| 109 | // Save "i", the position in which this region was enqueued. This will |
| 110 | // help faster lookup using enqueuedToBufferOffset_ later. |
| 111 | [region, this, i = regions_.size() - 1]() { |
| 112 | auto result = readInternal(region.offset, region.length, i); |
| 113 | BOLT_CHECK( |
| 114 | std::get<1>(result) != MAX_UINT64, |
| 115 | "Fail to read region offset={} length={}", |
| 116 | region.offset, |
| 117 | region.length); |
| 118 | return result; |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | bool BufferedInput::useVRead() const { |
| 123 | // Use value explicitly set by the user if any, otherwise use the GFLAG |
| 124 | // We want to update this on every use for now because during the onboarding |
| 125 | // to wsVRLoad=true we may change the value of this GFLAG programmatically |