MCPcopy Create free account
hub / github.com/bytedance/bolt / loadPosition

Method loadPosition

bolt/dwio/common/DirectInputStream.cpp:179–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179void 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_);

Callers

nothing calls this directly

Calls 14

isAsyncPreloadThreadFunction · 0.85
loadOrFutureMethod · 0.80
waitMethod · 0.80
incrementMethod · 0.80
findRunMethod · 0.80
runAtMethod · 0.80
coalescedLoadMethod · 0.45
getMethod · 0.45
stateMethod · 0.45
valueMethod · 0.45
getDataMethod · 0.45
numPagesMethod · 0.45

Tested by

no test coverage detected