CodeContext.h File Reference
#include "base/InstanceId.h"
#include "base/RefCount.h"
#include "base/Stopwatch.h"
#include <iosfwd>
Include dependency graph for CodeContext.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CodeContext
 
class  CodeContextGuard
 

Functions

std::ostream & operator<< (std::ostream &os, const CodeContext &ctx)
 by default, only small context gist is printed More...
 
std::ostream & CurrentCodeContextBrief (std::ostream &os)
 
std::ostream & CurrentCodeContextDetail (std::ostream &os)
 
template<typename Fun >
void CallBack (const CodeContext::Pointer &callbackContext, Fun &&callback)
 
template<typename Fun >
void CallService (const CodeContext::Pointer &serviceContext, Fun &&service)
 
template<typename Fun >
void CallContextCreator (Fun &&creator)
 

Detailed Description

Most error-reporting code cannot know what transaction or task Squid was working on when the error occurred. For example, when Squid HTTP request parser discovers a malformed header field, the parser can report the field contents, but that information is often useless for the admin without processing context details like which client sent the request or what the requested URL was. Moreover, even when the error reporting code does have access to some context details, it cannot separate important facts from noise because such classification is usually deployment-specific (i.e. cannot be hard-coded) and requires human expertise. The situation is aggravated by a busy Squid instance constantly switching from one processing context to another.

To solve these problems, Squid assigns a CodeContext object to a processing context. When Squid switches to another processing context, it switches the current CodeContext object as well. When Squid prints a level-0 or level-1 message to cache.log, it asks the current CodeContext object (if any) to report context details, allowing the admin to correlate the cache.log message with an access.log record.

Squid also reports processing context changes to cache.log when Squid level-5+ debugging is enabled.

CodeContext is being retrofitted into existing code with lots of places that switch processing context. Identifying and adjusting all those places takes time. Until then, there will be incorrect and missing context attributions.

Definition in file CodeContext.h.

Function Documentation

◆ CallBack()

template<typename Fun >
void CallBack ( const CodeContext::Pointer callbackContext,
Fun &&  callback 
)
inline

Executes service callback in callbackContext. If an exception occurs, the callback context is preserved, so that the exception is associated with the callback that triggered them (rather than with the service).

Service code running in its own service context should use this function.

Definition at line 116 of file CodeContext.h.

References CodeContext::Current(), and CodeContext::Reset().

Referenced by Comm::TcpAcceptor::acceptOne(), HappyOrderEnforcer::checkpoint(), IpcIoFile::checkTimeouts(), commHalfClosedCheck(), Ipc::UdsSender::DelayedRetry(), IpcIoFile::handleResponse(), idnsCallbackAllCallersWithNewAnswer(), Comm::TcpAcceptor::logAcceptError(), PeerSelectorPingMonitor::noteWaitOver(), peerCountMcastPeersDone(), Ipc::Forwarder::RequestTimedOut(), Ipc::Inquirer::RequestTimedOut(), and ClientInfo::writeOrDequeue().

◆ CallContextCreator()

template<typename Fun >
void CallContextCreator ( Fun &&  creator)
inline

Executes context creator in the service context. If an exception occurs, the creator context is preserved, so that the exception is associated with the creator that triggered them (rather than with the service).

Service code running in its own context should use this function to create new code contexts. TODO: Use or, if this pattern is not repeated, remove.

Definition at line 148 of file CodeContext.h.

References CodeContext::Current(), and CodeContext::Reset().

Referenced by peerCountMcastPeersStart().

◆ CallService()

template<typename Fun >
void CallService ( const CodeContext::Pointer serviceContext,
Fun &&  service 
)
inline

Executes service in serviceContext but due to automatic caller context restoration, service exceptions are associated with the caller that suffered from (and/or caused) them (rather than with the service itself).

Service code running in caller's context should use this function to escape into service context (e.g., for submitting caller-agnostic requests).

Definition at line 133 of file CodeContext.h.

Referenced by Ipc::Inquirer::HandleRemoteAck(), neighborUp(), IpcIoFile::push(), and IpcIoFile::scheduleTimeoutCheck().

◆ CurrentCodeContextBrief()

std::ostream & CurrentCodeContextBrief ( std::ostream &  os)

◆ CurrentCodeContextDetail()

std::ostream & CurrentCodeContextDetail ( std::ostream &  os)

Definition at line 96 of file CodeContext.cc.

References CodeContext::Current().

Referenced by Debug::Finish().

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const CodeContext ctx 
)
inline

Definition at line 86 of file CodeContext.h.

References CodeContext::codeContextGist().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors