]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/History.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / History.h
1 #ifndef SQUID_ADAPT_HISTORY_H
2 #define SQUID_ADAPT_HISTORY_H
3
4 #include "adaptation/DynamicGroupCfg.h"
5 #include "base/RefCount.h"
6 #include "base/Vector.h"
7 #include "HttpHeader.h"
8 #include "Notes.h"
9 #include "SquidString.h"
10
11 namespace Adaptation
12 {
13
14 /// collects information about adaptations related to a master transaction
15 class History: public RefCountable
16 {
17 public:
18 typedef RefCount<Adaptation::History> Pointer;
19
20 History();
21
22 /// record the start of a xact, return xact history ID
23 int recordXactStart(const String &serviceId, const timeval &when, bool retrying);
24
25 /// record the end of a xact identified by its history ID
26 void recordXactFinish(int hid);
27
28 /// dump individual xaction times to a string
29 void allLogString(const char *serviceId, String &buf);
30
31 /// dump xaction times, merging retried and retry times together
32 void sumLogString(const char *serviceId, String &buf);
33
34 /// sets or resets a cross-transactional database record
35 void updateXxRecord(const char *name, const String &value);
36
37 /// returns true and fills the record fields iff there is a db record
38 bool getXxRecord(String &name, String &value) const;
39
40 /// sets or resets next services for the Adaptation::Iterator to notice
41 void updateNextServices(const String &services);
42
43 /// returns true, fills the value, and resets iff next services were set
44 bool extractNextServices(String &value);
45
46 /// store the last meta header fields received from the adaptation service
47 void recordMeta(const HttpHeader *lm);
48
49 public:
50 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
51 HttpHeader lastMeta;
52 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
53 HttpHeader allMeta;
54 /// key:value pairs set by adaptation_meta, to be added to
55 /// AccessLogEntry::notes when ALE becomes available
56 NotePairs::Pointer metaHeaders;
57
58 /// sets future services for the Adaptation::AccessCheck to notice
59 void setFutureServices(const DynamicGroupCfg &services);
60
61 /// returns true, fills the value, and resets iff future services were set
62 bool extractFutureServices(DynamicGroupCfg &services);
63
64 private:
65 /// single Xaction stats (i.e., a historical record entry)
66 class Entry
67 {
68 public:
69 Entry(const String &serviceId, const timeval &when);
70 Entry(); // required by Vector<>
71
72 void stop(); ///< updates stats on transaction end
73 int rptm(); ///< returns response time [msec], calculates it if needed
74
75 String service; ///< adaptation service ID
76 timeval start; ///< when the xaction was started
77
78 private:
79 int theRptm; ///< calculated and cached response time value in msec
80
81 public:
82 bool retried; ///< whether the xaction was replaced by another
83 };
84
85 typedef Vector<Entry> Entries;
86 Entries theEntries; ///< historical record, in the order of xact starts
87
88 // theXx* will become a map<string,string>, but we only support one record
89 String theXxName; ///< name part of the cross-transactional database record
90 String theXxValue; ///< value part of the cross-xactional database record
91
92 String theNextServices; ///< services Adaptation::Iterator must use next
93 DynamicGroupCfg theFutureServices; ///< services AccessCheck must use
94 };
95
96 } // namespace Adaptation
97
98 #endif