8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 09:20:39 +01:00

Fixed CORE-6371: Avoid server crash on shutdown in case of wrong reference counting in UDR

This commit is contained in:
AlexPeshkoff 2020-07-24 18:45:48 +03:00
parent 02b5ba5bb6
commit ca12563ba5
7 changed files with 23 additions and 15 deletions

View File

@ -84,13 +84,13 @@ CommitNumber ActiveSnapshots::getSnapshotForVersion(CommitNumber version_cn)
// static method
Jrd::Attachment* Jrd::Attachment::create(Database* dbb)
Jrd::Attachment* Jrd::Attachment::create(Database* dbb, Firebird::IProvider* provider)
{
MemoryPool* const pool = dbb->createPool();
try
{
Attachment* const attachment = FB_NEW_POOL(*pool) Attachment(pool, dbb);
Attachment* const attachment = FB_NEW_POOL(*pool) Attachment(pool, dbb, provider);
pool->setStatsGroup(attachment->att_memory_stats);
return attachment;
}
@ -203,7 +203,7 @@ void Jrd::Attachment::backupStateReadUnLock(thread_db* tdbb)
}
Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb)
Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb, IProvider* provider)
: att_pool(pool),
att_memory_stats(&dbb->dbb_memory_stats),
att_database(dbb),
@ -251,7 +251,8 @@ Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb)
att_idle_timeout(0),
att_stmt_timeout(0),
att_batches(*pool),
att_initial_options(*pool)
att_initial_options(*pool),
att_provider(provider)
{
att_internal.grow(irq_MAX);
att_dyn_req.grow(drq_MAX);

View File

@ -396,7 +396,7 @@ public:
};
public:
static Attachment* create(Database* dbb);
static Attachment* create(Database* dbb, Firebird::IProvider* provider);
static void destroy(Attachment* const attachment);
MemoryPool* const att_pool; // Memory pool
@ -650,9 +650,14 @@ public:
void checkReplSetLock(thread_db* tdbb);
void invalidateReplSet(thread_db* tdbb, bool broadcast);
Firebird::IProvider* getProvider()
{
fb_assert(att_provider);
return att_provider;
}
private:
Attachment(MemoryPool* pool, Database* dbb);
Attachment(MemoryPool* pool, Database* dbb, Firebird::IProvider* provider);
~Attachment();
unsigned int att_idle_timeout; // seconds
@ -662,9 +667,10 @@ private:
Firebird::RefPtr<IdleTimer> att_idle_timer;
Firebird::Array<JBatch*> att_batches;
InitialOptions att_initial_options; // Initial session options
InitialOptions att_initial_options; // Initial session options
Lock* att_repl_lock; // Replication set lock
Firebird::IProvider* att_provider; // Provider which created this attachment
};

View File

@ -918,7 +918,7 @@ namespace Jrd {
UserId user;
user.setUserName("Database Crypter");
Jrd::Attachment* const attachment = Jrd::Attachment::create(&dbb);
Jrd::Attachment* const attachment = Jrd::Attachment::create(&dbb, nullptr);
RefPtr<SysStableAttachment> sAtt(FB_NEW SysStableAttachment(attachment));
attachment->setStable(sAtt);
attachment->att_filename = dbb.dbb_filename;

View File

@ -606,7 +606,7 @@ ExtEngineManager::ExternalContextImpl::ExternalContextImpl(thread_db* tdbb,
internalAttachment->getStable()->addRef();
externalAttachment = MasterInterfacePtr()->registerAttachment
(AutoPlugin<JProvider>(JProvider::getInstance()), internalAttachment->getInterface());
(internalAttachment->getProvider(), internalAttachment->getInterface());
}
ExtEngineManager::ExternalContextImpl::~ExternalContextImpl()

View File

@ -2959,7 +2959,7 @@ void BufferControl::cache_writer(BufferControl* bcb)
UserId user;
user.setUserName("Cache Writer");
Jrd::Attachment* const attachment = Jrd::Attachment::create(dbb);
Jrd::Attachment* const attachment = Jrd::Attachment::create(dbb, nullptr);
RefPtr<SysStableAttachment> sAtt(FB_NEW SysStableAttachment(attachment));
attachment->setStable(sAtt);
attachment->att_filename = dbb->dbb_filename;

View File

@ -1296,7 +1296,7 @@ static VdnResult verifyDatabaseName(const PathName&, FbStatusVector*, bool);
static void unwindAttach(thread_db* tdbb, const Exception& ex, FbStatusVector* userStatus, bool internalFlag);
static JAttachment* initAttachment(thread_db*, const PathName&, const PathName&, RefPtr<const Config>, bool,
const DatabaseOptions&, RefMutexUnlock&, IPluginConfig*, JProvider*);
static JAttachment* create_attachment(const PathName&, Database*, const DatabaseOptions&, bool newDb);
static JAttachment* create_attachment(const PathName&, Database*, IProvider* provider, const DatabaseOptions&, bool newDb);
static void prepare_tra(thread_db*, jrd_tra*, USHORT, const UCHAR*);
static void release_attachment(thread_db*, Attachment*);
static void start_transaction(thread_db* tdbb, bool transliterate, jrd_tra** tra_handle,
@ -7136,7 +7136,7 @@ static JAttachment* initAttachment(thread_db* tdbb, const PathName& expanded_nam
fb_assert(!(dbb->dbb_flags & DBB_new));
tdbb->setDatabase(dbb);
jAtt = create_attachment(alias_name, dbb, options, !attach_flag);
jAtt = create_attachment(alias_name, dbb, provider, options, !attach_flag);
if (dbb->dbb_linger_timer)
dbb->dbb_linger_timer->reset();
@ -7197,7 +7197,7 @@ static JAttachment* initAttachment(thread_db* tdbb, const PathName& expanded_nam
// now it's time to create DB objects that need MetaName
dbb->dbb_extManager = FB_NEW_POOL(*dbb->dbb_permanent) ExtEngineManager(*dbb->dbb_permanent);
jAtt = create_attachment(alias_name, dbb, options, !attach_flag);
jAtt = create_attachment(alias_name, dbb, provider, options, !attach_flag);
tdbb->setAttachment(jAtt->getHandle());
} // end scope
@ -7234,6 +7234,7 @@ static JAttachment* initAttachment(thread_db* tdbb, const PathName& expanded_nam
static JAttachment* create_attachment(const PathName& alias_name,
Database* dbb,
IProvider* provider,
const DatabaseOptions& options,
bool newDb)
{
@ -7258,7 +7259,7 @@ static JAttachment* create_attachment(const PathName& alias_name,
status_exception::raise(Arg::Gds(isc_att_shutdown));
}
attachment = Attachment::create(dbb);
attachment = Attachment::create(dbb, provider);
attachment->att_next = dbb->dbb_attachments;
dbb->dbb_attachments = attachment;
}

View File

@ -4781,7 +4781,7 @@ void Database::garbage_collector(Database* dbb)
UserId user;
user.setUserName("Garbage Collector");
Jrd::Attachment* const attachment = Jrd::Attachment::create(dbb);
Jrd::Attachment* const attachment = Jrd::Attachment::create(dbb, nullptr);
RefPtr<SysStableAttachment> sAtt(FB_NEW SysStableAttachment(attachment));
attachment->setStable(sAtt);
attachment->att_filename = dbb->dbb_filename;