CachePeer.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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#include "squid.h"
10#include "acl/Gadgets.h"
11#include "CachePeer.h"
12#include "defines.h"
13#include "neighbors.h"
15#include "pconn.h"
16#include "PeerDigest.h"
17#include "PeerPoolMgr.h"
18#include "SquidConfig.h"
19#include "util.h"
20
22
23CachePeer::CachePeer(const char * const hostname):
24 name(xstrdup(hostname)),
25 host(xstrdup(hostname))
26{
27 Tolower(host); // but .name preserves original spelling
28}
29
31{
32 xfree(name);
33 xfree(host);
34
35 while (NeighborTypeDomainList *l = typelist) {
36 typelist = l->next;
37 xfree(l->domain);
38 xfree(l);
39 }
40
42
43#if USE_CACHE_DIGESTS
44 void *digestTmp = nullptr;
45 if (cbdataReferenceValidDone(digest, &digestTmp))
46 peerDigestNotePeerGone(static_cast<PeerDigest *>(digestTmp));
48#endif
49
50 xfree(login);
51
52 delete standby.pool;
53
54 // the mgr job will notice that its owner is gone and stop
55 PeerPoolMgr::Checkpoint(standby.mgr, "peer gone");
56
58}
59
60void
62{
63 if (!tcp_up) {
64 debugs(15, 2, "connection to " << *this << " succeeded");
65 tcp_up = connect_fail_limit; // NP: so peerAlive() works properly.
66 peerAlive(this);
67 } else {
69 }
70}
71
72void
74{
75 if (Http::Is4xx(code))
76 return; // this failure is not our fault
77
79}
80
81// TODO: Require callers to detail failures instead of using one (and often
82// misleading!) "connection failed" phrase for all of them.
84void
86{
87 stats.last_connect_failure = squid_curtime;
88 if (tcp_up > 0)
89 --tcp_up;
90
91 const auto consideredAliveByAdmin = (stats.logged_state == PEER_ALIVE);
92 const auto level = consideredAliveByAdmin ? DBG_IMPORTANT : 2;
93 debugs(15, level, "ERROR: Connection to " << *this << " failed");
94
95 if (consideredAliveByAdmin) {
96 if (!tcp_up) {
97 debugs(15, DBG_IMPORTANT, "Detected DEAD " << neighborTypeStr(this) << ": " << name);
98 stats.logged_state = PEER_DEAD;
99 } else {
100 debugs(15, 2, "additional failures needed to mark this cache_peer DEAD: " << tcp_up);
101 }
102 } else {
103 assert(!tcp_up);
104 debugs(15, 2, "cache_peer " << *this << " is still DEAD");
105 }
106}
107
108void
109CachePeer::rename(const char * const newName)
110{
111 if (!newName || !*newName)
112 throw TextException("cache_peer name=value cannot be empty", Here());
113
114 xfree(name);
115 name = xstrdup(newName);
116}
117
118time_t
120{
121 if (connect_timeout_raw > 0)
122 return connect_timeout_raw;
124}
125
126std::ostream &
127operator <<(std::ostream &os, const CachePeer &p)
128{
129 return os << p.name;
130}
131
std::ostream & operator<<(std::ostream &os, const CachePeer &p)
identify the given cache peer in cache.log messages and such
Definition: CachePeer.cc:127
#define Here()
source code location of the caller
Definition: Here.h:15
time_t squid_curtime
Definition: stub_libtime.cc:20
class SquidConfig Config
Definition: SquidConfig.cc:12
#define assert(EX)
Definition: assert.h:17
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:320
#define cbdataReferenceValidDone(var, ptr)
Definition: cbdata.h:239
acl_access * access
Definition: CachePeer.h:105
CachePeer(const char *hostname)
Definition: CachePeer.cc:23
void noteSuccess()
reacts to a successful establishment of a connection to this cache_peer
Definition: CachePeer.cc:61
NeighborTypeDomainList * typelist
Definition: CachePeer.h:104
char * login
Definition: CachePeer.h:203
char * host
Definition: CachePeer.h:65
time_t connect_timeout_raw
connect_timeout; use connectTimeout() instead!
Definition: CachePeer.h:204
char * domain
Forced domain.
Definition: CachePeer.h:216
PeerDigest * digest
Definition: CachePeer.h:168
int tcp_up
Definition: CachePeer.h:175
void countFailure()
noteFailure() helper for handling failures attributed to this peer
Definition: CachePeer.cc:85
~CachePeer()
Definition: CachePeer.cc:30
int connect_fail_limit
Definition: CachePeer.h:205
struct CachePeer::@26 stats
struct CachePeer::@33 standby
optional "cache_peer standby=limit" feature
time_t connectTimeout() const
Definition: CachePeer.cc:119
void rename(const char *)
(re)configure cache_peer name=value
Definition: CachePeer.cc:109
char * name
Definition: CachePeer.h:60
char * digest_url
Definition: CachePeer.h:169
void noteFailure(Http::StatusCode code)
Definition: CachePeer.cc:73
representation of a neighbor_type_domain configuration directive. A POD
NeighborTypeDomainList * next
static void Checkpoint(const Pointer &mgr, const char *reason)
Definition: PeerPoolMgr.cc:229
time_t peer_connect
Definition: SquidConfig.h:117
struct SquidConfig::@93 Timeout
an std::runtime_error with thrower location info
Definition: TextException.h:21
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define PEER_ALIVE
Definition: defines.h:86
#define PEER_DEAD
Definition: defines.h:85
void aclDestroyAccessList(acl_access **list)
Definition: Gadgets.cc:276
StatusCode
Definition: StatusCode.h:20
bool Is4xx(const int sc)
whether this is a client error 4xx response status code
Definition: StatusCode.h:94
#define xfree
#define xstrdup
void peerAlive(CachePeer *p)
Definition: neighbors.cc:455
const char * neighborTypeStr(const CachePeer *p)
Definition: neighbors.cc:81
void peerDigestNotePeerGone(PeerDigest *pd)
Definition: peer_digest.cc:175
int code
Definition: smb-errors.c:145
SQUIDCEXTERN void Tolower(char *)
Definition: util.c:28

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors