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

Function readPins

bolt/common/caching/AsyncDataCache.cpp:996–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

994}
995
996CoalesceIoStats readPins(
997 const std::vector<CachePin>& pins,
998 int32_t maxGap,
999 int32_t rangesPerIo,
1000 std::function<uint64_t(int32_t index)> offsetFunc,
1001 std::function<void(
1002 const std::vector<CachePin>& pins,
1003 int32_t begin,
1004 int32_t end,
1005 uint64_t offset,
1006 const std::vector<folly::Range<char*>>& buffers)> readFunc) {
1007 return coalesceIo<CachePin, folly::Range<char*>>(
1008 pins,
1009 maxGap,
1010 rangesPerIo,
1011 std::move(offsetFunc),
1012 [&](int32_t index) { return pins[index].checkedEntry()->size(); },
1013 [&](int32_t index) {
1014 return std::max<int32_t>(
1015 1, pins[index].checkedEntry()->data().numRuns());
1016 },
1017 [&](const CachePin& pin, std::vector<folly::Range<char*>>& ranges) {
1018 auto* entry = pin.checkedEntry();
1019 auto& data = entry->data();
1020 uint64_t offsetInRuns = 0;
1021 auto size = entry->size();
1022 if (data.numPages() == 0) {
1023 ranges.push_back(
1024 folly::Range<char*>(pin.checkedEntry()->tinyData(), size));
1025 offsetInRuns = size;
1026 } else {
1027 for (int i = 0; i < data.numRuns(); ++i) {
1028 const auto run = data.runAt(i);
1029 const uint64_t bytes = run.numBytes();
1030 const uint64_t readSize = std::min(bytes, size - offsetInRuns);
1031 ranges.push_back(folly::Range<char*>(run.data<char>(), readSize));
1032 offsetInRuns += readSize;
1033 }
1034 }
1035 BOLT_CHECK_EQ(offsetInRuns, size);
1036 },
1037 [&](int32_t size, std::vector<folly::Range<char*>>& ranges) {
1038 // This hack allows us to store the size of the gap in the Range,
1039 // without actually allocating a buffer for it.
1040 ranges.push_back(folly::Range<char*>(nullptr, (char*)(uint64_t)size));
1041 },
1042 std::move(readFunc));
1043}
1044
1045} // namespace bytedance::bolt::cache

Callers 2

loadDataMethod · 0.85
loadMethod · 0.85

Calls 10

checkedEntryMethod · 0.80
numRunsMethod · 0.80
tinyDataMethod · 0.80
runAtMethod · 0.80
numBytesMethod · 0.80
minFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
numPagesMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected