justinli500 commented on code in PR #49855:
URL: https://github.com/apache/arrow/pull/49855#discussion_r3726269764
##########
cpp/src/arrow/io/caching.cc:
##########
@@ -224,53 +249,80 @@ struct ReadRangeCache::Impl {
++num_prefetched;
}
}
- return SliceBuffer(std::move(buf), range.offset - it->range.offset,
range.length);
}
- return Status::Invalid("ReadRangeCache did not find matching cache entry");
+ // Drop the lock before blocking on the I/O future so other threads can
+ // still do lookups while a previously queued read is in flight.
+ ARROW_ASSIGN_OR_RAISE(auto buf, fut.result());
+ return SliceBuffer(std::move(buf), slice_offset, range.length);
}
- virtual Future<> Wait() {
+ Future<> Wait() {
std::vector<Future<>> futures;
- for (auto& entry : entries) {
- futures.emplace_back(MaybeRead(&entry));
+ {
+ std::unique_lock<std::mutex> guard(entry_mutex);
+ futures.reserve(entries.size());
+ for (auto& entry : entries) {
+ futures.emplace_back(MaybeRead(&entry));
+ }
}
return AllComplete(futures);
}
+ // Cached ranges are sorted and non-overlapping, so entries ending at or
+ // before `end_offset` form a prefix. Keep a straddling entry.
+ int64_t EvictEntriesBefore(int64_t end_offset) {
+ std::unique_lock<std::mutex> guard(entry_mutex);
+ int64_t n_evicted = 0;
+ while (!entries.empty()) {
+ const auto& range = entries.front().range;
+ if (range.offset + range.length > end_offset) {
+ break;
+ }
+ entries.pop_front();
+ ++n_evicted;
+ }
+ return n_evicted;
Review Comment:
I made this void instead. Nothing uses the return value, and a byte count
could be misleading if something else still holds the buffers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]