Skip to content

Commit 6f2ceea

Browse files
IvanTopolcicfacebook-github-bot
authored andcommitted
Add original size and chunk logging for BigValueRoute set requests
Summary: This is a follow up to D76844605 which was reverted due to causing a build failure in Ceres MQB Reviewed By: disylh Differential Revision: D77383006 fbshipit-source-id: e6217ceb1bb8d0ced9c3d5e7a7549b7f73457b73
1 parent fc8f28a commit 6f2ceea

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

third-party/mcrouter/src/mcrouter/McrouterFiberContext.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ struct AxonContext {
6868
std::string poolFilter;
6969
};
7070

71+
struct BigValueContext {
72+
uint64_t originalItemSize{0};
73+
uint32_t numChunks{0};
74+
};
75+
7176
template <class RouterInfo>
7277
class fiber_local {
7378
private:
@@ -94,6 +99,7 @@ class fiber_local {
9499
std::shared_ptr<AxonContext> axonCtx{nullptr};
95100
int64_t accumulatedBeforeReqInjectedLatencyUs{0};
96101
int64_t accumulatedAfterReqInjectedLatencyUs{0};
102+
std::optional<BigValueContext> bigValueContext{std::nullopt};
97103
};
98104

99105
static auto makeGuardHelperBase(McrouterFiberContext&& tmp) {
@@ -313,6 +319,15 @@ class fiber_local {
313319
return folly::fibers::local<McrouterFiberContext>().load;
314320
}
315321

322+
static std::optional<BigValueContext>& getBigValueContext() {
323+
return folly::fibers::local<McrouterFiberContext>().bigValueContext;
324+
}
325+
326+
static void setBigValueContext(BigValueContext bigValueContext) {
327+
folly::fibers::local<McrouterFiberContext>().bigValueContext =
328+
bigValueContext;
329+
}
330+
316331
static void incNetworkTransportTimeBy(int64_t duration_us) {
317332
folly::fibers::local<McrouterFiberContext>().networkTransportTimeUs +=
318333
duration_us;

third-party/mcrouter/src/mcrouter/ProxyRequestContextTyped.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ class ProxyRequestContextWithInfo : public ProxyRequestContext {
207207
getProductId(request),
208208
getRegionalizationEntity(request),
209209
getUsecaseId(request),
210-
getReplySourceBitMask(reply));
210+
getReplySourceBitMask(reply),
211+
fiber_local<RouterInfo>::getBigValueContext());
211212
assert(logger_.hasValue());
212213
logger_->template log<Request>(loggerContext);
213214
assert(additionalLogger_.hasValue());

third-party/mcrouter/src/mcrouter/lib/RequestLoggerContext.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ struct RequestLoggerContext {
120120
std::optional<int64_t> productId_ = std::nullopt,
121121
std::optional<int32_t> regionalizationEntity_ = std::nullopt,
122122
std::optional<int64_t> usecaseId_ = std::nullopt,
123-
uint32_t replySourceBitMask_ = 0)
123+
uint32_t replySourceBitMask_ = 0,
124+
std::optional<BigValueContext> bigValueContext_ = std::nullopt)
124125
: strippedRoutingPrefix(strippedRoutingPrefix_),
125126
requestClass(requestClass_),
126127
poolName(poolName_),
@@ -140,7 +141,8 @@ struct RequestLoggerContext {
140141
productId(productId_),
141142
regionalizationEntity(regionalizationEntity_),
142143
usecaseId(usecaseId_),
143-
replySourceBitMask(replySourceBitMask_) {}
144+
replySourceBitMask(replySourceBitMask_),
145+
bigValueContext(bigValueContext_) {}
144146

145147
RequestLoggerContext(const RequestLoggerContext&) = delete;
146148
RequestLoggerContext& operator=(const RequestLoggerContext&) = delete;
@@ -165,6 +167,7 @@ struct RequestLoggerContext {
165167
std::optional<int32_t> regionalizationEntity;
166168
std::optional<uint64_t> usecaseId;
167169
const uint32_t replySourceBitMask;
170+
std::optional<BigValueContext> bigValueContext;
168171
};
169172

170173
} // namespace mcrouter

third-party/mcrouter/src/mcrouter/routes/BigValueRoute-inl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ typename std::enable_if_t<
234234
typename BigValueRoute<RouterInfo>::ChunksInfo>>
235235
BigValueRoute<RouterInfo>::chunkUpdateRequests(const Request& req) const {
236236
const folly::IOBuf& value = *req.value_ref();
237-
int numChunks = (value.computeChainDataLength() + options_.threshold - 1) /
238-
options_.threshold;
237+
uint64_t itemSize = value.computeChainDataLength();
238+
int numChunks = (itemSize + options_.threshold - 1) / options_.threshold;
239+
fiber_local<RouterInfo>::setBigValueContext(BigValueContext{
240+
.originalItemSize = itemSize,
241+
.numChunks = folly::to<uint32_t>(numChunks)});
239242
ChunksInfo info(numChunks, detail::hashBigValue(value));
240243

241244
std::vector<McSetRequest> chunkReqs;

0 commit comments

Comments
 (0)