Skip to content

Commit d265ef0

Browse files
committed
This should fix #8986: Race condition between VIO_update_in_place and the garbage collector; update RDB$DATABASE in regular autonomous transaction
1 parent d3866de commit d265ef0

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/dsql/DdlNodes.epp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6597,7 +6597,7 @@ bool RelationNode::checkDeletedId(thread_db* tdbb, MetaId& relId)
65976597
AutoCacheRequest request(tdbb, requestCacheId);
65986598
Attachment* attachment = tdbb->getAttachment();
65996599

6600-
FOR (REQUEST_HANDLE request)
6600+
FOR (REQUEST_HANDLE request TRANSACTION_HANDLE attachment->getMetaTransaction(tdbb))
66016601
P IN RDB$PAGES WITH
66026602
P.RDB$RELATION_ID EQ relId
66036603
{
@@ -6636,10 +6636,10 @@ MetaId RelationNode::generateRelId(thread_db* tdbb, MetaName name)
66366636
Attachment* attachment = tdbb->getAttachment();
66376637
MetaId relId = 0;
66386638

6639-
static const CachedRequestId idDb;
6640-
AutoCacheRequest requestDb(tdbb, idDb);
6639+
AUTO_HANDLE(requestDb);
6640+
auto* metaTransaction = attachment->getMetaTransaction(tdbb);
66416641

6642-
FOR(REQUEST_HANDLE requestDb)
6642+
FOR(REQUEST_HANDLE requestDb TRANSACTION_HANDLE metaTransaction)
66436643
D IN RDB$DATABASE
66446644
{
66456645
MetaId startId = D.RDB$RELATION_ID;
@@ -6655,10 +6655,9 @@ MetaId RelationNode::generateRelId(thread_db* tdbb, MetaName name)
66556655
relId = startId;
66566656
enum {MISS, VALID, FREE} found = FREE;
66576657

6658-
static const CachedRequestId idRels;
6659-
AutoCacheRequest requestRels(tdbb, idRels);
6658+
AUTO_HANDLE(requestRels);
66606659

6661-
FOR(REQUEST_HANDLE requestRels)
6660+
FOR(REQUEST_HANDLE requestRels TRANSACTION_HANDLE metaTransaction)
66626661
R IN RDB$RELATIONS
66636662
WITH R.RDB$RELATION_ID GE startId
66646663
AND R.RDB$RELATION_ID LT stopId
@@ -6678,9 +6677,26 @@ MetaId RelationNode::generateRelId(thread_db* tdbb, MetaName name)
66786677

66796678
if (found == VALID)
66806679
{
6681-
MODIFY D USING
6682-
D.RDB$RELATION_ID = relId + 1;
6683-
END_MODIFY
6680+
AUTO_HANDLE(requestMod);
6681+
6682+
jrd_tra* previous = tdbb->getTransaction();
6683+
jrd_tra* traMod = TRA_start(tdbb, 0, DEFAULT_LOCK_TIMEOUT);
6684+
Cleanup rollback([&]()
6685+
{
6686+
if (traMod)
6687+
TRA_rollback(tdbb, traMod, false, true);
6688+
tdbb->setTransaction(previous);
6689+
});
6690+
6691+
FOR(REQUEST_HANDLE requestMod TRANSACTION_HANDLE traMod)
6692+
DBMOD IN RDB$DATABASE
6693+
MODIFY DBMOD USING
6694+
DBMOD.RDB$RELATION_ID = relId + 1;
6695+
END_MODIFY
6696+
END_FOR
6697+
6698+
TRA_commit(tdbb, traMod, false);
6699+
traMod = nullptr;
66846700

66856701
// !!!!!! printf(" %d\n", relId); fflush(stdout);
66866702
return relId;

src/jrd/SystemTriggers.epp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,14 +1590,18 @@ void afterInsertRelation(thread_db* tdbb, Record* record)
15901590

15911591
// Do not access external file info from cache - it may be not usable yet
15921592
// On contrary rel_flags (and therefore check for view) are OK
1593-
if (relation && !EVL_field(nullptr, record, f_rel_ext_file, &desc) &&
1594-
!relation->isView())
1593+
fb_assert(relation);
1594+
if (relation)
15951595
{
1596-
// create the table
1597-
DPM_create_relation(tdbb, relation);
1598-
}
1596+
if (!EVL_field(nullptr, record, f_rel_ext_file, &desc) &&
1597+
!relation->isView())
1598+
{
1599+
// create the table
1600+
DPM_create_relation(tdbb, relation);
1601+
}
15991602

1600-
relation->rel_flags |= REL_get_dependencies;
1603+
relation->rel_flags |= REL_get_dependencies;
1604+
}
16011605
}
16021606

16031607
}

0 commit comments

Comments
 (0)