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 CallAndRestore_ (const CodeContext::Pointer &context, Fun &&fun)
 
template<typename Fun >
void CallBack (const CodeContext::Pointer &callbackContext, Fun &&callback)
 
template<typename Fun >
void CallParser (const CodeContext::Pointer &parsingContext, Fun &&parse)
 
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

◆ CallAndRestore_()

template<typename Fun >
void CallAndRestore_ ( const CodeContext::Pointer context,
Fun &&  fun 
)
inline

A helper that calls the given function in the given call context. If the function throws, the call context is preserved, so that the exception is associated with the context that triggered it.

Definition at line 114 of file CodeContext.h.

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

Referenced by CallBack(), and CallParser().

◆ CallBack()

◆ 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 166 of file CodeContext.h.

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

Referenced by peerCountMcastPeersStart().

◆ CallParser()

template<typename Fun >
void CallParser ( const CodeContext::Pointer parsingContext,
Fun &&  parse 
)
inline

To supply error-reporting code with parsing context X (where the error occurred), parsing code should use this function when initiating parsing inside that context X.

See also
CallAndRestore_()

Definition at line 138 of file CodeContext.h.

References CallAndRestore_(), and parse().

Referenced by Acl::Node::ParseNamedAcl().

◆ 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 151 of file CodeContext.h.

Referenced by PeerPoolMgr::Checkpoint(), Ipc::Inquirer::HandleRemoteAck(), neighborUp(), IpcIoFile::push(), IpcIoFile::scheduleTimeoutCheck(), and PeerPoolMgrsRr::syncConfig().

◆ 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