1 #ifndef SQUID_ADAPT_HISTORY_H
2 #define SQUID_ADAPT_HISTORY_H
4 #include "adaptation/DynamicGroupCfg.h"
5 #include "base/RefCount.h"
6 #include "HttpHeader.h"
9 #include "SquidString.h"
14 /// collects information about adaptations related to a master transaction
15 class History
: public RefCountable
18 typedef RefCount
<Adaptation::History
> Pointer
;
22 /// record the start of a xact, return xact history ID
23 int recordXactStart(const String
&serviceId
, const timeval
&when
, bool retrying
);
25 /// record the end of a xact identified by its history ID
26 void recordXactFinish(int hid
);
28 /// dump individual xaction times to a string
29 void allLogString(const char *serviceId
, String
&buf
);
31 /// dump xaction times, merging retried and retry times together
32 void sumLogString(const char *serviceId
, String
&buf
);
34 /// sets or resets a cross-transactional database record
35 void updateXxRecord(const char *name
, const String
&value
);
37 /// returns true and fills the record fields iff there is a db record
38 bool getXxRecord(String
&name
, String
&value
) const;
40 /// sets or resets next services for the Adaptation::Iterator to notice
41 void updateNextServices(const String
&services
);
43 /// returns true, fills the value, and resets iff next services were set
44 bool extractNextServices(String
&value
);
46 /// store the last meta header fields received from the adaptation service
47 void recordMeta(const HttpHeader
*lm
);
49 void recordAdaptationService(SBuf
&srvId
);
51 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
53 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
55 /// key:value pairs set by adaptation_meta, to be added to
56 /// AccessLogEntry::notes when ALE becomes available
57 NotePairs::Pointer metaHeaders
;
59 typedef std::vector
<SBuf
> AdaptationServices
;
60 AdaptationServices theAdaptationServices
; ///< The service groups used
62 /// sets future services for the Adaptation::AccessCheck to notice
63 void setFutureServices(const DynamicGroupCfg
&services
);
65 /// returns true, fills the value, and resets iff future services were set
66 bool extractFutureServices(DynamicGroupCfg
&services
);
69 /// single Xaction stats (i.e., a historical record entry)
73 Entry(const String
&serviceId
, const timeval
&when
);
74 Entry(); // required by Vector<>
76 void stop(); ///< updates stats on transaction end
77 int rptm(); ///< returns response time [msec], calculates it if needed
79 String service
; ///< adaptation service ID
80 timeval start
; ///< when the xaction was started
83 int theRptm
; ///< calculated and cached response time value in msec
86 bool retried
; ///< whether the xaction was replaced by another
89 typedef std::vector
<Entry
> Entries
;
90 Entries theEntries
; ///< historical record, in the order of xact starts
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
96 String theNextServices
; ///< services Adaptation::Iterator must use next
97 DynamicGroupCfg theFutureServices
; ///< services AccessCheck must use
100 } // namespace Adaptation