@@ -239,14 +239,20 @@ class CacheStressor : public Stressor {
239239 }
240240
241241 // populate the input item handle according to the stress setup.
242- void populateItem (WriteHandle& handle) {
242+ void populateItem (WriteHandle& handle, const std::string& itemValue = " " ) {
243243 if (!config_.populateItem ) {
244244 return ;
245245 }
246246 XDCHECK (handle);
247247 XDCHECK_LE (cache_->getSize (handle), 4ULL * 1024 * 1024 );
248248 if (cache_->consistencyCheckEnabled ()) {
249249 cache_->setUint64ToItem (handle, folly::Random::rand64 (rng));
250+ }
251+
252+ if (!itemValue.empty ()) {
253+ // Add the null character to ensure this is a proper c string.
254+ // TODO(T141356292): Clean this up to avoid allocating a new string
255+ cache_->setStringItem (handle, itemValue + " \0 " );
250256 } else {
251257 cache_->setStringItem (handle, hardcodedString_);
252258 }
@@ -323,7 +329,7 @@ class CacheStressor : public Stressor {
323329 }
324330 auto lock = chainedItemAcquireUniqueLock (*key);
325331 result = setKey (pid, stats, key, *(req.sizeBegin ), req.ttlSecs ,
326- req.admFeatureMap );
332+ req.admFeatureMap , req. itemValue );
327333
328334 break ;
329335 }
@@ -353,7 +359,7 @@ class CacheStressor : public Stressor {
353359 slock = {};
354360 xlock = chainedItemAcquireUniqueLock (*key);
355361 setKey (pid, stats, key, *(req.sizeBegin ), req.ttlSecs ,
356- req.admFeatureMap );
362+ req.admFeatureMap , req. itemValue );
357363 }
358364 } else {
359365 result = OpResultType::kGetHit ;
@@ -462,7 +468,8 @@ class CacheStressor : public Stressor {
462468 const std::string* key,
463469 size_t size,
464470 uint32_t ttlSecs,
465- const std::unordered_map<std::string, std::string>& featureMap) {
471+ const std::unordered_map<std::string, std::string>& featureMap,
472+ const std::string& itemValue) {
466473 // check the admission policy first, and skip the set operation
467474 // if the policy returns false
468475 if (config_.admPolicy && !config_.admPolicy ->accept (featureMap)) {
@@ -475,7 +482,7 @@ class CacheStressor : public Stressor {
475482 ++stats.setFailure ;
476483 return OpResultType::kSetFailure ;
477484 } else {
478- populateItem (it);
485+ populateItem (it, itemValue );
479486 cache_->insertOrReplace (it);
480487 return OpResultType::kSetSuccess ;
481488 }
@@ -501,7 +508,8 @@ class CacheStressor : public Stressor {
501508 if (config_.checkConsistency && cache_->isInvalidKey (req.key )) {
502509 continue ;
503510 }
504- // TODO: allow callback on nvm eviction instead of checking it repeatedly.
511+ // TODO: allow callback on nvm eviction instead of checking it
512+ // repeatedly.
505513 if (config_.checkNvmCacheWarmUp &&
506514 folly::Random::oneIn (kNvmCacheWarmUpCheckRate )) {
507515 checkNvmCacheWarmedUp (req.timestamp );
0 commit comments