IcingaDB#Stop(): don't block shutdown, timeout instead

This commit is contained in:
Alexander A. Klimov 2022-03-01 15:28:03 +01:00
parent 3a8efcb4ea
commit 6b5106ffdd
2 changed files with 10 additions and 4 deletions

View File

@ -172,7 +172,9 @@ void IcingaDB::Start(bool runtimeCreated)
m_Rcon->SuppressQueryKind(Prio::CheckResult);
m_Rcon->SuppressQueryKind(Prio::RuntimeStateSync);
m_HistoryThread = std::thread([this]() { ForwardHistoryEntries(); });
Ptr keepAlive (this);
m_HistoryThread = std::async(std::launch::async, [this, keepAlive]() { ForwardHistoryEntries(); });
}
void IcingaDB::ExceptionHandler(boost::exception_ptr exp)
@ -234,7 +236,11 @@ void IcingaDB::Stop(bool runtimeRemoved)
Log(LogInformation, "IcingaDB")
<< "Flushing history data buffer to Redis.";
m_HistoryThread.join();
if (m_HistoryThread.wait_for(std::chrono::minutes(1)) == std::future_status::timeout) {
Log(LogCritical, "IcingaDB")
<< "Flushing takes more than one minute (while we're about to shut down). Giving up and discarding "
<< m_HistoryBulker.Size() << " queued history queries.";
}
Log(LogInformation, "IcingaDB")
<< "'" << GetName() << "' stopped.";

View File

@ -15,10 +15,10 @@
#include "remote/messageorigin.hpp"
#include <atomic>
#include <chrono>
#include <future>
#include <memory>
#include <mutex>
#include <set>
#include <thread>
#include <unordered_map>
#include <utility>
@ -182,7 +182,7 @@ private:
Timer::Ptr m_StatsTimer;
WorkQueue m_WorkQueue{0, 1, LogNotice};
std::thread m_HistoryThread;
std::future<void> m_HistoryThread;
Bulker<RedisConnection::Query> m_HistoryBulker {4096, std::chrono::milliseconds(250)};
String m_PrefixConfigObject;