From 4ddbb69de0430d1b3dd0c2d9c2dbf705762bc45c Mon Sep 17 00:00:00 2001 From: Vlad Khorsun Date: Wed, 15 Jan 2025 11:52:51 +0200 Subject: [PATCH] Fixed bug #8386 : Crash when creating index on table that uses UDR and ParallelWorkers > 1 --- src/jrd/WorkerAttachment.cpp | 19 +++++++++++-------- src/jrd/WorkerAttachment.h | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/jrd/WorkerAttachment.cpp b/src/jrd/WorkerAttachment.cpp index 8c9a4df8a3d..ac2dcbf67d0 100644 --- a/src/jrd/WorkerAttachment.cpp +++ b/src/jrd/WorkerAttachment.cpp @@ -50,7 +50,8 @@ const unsigned WORKER_IDLE_TIMEOUT = 60; // 1 minute /// class WorkerStableAttachment WorkerStableAttachment::WorkerStableAttachment(FbStatusVector* status, Jrd::Attachment* attachment) : - SysStableAttachment(attachment) + SysStableAttachment(attachment), + m_provider(attachment->getProvider()) { UserId user; user.setUserName(""); @@ -69,6 +70,7 @@ WorkerStableAttachment::WorkerStableAttachment(FbStatusVector* status, Jrd::Atta Monitoring::publishAttachment(tdbb); initDone(); + m_provider->addRef(); } WorkerStableAttachment::~WorkerStableAttachment() @@ -76,12 +78,12 @@ WorkerStableAttachment::~WorkerStableAttachment() fini(); } -WorkerStableAttachment* WorkerStableAttachment::create(FbStatusVector* status, Jrd::Database* dbb) +WorkerStableAttachment* WorkerStableAttachment::create(FbStatusVector* status, Database* dbb, JProvider* provider) { Attachment* attachment = NULL; try { - attachment = Attachment::create(dbb, NULL); + attachment = Attachment::create(dbb, provider); attachment->att_filename = dbb->dbb_filename; attachment->att_flags |= ATT_worker; @@ -120,6 +122,8 @@ void WorkerStableAttachment::fini() BackgroundContextHolder tdbb(dbb, attachment, &status_vector, FB_FUNCTION); Monitoring::cleanupAttachment(tdbb); + dbb->dbb_extManager->closeAttachment(tdbb, attachment); + attachment->releaseLocks(tdbb); LCK_fini(tdbb, LCK_OWNER_attachment); @@ -433,18 +437,17 @@ StableAttachmentPart* WorkerAttachment::doAttach(FbStatusVector* status, Databas { StableAttachmentPart* sAtt = NULL; + AutoPlugin jInstance(JProvider::getInstance()); + //jInstance->setDbCryptCallback(&status, tdbb->getAttachment()->att_crypt_callback); + if (Config::getServerMode() == MODE_SUPER) - sAtt = WorkerStableAttachment::create(status, dbb); + sAtt = WorkerStableAttachment::create(status, dbb, jInstance); else { ClumpletWriter dpb(ClumpletReader::Tagged, MAX_DPB_SIZE, isc_dpb_version1); dpb.insertString(isc_dpb_trusted_auth, DBA_USER_NAME); dpb.insertInt(isc_dpb_worker_attach, 1); - AutoPlugin jInstance(JProvider::getInstance()); - - //jInstance->setDbCryptCallback(&status, tdbb->getAttachment()->att_crypt_callback); - JAttachment* jAtt = jInstance->attachDatabase(status, dbb->dbb_filename.c_str(), dpb.getBufferLength(), dpb.getBuffer()); diff --git a/src/jrd/WorkerAttachment.h b/src/jrd/WorkerAttachment.h index 742f1208100..0223dfd71b2 100644 --- a/src/jrd/WorkerAttachment.h +++ b/src/jrd/WorkerAttachment.h @@ -46,7 +46,7 @@ namespace Jrd class WorkerStableAttachment : public SysStableAttachment { public: - static WorkerStableAttachment* create(FbStatusVector* status, Jrd::Database* dbb); + static WorkerStableAttachment* create(FbStatusVector* status, Database* dbb, JProvider* provider); void fini(); @@ -56,6 +56,8 @@ class WorkerStableAttachment : public SysStableAttachment private: explicit WorkerStableAttachment(FbStatusVector* status, Jrd::Attachment* att); virtual ~WorkerStableAttachment(); + + Firebird::AutoPlugin m_provider; };