in mcrouter/AsyncLog.cpp [214:285]
bool AsyncLog::writeDelete(
const AccessPoint& ap,
folly::StringPiece key,
folly::StringPiece poolName,
std::unordered_map<std::string, uint64_t> attributes) {
dynamic json = dynamic::array;
const auto& host = ap.getHost();
const auto port = options_.asynclog_port_override == 0
? ap.getPort()
: options_.asynclog_port_override;
if (options_.use_asynclog_version2) {
json = dynamic::object;
json["s"] = options_.service_name;
json["f"] = options_.flavor_name;
json["r"] = options_.default_route.getRegion();
json["h"] = folly::sformat("[{}]:{}", host, port);
json["p"] = poolName.str();
json["k"] = key.str();
if (attributes.size() != 0) {
json["a"] = folly::toDynamic(attributes);
}
} else {
/* ["host", port, escaped_command] */
json.push_back(host);
json.push_back(port);
json.push_back(folly::sformat("delete {}\r\n", key));
}
if (!openFile()) {
MC_LOG_FAILURE(
options_,
memcache::failure::Category::kSystemError,
"asynclog_open() failed (key {}, pool {})",
key,
poolName);
return false;
}
// ["AS1.0", 1289416829.836, "C", ["10.0.0.1", 11302, "delete foo\r\n"]]
// OR ["AS2.0", 1289416829.836, "C", {"f":"flavor","h":"[10.0.0.1]:11302",
// "p":"pool_name","k":"foo\r\n"}]
dynamic jsonOut = dynamic::array;
if (options_.use_asynclog_version2) {
jsonOut.push_back(kAsyncLogMagic2);
} else {
jsonOut.push_back(kAsyncLogMagic);
}
auto timestamp_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
jsonOut.push_back(1e-3 * timestamp_ms);
jsonOut.push_back(std::string("C"));
jsonOut.push_back(json);
auto jstr = folly::toJson(jsonOut) + "\n";
ssize_t size = folly::writeFull(file_->fd(), jstr.data(), jstr.size());
if (size == -1 || size_t(size) < jstr.size()) {
MC_LOG_FAILURE(
options_,
memcache::failure::Category::kSystemError,
"Error fully writing asynclog request (key {}, pool {})",
key,
poolName);
return false;
}
return true;
}