Skip to content

Commit

Permalink
[Server] Replace XrdOucTrace by XrdSysTrace (internal change).
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 authored and simonmichal committed Oct 11, 2021
1 parent eb6643d commit 00dd813
Show file tree
Hide file tree
Showing 41 changed files with 211 additions and 203 deletions.
2 changes: 1 addition & 1 deletion src/Xrd/XrdConfig.cc
Expand Up @@ -104,7 +104,7 @@ namespace XrdGlobal
XrdOucString totalCF;
extern XrdSysLogger Logger;
extern XrdSysError Log;
extern XrdOucTrace XrdTrace;
extern XrdSysTrace XrdTrace;
extern XrdScheduler Sched;
extern XrdBuffManager BuffPool;
extern XrdTlsContext *tlsCtx;
Expand Down
4 changes: 2 additions & 2 deletions src/Xrd/XrdGlobals.cc
Expand Up @@ -32,7 +32,7 @@
#include "Xrd/XrdInet.hh"
#include "Xrd/XrdScheduler.hh"

#include "XrdOuc/XrdOucTrace.hh"
#include "XrdSys/XrdSysTrace.hh"

#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysError.hh"
Expand All @@ -46,7 +46,7 @@ namespace XrdGlobal
{
XrdSysLogger Logger;
XrdSysError Log(&Logger, "Xrd");
XrdOucTrace XrdTrace(&Log);
XrdSysTrace XrdTrace("Xrd", &Logger);
XrdScheduler Sched(&Log, &XrdTrace);
XrdBuffManager BuffPool;
XrdTlsContext *tlsCtx = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/Xrd/XrdObject.hh
Expand Up @@ -82,7 +82,7 @@ time_t QTime; // Only used for time-managed objects
// Note to properly cleanup this type of queue you must call Set() at least
// once to cause the time element to be sceduled.

class XrdOucTrace;
class XrdSysTrace;
class XrdScheduler;

template <class T>
Expand Down Expand Up @@ -111,7 +111,7 @@ inline void Push(XrdObject<T> *Node)

void Set(int inQMax, time_t agemax=1800);

void Set(XrdScheduler *sp, XrdOucTrace *tp, int TraceChk=0)
void Set(XrdScheduler *sp, XrdSysTrace *tp, int TraceChk=0)
{Sched = sp; Trace = tp; TraceON = TraceChk;}

void DoIt();
Expand All @@ -133,7 +133,7 @@ int MininQ;
int MaxinQ;
time_t Maxage;
XrdScheduler *Sched;
XrdOucTrace *Trace;
XrdSysTrace *Trace;
int TraceON;
const char *TraceID;
};
Expand Down
7 changes: 3 additions & 4 deletions src/Xrd/XrdObject.icc
Expand Up @@ -28,7 +28,7 @@
/******************************************************************************/

#include "Xrd/XrdScheduler.hh"
#include "XrdOuc/XrdOucTrace.hh"
#include "XrdSys/XrdSysTrace.hh"

/******************************************************************************/
/* D o I t */
Expand Down Expand Up @@ -73,9 +73,8 @@ void XrdObjectQ<T>::DoIt()
// Trace as needed
//
if (TraceON && Trace->Tracing(TraceON))
{Trace->Beg(TraceID);
cerr <<Comment <<" trim done; " <<Count <<" of " <<oldcnt <<" kept";
Trace->End();
{SYSTRACE(Trace->, 0, TraceID, 0,
Comment <<" trim done; " <<Count <<" of " <<oldcnt <<" kept");
}

// Reschedule ourselves if we must do so
Expand Down
103 changes: 66 additions & 37 deletions src/Xrd/XrdScheduler.cc
Expand Up @@ -41,6 +41,7 @@

#include "Xrd/XrdJob.hh"
#include "Xrd/XrdScheduler.hh"
#include "XrdOuc/XrdOucTrace.hh" // For ABI compatibility only!
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysLogger.hh"

Expand Down Expand Up @@ -93,12 +94,70 @@ void *XrdStartWorking(void *carg)
/* C o n s t r u c t o r */
/******************************************************************************/

XrdScheduler::XrdScheduler(XrdSysError *eP, XrdSysTrace *tP,
int minw, int maxw, int maxi)
: XrdJob("underused thread monitor"),
XrdTraceOld(0), WorkAvail(0, "sched work")
{
Boot(eP, tP, minw, maxw, maxi);
}

/******************************************************************************/


XrdScheduler::XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
int minw, int maxw, int maxi)
: XrdJob("underused thread monitor"),
XrdTraceOld(tP), WorkAvail(0, "sched work")
{

// Invoke the main initialization function with a new style trace object
//
Boot(eP, new XrdSysTrace("Xrd", eP->logger()), minw, maxw, maxi);
}

