(ixbots) fix tsan data race error when accessing verbose parameter

This commit is contained in:
Benjamin Sergeant 2020-05-04 17:15:35 -07:00
parent 4f17cd5e74
commit af003fc79b
8 changed files with 5 additions and 49 deletions

View File

@ -21,7 +21,6 @@ namespace ix
const std::string& channel, const std::string& channel,
const std::string& filter, const std::string& filter,
const std::string& position, const std::string& position,
bool verbose,
bool enableHeartbeat, bool enableHeartbeat,
int runtime) int runtime)
{ {
@ -117,7 +116,6 @@ namespace ix
&filter, &filter,
&subscriptionPosition, &subscriptionPosition,
&jsonWriter, &jsonWriter,
verbose,
&throttled, &throttled,
&receivedCount, &receivedCount,
&fatalCobraError, &fatalCobraError,
@ -146,18 +144,11 @@ namespace ix
subscriptionPosition, subscriptionPosition,
[this, [this,
&jsonWriter, &jsonWriter,
verbose,
&throttled, &throttled,
&receivedCount, &receivedCount,
&subscriptionPosition, &subscriptionPosition,
&fatalCobraError, &fatalCobraError,
&sentCount](const Json::Value& msg, const std::string& position) { &sentCount](const Json::Value& msg, const std::string& position) {
if (verbose)
{
CoreLogger::info("Subscriber received message "
+ position + " -> " + jsonWriter.write(msg));
}
subscriptionPosition = position; subscriptionPosition = position;
// If we cannot send to sentry fast enough, drop the message // If we cannot send to sentry fast enough, drop the message
@ -169,8 +160,8 @@ namespace ix
++receivedCount; ++receivedCount;
_onBotMessageCallback( _onBotMessageCallback(
msg, position, verbose, msg, position, throttled,
throttled, fatalCobraError, sentCount); fatalCobraError, sentCount);
}); });
} }
else if (event->type == ix::CobraEventType::Subscribed) else if (event->type == ix::CobraEventType::Subscribed)

View File

@ -16,7 +16,6 @@ namespace ix
{ {
using OnBotMessageCallback = std::function<void(const Json::Value&, using OnBotMessageCallback = std::function<void(const Json::Value&,
const std::string&, const std::string&,
const bool verbose,
std::atomic<bool>&, std::atomic<bool>&,
std::atomic<bool>&, std::atomic<bool>&,
std::atomic<uint64_t>&)>; std::atomic<uint64_t>&)>;
@ -30,7 +29,6 @@ namespace ix
const std::string& channel, const std::string& channel,
const std::string& filter, const std::string& filter,
const std::string& position, const std::string& position,
bool verbose,
bool enableHeartbeat, bool enableHeartbeat,
int runtime); int runtime);

View File

