X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fcommon%2FLogEntry.h;h=4feea3d419fc7c15d8752cf77d71df1f020154d5;hb=31f18b776d001752a193a7cec8bb49033c1a904c;hp=c3b9d2305ca11d98c246424a453833b50eca5fd4;hpb=40152f1e46a80b3405e5558a442ee632198dfd24;p=ceph.git diff --git a/ceph/src/common/LogEntry.h b/ceph/src/common/LogEntry.h index c3b9d2305..4feea3d41 100644 --- a/ceph/src/common/LogEntry.h +++ b/ceph/src/common/LogEntry.h @@ -15,10 +15,9 @@ #ifndef CEPH_LOGENTRY_H #define CEPH_LOGENTRY_H -#include "include/types.h" #include "include/utime.h" -#include "include/encoding.h" #include "msg/msg_types.h" // for entity_inst_t +#include "common/entity_name.h" namespace ceph { class Formatter; @@ -55,26 +54,51 @@ string clog_type_to_string(clog_type t); struct LogEntryKey { +private: + uint64_t _hash = 0; + + void _calc_hash() { + hash h; + _hash = seq + h(who); + } + entity_inst_t who; utime_t stamp; - uint64_t seq; + uint64_t seq = 0; - LogEntryKey() : seq(0) {} - LogEntryKey(const entity_inst_t& w, utime_t t, uint64_t s) : who(w), stamp(t), seq(s) {} +public: + LogEntryKey() {} + LogEntryKey(const entity_inst_t& w, utime_t t, uint64_t s) + : who(w), stamp(t), seq(s) { + _calc_hash(); + } + + uint64_t get_hash() const { + return _hash; + } void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(list& o); + + friend bool operator==(const LogEntryKey& l, const LogEntryKey& r) { + return l.who == r.who && l.stamp == r.stamp && l.seq == r.seq; + } }; WRITE_CLASS_ENCODER_FEATURES(LogEntryKey) -static inline bool operator==(const LogEntryKey& l, const LogEntryKey& r) { - return l.who == r.who && l.stamp == r.stamp && l.seq == r.seq; -} +namespace std { + template<> struct hash { + size_t operator()(const LogEntryKey& r) const { + return r.get_hash(); + } + }; +} // namespace std struct LogEntry { entity_inst_t who; + EntityName name; utime_t stamp; uint64_t seq; clog_type prio; @@ -97,21 +121,22 @@ WRITE_CLASS_ENCODER_FEATURES(LogEntry) struct LogSummary { version_t version; list tail; + ceph::unordered_set keys; LogSummary() : version(0) {} void add(const LogEntry& e) { tail.push_back(e); - while (tail.size() > 50) + keys.insert(tail.back().key()); + } + void prune(size_t max) { + while (tail.size() > max) { + keys.erase(tail.front().key()); tail.pop_front(); + } } bool contains(const LogEntryKey& k) const { - for (list::const_iterator p = tail.begin(); - p != tail.end(); - ++p) - if (p->key() == k) - return true; - return false; + return keys.count(k); } void encode(bufferlist& bl, uint64_t features) const; @@ -121,7 +146,7 @@ struct LogSummary { }; WRITE_CLASS_ENCODER_FEATURES(LogSummary) -inline ostream& operator<<(ostream& out, clog_type t) +inline ostream& operator<<(ostream& out, const clog_type t) { switch (t) { case CLOG_DEBUG: @@ -141,7 +166,8 @@ inline ostream& operator<<(ostream& out, clog_type t) inline ostream& operator<<(ostream& out, const LogEntry& e) { - return out << e.stamp << " " << e.who << " " << e.seq << " : " + return out << e.stamp << " " << e.name << " " << e.who + << " " << e.seq << " : " << e.channel << " " << e.prio << " " << e.msg; }