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