Skip to content

Commit

Permalink
Postfix for #7917: Hang in a case of error when sweep thread is attac…
Browse files Browse the repository at this point in the history
…hing to database; fixed CS case.
  • Loading branch information
AlexPeshkoff committed Jan 5, 2024
1 parent e62ec5c commit 1d1e3a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/common/ThreadStart.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ inline ThreadId getThreadId()
#define USE_FINI_SEM
#endif

template <typename TA>
template <typename TA, void (*cleanup) (TA) = nullptr>
class ThreadFinishSync
{
public:
Expand Down Expand Up @@ -203,6 +203,9 @@ class ThreadFinishSync
threadArg->exceptionHandler(ex, threadRoutine);
}
#endif

if (cleanup)
cleanup(threadArg);
closing = true;
}
};
Expand Down
27 changes: 16 additions & 11 deletions src/jrd/tra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,11 +2718,6 @@ namespace {
: dbb(d)
{ }

void waitForStartup()
{
sem.enter();
}

static void runSweep(SweepParameter* par)
{
FbLocalStatus status;
Expand All @@ -2745,7 +2740,6 @@ namespace {
prov->setDbCryptCallback(&status, cryptCallback);
status.check();
}
par->sem.release();

AutoDispose<IXpbBuilder> dpb(UtilInterfacePtr()->getXpbBuilder(&status, IXpbBuilder::DPB, nullptr, 0));
status.check();
Expand All @@ -2769,14 +2763,26 @@ namespace {
ex.stuffException(&st);
if (st->getErrors()[1] != isc_att_shutdown)
iscLogException("Automatic sweep error", ex);

if (dbb)
{
dbb->clearSweepStarting();
SPTHR_DEBUG(fprintf(stderr, "called clearSweepStarting() dbb=%p par=%p\n", dbb, this));
dbb = nullptr;
}
}

static void cleanup(SweepParameter* par)
{
SPTHR_DEBUG(fprintf(stderr, "Cleanup dbb=%p par=%p\n", par->dbb, par));
delete par;
}

private:
Semaphore sem;
Database* dbb;
};

typedef ThreadFinishSync<SweepParameter*> SweepSync;
typedef ThreadFinishSync<SweepParameter*, SweepParameter::cleanup> SweepSync;
InitInstance<HalfStaticArray<SweepSync*, 16> > sweepThreads;
GlobalPtr<Mutex> swThrMutex;
bool sweepDown = false;
Expand Down Expand Up @@ -2848,10 +2854,9 @@ static void start_sweeper(thread_db* tdbb)
}

AutoPtr<SweepSync> sweepSync(FB_NEW SweepSync(*getDefaultMemoryPool(), SweepParameter::runSweep));
SweepParameter swPar(dbb);
sweepSync->run(&swPar);
SweepParameter* swPar = FB_NEW_POOL(*dbb->dbb_permanent) SweepParameter(dbb);
sweepSync->run(swPar);
started = true;
swPar.waitForStartup();
sweepThreads().add(sweepSync.release());
}
catch (const Exception&)
Expand Down

0 comments on commit 1d1e3a5

Please sign in to comment.