| 177 | } |
| 178 | |
| 179 | void DirectInputStream::loadPosition() { |
| 180 | BOLT_CHECK_LT(offsetInRegion_, region_.length); |
| 181 | if (bufferedInput_->preloaded()) { |
| 182 | const auto range = bufferedInput_->preloadedData( |
| 183 | region_.offset + offsetInRegion_, region_.length - offsetInRegion_); |
| 184 | run_ = reinterpret_cast<uint8_t*>(const_cast<char*>(range.data())); |
| 185 | runSize_ = range.size(); |
| 186 | offsetInRun_ = 0; |
| 187 | offsetOfRun_ = 0; |
| 188 | BOLT_CHECK_GT(runSize_, 0); |
| 189 | return; |
| 190 | } |
| 191 | if (!loaded_) { |
| 192 | loaded_ = true; |
| 193 | auto load = bufferedInput_->coalescedLoad(this); |
| 194 | loadAddr_ = (uint64_t)load.get(); |
| 195 | if (load) { |
| 196 | folly::SemiFuture<bool> waitFuture(false); |
| 197 | uint64_t usecs = 0; |
| 198 | { |
| 199 | MicrosecondTimer timer(&usecs); |
| 200 | if (!load->loadOrFuture(&waitFuture)) { |
| 201 | auto& exec = folly::QueuedImmediateExecutor::instance(); |
| 202 | std::move(waitFuture).via(&exec).wait(); |
| 203 | } |
| 204 | if (load->state() == cache::CoalescedLoad::State::kPlanned) { |
| 205 | if (isAsyncPreloadThread()) { // possibly from preloading metaData |
| 206 | throw std::runtime_error(fmt::format( |
| 207 | "{} preload {} failed", |
| 208 | folly::getCurrentThreadName().value(), |
| 209 | loadAddr_)); |
| 210 | } |
| 211 | LOG(WARNING) << "sync reload load " << loadAddr_ << " after waiting " |
| 212 | << usecs << " us"; |
| 213 | auto res = load->loadOrFuture(nullptr); |
| 214 | BOLT_CHECK( |
| 215 | res && load->state() == cache::CoalescedLoad::State::kLoaded); |
| 216 | } |
| 217 | loadedRegion_.offset = region_.offset; |
| 218 | loadedRegion_.length = load->getData(region_.offset, data_, tinyData_); |
| 219 | } |
| 220 | ioStats_->queryThreadIoLatencyAsync().increment(usecs); |
| 221 | ioStats_->queryThreadIoLatency().increment(usecs); |
| 222 | } else { |
| 223 | // Standalone stream, not part of coalesced load. |
| 224 | loadedRegion_.offset = 0; |
| 225 | loadedRegion_.length = 0; |
| 226 | } |
| 227 | } |
| 228 | // Check if position outside of loaded bounds. |
| 229 | if (loadedRegion_.length == 0 || |
| 230 | region_.offset + offsetInRegion_ < loadedRegion_.offset || |
| 231 | region_.offset + offsetInRegion_ >= |
| 232 | loadedRegion_.offset + loadedRegion_.length) { |
| 233 | loadedRegion_.offset = region_.offset + offsetInRegion_; |
| 234 | loadedRegion_.length = (offsetInRegion_ + loadQuantum_ <= region_.length) |
| 235 | ? loadQuantum_ |
| 236 | : (region_.length - offsetInRegion_); |
nothing calls this directly
no test coverage detected