diff --git a/src/jrd/WorkerAttachment.cpp b/src/jrd/WorkerAttachment.cpp index 8c9a4df8a3..65798c4277 100644 --- a/src/jrd/WorkerAttachment.cpp +++ b/src/jrd/WorkerAttachment.cpp @@ -76,12 +76,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 +120,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 +435,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()); @@ -456,6 +457,7 @@ StableAttachmentPart* WorkerAttachment::doAttach(FbStatusVector* status, Databas { sAtt->addRef(); // !! sAtt->getHandle()->setIdleTimeout(WORKER_IDLE_TIMEOUT); + jInstance->addRef(); } return sAtt; @@ -465,6 +467,15 @@ void WorkerAttachment::doDetach(FbStatusVector* status, StableAttachmentPart* sA { status->init(); + AutoPlugin provider; + { + AttSyncLockGuard guard(*sAtt->getSync(), FB_FUNCTION); + + Attachment* attachment = sAtt->getHandle(); + if (attachment) + provider.reset(attachment->getProvider()); + } + // if (att->att_flags & ATT_system) if (Config::getServerMode() == MODE_SUPER) { diff --git a/src/jrd/WorkerAttachment.h b/src/jrd/WorkerAttachment.h index 742f120810..dd366573f1 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();