]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/History.h
Prep for merge from trunk: undo branch r13313, r13312, and r13311 that were
[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 "HttpHeader.h"
7 #include "Notes.h"
8 #include "SBuf.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 void recordAdaptationService(SBuf &srvId);
50 public:
51 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
52 HttpHeader lastMeta;
53 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
54 HttpHeader allMeta;
55 /// key:value pairs set by adaptation_meta, to be added to
56 /// AccessLogEntry::notes when ALE becomes available
57 NotePairs::Pointer metaHeaders;
58
59 typedef std::vector<SBuf> AdaptationServices;
60 AdaptationServices theAdaptationServices; ///< The service groups used
61
62 /// sets future services for the Adaptation::AccessCheck to notice
63 void setFutureServices(const DynamicGroupCfg &services);
64
65 /// returns true, fills the value, and resets iff future services were set
66 bool extractFutureServices(DynamicGroupCfg &services);
67
68 private:
69 /// single Xaction stats (i.e., a historical record entry)
70 class Entry
71 {
72 public:
73 Entry(const String &serviceId, const timeval &when);
74 Entry(); // required by Vector<>
75
76 void stop(); ///< updates stats on transaction end
77 int rptm(); ///< returns response time [msec], calculates it if needed
78
79 String service; ///< adaptation service ID
80 timeval start; ///< when the xaction was started
81
82 private:
83 int theRptm; ///< calculated and cached response time value in msec
84
85 public:
86 bool retried; ///< whether the xaction was replaced by another
87 };
88
89 typedef std::vector<Entry> Entries;
90 Entries theEntries; ///< historical record, in the order of xact starts
91
92 // theXx* will become a map<string,string>, but we only support one record
93 String theXxName; ///< name part of the cross-transactional database record
94 String theXxValue; ///< value part of the cross-xactional database record
95
96 String theNextServices; ///< services Adaptation::Iterator must use next
97 DynamicGroupCfg theFutureServices; ///< services AccessCheck must use
98 };
99
100 } // namespace Adaptation
101
102 #endif