/******************************************************************************/

// This constructor creates a self contained scheduler.
//
XrdScheduler::XrdScheduler(int minw, int maxw, int maxi)
: XrdJob("underused thread monitor"),
WorkAvail(0, "sched work")
{
XrdSysLogger *Logger;
int eFD;

// Get a file descriptor mirroring standard error
//
#if ( defined(__linux__) || defined(__GNU__) ) && defined(F_DUPFD_CLOEXEC)
eFD = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 0);
#else
eFD = dup(STDERR_FILENO);
fcntl(eFD, F_SETFD, FD_CLOEXEC);
#endif

// Now we need to get a logger object. We make this a real dumb one.
//
Logger = new XrdSysLogger(eFD, 0);
XrdLog = new XrdSysError(Logger);

// Now get a trace object
//
XrdTrace = new XrdSysTrace("Xrd", Logger);
if (getenv("XRDDEBUG") != 0) XrdTrace->What = TRACE_SCHED;

// Set remaining values. We do no use maximum possible threads here.
//
Init(minw, maxw, maxi);
}

/******************************************************************************/
/* Private: B o o t */
/******************************************************************************/

void XrdScheduler::Boot(XrdSysError *eP, XrdSysTrace *tP,
int minw, int maxw, int maxi)
{
// Perform common initialization
//
XrdLog = eP;
Expand Down Expand Up @@ -151,41 +210,6 @@ XrdScheduler::XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
#endif

}

/******************************************************************************/

// This constructor creates a self contained scheduler.
//
XrdScheduler::XrdScheduler(int minw, int maxw, int maxi)
: XrdJob("underused thread monitor"),
WorkAvail(0, "sched work")
{
XrdSysLogger *Logger;
int eFD;

// Get a file descriptor mirroring standard error
//
#if ( defined(__linux__) || defined(__GNU__) ) && defined(F_DUPFD_CLOEXEC)
eFD = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 0);
#else
eFD = dup(STDERR_FILENO);
fcntl(eFD, F_SETFD, FD_CLOEXEC);
#endif

// Now we need to get a logger object. We make this a real dumb one.
//
Logger = new XrdSysLogger(eFD, 0);
XrdLog = new XrdSysError(Logger);

// Now get a trace object
//
XrdTrace = new XrdOucTrace(XrdLog);
if (getenv("XRDDEBUG") != 0) XrdTrace->What = TRACE_SCHED;

// Set remaining values. We do no use maximum possible threads here.
//
Init(minw, maxw, maxi);
}

/******************************************************************************/
/* D e s t r u c t o r */
Expand Down Expand Up @@ -536,8 +560,13 @@ void XrdScheduler::setParms(int minw, int maxw, int avlw, int maxi, int once)

void XrdScheduler::Start() // Serialized one time call!
{
int retc, numw;
pthread_t tid;
int retc, numw;
pthread_t tid;

// Provide ABI compatibility for XrdOucTrace which is deprecated!
//
if (getenv("XRDDEBUG") != 0) XrdTrace->What = TRACE_SCHED;
else if (XrdTraceOld) XrdTrace->What |= XrdTraceOld->What;

// Start a time based scheduler
//
Expand Down
16 changes: 14 additions & 2 deletions src/Xrd/XrdScheduler.hh
Expand Up @@ -38,6 +38,7 @@
class XrdOucTrace;
class XrdSchedulerPID;
class XrdSysError;
class XrdSysTrace;

#define MAX_SCHED_PROCS 30000

Expand Down Expand Up @@ -80,18 +81,28 @@ int num_Jobs; // Number of jobs scheduled
int max_QLength; // Longest queue length we had
int num_Limited; // Number of times max was reached

// Constructor and destructor
// This is the preferred constructor
//
XrdScheduler(XrdSysError *eP, XrdSysTrace *tP,
int minw=8, int maxw=8192, int maxi=780);

// This constructor is only maintained for ABI compatibility and will be
// removed in a future major release. While syntactically compatible the
// sematics now are slightly different and tracing might not occur.
//
XrdScheduler(XrdSysError *eP, XrdOucTrace *tP,
int minw=8, int maxw=8192, int maxi=780);

// This constructor is used for a stand-alone scheduler.
//
XrdScheduler(int minw=3, int maxw=128, int maxi=12);

~XrdScheduler();

private:
XrdSysError *XrdLog;
XrdOucTrace *XrdTrace;
XrdSysTrace *XrdTrace;
XrdOucTrace *XrdTraceOld; // This is only used for ABI compatibility

XrdSysMutex DispatchMutex; // Disp: Protects above area
int idl_Workers; // Disp: Number of idle workers
Expand All @@ -116,6 +127,7 @@ XrdSysMutex TimerMutex; // Protects scheduler area
XrdSchedulerPID *firstPID;
XrdSysMutex ReaperMutex;

void Boot(XrdSysError *eP, XrdSysTrace *tP, int minw, int maxw, int maxi);
void hireWorker(int dotrace=1);
void Init(int minw, int maxw, int maxi);
void Monitor();
Expand Down
14 changes: 5 additions & 9 deletions src/Xrd/XrdTrace.hh
Expand Up @@ -48,28 +48,24 @@

#ifndef NODEBUG

#include "XrdOuc/XrdOucTrace.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysTrace.hh"

namespace XrdGlobal
{
extern XrdOucTrace XrdTrace;
extern XrdSysTrace XrdTrace;
}

#include "XrdSys/XrdSysHeaders.hh"
#include "XrdOuc/XrdOucTrace.hh"

#ifndef XRD_TRACE
#define XRD_TRACE XrdGlobal::XrdTrace.
#endif

#define TRACE(act, x) \
if (XRD_TRACE What & TRACE_ ## act) \
{XRD_TRACE Beg(TraceID); cerr <<x; XRD_TRACE End();}
if (XRD_TRACE What & TRACE_ ## act) {SYSTRACE(XRD_TRACE, 0, TraceID, 0, x)}

#define TRACEI(act, x) \
if (XRD_TRACE What & TRACE_ ## act) \
{XRD_TRACE Beg(TraceID,TRACE_IDENT); cerr <<x; \
XRD_TRACE End();}
{SYSTRACE(XRD_TRACE, TRACE_IDENT, TraceID, 0, x)}

#define TRACING(x) XRD_TRACE What & x

Expand Down
2 changes: 1 addition & 1 deletion src/XrdHttp.cmake
Expand Up @@ -29,7 +29,7 @@ if( BUILD_HTTP )
XrdHttp/XrdHttpSecXtractor.hh
XrdHttp/XrdHttpExtHandler.cc XrdHttp/XrdHttpExtHandler.hh
XrdHttp/XrdHttpStatic.hh
XrdHttp/XrdHttpTrace.cc XrdHttp/XrdHttpTrace.hh
XrdHttp/XrdHttpTrace.hh
XrdHttp/XrdHttpUtils.cc XrdHttp/XrdHttpUtils.hh )

add_library(
Expand Down
25 changes: 17 additions & 8 deletions src/XrdHttp/XrdHttpProtocol.cc
Expand Up @@ -105,6 +105,13 @@ XrdSecService *XrdHttpProtocol::CIA = 0; // Authentication Server
int XrdHttpProtocol::m_bio_type = 0; // BIO type identifier for our custom BIO.
BIO_METHOD *XrdHttpProtocol::m_bio_method = NULL; // BIO method constructor.

XrdSysTrace XrdHttpTrace("http");

namespace
{
const char *TraceID = "Protocol";
}

namespace XrdHttpProtoInfo
{
XrdTlsContext *xrdctx = 0;
Expand Down Expand Up @@ -462,7 +469,7 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here
{
int rc = 0;

TRACEI(DEBUG, " Process. lp:" << lp << " reqstate: " << CurrentReq.reqstate);
TRACEI(DEBUG, " Process. lp:"<<(void *)lp<<" reqstate: "<<CurrentReq.reqstate);

if (!myBuff || !myBuff->buff || !myBuff->bsize) {
TRACE(ALL, " Process. No buffer available. Internal error.");
Expand Down Expand Up @@ -576,7 +583,7 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here

// Read as many lines as possible into the buffer. An empty line breaks
while ((rc = BuffgetLine(tmpline)) > 0) {
TRACE(DEBUG, " rc:" << rc << " got hdr line: " << tmpline);
TRACE(DEBUG, " rc:" << rc << " got hdr line: " << tmpline.c_str());

if ((rc == 2) && (tmpline.length() > 1) && (tmpline[rc - 1] == '\n')) {
CurrentReq.headerok = true;
Expand All @@ -586,7 +593,7 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here


if (CurrentReq.request == CurrentReq.rtUnset) {
TRACE(DEBUG, " Parsing first line: " << tmpline);
TRACE(DEBUG, " Parsing first line: " << tmpline.c_str());
int result = CurrentReq.parseFirstLine((char *)tmpline.c_str(), rc);
if (result < 0) {
TRACE(DEBUG, " Parsing of first line failed with " << result);
Expand Down Expand Up @@ -687,7 +694,8 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here
dest += ":";
dest += Port_str;
dest += CurrentReq.resource.c_str();
TRACEI(REQ, " rc:" << rc << " self-redirecting to http with security token: '" << dest << "'");
TRACEI(REQ," rc:"<<rc<<" self-redirecting to http with security token: '"
<< dest.c_str() << "'");


CurrentReq.appendOpaque(dest, &SecEntity, hash, timenow);
Expand Down Expand Up @@ -1589,7 +1597,7 @@ int XrdHttpProtocol::Configure(char *parms, XrdProtocol_Config * pi) {
// Copy out the special info we want to use at top level
//
eDest.logger(pi->eDest->logger());
XrdHttpTrace = new XrdOucTrace(&eDest);
XrdHttpTrace.SetLogger(pi->eDest->logger());
// SI = new XrdXrootdStats(pi->Stats);
Sched = pi->Sched;
BPool = pi->BPool;
Expand All @@ -1612,7 +1620,7 @@ int XrdHttpProtocol::Configure(char *parms, XrdProtocol_Config * pi) {
//
rdf = (parms && *parms ? parms : pi->ConfigFN);
if (rdf && Config(rdf, pi->theEnv)) return 0;
if (pi->DebugON) XrdHttpTrace->What = TRACE_ALL;
if (pi->DebugON) XrdHttpTrace.What = TRACE_ALL;

// Set the redirect flag if we are a pure redirector
myRole = kXR_isServer;
Expand All @@ -1633,7 +1641,8 @@ int XrdHttpProtocol::Configure(char *parms, XrdProtocol_Config * pi) {

// Schedule protocol object cleanup
//
ProtStack.Set(pi->Sched, XrdHttpTrace, TRACE_MEM);
ProtStack.Set(pi->Sched, &XrdHttpTrace,
(XrdHttpTrace.What & TRACE_MEM ? TRACE_MEM : 0));
ProtStack.Set((pi->ConnMax / 3 ? pi->ConnMax / 3 : 30), 60 * 60);

// Return success
Expand Down Expand Up @@ -2720,7 +2729,7 @@ int XrdHttpProtocol::xtrace(XrdOucStream & Config) {
}
val = Config.GetWord();
}
XrdHttpTrace->What = trval;
XrdHttpTrace.What = trval;
return 0;
}

Expand Down

0 comments on commit 00dd813

Please sign in to comment.