Skip to content

Commit 9ed770f

Browse files
danolivoarssher
authored andcommitted
[PGPRO-4074] Port fix the foreign_key.sql regression test problem.
Cherry pick of [PGPRO-3171] Fix the foreign_key.sql regression test problem. We allow to apply transactions with temporary tables by any worker. Each worker has MyBackendId. At the stage of initialization of temporary relation into the relcache, it is set rel->rd_backend to MyBackendId. If worker try to open the ralation it will use rd-backend field to construct the path. If it is differ from the rd_backend of relation creator we catch the ERROR "could not open file ..." Fix the problem by modify BackendIdForTempRelations() routine. Now all workers will initialize its rd_backend field of corresponding temporary relation by the same value. (cherry picked from commit fae6fc9b861fd7518cb5df8ae506b6f63c5434f6) ars: Funnily enough, the patch has been forgotten in v12 but I've failed to reproduce the original issue there. I suspect it has to do with PGPRO-3124 patch who delays temp table file creation as late as possible (which on receiver side in mm should mean never create the file, as temp table is ever empty there), but not 100% sure. tags: multimaster (cherry picked from commit 69036af77ebb5cc51f2733a5a6bcb76a780967d3)
1 parent 49ddc13 commit 9ed770f

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/backend/catalog/namespace.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,6 +3326,28 @@ GetTempToastNamespace(void)
33263326
return myTempToastNamespace;
33273327
}
33283328

3329+
/*
3330+
* MTM-CRUTCH.
3331+
*
3332+
* The BackendId to use for our session's temp relations is normally our own,
3333+
* but parallel workers should use their leader's ID.
3334+
* In a multimaster configuration it is a session id from the node, which
3335+
* connected to the user.
3336+
*/
3337+
int
3338+
BackendIdForTempRelations(void)
3339+
{
3340+
Oid nspOid, tnspOid;
3341+
3342+
GetTempNamespaceState(&nspOid, &tnspOid);
3343+
3344+
if (OidIsValid(nspOid))
3345+
return GetTempNamespaceBackendId(nspOid);
3346+
else if(OidIsValid(tnspOid))
3347+
return GetTempNamespaceBackendId(tnspOid);
3348+
else
3349+
return ParallelMasterBackendId == InvalidBackendId ? MyBackendId : ParallelMasterBackendId;
3350+
}
33293351

33303352
/*
33313353
* GetTempNamespaceState - fetch status of session's temporary namespace

src/backend/catalog/storage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "access/xlog.h"
2626
#include "access/xloginsert.h"
2727
#include "access/xlogutils.h"
28+
#include "catalog/namespace.h"
2829
#include "catalog/storage.h"
2930
#include "catalog/storage_xlog.h"
3031
#include "miscadmin.h"

src/include/catalog/namespace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ extern bool isOtherTempNamespace(Oid namespaceId);
156156
extern TempNamespaceStatus checkTempNamespaceStatus(Oid namespaceId);
157157
extern int GetTempNamespaceBackendId(Oid namespaceId);
158158
extern Oid GetTempToastNamespace(void);
159+
extern int BackendIdForTempRelations(void);
159160
extern void GetTempNamespaceState(Oid *tempNamespaceId,
160161
Oid *tempToastNamespaceId);
161162
extern void SetTempNamespaceState(Oid tempNamespaceId,

src/include/storage/backendid.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,4 @@ extern PGDLLIMPORT BackendId MyBackendId; /* backend id of this backend */
2727
/* backend id of our parallel session leader, or InvalidBackendId if none */
2828
extern PGDLLIMPORT BackendId ParallelMasterBackendId;
2929

30-
/*
31-
* The BackendId to use for our session's temp relations is normally our own,
32-
* but parallel workers should use their leader's ID.
33-
*/
34-
#define BackendIdForTempRelations() \
35-
(ParallelMasterBackendId == InvalidBackendId ? MyBackendId : ParallelMasterBackendId)
36-
3730
#endif /* BACKENDID_H */

0 commit comments

Comments
 (0)