Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup batches inside the engine if they were not released explicity before disconnection #8341

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/dsql/DsqlBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,20 @@ DsqlBatch::DsqlBatch(DsqlDmlRequest* req, const dsql_msg* /*message*/, IMessageM

// assign initial default BPB
setDefBpb(FB_NELEM(initBlobParameters), initBlobParameters);
}

if (const auto att = m_dsqlRequest->req_dbb->dbb_attachment)
att->registerBatch(this);
}

DsqlBatch::~DsqlBatch()
{
if (m_batch)
m_batch->resetHandle();
if (m_dsqlRequest)
m_dsqlRequest->req_batch = NULL;
m_dsqlRequest->req_batch = nullptr;

if (const auto att = m_dsqlRequest->req_dbb->dbb_attachment)
att->deregisterBatch(this);
}

Attachment* DsqlBatch::getAttachment() const
Expand Down
10 changes: 7 additions & 3 deletions src/jrd/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "../jrd/replication/Applier.h"
#include "../jrd/replication/Manager.h"

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

#include "../common/classes/fb_string.h"
Expand Down Expand Up @@ -288,9 +289,6 @@ Jrd::Attachment::~Attachment()

delete att_trace_manager;

for (unsigned n = 0; n < att_batches.getCount(); ++n)
att_batches[n]->resetHandle();

for (Function** iter = att_functions.begin(); iter < att_functions.end(); ++iter)
{
Function* const function = *iter;
Expand Down Expand Up @@ -449,6 +447,12 @@ void Jrd::Attachment::storeBinaryBlob(thread_db* tdbb, jrd_tra* transaction,
blob->BLB_close(tdbb);
}

void Jrd::Attachment::releaseBatches()
{
while (att_batches.hasData())
delete att_batches.pop();
}

void Jrd::Attachment::releaseGTTs(thread_db* tdbb)
{
if (!att_relations)
Expand Down
7 changes: 4 additions & 3 deletions src/jrd/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ class Attachment : public pool_alloc<type_att>
void storeBinaryBlob(thread_db* tdbb, jrd_tra* transaction, bid* blobId,
const Firebird::ByteChunk& chunk);

void releaseBatches();
void releaseGTTs(thread_db* tdbb);
void resetSession(thread_db* tdbb, jrd_tra** traHandle);

Expand Down Expand Up @@ -796,12 +797,12 @@ class Attachment : public pool_alloc<type_att>
}

// batches control
void registerBatch(JBatch* b)
void registerBatch(DsqlBatch* b)
{
att_batches.add(b);
}

void deregisterBatch(JBatch* b)
void deregisterBatch(DsqlBatch* b)
{
att_batches.findAndRemove(b);
}
Expand Down Expand Up @@ -864,7 +865,7 @@ class Attachment : public pool_alloc<type_att>
unsigned int att_stmt_timeout; // milliseconds
Firebird::RefPtr<Firebird::TimerImpl> att_idle_timer;

Firebird::Array<JBatch*> att_batches;
Firebird::Array<DsqlBatch*> att_batches;
InitialOptions att_initial_options; // Initial session options
DebugOptions att_debug_options;
Firebird::AutoPtr<ProfilerManager> att_profiler_manager; // ProfilerManager
Expand Down
6 changes: 2 additions & 4 deletions src/jrd/jrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6070,7 +6070,6 @@ JBatch* JStatement::createBatch(Firebird::CheckStatusWrapper* status, Firebird::
batch = FB_NEW JBatch(dsqlBatch, this, inMetadata);
batch->addRef();
dsqlBatch->setInterfacePtr(batch);
tdbb->getAttachment()->registerBatch(batch);
}
catch (const Exception& ex)
{
Expand Down Expand Up @@ -6146,9 +6145,6 @@ void JBatch::freeEngineData(Firebird::CheckStatusWrapper* user_status)

try
{
Attachment* att = getAttachment()->getHandle();
if (att)
att->deregisterBatch(this);
delete batch;
batch = nullptr;
}
Expand Down Expand Up @@ -7726,6 +7722,8 @@ void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment, XThreadEns
if (attachment->att_event_session)
dbb->eventManager()->deleteSession(attachment->att_event_session);

attachment->releaseBatches();

// CMP_release() changes att_requests.
while (attachment->att_requests.hasData())
CMP_release(tdbb, attachment->att_requests.back());
Expand Down
Loading