Skip to content

Commit

Permalink
Log failure to dump configs less frequently
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andreazevedo authored and facebook-github-bot committed Mar 16, 2017
1 parent 3e441cc commit 2d0b818
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions mcrouter/ConfigApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ bool setupDumpConfigToDisk(const McrouterOptions& opts) {
return true;
}

template <class Tag>
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:";
Expand Down Expand Up @@ -426,21 +440,24 @@ void ConfigApi::dumpConfigSourceToDisk(
ensureHasPermission(filePath, 0666);
backupFileIt->second = md5OrVersion;
} else {
MC_LOG_FAILURE(
logFailureEveryN<DumpFileTag>(
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<TouchFileTag>(
opts_,
memcache::failure::Category::kOther,
"Error while touching backup config file {}",
filePath);
folly::sformat(
"Error while touching backup config file {}", filePath),
1000);
ensureConfigDirectoryExists(directory);
}
}
Expand Down

0 comments on commit 2d0b818

Please sign in to comment.