Skip to content

Commit a2b2939

Browse files
authored
Merge pull request #16991 from ghalliday/deblacklist-2
HPCC-28920 Roxie crash in DBGLOG from deblacklist() Reviewed-by: Mark Kelly [email protected] Reviewed-by: Gavin Halliday <[email protected]> Merged-by: Gavin Halliday <[email protected]>
2 parents aaf6a28 + 45a99f0 commit a2b2939

File tree

6 files changed

+44
-32
lines changed

6 files changed

+44
-32
lines changed

common/thorhelper/thorsoapcall.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class BlackLister : public CInterface, implements IThreadFactory
464464
unsigned delay = 5000;
465465
for (unsigned i = 0; i < BLACKLIST_RETRIES; i++)
466466
{
467+
// DBGLOG("Trying to deblacklist");
467468
try
468469
{
469470
Owned<ISocket> s = ISocket::connect_timeout(ep, 10000);

roxie/ccd/ccdmain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ int CCD_API roxie_main(int argc, const char *argv[], const char * defaultYaml)
828828

829829
// Tracing feature flags
830830
TraceFlags traceLevelFlag = traceLevel ? TraceFlags::Standard : TraceFlags::None;
831-
updateTraceFlags(loadTraceFlags(topology, roxieTraceOptions, traceLevelFlag | traceRoxieActiveQueries));
831+
updateTraceFlags(loadTraceFlags(topology, roxieTraceOptions, traceLevelFlag | traceRoxieActiveQueries), true);
832832

833833
//Logging stuff
834834
#ifndef _CONTAINERIZED

system/jlib/jlog.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ static LogMsgJobInfo globalDefaultJobInfo(UnknownJob, UnknownUser);
261261

262262
// NOTE - extern thread_local variables are very inefficient - don't be tempted to expose the variables directly
263263

264+
static TraceFlags defaultTraceFlags = TraceFlags::Standard;
264265
static thread_local LogMsgJobInfo defaultJobInfo;
265266
static thread_local TraceFlags threadTraceFlags = TraceFlags::Standard;
266267
static thread_local const IContextLogger *default_thread_logctx = nullptr;
@@ -3130,16 +3131,10 @@ bool doTrace(TraceFlags featureFlag, TraceFlags level)
31303131
return (threadTraceFlags & featureFlag) == featureFlag;
31313132
}
31323133

3133-
void setTraceFlag(TraceFlags flag, bool enable)
3134-
{
3135-
if (enable)
3136-
threadTraceFlags |= flag;
3137-
else
3138-
threadTraceFlags &= ~flag;
3139-
}
3140-
3141-
void updateTraceFlags(TraceFlags flag)
3134+
void updateTraceFlags(TraceFlags flag, bool global)
31423135
{
3136+
if (global)
3137+
defaultTraceFlags = flag;
31433138
threadTraceFlags = flag;
31443139
}
31453140

@@ -3148,10 +3143,9 @@ TraceFlags queryTraceFlags()
31483143
return threadTraceFlags;
31493144
}
31503145

3151-
void setTraceLevel(TraceFlags level)
3146+
TraceFlags queryDefaultTraceFlags()
31523147
{
3153-
threadTraceFlags &= ~TraceFlags::LevelMask;
3154-
threadTraceFlags |= (level & TraceFlags::LevelMask);
3148+
return defaultTraceFlags;
31553149
}
31563150

31573151
LogContextScope::LogContextScope(const IContextLogger *ctx)

system/jlib/jthread.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,17 @@ void Thread::init(const char *_name)
371371
stacksize = 0; // default is EXE default stack size (set by /STACK)
372372
}
373373

374+
void Thread::getThreadLoggingInfo()
375+
{
376+
::getThreadLoggingInfo(logctx, traceFlags);
377+
}
378+
379+
void Thread::setThreadLoggingInfo(const IContextLogger *_logctx, TraceFlags _traceFlags)
380+
{
381+
logctx = _logctx;
382+
traceFlags = _traceFlags;
383+
}
384+
374385
void Thread::start()
375386
{
376387
if (alive) {
@@ -382,7 +393,6 @@ void Thread::start()
382393
return;
383394
}
384395
Link();
385-
getThreadLoggingInfo(logctx, traceFlags); // New thread uses context from parent. This may or may not be a good idea by default!
386396
startRelease();
387397
}
388398

@@ -562,7 +572,7 @@ void CThreadedPersistent::threadmain()
562572
break;
563573
try
564574
{
565-
resetThreadLogging(logctx, traceFlags);
575+
resetThreadLogging(athread.logctx, athread.traceFlags);
566576
owner->threadmain();
567577
// Note we do NOT call the thread reset hook here - these threads are expected to be able to preserve state, I think
568578
}
@@ -594,7 +604,6 @@ void CThreadedPersistent::start()
594604
PrintStackReport();
595605
throw MakeStringExceptionDirect(-1, msg.str());
596606
}
597-
getThreadLoggingInfo(logctx, traceFlags); // New thread uses context from parent. This may or may not be a good idea by default!
598607
sem.signal();
599608
}
600609

