Module: check_mk
Branch: master
Commit: a6255e7fc31a58576664b2537b99df6ebe9cdcac
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a6255e7fc31a58…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Feb 27 14:31:35 2019 +0100
Simplification: Use MonitoringCore::maxCachedMessages more often.
Much easier, and it even removes two ugly '#ifdef CMC' conditionals.
Change-Id: I21d27471dfb8201b5689e561b85352178ae7b6aa
---
livestatus/src/LogCache.cc | 28 +++++++---------------------
livestatus/src/LogCache.h | 6 +-----
livestatus/src/Store.cc | 2 +-
livestatus/src/Store.h | 1 -
4 files changed, 9 insertions(+), 28 deletions(-)
diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc
index 61580d9..49380d1 100644
--- a/livestatus/src/LogCache.cc
+++ b/livestatus/src/LogCache.cc
@@ -37,25 +37,11 @@ namespace {
constexpr unsigned long check_mem_cycle = 1000;
} // namespace
-LogCache::LogCache(MonitoringCore *mc, unsigned long max_cached_messages)
- : _mc(mc)
- , _num_cached_log_messages(0)
- , _max_cached_messages(max_cached_messages)
- , _num_at_last_check(0) {
+LogCache::LogCache(MonitoringCore *mc)
+ : _mc(mc), _num_cached_log_messages(0), _num_at_last_check(0) {
update();
}
-#ifdef CMC
-void LogCache::setMaxCachedMessages(unsigned long m) {
- if (m != _max_cached_messages) {
- Notice(logger())
- << "changing maximum number of messages for log file cache to
"
- << m;
- _max_cached_messages = m;
- }
-}
-#endif
-
void LogCache::update() {
if (!_logfiles.empty() &&
_mc->last_logfile_rotation() <= _last_index_update) {
@@ -114,7 +100,7 @@ void LogCache::addToIndex(std::unique_ptr<Logfile> logfile) {
not the messages that just has been loaded.
*/
void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned logclasses) {
- if (++_num_cached_log_messages <= _max_cached_messages) {
+ if (++_num_cached_log_messages <= _mc->maxCachedMessages()) {
return; // current message count still allowed, everything ok
}
@@ -139,7 +125,7 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
if (it->second->size() > 0) {
_num_cached_log_messages -= it->second->size();
it->second->flush(); // drop all messages of that file
- if (_num_cached_log_messages <= _max_cached_messages) {
+ if (_num_cached_log_messages <= _mc->maxCachedMessages()) {
// remember the number of log messages in cache when
// the last memory-release was done. No further
// release-check shall be done until that number changes.
@@ -164,7 +150,7 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
// flush only messages not needed for current query
long freed = it->second->freeMessages(~logclasses);
_num_cached_log_messages -= freed;
- if (_num_cached_log_messages <= _max_cached_messages) {
+ if (_num_cached_log_messages <= _mc->maxCachedMessages()) {
_num_at_last_check = _num_cached_log_messages;
return;
}
@@ -181,7 +167,7 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
<< " number of entries";
_num_cached_log_messages -= it->second->size();
it->second->flush();
- if (_num_cached_log_messages <= _max_cached_messages) {
+ if (_num_cached_log_messages <= _mc->maxCachedMessages()) {
_num_at_last_check = _num_cached_log_messages;
return;
}
@@ -194,7 +180,7 @@ void LogCache::logLineHasBeenAdded(Logfile *logfile, unsigned
logclasses) {
Debug(logger()) << "cannot unload more messages, still "
<< _num_cached_log_messages << " loaded (max is
"
- << _max_cached_messages << ")";
+ << _mc->maxCachedMessages() << ")";
}
size_t LogCache::numCachedLogMessages() const {
diff --git a/livestatus/src/LogCache.h b/livestatus/src/LogCache.h
index 5b8954e..79cd9f2 100644
--- a/livestatus/src/LogCache.h
+++ b/livestatus/src/LogCache.h
@@ -41,10 +41,7 @@ class LogCache {
public:
std::mutex _lock;
- LogCache(MonitoringCore *mc, unsigned long max_cached_messages);
-#ifdef CMC
- void setMaxCachedMessages(unsigned long m);
-#endif
+ explicit LogCache(MonitoringCore *mc);
size_t numCachedLogMessages() const;
void logLineHasBeenAdded(Logfile *logfile, unsigned logclasses);
void update();
@@ -54,7 +51,6 @@ public:
private:
MonitoringCore *const _mc;
size_t _num_cached_log_messages;
- size_t _max_cached_messages;
size_t _num_at_last_check;
logfiles_t _logfiles;
std::chrono::system_clock::time_point _last_index_update;
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index a862898..5c1aa24 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -46,7 +46,7 @@ Store::Store(MonitoringCore *mc)
: _mc(mc)
, _downtimes(mc)
, _comments(mc)
- , _log_cache(mc, mc->maxCachedMessages())
+ , _log_cache(mc)
, _table_columns(mc)
, _table_commands(mc)
, _table_comments(mc)
diff --git a/livestatus/src/Store.h b/livestatus/src/Store.h
index 669ac4d..9230d8c 100644
--- a/livestatus/src/Store.h
+++ b/livestatus/src/Store.h
@@ -84,7 +84,6 @@ public:
bool answerGetRequest(const std::list<std::string> &lines,
OutputBuffer &output, const std::string &tablename);
void answerCommandRequest(const char *command, Logger *logger);
- void setMaxCachedMessages(unsigned long m);
void switchStatehistTable();
void buildStatehistCache();
void flushStatehistCache();