From 2d0b818f9c7d9e8a4667fd84536e58bd771776b5 Mon Sep 17 00:00:00 2001 From: Andre Pinto Date: Wed, 15 Mar 2017 17:50:54 -0700 Subject: [PATCH] Log failure to dump configs less frequently Summary: It's not necessary to log every single failure to dump last valid configs. Reviewed By: jmswen Differential Revision: D4711040 fbshipit-source-id: 774f2659213dcdfe23ef927092397f2b1e71cc5e --- mcrouter/ConfigApi.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mcrouter/ConfigApi.cpp b/mcrouter/ConfigApi.cpp index 0d8ec90c6..1ce400d5d 100644 --- a/mcrouter/ConfigApi.cpp +++ b/mcrouter/ConfigApi.cpp @@ -86,6 +86,20 @@ bool setupDumpConfigToDisk(const McrouterOptions& opts) { return true; } +template +void logFailureEveryN( + const McrouterOptions& opts, + const char* category, + std::string msg, + int n) { + static thread_local uint64_t count = 0; + if ((count++ % n) == 0) { + MC_LOG_FAILURE(opts, category, msg); + } +} +struct DumpFileTag; +struct TouchFileTag; + } // anonymous namespace const char* const ConfigApi::kFilePrefix = "file:"; @@ -426,21 +440,24 @@ void ConfigApi::dumpConfigSourceToDisk( ensureHasPermission(filePath, 0666); backupFileIt->second = md5OrVersion; } else { - MC_LOG_FAILURE( + logFailureEveryN( opts_, memcache::failure::Category::kOther, - "Error while dumping last valid config to disk. " - "Failed to write file {}.", - filePath); + folly::sformat( + "Error while dumping last valid config to disk. " + "Failed to write file {}.", + filePath), + 1000); ensureConfigDirectoryExists(directory); } } else { if (!touchFile(filePath)) { - MC_LOG_FAILURE( + logFailureEveryN( opts_, memcache::failure::Category::kOther, - "Error while touching backup config file {}", - filePath); + folly::sformat( + "Error while touching backup config file {}", filePath), + 1000); ensureConfigDirectoryExists(directory); } }