8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 12:03:02 +01:00

Cleanup and use the explicit rollback via TIP for all kinds of forced disconnections.

This commit is contained in:
dimitr 2013-09-04 17:44:52 +00:00
parent 66b47b6818
commit 8cfcf51305
2 changed files with 18 additions and 31 deletions

View File

@ -655,7 +655,7 @@ static void init_monitoring_lock(thread_db*);
static ISC_STATUS handle_error(ISC_STATUS*, ISC_STATUS); static ISC_STATUS handle_error(ISC_STATUS*, ISC_STATUS);
static void run_commit_triggers(thread_db* tdbb, jrd_tra* transaction); static void run_commit_triggers(thread_db* tdbb, jrd_tra* transaction);
static void verify_request_synchronization(jrd_req*& request, SSHORT level); static void verify_request_synchronization(jrd_req*& request, SSHORT level);
static unsigned int purge_transactions(thread_db*, Attachment*, const bool, const ULONG); static void purge_transactions(thread_db*, Attachment*, const bool);
namespace { namespace {
enum VdnResult {VDN_FAIL, VDN_OK, VDN_SECURITY}; enum VdnResult {VDN_FAIL, VDN_OK, VDN_SECURITY};
} }
@ -2442,8 +2442,13 @@ ISC_STATUS GDS_DETACH(ISC_STATUS* user_status, Attachment** handle)
AttachmentHolder attHolder(tdbb, attachment, "GDS_DETACH"); AttachmentHolder attHolder(tdbb, attachment, "GDS_DETACH");
DatabaseContextHolder dbbHolder(tdbb); DatabaseContextHolder dbbHolder(tdbb);
Database* const dbb = tdbb->getDatabase();
purge_attachment(tdbb, attachment, false); const bool force = engineShutdown ||
(dbb->dbb_ast_flags & DBB_shutdown) ||
(attachment->att_flags & ATT_shutdown);
purge_attachment(tdbb, attachment, force);
*handle = NULL; *handle = NULL;
} }
catch (const Exception& ex) catch (const Exception& ex)
@ -2518,7 +2523,7 @@ ISC_STATUS GDS_DROP_DATABASE(ISC_STATUS* user_status, Attachment** handle)
} }
// Forced release of all transactions // Forced release of all transactions
purge_transactions(tdbb, attachment, true, attachment->att_flags); purge_transactions(tdbb, attachment, true);
tdbb->tdbb_flags |= TDBB_detaching; tdbb->tdbb_flags |= TDBB_detaching;
@ -6204,10 +6209,7 @@ static void ExtractDriveLetter(const TEXT* file_name, ULONG* drive_mask)
#endif #endif
static unsigned int purge_transactions(thread_db* tdbb, static void purge_transactions(thread_db* tdbb, Attachment* attachment, const bool force_flag)
Attachment* attachment,
const bool force_flag,
const ULONG att_flags)
{ {
/************************************** /**************************************
* *
@ -6220,8 +6222,8 @@ static unsigned int purge_transactions(thread_db* tdbb,
* from an attachment * from an attachment
* *
**************************************/ **************************************/
Database* dbb = attachment->att_database; Database* const dbb = attachment->att_database;
jrd_tra* trans_dbk = attachment->att_dbkey_trans; jrd_tra* const trans_dbk = attachment->att_dbkey_trans;
unsigned int count = 0; unsigned int count = 0;
jrd_tra* next; jrd_tra* next;
@ -6231,8 +6233,7 @@ static unsigned int purge_transactions(thread_db* tdbb,
next = transaction->tra_next; next = transaction->tra_next;
if (transaction != trans_dbk) if (transaction != trans_dbk)
{ {
if ((transaction->tra_flags & TRA_prepared) || (dbb->dbb_ast_flags & DBB_shutdown) || if (transaction->tra_flags & TRA_prepared)
(att_flags & ATT_shutdown))
{ {
TraceTransactionEnd trace(transaction, false, false); TraceTransactionEnd trace(transaction, false, false);
EDS::Transaction::jrdTransactionEnd(tdbb, transaction, false, false, true); EDS::Transaction::jrdTransactionEnd(tdbb, transaction, false, false, true);
@ -6247,25 +6248,15 @@ static unsigned int purge_transactions(thread_db* tdbb,
if (count) if (count)
{ {
return count; ERR_post(Arg::Gds(isc_open_trans) << Arg::Num(count));
} }
// If there's a side transaction for db-key scope, get rid of it // If there's a side transaction for db-key scope, get rid of it
if (trans_dbk) if (trans_dbk)
{ {
attachment->att_dbkey_trans = NULL; attachment->att_dbkey_trans = NULL;
if ((dbb->dbb_ast_flags & DBB_shutdown) || (att_flags & ATT_shutdown)) TRA_commit(tdbb, trans_dbk, false);
{
TraceTransactionEnd trace(trans_dbk, false, false);
TRA_release_transaction(tdbb, trans_dbk, &trace);
}
else
{
TRA_commit(tdbb, trans_dbk, false);
}
} }
return 0;
} }
@ -6345,7 +6336,7 @@ static void purge_attachment(thread_db* tdbb, Attachment* attachment, const bool
{ {
if (!force_flag) if (!force_flag)
{ {
attachment->att_flags |= (ATT_shutdown | ATT_purge_error); attachment->att_flags |= ATT_shutdown;
throw; throw;
} }
} }
@ -6362,18 +6353,14 @@ static void purge_attachment(thread_db* tdbb, Attachment* attachment, const bool
if (!(dbb->dbb_flags & DBB_bugcheck)) if (!(dbb->dbb_flags & DBB_bugcheck))
{ {
// Check for any pending transactions // Check for any pending transactions
unsigned int count = purge_transactions(tdbb, attachment, force_flag, att_flags); purge_transactions(tdbb, attachment, force_flag);
if (count)
{
ERR_post(Arg::Gds(isc_open_trans) << Arg::Num(count));
}
} }
} }
catch (const Exception&) catch (const Exception&)
{ {
if (!force_flag) if (!force_flag)
{ {
attachment->att_flags |= (ATT_shutdown | ATT_purge_error); attachment->att_flags |= ATT_shutdown;
throw; throw;
} }
} }

View File

@ -353,7 +353,7 @@ private:
const ULONG ATT_no_cleanup = 0x1; // Don't expunge, purge, or garbage collect const ULONG ATT_no_cleanup = 0x1; // Don't expunge, purge, or garbage collect
const ULONG ATT_shutdown = 0x2; // attachment has been shutdown const ULONG ATT_shutdown = 0x2; // attachment has been shutdown
const ULONG ATT_purge_error = 0x4; // trouble happened in purge attachment //const ULONG ATT_purge_error = 0x4; // trouble happened in purge attachment
const ULONG ATT_shutdown_manager = 0x8; // attachment requesting shutdown const ULONG ATT_shutdown_manager = 0x8; // attachment requesting shutdown
const ULONG ATT_lck_init_done = 0x10; // LCK_init() called for the attachment const ULONG ATT_lck_init_done = 0x10; // LCK_init() called for the attachment
const ULONG ATT_exclusive = 0x20; // attachment wants exclusive database access const ULONG ATT_exclusive = 0x20; // attachment wants exclusive database access