MCPcopy Create free account
hub / github.com/apache/arrow / Read

Method Read

cpp/src/arrow/io/caching.cc:202–232  ·  view source on GitHub ↗

Read the given range from the cache, blocking if needed. Cannot read a range that spans cache entries.

Source from the content-addressed store, hash-verified

200 // Read the given range from the cache, blocking if needed. Cannot read a range
201 // that spans cache entries.
202 virtual Result<std::shared_ptr<Buffer>> Read(ReadRange range) {
203 if (range.length == 0) {
204 static const uint8_t byte = 0;
205 return std::make_shared<Buffer>(&byte, 0);
206 }
207
208 const auto it = std::lower_bound(
209 entries.begin(), entries.end(), range,
210 [](const RangeCacheEntry& entry, const ReadRange& range) {
211 return entry.range.offset + entry.range.length < range.offset + range.length;
212 });
213 if (it != entries.end() && it->range.Contains(range)) {
214 auto fut = MaybeRead(&*it);
215 ARROW_ASSIGN_OR_RAISE(auto buf, fut.result());
216 if (options.lazy && options.prefetch_limit > 0) {
217 int64_t num_prefetched = 0;
218 for (auto next_it = it + 1;
219 next_it != entries.end() && num_prefetched < options.prefetch_limit;
220 ++next_it) {
221 if (!next_it->future.is_valid()) {
222 next_it->future =
223 file->ReadAsync(ctx, next_it->range.offset, next_it->range.length,
224 /*allow_short_read=*/false);
225 }
226 ++num_prefetched;
227 }
228 }
229 return SliceBuffer(std::move(buf), range.offset - it->range.offset, range.length);
230 }
231 return Status::Invalid("ReadRangeCache did not find matching cache entry");
232 }
233
234 virtual Future<> Wait() {
235 std::vector<Future<>> futures;

Callers

nothing calls this directly

Calls 7

SliceBufferFunction · 0.85
InvalidFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
ContainsMethod · 0.45
is_validMethod · 0.45
ReadAsyncMethod · 0.45

Tested by

no test coverage detected