@ -26,42 +26,19 @@ namespace ix
int runtime) int runtime)
{ {
CobraBot bot; CobraBot bot;
bot.setOnBotMessageCallback([&sentryClient](const Json::Value& msg, bot.setOnBotMessageCallback([&sentryClient, &verbose](const Json::Value& msg,
const std::string& /*position*/, const std::string& /*position*/,
const bool verbose,
std::atomic<bool>& throttled, std::atomic<bool>& throttled,
std::atomic<bool>& /*fatalCobraError*/, std::atomic<bool>& /*fatalCobraError*/,
std::atomic<uint64_t>& sentCount) -> void { std::atomic<uint64_t>& sentCount) -> void {
sentryClient.send(msg, verbose, sentryClient.send(msg, verbose,
[&sentCount, &throttled, &verbose](const HttpResponsePtr& response) { [&sentCount, &throttled](const HttpResponsePtr& response) {
if (!response) if (!response)
{ {
CoreLogger::warn("Null HTTP Response"); CoreLogger::warn("Null HTTP Response");
return; return;
} }
if (verbose)
{
for (auto it : response->headers)
{
CoreLogger::info(it.first + ": " + it.second);
}
CoreLogger::info("Upload size: " + std::to_string(response->uploadSize));
CoreLogger::info("Download size: " + std::to_string(response->downloadSize));
CoreLogger::info("Status: " + std::to_string(response->statusCode));
if (response->errorCode != HttpErrorCode::Ok)
{
CoreLogger::info("error message: " + response->errorMsg);
}
if (response->headers["Content-Type"] != "application/octet-stream")
{
CoreLogger::info("payload: " + response->payload);
}
}
if (response->statusCode == 200) if (response->statusCode == 200)
{ {
sentCount++; sentCount++;
@ -103,7 +80,6 @@ namespace ix
channel, channel,
filter, filter,
position, position,
verbose,
enableHeartbeat, enableHeartbeat,
runtime); runtime);
} }

View File

@ -73,9 +73,8 @@ namespace ix
CobraBot bot; CobraBot bot;
bot.setOnBotMessageCallback( bot.setOnBotMessageCallback(
[&statsdClient, &tokens, &gauge, &timer](const Json::Value& msg, [&statsdClient, &tokens, &gauge, &timer, &verbose](const Json::Value& msg,
const std::string& /*position*/, const std::string& /*position*/,
const bool verbose,
std::atomic<bool>& /*throttled*/, std::atomic<bool>& /*throttled*/,
std::atomic<bool>& fatalCobraError, std::atomic<bool>& fatalCobraError,
std::atomic<uint64_t>& sentCount) -> void { std::atomic<uint64_t>& sentCount) -> void {
@ -146,7 +145,6 @@ namespace ix
channel, channel,
filter, filter,
position, position,
verbose,
enableHeartbeat, enableHeartbeat,
runtime); runtime);
} }

View File

@ -69,7 +69,6 @@ namespace ix
const std::string& position, const std::string& position,
bool fluentd, bool fluentd,
bool quiet, bool quiet,
bool verbose,
bool enableHeartbeat, bool enableHeartbeat,
int runtime) int runtime)
{ {
@ -79,7 +78,6 @@ namespace ix
bot.setOnBotMessageCallback( bot.setOnBotMessageCallback(
[&fluentd, &quiet, &jsonWriter](const Json::Value& msg, [&fluentd, &quiet, &jsonWriter](const Json::Value& msg,
const std::string& position, const std::string& position,
const bool /*verbose*/,
std::atomic<bool>& /*throttled*/, std::atomic<bool>& /*throttled*/,
std::atomic<bool>& /*fatalCobraError*/, std::atomic<bool>& /*fatalCobraError*/,
std::atomic<uint64_t>& sentCount) -> void { std::atomic<uint64_t>& sentCount) -> void {
@ -94,7 +92,6 @@ namespace ix
channel, channel,
filter, filter,
position, position,
verbose,
enableHeartbeat, enableHeartbeat,
runtime); runtime);
} }

View File

@ -18,7 +18,6 @@ namespace ix
const std::string& position, const std::string& position,
bool fluentd, bool fluentd,
bool quiet, bool quiet,
bool verbose,
bool enableHeartbeat, bool enableHeartbeat,
int runtime); int runtime);
} // namespace ix } // namespace ix

View File

@ -87,7 +87,6 @@ TEST_CASE("Cobra_to_stdout_bot", "[cobra_bots]")
std::string filter; std::string filter;
std::string position("$"); std::string position("$");
bool verbose = true;
bool quiet = false; bool quiet = false;
bool enableHeartbeat = false; bool enableHeartbeat = false;
@ -103,7 +102,6 @@ TEST_CASE("Cobra_to_stdout_bot", "[cobra_bots]")
position, position,
fluentd, fluentd,
quiet, quiet,
verbose,
enableHeartbeat, enableHeartbeat,
runtime); runtime);
// //

View File

@ -528,7 +528,6 @@ int main(int argc, char** argv)
position, position,
fluentd, fluentd,
quiet, quiet,
verbose,
enableHeartbeat, enableHeartbeat,
runtime); runtime);
ret = (int) sentCount; ret = (int) sentCount;