Skip to content

Commit 3a37d57

Browse files
byahn0996facebook-github-bot
authored andcommitted
Fix for garbage key with OnlineGenerator
Summary: With D58703719, key in Request struct was changed from sting to string_view, but for OnlineGenerator, key string won't live enough and garbage key was being used. This fixes the issue in simple way. (Since this issue will be only for OnlineGenerator, one field was simply added just for OnlineGenerator use case, rather than changing key back to string type). Reviewed By: therealgymmy Differential Revision: D69500945 fbshipit-source-id: eef3cd974bcaca0a1050735187ccf99382621474
1 parent 9b129bb commit 3a37d57

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cachelib/cachebench/util/Request.h

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ struct Request {
172172

173173
std::string_view key;
174174

175+
// For online generator, key will be created on the fly and should be valid
176+
// until this request is processed. Since 'key' is a string_view type, this
177+
// field will store the actual string for the lifetime of this request.
178+
std::string onlineKeyString;
179+
175180
// size iterators in case this request is
176181
// deemed to be a chained item.
177182
// If not chained, the size is *sizeBegin

cachelib/cachebench/workload/OnlineGenerator.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ const Request& OnlineGenerator::getReq(uint8_t poolId,
5555
std::optional<uint64_t>) {
5656
size_t keyIdx = getKeyIdx(poolId, gen);
5757

58-
std::string key(req_->key);
59-
generateKey(poolId, keyIdx, key);
58+
generateKey(poolId, keyIdx, req_->onlineKeyString);
6059
auto sizes = generateSize(poolId, keyIdx);
6160
req_->sizeBegin = sizes->begin();
6261
req_->sizeEnd = sizes->end();
63-
req_->key = key;
62+
req_->key = req_->onlineKeyString;
63+
6464
auto op =
6565
static_cast<OpType>(workloadDist_[workloadIdx(poolId)].sampleOpDist(gen));
6666
req_->setOp(op);

0 commit comments

Comments
 (0)