helper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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 
9 /* DEBUG: section 84 Helper process maintenance */
10 
11 #ifndef SQUID_HELPER_H
12 #define SQUID_HELPER_H
13 
14 #include "base/AsyncCall.h"
15 #include "base/InstanceId.h"
16 #include "cbdata.h"
17 #include "comm/forward.h"
18 #include "dlink.h"
19 #include "helper/ChildConfig.h"
20 #include "helper/forward.h"
21 #include "helper/Reply.h"
22 #include "helper/Request.h"
23 #include "ip/Address.h"
24 #include "sbuf/SBuf.h"
25 
26 #include <list>
27 #include <map>
28 #include <queue>
29 
30 class Packable;
31 class wordlist;
32 
33 namespace Helper
34 {
36 class Xaction {
38 public:
39  Xaction(HLPCB *c, void *d, const char *b): request(c, d, b) {}
42 };
43 }
44 
60 class helper
61 {
63 
64 public:
65  inline helper(const char *name) :
66  cmdline(NULL),
67  id_name(name),
68  ipc_type(0),
69  droppedRequests(0),
70  overloadStart(0),
71  last_queue_warn(0),
72  last_restart(0),
73  timeout(0),
76  eom('\n') {
77  memset(&stats, 0, sizeof(stats));
78  }
79  ~helper();
80 
83 
85  bool trySubmit(const char *buf, HLPCB * callback, void *data);
86 
90 
92  void packStatsInto(Packable *p, const char *label = NULL) const;
95  bool willOverload() const;
96 
97 public:
100  std::queue<Helper::Xaction *> queue;
101  const char *id_name;
103  int ipc_type;
105  unsigned int droppedRequests;
106  time_t overloadStart;
108  time_t last_restart;
109  time_t timeout;
113  char eom;
114 
115  struct _stats {
116  int requests;
117  int replies;
118  int timedout;
121  } stats;
122 
123 protected:
124  friend void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
125  bool queueFull() const;
126  bool overloaded() const;
127  void syncQueueStats();
128  bool prepSubmit();
129  void submit(const char *buf, HLPCB * callback, void *data);
130 };
131 
132 class statefulhelper : public helper
133 {
135 
136 public:
137  inline statefulhelper(const char *name) : helper(name) {}
138  inline ~statefulhelper() {}
139 
140 private:
141  friend void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPCB * callback, void *data, helper_stateful_server * lastserver);
142  void submit(const char *buf, HLPCB * callback, void *data, helper_stateful_server *lastserver);
143  bool trySubmit(const char *buf, HLPCB * callback, void *data, helper_stateful_server *lastserver);
144 };
145 
150 {
151 public:
157  void closePipesSafely(const char *name);
158 
165  void closeWritePipeSafely(const char *name);
166 
167 public:
171  int pid;
175  void *hIpc;
176 
177  char *rbuf;
178  size_t rbuf_sz;
179  size_t roffset;
180 
181  struct timeval dispatch_time;
182  struct timeval answer_time;
183 
185 
186  struct _helper_flags {
187  bool writing;
188  bool closing;
189  bool shutdown;
190  bool reserved;
191  } flags;
192 
193  typedef std::list<Helper::Xaction *> Requests;
195 
196  struct {
197  uint64_t uses; //< requests sent to this helper
198  uint64_t replies; //< replies received from this helper
199  uint64_t pending; //< queued lookups waiting to be sent to this helper
200  uint64_t releases; //< times release() has been called on this helper (if stateful)
201  uint64_t timedout; //< requests which timed-out
202  } stats;
203  void initStats();
204 };
205 
206 class MemBuf;
207 class CommTimeoutCbParams;
208 
210 {
212 
213 public:
214  uint64_t nextRequestId;
215 
218 
220 
226 
229 
230  // STL says storing std::list iterators is safe when changing the list
231  typedef std::map<uint64_t, Requests::iterator> RequestIndex;
233 
238  Helper::Xaction *popRequest(int requestId);
239 
242  void checkForTimedOutRequests(bool const retry);
243 
245  static void requestTimeout(const CommTimeoutCbParams &io);
246 };
247 
249 {
251 
252 public:
254 };
255 
256 /* helper.c */
257 void helperOpenServers(helper * hlp);
259 void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
260 void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPCB * callback, void *data, helper_stateful_server * lastserver);
261 void helperShutdown(helper * hlp);
264 
265 #endif /* SQUID_HELPER_H */
266 
void submit(const char *buf, HLPCB *callback, void *data)
dispatches or enqueues a helper requests; does not enforce queue limits
Definition: helper.cc:481
dlink_list servers
Definition: helper.h:99
void const char HLPCB * callback
Definition: stub_helper.cc:16
std::queue< Helper::Xaction * > queue
Definition: helper.h:100
bool prepSubmit()
Definition: helper.cc:443
RequestIndex requestsIndex
maps request IDs to requests
Definition: helper.h:232
void helperStatefulReleaseServer(helper_stateful_server *srv)
Definition: helper.cc:539
void packStatsInto(Packable *p, const char *label=NULL) const
Dump some stats about the helper state to a Packable object.
Definition: helper.cc:553
Definition: SBuf.h:87
struct timeval dispatch_time
Definition: helper.h:181
Definition: helper.h:60
Helper::ChildConfig childs
Configuration settings for number running.
Definition: helper.h:102
helper(const char *name)
Definition: helper.h:65
void syncQueueStats()
synchronizes queue-dependent measurements with the current queue state
Definition: helper.cc:416
Holds the required data to serve a helper request.
Definition: helper.h:36
int avg_svc_time
Definition: helper.h:120
wordlist * cmdline
Definition: helper.h:98
void closePipesSafely(const char *name)
Definition: helper.cc:75
struct timeval answer_time
Definition: helper.h:182
int ipc_type
Definition: helper.h:103
char * p
Definition: membanger.c:43
time_t last_queue_warn
Definition: helper.h:107
statefulhelper * parent
Definition: helper.h:250
Ip::Address addr
Definition: helper.h:172
std::list< Helper::Xaction * > Requests
Definition: helper.h:193
Helper::Request request
Definition: helper.h:40
size_t roffset
Definition: helper.h:179
uint64_t timedout
Definition: helper.h:201
static void requestTimeout(const CommTimeoutCbParams &io)
Read timeout handler.
Definition: helper.cc:1495
helper * parent
Definition: helper.h:219
bool overloaded() const
Definition: helper.cc:410
Helper::Xaction * popRequest(int requestId)
Definition: helper.cc:848
dlink_node link
Definition: helper.h:184
void HLPCB(void *, const Helper::Reply &)
Definition: forward.h:27
void const char HLPCB void * data
Definition: stub_helper.cc:16
bool retryTimedOut
Whether the timed-out requests must retried.
Definition: helper.h:110
char * rbuf
Definition: helper.h:177
statefulhelper(const char *name)
Definition: helper.h:137
MEMPROXY_CLASS(Helper::Xaction)
time_t overloadStart
when the helper became overloaded (zero if it is not)
Definition: helper.h:106
Comm::ConnectionPointer writePipe
Definition: helper.h:174
void helperStatefulSubmit(statefulhelper *hlp, const char *buf, HLPCB *callback, void *data, helper_stateful_server *lastserver)
lastserver = "server last used as part of a reserved request sequence"
Definition: helper.cc:490
void helperShutdown(helper *hlp)
Definition: helper.cc:616
struct HelperServerBase::_helper_flags flags
friend void helperStatefulSubmit(statefulhelper *hlp, const char *buf, HLPCB *callback, void *data, helper_stateful_server *lastserver)
lastserver = "server last used as part of a reserved request sequence"
Definition: helper.cc:490
const char * id_name
Definition: helper.h:101
int timedout
Definition: helper.h:118
friend void helperSubmit(helper *hlp, const char *buf, HLPCB *callback, void *data)
Definition: helper.cc:397
uint64_t nextRequestId
Definition: helper.h:211
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
void helperSubmit(helper *hlp, const char *buf, HLPCB *callback, void *data)
Definition: helper.cc:397
time_t last_restart
Definition: helper.h:108
Helper::Xaction * replyXaction
Definition: helper.h:225
Helper::Xaction * nextRequest()
Definition: helper.cc:1217
SBuf onTimedOutResponse
The response to use when helper response timedout.
Definition: helper.h:112
int requests
Definition: helper.h:116
~statefulhelper()
Definition: helper.h:138
void const char * buf
Definition: stub_helper.cc:16
unsigned int droppedRequests
requests not sent during helper overload
Definition: helper.h:105
void initStats()
Definition: helper.cc:65
void helperStatefulOpenServers(statefulhelper *hlp)
Definition: helper.cc:256
uint64_t uses
Definition: helper.h:197
bool retryBrokenHelper
Whether the requests must retried on BH replies.
Definition: helper.h:111
void helperStatefulShutdown(statefulhelper *hlp)
Definition: helper.cc:653
void submit(const char *buf, HLPCB *callback, void *data, helper_stateful_server *lastserver)
Definition: helper.cc:507
Comm::ConnectionPointer readPipe
Definition: helper.h:173
void helperOpenServers(helper *hlp)
Definition: helper.cc:125
Helper::Reply reply
Definition: helper.h:41
~helper()
Definition: helper.cc:699
void closeWritePipeSafely(const char *name)
Definition: helper.cc:101
bool queueFull() const
whether queuing an additional request would overload the helper
Definition: helper.cc:405
Ip::Address addr
Definition: helper.h:104
Xaction(HLPCB *c, void *d, const char *b)
Definition: helper.h:39
uint64_t releases
Definition: helper.h:200
time_t timeout
Requests timeout.
Definition: helper.h:109
Definition: MemBuf.h:23
bool trySubmit(const char *buf, HLPCB *callback, void *data, helper_stateful_server *lastserver)
If possible, submit request. Otherwise, either kill Squid or return false.
Definition: helper.cc:498
void * hIpc
Definition: helper.h:175
char eom
The char which marks the end of (response) message, normally ' '.
Definition: helper.h:113
bool ignoreToEom
Whether to ignore current message, because it is timed-out or other reason.
Definition: helper.h:228
std::map< uint64_t, Requests::iterator > RequestIndex
Definition: helper.h:231
size_t rbuf_sz
Definition: helper.h:178
void checkForTimedOutRequests(bool const retry)
Definition: helper.cc:1456
Requests requests
requests in order of submission/expiration
Definition: helper.h:194
bool trySubmit(const char *buf, HLPCB *callback, void *data)
If possible, submit request. Otherwise, either kill Squid or return false.
Definition: helper.cc:470
uint64_t replies
Definition: helper.h:198
int queue_size
Definition: helper.h:119
MemBuf * wqueue
Definition: helper.h:216
#define NULL
Definition: types.h:166
MemBuf * writebuf
Definition: helper.h:217
bool willOverload() const
Definition: helper.cc:611
#define false
Definition: GnuRegex.c:233
const InstanceId< HelperServerBase > index
Definition: helper.h:170
uint64_t pending
Definition: helper.h:199
void submitRequest(Helper::Xaction *r)
Definition: helper.cc:370
struct HelperServerBase::@75 stats
struct helper::_stats stats

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors