in src/hbase/client/async-table-result-scanner.cc [46:82]
std::shared_ptr<Result> AsyncTableResultScanner::Next() {
VLOG(5) << "AsyncTableResultScanner: Next()";
std::shared_ptr<Result> result = nullptr;
std::shared_ptr<ScanResumer> local_resumer = nullptr;
{
std::unique_lock<std::mutex> mlock(mutex_);
while (queue_.empty()) {
if (closed_) {
return nullptr;
}
if (error_) {
throw error_;
}
cond_.wait(mlock);
}
result = queue_.front();
queue_.pop();
cache_size_ -= EstimatedSizeWithSharedPtr(result);
if (resumer_ != nullptr && cache_size_ <= max_cache_size_ / 2) {
VLOG(1) << std::this_thread::get_id() << " resume scan prefetching";
local_resumer = resumer_;
resumer_ = nullptr;
}
}
// Need to call ScanResumer::Resume() outside of the scope of the mutex. The reason is that
// folly/wangle event loop might end up running the attached logic(.then()) at the Scan RPC
// in the same event thread before returning from the previous call. This seems like the
// wrong thing to do(™), but we cannot fix that now. Since the call back can end up calling
// this::OnNext(), we should unlock the mutex.
if (local_resumer != nullptr) {
local_resumer->Resume();
}
return result;
}