Module: check_mk
Branch: master
Commit: 14f8aabc2b07b534a50a41cf1e2c1e42e7cfe231
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=14f8aabc2b07b5…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Aug 31 17:03:11 2018 +0200
Simplify LogCache interface.
Change-Id: I2591aaade1f4983e20323dff8eef6de4d5ea8455
---
livestatus/src/LogCache.cc | 13 +++++--------
livestatus/src/LogCache.h | 3 +--
livestatus/src/TableLog.cc | 3 ++-
livestatus/src/TableStateHistory.cc | 3 ++-
4 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc
index 14afde4..a3c9681 100644
--- a/livestatus/src/LogCache.cc
+++ b/livestatus/src/LogCache.cc
@@ -43,7 +43,7 @@ LogCache::LogCache(MonitoringCore *mc, unsigned long
max_cached_messages)
: _mc(mc)
, _max_cached_messages(max_cached_messages)
, _num_at_last_check(0) {
- updateLogfileIndex();
+ update();
}
#ifdef CMC
@@ -57,15 +57,12 @@ void LogCache::setMaxCachedMessages(unsigned long m) {
}
#endif
-bool LogCache::update() {
- if (_logfiles.empty() ||
- _mc->last_logfile_rotation() > _last_index_update) {
- updateLogfileIndex();
+void LogCache::update() {
+ if (!_logfiles.empty() &&
+ _mc->last_logfile_rotation() <= _last_index_update) {
+ return;
}
- return !_logfiles.empty();
-}
-void LogCache::updateLogfileIndex() {
Informational(logger()) << "updating log file index";
_logfiles.clear();
diff --git a/livestatus/src/LogCache.h b/livestatus/src/LogCache.h
index 0eea98c..de3d265 100644
--- a/livestatus/src/LogCache.h
+++ b/livestatus/src/LogCache.h
@@ -46,7 +46,7 @@ public:
void setMaxCachedMessages(unsigned long m);
#endif
void logLineHasBeenAdded(Logfile *logfile, unsigned logclasses);
- bool update(); // returns true if at least one log file has been found
+ void update();
auto begin() { return _logfiles.begin(); }
auto end() { return _logfiles.end(); }
@@ -57,7 +57,6 @@ private:
logfiles_t _logfiles;
std::chrono::system_clock::time_point _last_index_update;
- void updateLogfileIndex();
void addToIndex(std::unique_ptr<Logfile> logfile);
Logger *logger() const;
};
diff --git a/livestatus/src/TableLog.cc b/livestatus/src/TableLog.cc
index b7097cf..abdf069 100644
--- a/livestatus/src/TableLog.cc
+++ b/livestatus/src/TableLog.cc
@@ -126,7 +126,8 @@ std::string TableLog::namePrefix() const { return "log_"; }
void TableLog::answerQuery(Query *query) {
std::lock_guard<std::mutex> lg(_log_cache->_lock);
- if (!_log_cache->update()) {
+ _log_cache->update();
+ if (_log_cache->begin() == _log_cache->end()) {
return;
}
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index a3e2157..7086369 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -276,7 +276,8 @@ std::unique_ptr<Filter> TableStateHistory::createPartialFilter(
void TableStateHistory::answerQuery(Query *query) {
auto object_filter = createPartialFilter(*query);
std::lock_guard<std::mutex> lg(_log_cache->_lock);
- if (!_log_cache->update()) {
+ _log_cache->update();
+ if (_log_cache->begin() == _log_cache->end()) {
return;
}