Module: check_mk
Branch: master
Commit: e82940c9a459d60832a1e7d1526d14995a5e7049
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e82940c9a459d6…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Aug 31 15:48:41 2018 +0200
Removed unused parameter/field. Improved const-correctness and naming.
Change-Id: I783e2b47b45304ba047df8ebf1f46f4fc5e17470
---
livestatus/src/Logfile.cc | 14 +++++---------
livestatus/src/Logfile.h | 3 +--
livestatus/src/TableStateHistory.cc | 15 +++++----------
livestatus/src/TableStateHistory.h | 7 +++----
4 files changed, 14 insertions(+), 25 deletions(-)
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index faea8a2..f66efb1 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -208,8 +208,7 @@ bool Logfile::processLogLine(size_t lineno, std::string line,
return true;
}
-logfile_entries_t *Logfile::getEntriesFromQuery(const Query * /*unused*/,
- unsigned logclasses) {
+const logfile_entries_t *Logfile::getEntriesFor(unsigned logclasses) {
// Make sure existing references to objects point to correct world
updateReferences();
// make sure all messages are present
@@ -219,13 +218,10 @@ logfile_entries_t *Logfile::getEntriesFromQuery(const Query *
/*unused*/,
bool Logfile::answerQueryReverse(Query *query, time_t since, time_t until,
unsigned logclasses) {
- // Make sure existing references to objects point to correct world
- updateReferences();
- // make sure all messages are present
- load(logclasses);
- uint64_t untilkey = makeKey(until, 999999999);
- auto it = _entries.upper_bound(untilkey);
- while (it != _entries.begin()) {
+ auto entries = getEntriesFor(logclasses);
+ // TODO(sp) Move the stuff below out of this class. Tricky part: makeKey
+ auto it = entries->upper_bound(makeKey(until, 999999999));
+ while (it != entries->begin()) {
--it;
// end found or limit exceeded?
if (it->second->_time < since ||
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index e188a37..4a97391 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -60,8 +60,7 @@ public:
long freeMessages(unsigned logclasses);
// for TableStateHistory
- logfile_entries_t *getEntriesFromQuery(const Query *query,
- unsigned logclasses);
+ const logfile_entries_t *getEntriesFor(unsigned logclasses);
// for TableLog::answerQuery
bool answerQueryReverse(Query *query, time_t since, time_t until,
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index 8ead016..a3e2157 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -212,8 +212,7 @@ void TableStateHistory::getPreviousLogentry() {
return;
}
--_it_logs;
- _entries =
- _it_logs->second->getEntriesFromQuery(_query, classmask_statehist);
+ _entries = _it_logs->second->getEntriesFor(classmask_statehist);
_it_entries = _entries->end();
}
--_it_entries;
@@ -230,8 +229,7 @@ LogEntry *TableStateHistory::getNextLogentry() {
return nullptr;
}
++_it_logs;
- _entries =
- _it_logs->second->getEntriesFromQuery(_query, classmask_statehist);
+ _entries = _it_logs->second->getEntriesFor(classmask_statehist);
_it_entries = _entries->begin();
}
return _it_entries->second.get();
@@ -291,20 +289,18 @@ void TableStateHistory::answerQuery(Query *query) {
// Store hosts/services that we have filtered out here
std::set<HostServiceKey> object_blacklist;
- _query = query;
-
// Optimize time interval for the query. In log querys there should always
// be a time range in form of one or two filter expressions over time. We
// use that to limit the number of logfiles we need to scan and to find the
// optimal entry point into the logfile
- if (auto glb = _query->greatestLowerBoundFor("time")) {
+ if (auto glb = query->greatestLowerBoundFor("time")) {
_since = *glb;
} else {
query->invalidRequest(
"Start of timeframe required. e.g. Filter: time > 1234567890");
return;
}
- _until = _query->leastUpperBoundFor("time").value_or(time(nullptr)) +
1;
+ _until = query->leastUpperBoundFor("time").value_or(time(nullptr)) + 1;
_query_timeframe = _until - _since - 1;
if (_query_timeframe == 0) {
@@ -330,8 +326,7 @@ void TableStateHistory::answerQuery(Query *query) {
}
// Determine initial logentry
- _entries =
- _it_logs->second->getEntriesFromQuery(query, classmask_statehist);
+ _entries = _it_logs->second->getEntriesFor(classmask_statehist);
if (!_entries->empty() && _it_logs != newest_log) {
_it_entries = _entries->end();
// Check last entry. If it's younger than _since -> use this logfile too
diff --git a/livestatus/src/TableStateHistory.h b/livestatus/src/TableStateHistory.h
index ad6fbbb..f7fe797 100644
--- a/livestatus/src/TableStateHistory.h
+++ b/livestatus/src/TableStateHistory.h
@@ -64,7 +64,6 @@ private:
LogCache *_log_cache;
int _query_timeframe;
- const Query *_query;
int _since;
int _until;
@@ -72,9 +71,9 @@ private:
std::map<std::string, int> _notification_periods;
// Helper functions to traverse through logfiles
- logfiles_t::iterator _it_logs;
- logfile_entries_t *_entries;
- logfile_entries_t::iterator _it_entries;
+ logfiles_t::const_iterator _it_logs;
+ const logfile_entries_t *_entries;
+ logfile_entries_t::const_iterator _it_entries;
void getPreviousLogentry();
LogEntry *getNextLogentry();