Skip to content

Commit

Permalink
This should fix bug CORE-5419 : Index garbage collection on varchar c…
Browse files Browse the repository at this point in the history
…olumn causes server to hang
  • Loading branch information
hvlad committed Jan 27, 2017
1 parent 9c32751 commit 2d26794
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/jrd/Database.h
Expand Up @@ -150,7 +150,7 @@ class Database : public pool_alloc<type_dbb>, public Firebird::PublicHandle
class Sync : public Firebird::RefCounted
{
public:
Sync() : threadId(0), isAst(false)
Sync() : threadId(0), isAst(false), lockCounter(0)
#ifdef DEV_BUILD
, lockCount(0)
#endif
Expand All @@ -164,6 +164,7 @@ class Database : public pool_alloc<type_dbb>, public Firebird::PublicHandle
--waiters;
threadId = getThreadId();
isAst = ast;
lockCounter++;
#ifdef DEV_BUILD
++lockCount;
#endif
Expand All @@ -186,6 +187,11 @@ class Database : public pool_alloc<type_dbb>, public Firebird::PublicHandle
return (waiters.value() > 0);
}

FB_UINT64 getLockCounter() const
{
return lockCounter;
}

#ifdef DEV_BUILD
bool locked() const
{
Expand Down Expand Up @@ -222,6 +228,7 @@ class Database : public pool_alloc<type_dbb>, public Firebird::PublicHandle
Firebird::AtomicCounter waiters;
FB_THREAD_ID threadId;
bool isAst;
volatile FB_UINT64 lockCounter;
#ifdef DEV_BUILD
int lockCount;
#endif
Expand Down
14 changes: 12 additions & 2 deletions src/jrd/jrd.cpp
Expand Up @@ -4402,8 +4402,18 @@ bool JRD_reschedule(thread_db* tdbb, SLONG quantum, bool punt)

if (dbb->dbb_sync->hasContention())
{
Database::Checkout dcoHolder(dbb);
THREAD_YIELD();
const FB_UINT64 counter = dbb->dbb_sync->getLockCounter();
{
Database::Checkout dcoHolder(dbb);
THREAD_YIELD();

// if nobody was able to lock dbb_sync, sleep a bit longer
while (dbb->dbb_sync->hasContention() &&
counter == dbb->dbb_sync->getLockCounter())
{
THREAD_SLEEP(1);
}
}
}

try {
Expand Down

0 comments on commit 2d26794

Please sign in to comment.