Skip to content
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
1 change: 1 addition & 0 deletions src/jrd/Relation.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ const ULONG REL_jrd_view = 0x10000; // relation is VIEW
const ULONG REL_gc_blocking = 0x20000; // request to downgrade\release gc lock
const ULONG REL_gc_disabled = 0x40000; // gc is disabled temporarily
const ULONG REL_gc_lockneed = 0x80000; // gc lock should be acquired
const ULONG REL_rescan = 0x100000; // rescan request was submitted while relation being scanning


/// class jrd_rel
Expand Down
9 changes: 8 additions & 1 deletion src/jrd/dfw.epp
Original file line number Diff line number Diff line change
Expand Up @@ -6129,8 +6129,15 @@ static bool make_version(thread_db* tdbb, SSHORT phase, DeferredWork* work, jrd_
DFW_post_work(transaction, dfw_scan_relation, NULL, relation->rel_id);

// signal others about new format presence
LCK_lock(tdbb, relation->rel_rescan_lock, LCK_EX, LCK_WAIT);
LCK_release(tdbb, relation->rel_rescan_lock);
{
// Use temp lock to avoid AST call
Lock tmpLock(tdbb, sizeof(SLONG), LCK_rel_rescan);
tmpLock.setKey(relation->rel_id);

LCK_lock(tdbb, &tmpLock, LCK_EX, LCK_WAIT);
LCK_release(tdbb, &tmpLock);
}

break;
}
Expand Down
45 changes: 40 additions & 5 deletions src/jrd/met.epp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ static void save_trigger_data(thread_db*, TrigVector**, jrd_rel*, JrdStatement*,
const TEXT*, FB_UINT64, SSHORT, USHORT, const MetaName&, const string&,
const bid*, Nullable<bool> ssDefiner);
static void scan_partners(thread_db*, jrd_rel*);
static void scan_relation(thread_db*, jrd_rel*);
static void store_dependencies(thread_db*, CompilerScratch*, const jrd_rel*,
const MetaName&, int, jrd_tra*);
static bool verify_TRG_ignore_perm(thread_db*, const MetaName&);
Expand Down Expand Up @@ -3892,6 +3893,27 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
* Scan a relation for view RecordSelExpr, computed by expressions, missing
* expressions, and validation expressions.
*
**************************************/

while (!(relation->rel_flags & (REL_scanned | REL_deleted)))
{
scan_relation(tdbb, relation);
}
}


static void scan_relation(thread_db* tdbb, jrd_rel* relation)
{
/**************************************
*
* s c a n _ r e l a t i o n
*
**************************************
*
* Functional description
* Scan a relation for view RecordSelExpr, computed by expressions, missing
* expressions, and validation expressions.
*
**************************************/
SET_TDBB(tdbb);
TrigVector* triggers[TRIGGER_MAX];
Expand All @@ -3911,10 +3933,13 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)

try {

if (relation->rel_flags & (REL_scanned | REL_deleted))
return;
fb_assert(!(relation->rel_flags & (REL_scanned | REL_deleted)));

relation->rel_flags |= REL_being_scanned;

LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
relation->rel_flags &= ~REL_rescan;

dependencies = (relation->rel_flags & REL_get_dependencies) ? true : false;
sys_triggers = (relation->rel_flags & REL_sys_triggers) ? true : false;
relation->rel_flags &= ~(REL_get_dependencies | REL_sys_triggers);
Expand Down Expand Up @@ -4217,9 +4242,14 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
relation->replaceTriggers(tdbb, triggers);
}

LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
relation->rel_flags &= ~REL_being_scanned;

if (relation->rel_flags & REL_rescan)
{
LCK_release(tdbb, relation->rel_rescan_lock);
relation->rel_flags &= ~(REL_scanned | REL_rescan);
}

relation->rel_current_format = NULL;

} // try
Expand Down Expand Up @@ -4526,8 +4556,13 @@ static int rescan_ast_relation(void* ast_object)

AsyncContextHolder tdbb(dbb, FB_FUNCTION, relation->rel_rescan_lock);

LCK_release(tdbb, relation->rel_rescan_lock);
relation->rel_flags &= ~REL_scanned;
if (relation->rel_flags & REL_being_scanned)
relation->rel_flags |= REL_rescan;
else
{
LCK_release(tdbb, relation->rel_rescan_lock);
relation->rel_flags &= ~REL_scanned;
}
}
catch (const Firebird::Exception&)
{} // no-op
Expand Down
Loading