@@ -674,6 +683,7 @@ void CAsyncFor::For(unsigned num,unsigned maxatonce,bool abortFollowingException
674683
{
675684
idx = _idx;
676685
self = _self;
686+
getThreadLoggingInfo();
677687
}
678688
int run()
679689
{
@@ -726,6 +736,7 @@ void CAsyncFor::For(unsigned num,unsigned maxatonce,bool abortFollowingException
726736
{
727737
idx = _idx;
728738
self = _self;
739+
getThreadLoggingInfo();
729740
}
730741
int run()
731742
{
@@ -805,10 +816,7 @@ class CPooledThreadWrapper;
805816
class CThreadPoolBase
806817
{
807818
public:
808-
CThreadPoolBase()
809-
{
810-
getThreadLoggingInfo(logctx, traceFlags); // Threads in pool use context that was in force when threadpool was created. This may or may not be a good idea by default!
811-
}
819+
CThreadPoolBase() {}
812820
virtual ~CThreadPoolBase() {}
813821
protected: friend class CPooledThreadWrapper;
814822
IExceptionHandler *exceptionHandler;
@@ -823,7 +831,7 @@ protected: friend class CPooledThreadWrapper;
823831
unsigned targetpoolsize;
824832
unsigned delay;
825833
const IContextLogger *logctx = nullptr;
826-
TraceFlags traceFlags = TraceFlags::Standard;
834+
TraceFlags traceFlags = queryDefaultTraceFlags();
827835
Semaphore availsem;
828836
std::atomic_uint numrunning{0};
829837
virtual void notifyStarted(CPooledThreadWrapper *item)=0;
@@ -1277,6 +1285,15 @@ class CThreadPool: public CThreadPoolBase, implements IThreadPool, public CInter
12771285
}
12781286
return false;
12791287
}
1288+
void getThreadLoggingInfo()
1289+
{
1290+
::getThreadLoggingInfo(logctx, traceFlags);
1291+
}
1292+
void setThreadLoggingInfo(const IContextLogger *_logctx, TraceFlags _traceFlags)
1293+
{
1294+
logctx = _logctx;
1295+
traceFlags = _traceFlags;
1296+
}
12801297
};
12811298

12821299

system/jlib/jthread.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class jlib_decl QueryTerminationCleanup
7676

7777
class jlib_decl Thread : public CInterface, public IThread
7878
{
79+
friend class CThreadedPersistent;
7980
private:
8081
ThreadId threadid;
8182
unsigned short stacksize; // in 4K blocks
@@ -98,7 +99,7 @@ class jlib_decl Thread : public CInterface, public IThread
9899
protected:
99100
StringAttr cthreadname;
100101
const IContextLogger *logctx = nullptr;
101-
TraceFlags traceFlags = TraceFlags::Standard;
102+
TraceFlags traceFlags = queryDefaultTraceFlags();
102103
public:
103104
#ifndef _WIN32
104105
Semaphore suspend;
@@ -119,6 +120,8 @@ class jlib_decl Thread : public CInterface, public IThread
119120
const char *getName() { return cthreadname.isEmpty() ? "unknown" : cthreadname.str(); }
120121
bool isAlive() { return alive; }
121122
bool join(unsigned timeout=INFINITE);
123+
void getThreadLoggingInfo(); // Capture current thread logging context to be used by this thread when started
124+
void setThreadLoggingInfo(const IContextLogger * _logctx, TraceFlags _traceFlags); // Set a specified thread logging context to be used when this thread is started
122125

123126
virtual void start();
124127
virtual void startRelease();
@@ -174,8 +177,6 @@ class jlib_decl CThreadedPersistent
174177
std::atomic_uint state;
175178
bool halt;
176179
enum ThreadStates { s_ready, s_running, s_joining };
177-
const IContextLogger *logctx = nullptr;
178-
TraceFlags traceFlags = TraceFlags::Standard;
179180
void threadmain();
180181
public:
181182
CThreadedPersistent(const char *name, IThreaded *_owner);
@@ -267,6 +268,8 @@ interface IThreadPool : extends IInterface
267268
virtual PooledThreadHandle startNoBlock(void *param)=0; // starts a new thread if it can do so without blocking, else throws exception
268269
virtual void setStartDelayTracing(unsigned secs) = 0; // set start delay tracing period
269270
virtual bool waitAvailable(unsigned timeout) = 0; // wait until a pool member is available
271+
virtual void getThreadLoggingInfo() = 0; // Capture current thread logging context to be used by thread in pool when started
272+
virtual void setThreadLoggingInfo(const IContextLogger * _logctx, TraceFlags _traceFlags) = 0; // Set a specified thread logging context to be used by thredas in pool when started
270273
};
271274

272275
extern jlib_decl IThreadPool *createThreadPool(

system/jlib/jtrace.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,15 @@ interface IPropertyTree;
114114

115115
extern jlib_decl bool doTrace(TraceFlags featureFlag, TraceFlags level=TraceFlags::Standard);
116116

117-
// Overwrites current trace flags for active thread (and any it creates)
118-
extern jlib_decl void updateTraceFlags(TraceFlags flag);
119-
120-
// Set a single trace flags for the active thread (and any it creates)
121-
extern jlib_decl void setTraceFlag(TraceFlags flag, bool enable);
122-
123-
// Set the trace detail level for the active thread (and any it creates)
124-
extern jlib_decl void setTraceLevel(TraceFlags level);
117+
// Overwrites current trace flags for active thread (and optionally the global default for new threads)
118+
extern jlib_decl void updateTraceFlags(TraceFlags flag, bool global = false);
125119

126120
// Retrieve current trace flags for the active thread
127121
extern jlib_decl TraceFlags queryTraceFlags();
128122

123+
// Retrieve default trace flags for new threads
124+
extern jlib_decl TraceFlags queryDefaultTraceFlags();
125+
129126
// Load trace flags from a property tree - typically the global config
130127
// See also the workunit-variant in workunit.hpp
131128

0 commit comments

Comments
 (0)