Skip to content

Commit

Permalink
Fixed #7304: Events in system attachments (like garbage collector) ar…
Browse files Browse the repository at this point in the history
…e not traced
  • Loading branch information
AlexPeshkoff committed Sep 15, 2022
1 parent fa154ca commit 711eb3e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 24 deletions.
9 changes: 8 additions & 1 deletion src/jrd/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "firebird.h"
#include "../jrd/Attachment.h"
#include "../jrd/MetaName.h"
#include "../jrd/Database.h"
#include "../jrd/Function.h"
#include "../jrd/nbak.h"
Expand All @@ -46,8 +47,9 @@
#include "../jrd/replication/Applier.h"
#include "../jrd/replication/Manager.h"

#include "../dsql/DsqlStatementCache.h"

#include "../common/classes/fb_string.h"
#include "../jrd/MetaName.h"
#include "../common/StatusArg.h"
#include "../common/TimeZoneUtil.h"
#include "../common/isc_proto.h"
Expand Down Expand Up @@ -835,6 +837,11 @@ void Jrd::Attachment::releaseLocks(thread_db* tdbb)
for (bool getResult = accessor.getFirst(); getResult; getResult = accessor.getNext())
LCK_release(tdbb, accessor.current()->second.lock);

// Release dsql statement cache lock

if (att_dsql_instance)
att_dsql_instance->dbb_statement_cache->purge(tdbb);

// Release the remaining locks

if (att_id_lock)
Expand Down
20 changes: 20 additions & 0 deletions src/jrd/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,26 @@ class Attachment : public pool_alloc<type_att>
bool dsqlKeepBlr = false;
};

class UseCountHolder
{
public:
explicit UseCountHolder(Attachment* a)
: att(a)
{
if (att)
att->att_use_count++;
}

~UseCountHolder()
{
if (att)
att->att_use_count--;
}

private:
Attachment* att;
};

public:
static Attachment* create(Database* dbb, JProvider* provider);
static void destroy(Attachment* const attachment);
Expand Down
18 changes: 1 addition & 17 deletions src/jrd/CryptoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,23 +959,7 @@ namespace Jrd {
tdbb->markAsSweeper();

DatabaseContextHolder dbHolder(tdbb);

class UseCountHolder
{
public:
explicit UseCountHolder(Attachment* a)
: att(a)
{
att->att_use_count++;
}
~UseCountHolder()
{
att->att_use_count--;
}
private:
Attachment* att;
};
UseCountHolder use_count(att);
Attachment::UseCountHolder use_count(att);

// get ready...
AutoSetRestore<Attachment*> attSet(&cryptAtt, att);
Expand Down
2 changes: 1 addition & 1 deletion src/jrd/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ bool Mapping::DbHandle::attach(const char* aliasDb, ICryptKeyCallback* cryptCb)
if (!(missing || down))
check("IProvider::attachDatabase", &st);

// down/missing security DB is not a reason to fail mapping
// down/missing DB is not a reason to fail mapping
}
else
assignRefNoIncr(att);
Expand Down
1 change: 1 addition & 0 deletions src/jrd/cch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2979,6 +2979,7 @@ void BufferControl::cache_writer(BufferControl* bcb)
attachment->att_user = &user;

BackgroundContextHolder tdbb(dbb, attachment, &status_vector, FB_FUNCTION);
Jrd::Attachment::UseCountHolder use(attachment);

try
{
Expand Down
26 changes: 21 additions & 5 deletions src/jrd/jrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4920,10 +4920,16 @@ void SysStableAttachment::initDone()
{
Jrd::Attachment* attachment = getHandle();
Database* dbb = attachment->att_database;
SyncLockGuard guard(&dbb->dbb_sys_attach, SYNC_EXCLUSIVE, "SysStableAttachment::initDone");

attachment->att_next = dbb->dbb_sys_attachments;
dbb->dbb_sys_attachments = attachment;
{ // scope
SyncLockGuard guard(&dbb->dbb_sys_attach, SYNC_EXCLUSIVE, "SysStableAttachment::initDone");

attachment->att_next = dbb->dbb_sys_attachments;
dbb->dbb_sys_attachments = attachment;
}

// make system attachments traceable
attachment->att_trace_manager->activate();
}


Expand Down Expand Up @@ -7267,9 +7273,9 @@ static JAttachment* initAttachment(thread_db* tdbb, const PathName& expanded_nam
{
if (attach_flag)
{
if (!dbb->dbb_init_fini->doesExist())
if ((!dbb->dbb_init_fini->doesExist()) || (dbb->dbb_flags & DBB_new))
{
// database is shutting down
// database is shutting down or not opened completely
dbb = dbb->dbb_next;
continue;
}
Expand Down Expand Up @@ -8575,7 +8581,17 @@ static void unwindAttach(thread_db* tdbb, const char* filename, const Exception&
traceManager->event_attach(&conn, flags & UNWIND_CREATE, ITracePlugin::RESULT_FAILED);
}
else
{
auto dbb = tdbb->getDatabase();
if (dbb && (dbb->dbb_flags & DBB_new))
{
// attach failed before completion of DBB initialization
// that's hardly recoverable error - avoid extra problems in mapping
dbb->dbb_flags |= DBB_bugcheck;
}

trace_failed_attach(filename, options, flags & UNWIND_CREATE, userStatus, callback);
}

const char* func = flags & UNWIND_CREATE ? "JProvider::createDatabase" : "JProvider::attachDatabase";
transliterateException(tdbb, ex, userStatus, func);
Expand Down
1 change: 1 addition & 0 deletions src/jrd/vio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5194,6 +5194,7 @@ void Database::garbage_collector(Database* dbb)
attachment->att_user = &user;

BackgroundContextHolder tdbb(dbb, attachment, &status_vector, FB_FUNCTION);
Jrd::Attachment::UseCountHolder use(attachment);
tdbb->markAsSweeper();

record_param rpb;
Expand Down

0 comments on commit 711eb3e

Please sign in to comment.