Fix assertion failure in maintenance daemon during Citus upgrades (#7537)

Fixes https://github.com/citusdata/citus/issues/7536.

Note to reviewer:

Before this commit, the following results in an assertion failure when
executed locally and this won't be the case anymore:
```console
make -C src/test/regress/ check-citus-upgrade-local citus-old-version=v10.2.0
```

Note that this doesn't happen on CI as we don't enable assertions there.

---------

Co-authored-by: Jelte Fennema-Nio <jelte.fennema@microsoft.com>
pull/7522/head
Onur Tirtir 2024-03-20 01:10:12 +01:00 committed by GitHub
parent d129064280
commit 0acb5f6e86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 4 deletions

View File

@ -34,6 +34,7 @@
#include "utils/fmgroids.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/syscache.h"
#include "utils/xid8.h"
#include "pg_version_constants.h"
@ -261,11 +262,28 @@ RecoverWorkerTransactions(WorkerNode *workerNode)
continue;
}
/* Check if the transaction is created by an outer transaction from a non-main database */
bool outerXidIsNull = false;
Datum outerXidDatum = heap_getattr(heapTuple,
Anum_pg_dist_transaction_outerxid,
tupleDescriptor, &outerXidIsNull);
Datum outerXidDatum = 0;
if (EnableVersionChecks ||
SearchSysCacheExistsAttName(DistTransactionRelationId(), "outer_xid"))
{
/* Check if the transaction is created by an outer transaction from a non-main database */
outerXidDatum = heap_getattr(heapTuple,
Anum_pg_dist_transaction_outerxid,
tupleDescriptor, &outerXidIsNull);
}
else
{
/*
* Normally we don't try to recover prepared transactions when the
* binary version doesn't match the sql version. However, we skip
* those checks in regression tests by disabling
* citus.enable_version_checks. And when this is the case, while
* the C code looks for "outer_xid" attribute, pg_dist_transaction
* doesn't yet have it.
*/
Assert(!EnableVersionChecks);
}
TransactionId outerXid = 0;
if (!outerXidIsNull)