Skip to content

Commit

Permalink
1) Implemented CORE-793. More work is required to terminate idle CS p…
Browse files Browse the repository at this point in the history
…rocesses, this will be done the next week.

2) Fixed the "lock conflict" error for the CS monitoring in v2.5.
  • Loading branch information
dyemanov committed Apr 23, 2008
1 parent f4e86a9 commit a355c60
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/jrd/DatabaseSnapshot.cpp
Expand Up @@ -234,6 +234,10 @@ void DatabaseSnapshot::SharedMemory::garbageCollect(thread_db* tdbb, bool self)
}
else
{
ISC_STATUS_ARRAY temp_status;
ISC_STATUS* const org_status = tdbb->tdbb_status_vector;
tdbb->tdbb_status_vector = temp_status;

memcpy(temp_lock->lck_key.lck_string, &guid, sizeof(FB_GUID));
if (LCK_lock(tdbb, temp_lock, LCK_EX, LCK_NO_WAIT))
{
Expand All @@ -248,6 +252,8 @@ void DatabaseSnapshot::SharedMemory::garbageCollect(thread_db* tdbb, bool self)
// Don't remove its data.
garbage_collect = false;
}

tdbb->tdbb_status_vector = org_status;
}
}

Expand Down
37 changes: 28 additions & 9 deletions src/jrd/VirtualTable.cpp
Expand Up @@ -67,28 +67,47 @@ void VirtualTable::erase(thread_db* tdbb, record_param* rpb)
jrd_rel* relation = rpb->rpb_relation;
fb_assert(relation);

if (relation->rel_id != rel_mon_statements)
ERR_post(isc_read_only, 0);

// Get transaction id
dsc desc;
if (!EVL_field(relation, rpb->rpb_record, f_mon_stmt_tra_id, &desc))
return;
lck_t lock_type;

if (relation->rel_id == rel_mon_attachments)
{
// Get attachment id
if (!EVL_field(relation, rpb->rpb_record, f_mon_att_id, &desc))
return;
lock_type = LCK_attachment;
}
else if (relation->rel_id == rel_mon_statements)
{
// Get transaction id
if (!EVL_field(relation, rpb->rpb_record, f_mon_stmt_tra_id, &desc))
return;
lock_type = LCK_cancel;
}
else
{
ERR_post(isc_read_only, 0);
}

const SLONG id = MOV_get_long(&desc, 0);

// Post a blocking request
Lock temp_lock;
temp_lock.lck_dbb = dbb;
temp_lock.lck_type = LCK_cancel;
temp_lock.lck_type = lock_type;
temp_lock.lck_parent = dbb->dbb_lock;
temp_lock.lck_owner_handle =
LCK_get_owner_handle(tdbb, temp_lock.lck_type);
temp_lock.lck_owner_handle = LCK_get_owner_handle(tdbb, temp_lock.lck_type);
temp_lock.lck_length = sizeof(SLONG);
temp_lock.lck_key.lck_long = id;

ISC_STATUS_ARRAY temp_status;
ISC_STATUS* const org_status = tdbb->tdbb_status_vector;
tdbb->tdbb_status_vector = temp_status;

if (LCK_lock(tdbb, &temp_lock, LCK_EX, -1))
LCK_release(tdbb, &temp_lock);

tdbb->tdbb_status_vector = org_status;
}


Expand Down
31 changes: 30 additions & 1 deletion src/jrd/pag.cpp
Expand Up @@ -103,6 +103,7 @@
using namespace Jrd;
using namespace Ods;

static int blocking_ast_attachment(void*);
static void find_clump_space(SLONG, WIN*, pag**, USHORT, USHORT, const UCHAR*,
USHORT);
static bool find_type(SLONG, WIN*, pag**, USHORT, USHORT, UCHAR**,
Expand Down Expand Up @@ -959,7 +960,9 @@ SLONG PAG_attachment_id(thread_db* tdbb)
lock->lck_length = sizeof(SLONG);
lock->lck_key.lck_long = attachment->att_attachment_id;
lock->lck_dbb = dbb;
LCK_lock(tdbb, lock, LCK_write, LCK_WAIT);
lock->lck_ast = blocking_ast_attachment;
lock->lck_object = attachment;
LCK_lock(tdbb, lock, LCK_EX, LCK_WAIT);

return attachment->att_attachment_id;
}
Expand Down Expand Up @@ -2019,6 +2022,32 @@ int PAG_unlicensed()
*/


static int blocking_ast_attachment(void* ast_object)
{
Attachment* const attachment = static_cast<Attachment*>(ast_object);

try
{
Database* const dbb = attachment->att_database;
Database::SyncGuard dsGuard(dbb, true);

ThreadContextHolder tdbb;
tdbb->setDatabase(dbb);
tdbb->setAttachment(attachment);

Jrd::ContextPoolHolder context(tdbb, dbb->dbb_permanent);

attachment->att_flags |= ATT_shutdown;

LCK_release(tdbb, attachment->att_id_lock);
}
catch (const Firebird::Exception&)
{} // no-op

return 0;
}


static void find_clump_space(SLONG page_num,
WIN* window,
PAG* ppage,
Expand Down

0 comments on commit a355c60

Please sign in to comment.