#include "squid.h"
#include "acl/Gadgets.h"
+#include "base/PrecomputedCodeContext.h"
#include "CachePeer.h"
#include "defines.h"
#include "neighbors.h"
#include "pconn.h"
#include "PeerDigest.h"
#include "PeerPoolMgr.h"
+#include "sbuf/Stream.h"
#include "SquidConfig.h"
#include "util.h"
CachePeer::CachePeer(const char * const hostname):
name(xstrdup(hostname)),
host(xstrdup(hostname)),
- tlsContext(secure, sslContext)
+ tlsContext(secure, sslContext),
+ probeCodeContext(new PrecomputedCodeContext("cache_peer probe", ToSBuf("current cache_peer probe: ", *this)))
{
Tolower(host); // but .name preserves original spelling
}
#include "acl/forward.h"
#include "base/CbcPointer.h"
+#include "base/forward.h"
#include "enums.h"
#include "http/StatusCode.h"
#include "icp_opcode.h"
int front_end_https = 0; ///< 0 - off, 1 - on, 2 - auto
int connection_auth = 2; ///< 0 - off, 1 - on, 2 - auto
+ PrecomputedCodeContextPointer probeCodeContext;
+
private:
void countFailure();
};
#include "squid.h"
#include "AccessLogEntry.h"
#include "base/AsyncCallbacks.h"
+#include "base/PrecomputedCodeContext.h"
#include "base/RunnersRegistry.h"
#include "CachePeer.h"
#include "CachePeers.h"
#include "neighbors.h"
#include "pconn.h"
#include "PeerPoolMgr.h"
+#include "sbuf/Stream.h"
#include "security/BlindPeerConnector.h"
#include "SquidConfig.h"
PeerPoolMgr::PeerPoolMgr(CachePeer *aPeer): AsyncJob("PeerPoolMgr"),
peer(cbdataReference(aPeer)),
- request(),
transportWait(),
encryptionWait(),
addrUsed(0)
{
+ const auto mx = MasterXaction::MakePortless<XactionInitiator::initPeerPool>();
+
+ codeContext = new PrecomputedCodeContext("cache_peer standby pool", ToSBuf("current cache_peer standby pool: ", *peer,
+ Debug::Extra, "current master transaction: ", mx->id));
+
+ // ErrorState, getOutgoingAddress(), and other APIs may require a request.
+ // We fake one. TODO: Optionally send this request to peers?
+ request = new HttpRequest(Http::METHOD_OPTIONS, AnyP::PROTO_HTTP, "http", "*", mx);
+ request->url.host(peer->host);
}
PeerPoolMgr::~PeerPoolMgr()
PeerPoolMgr::start()
{
AsyncJob::start();
-
- const auto mx = MasterXaction::MakePortless<XactionInitiator::initPeerPool>();
- // ErrorState, getOutgoingAddress(), and other APIs may require a request.
- // We fake one. TODO: Optionally send this request to peers?
- request = new HttpRequest(Http::METHOD_OPTIONS, AnyP::PROTO_HTTP, "http", "*", mx);
- request->url.host(peer->host);
-
checkpoint("peer initialized");
}
void
PeerPoolMgr::Checkpoint(const Pointer &mgr, const char *reason)
{
- CallJobHere1(48, 5, mgr, PeerPoolMgr, checkpoint, reason);
+ if (!mgr.valid()) {
+ debugs(48, 5, reason << " but no mgr");
+ return;
+ }
+
+ CallService(mgr->codeContext, [&] {
+ CallJobHere1(48, 5, mgr, PeerPoolMgr, checkpoint, reason);
+ });
}
/// launches PeerPoolMgrs for peers configured with standby.limit
if (p->standby.limit) {
p->standby.mgr = new PeerPoolMgr(p);
p->standby.pool = new PconnPool(p->name, p->standby.mgr);
- AsyncJob::Start(p->standby.mgr.get());
+ CallService(p->standby.mgr->codeContext, [&] {
+ AsyncJob::Start(p->standby.mgr.get());
+ });
}
}
}
#define SQUID_SRC_PEERPOOLMGR_H
#include "base/AsyncJob.h"
+#include "base/forward.h"
#include "base/JobWait.h"
#include "comm/forward.h"
#include "security/forward.h"
explicit PeerPoolMgr(CachePeer *aPeer);
~PeerPoolMgr() override;
+ PrecomputedCodeContextPointer codeContext;
+
protected:
/* AsyncJob API */
void start() override;
OnOff.h \
Packable.h \
PackableStream.h \
+ PrecomputedCodeContext.h \
Random.cc \
Random.h \
RandomUuid.cc \
--- /dev/null
+/*
+ * Copyright (C) 1996-2024 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_BASE_PRECOMPUTEDCODECONTEXT_H
+#define SQUID_SRC_BASE_PRECOMPUTEDCODECONTEXT_H
+
+#include "base/CodeContext.h"
+#include "base/InstanceId.h"
+#include "sbuf/SBuf.h"
+
+#include <ostream>
+
+/// CodeContext with constant details known at construction time
+class PrecomputedCodeContext: public CodeContext
+{
+public:
+ typedef RefCount<PrecomputedCodeContext> Pointer;
+
+ PrecomputedCodeContext(const char *gist, const SBuf &detail): gist_(gist), detail_(detail)
+ {}
+
+ /* CodeContext API */
+ ScopedId codeContextGist() const override { return ScopedId(gist_); }
+ std::ostream &detailCodeContext(std::ostream &os) const override { return os << Debug::Extra << detail_; }
+
+private:
+ const char *gist_; ///< the id used in codeContextGist()
+ const SBuf detail_; ///< the detail used in detailCodeContext()
+};
+
+#endif /* SQUID_SRC_BASE_PRECOMPUTEDCODECONTEXT_H */
+
class CallDialer;
class CodeContext;
class DelayedAsyncCalls;
+class PrecomputedCodeContext;
class Raw;
class RegexPattern;
class ScopedId;
typedef CbcPointer<AsyncJob> AsyncJobPointer;
typedef RefCount<CodeContext> CodeContextPointer;
using AsyncCallPointer = RefCount<AsyncCall>;
+using PrecomputedCodeContextPointer = RefCount<PrecomputedCodeContext>;
#endif /* SQUID_SRC_BASE_FORWARD_H */
#include "base/EnumIterator.h"
#include "base/IoManip.h"
#include "base/PackableStream.h"
+#include "base/PrecomputedCodeContext.h"
#include "CacheDigest.h"
#include "CachePeer.h"
#include "CachePeers.h"
reqnum = icpSetCacheKey((const cache_key *)entry->key);
+ const auto savedContext = CodeContext::Current();
for (size_t i = 0; i < Config.peers->size(); ++i) {
const auto p = &Config.peers->nextPeerToPing(i);
+ CodeContext::Reset(p->probeCodeContext);
+
debugs(15, 5, "candidate: " << *p);
if (!peerWouldBePinged(p, ps))
if ((p->type != PEER_MULTICAST) && (p->stats.probe_start == 0))
p->stats.probe_start = squid_curtime;
}
+ CodeContext::Reset(savedContext);
/*
* How many replies to expect?
neighborUp(const CachePeer * p)
{
if (!p->tcp_up) {
- // TODO: When CachePeer gets its own CodeContext, pass that context instead of nullptr
- CallService(nullptr, [&] {
+ CallService(p->probeCodeContext, [&] {
peerProbeConnect(const_cast<CachePeer*>(p));
});
return 0;
static void
peerDnsRefreshStart()
{
- for (const auto &p: CurrentCachePeers())
+ const auto savedContext = CodeContext::Current();
+ for (const auto &p: CurrentCachePeers()) {
+ CodeContext::Reset(p->probeCodeContext);
ipcache_nbgethostbyname(p->host, peerDNSConfigure, p.get());
+ }
+ CodeContext::Reset(savedContext);
peerScheduleDnsRefreshCheck(3600.0);
}