Skip to content

Commit

Permalink
Clean up mutateObject() logging
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: therealgymmy, fbarotov

Differential Revision: D47481033

fbshipit-source-id: 4f08db250c262cfe02fc018b141e2b9248b4be5d
  • Loading branch information
Jiayue Bao authored and facebook-github-bot committed Jul 17, 2023
1 parent 70f2add commit 4a47684
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
17 changes: 3 additions & 14 deletions cachelib/experimental/objcache2/ObjectCache-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ bool ObjectCache<AllocatorT>::recover() {
template <typename AllocatorT>
template <typename T>
void ObjectCache<AllocatorT>::mutateObject(const std::shared_ptr<T>& object,
std::function<void()> mutateCb,
const std::string& mutateCtx) {
std::function<void()> mutateCb) {
if (!object) {
return;
}
Expand All @@ -454,31 +453,21 @@ void ObjectCache<AllocatorT>::mutateObject(const std::shared_ptr<T>& object,

auto& hdl = getWriteHandleRefInternal<T>(object);
size_t memUsageDiff = 0;
size_t oldObjectSize = 0;
if (memUsageAfter > memUsageBefore) { // updated to a larger value
memUsageDiff = memUsageAfter - memUsageBefore;
// do atomic update on objectSize
oldObjectSize = __sync_fetch_and_add(
__sync_fetch_and_add(
&(reinterpret_cast<ObjectCacheItem*>(hdl->getMemory())->objectSize),
memUsageDiff);
totalObjectSizeBytes_.fetch_add(memUsageDiff, std::memory_order_relaxed);
} else if (memUsageAfter < memUsageBefore) { // updated to a smaller value
memUsageDiff = memUsageBefore - memUsageAfter;
// do atomic update on objectSize
oldObjectSize = __sync_fetch_and_sub(
__sync_fetch_and_sub(
&(reinterpret_cast<ObjectCacheItem*>(hdl->getMemory())->objectSize),
memUsageDiff);
totalObjectSizeBytes_.fetch_sub(memUsageDiff, std::memory_order_relaxed);
}

// TODO T149177357: for debugging purpose, remove the log later
XLOGF_EVERY_MS(
INFO, 60'000,
"[Object-Cache mutate][{}] type: {}, memUsageBefore: {}, memUsageAfter: "
"{}, memUsageDiff:{}, oldObjectSize: {}, curObjectSize: {}, "
"curTotalObjectSize: {}",
mutateCtx, typeid(T).name(), memUsageBefore, memUsageAfter, memUsageDiff,
oldObjectSize, getObjectSize(object), getTotalObjectSize());
}

} // namespace objcache2
Expand Down
5 changes: 1 addition & 4 deletions cachelib/experimental/objcache2/ObjectCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,9 @@ class ObjectCache : public ObjectCacheBase<AllocatorT> {
// @param object shared pointer of the object to be mutated (must be
// fetched from ObjectCache APIs)
// @param mutateCb callback containing the mutation logic
// @param mutateCtx context string of this mutation operation, for
// logging purpose
template <typename T>
void mutateObject(const std::shared_ptr<T>& object,
std::function<void()> mutateCb,
const std::string& mutateCtx = "");
std::function<void()> mutateCb);

// Get the size of the object
//
Expand Down

0 comments on commit 4a47684

Please sign in to comment.