ApiListener#ReplayLog(): read current log file too instead of rotating

(cherry picked from commit 407e77883c)
This commit is contained in:
Alexander A. Klimov 2019-04-17 15:42:39 +02:00 committed by Michael Friedrich
parent c55e4e122f
commit 40a19e41d0
1 changed files with 19 additions and 9 deletions

View File

@ -36,6 +36,12 @@
#include "base/statsfunction.hpp"
#include "base/exception.hpp"
#include <fstream>
#include <memory>
#include <openssl/ssl.h>
#include <openssl/tls1.h>
#include <openssl/x509.h>
#include <sstream>
#include <utility>
using namespace icinga;
@ -1152,7 +1158,6 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
boost::mutex::scoped_lock lock(m_LogLock);
CloseLogFile();
RotateLogFile();
if (count == -1 || count > 50000) {
OpenLogFile();
@ -1167,16 +1172,21 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, std::ref(files), _1), GlobFile);
std::sort(files.begin(), files.end());
std::vector<std::pair<int, String>> allFiles;
for (int ts : files) {
String path = GetApiDir() + "log/" + Convert::ToString(ts);
if (ts >= peer_ts) {
allFiles.emplace_back(ts, GetApiDir() + "log/" + Convert::ToString(ts));
}
}
if (ts < peer_ts)
continue;
allFiles.emplace_back(Utility::GetTime() + 1, GetApiDir() + "log/current");
for (auto& file : allFiles) {
Log(LogNotice, "ApiListener")
<< "Replaying log: " << path;
<< "Replaying log: " << file.second;
auto *fp = new std::fstream(path.CStr(), std::fstream::in | std::fstream::binary);
auto *fp = new std::fstream(file.second.CStr(), std::fstream::in | std::fstream::binary);
StdioStream::Ptr logStream = new StdioStream(fp, true);
String message;
@ -1196,7 +1206,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
pmessage = JsonDecode(message);
} catch (const std::exception&) {
Log(LogWarning, "ApiListener")
<< "Unexpected end-of-file for cluster log: " << path;
<< "Unexpected end-of-file for cluster log: " << file.second;
/* Log files may be incomplete or corrupted. This is perfectly OK. */
break;
@ -1233,8 +1243,8 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
peer_ts = pmessage->Get("timestamp");
if (ts > logpos_ts + 10) {
logpos_ts = ts;
if (file.first > logpos_ts + 10) {
logpos_ts = file.first;
Dictionary::Ptr lmessage = new Dictionary({
{ "jsonrpc", "2.0" },