!1042 将全局变量relfilenode_skey改为session级,修复逻辑复制问题

Merge pull request !1042 from maxiang/master
This commit is contained in:
opengauss-bot
2021-06-18 17:23:34 +08:00
committed by Gitee
2 changed files with 16 additions and 15 deletions

View File

@ -34,9 +34,6 @@
#include "utils/relmapper.h"
#include "utils/snapmgr.h"
/* built first time through in InitializeRelfilenodeMap */
ScanKeyData relfilenode_skey[2];
typedef struct {
Oid reltablespace;
Oid relfilenode;
@ -79,26 +76,27 @@ static void RelfilenodeMapInvalidateCallback(Datum arg, Oid relid)
* RelfilenodeMapInvalidateCallback
* Initialize cache, either on first use or after a reset.
*/
static void InitializeRelfilenodeMap(void)
static void InitializeRelfilenodeMap()
{
HASHCTL ctl;
int i;
/* build skey */
errno_t ret = memset_s(&relfilenode_skey, sizeof(relfilenode_skey), 0, sizeof(relfilenode_skey));
errno_t ret = memset_s(&u_sess->relmap_cxt.relfilenodeSkey, sizeof(u_sess->relmap_cxt.relfilenodeSkey), 0,
sizeof(u_sess->relmap_cxt.relfilenodeSkey));
securec_check(ret, "\0", "\0");
for (i = 0; i < 2; i++) {
fmgr_info_cxt(F_OIDEQ, &relfilenode_skey[i].sk_func, u_sess->cache_mem_cxt);
relfilenode_skey[i].sk_strategy = BTEqualStrategyNumber;
relfilenode_skey[i].sk_subtype = InvalidOid;
relfilenode_skey[i].sk_collation = InvalidOid;
fmgr_info_cxt(F_OIDEQ, &u_sess->relmap_cxt.relfilenodeSkey[i].sk_func, u_sess->cache_mem_cxt);
u_sess->relmap_cxt.relfilenodeSkey[i].sk_strategy = BTEqualStrategyNumber;
u_sess->relmap_cxt.relfilenodeSkey[i].sk_subtype = InvalidOid;
u_sess->relmap_cxt.relfilenodeSkey[i].sk_collation = InvalidOid;
}
relfilenode_skey[0].sk_attno = Anum_pg_class_reltablespace;
relfilenode_skey[1].sk_attno = Anum_pg_class_relfilenode;
u_sess->relmap_cxt.relfilenodeSkey[0].sk_attno = Anum_pg_class_reltablespace;
u_sess->relmap_cxt.relfilenodeSkey[1].sk_attno = Anum_pg_class_relfilenode;
/* Initialize the hash table. */
HASHCTL ctl;
ret = memset_s(&ctl, sizeof(ctl), 0, sizeof(ctl));
securec_check(ret, "\0", "\0");
ctl.keysize = sizeof(RelfilenodeMapKey);
@ -135,8 +133,9 @@ Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
ScanKeyData skey[2];
Oid relid;
int rc = 0;
if (u_sess->relmap_cxt.RelfilenodeMapHash == NULL)
if (u_sess->relmap_cxt.RelfilenodeMapHash == NULL) {
InitializeRelfilenodeMap();
}
/* pg_class will show 0 when the value is actually u_sess->proc_cxt.MyDatabaseTableSpace */
if (reltablespace == u_sess->proc_cxt.MyDatabaseTableSpace)
@ -185,7 +184,7 @@ Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
relation = heap_open(RelationRelationId, AccessShareLock);
/* copy scankey to local copy, it will be modified during the scan */
rc = memcpy_s(skey, sizeof(skey), relfilenode_skey, sizeof(skey));
rc = memcpy_s(skey, sizeof(skey), u_sess->relmap_cxt.relfilenodeSkey, sizeof(skey));
securec_check(rc, "", "");
/* set scan arguments */
@ -264,7 +263,7 @@ Oid PartitionRelidByRelfilenode(Oid reltablespace, Oid relfilenode, Oid& partati
/* check plain relations by looking in pg_class */
relation = heap_open(PartitionRelationId, AccessShareLock);
rc = memcpy_s(skey, sizeof(skey), relfilenode_skey, sizeof(skey));
rc = memcpy_s(skey, sizeof(skey), u_sess->relmap_cxt.relfilenodeSkey, sizeof(skey));
securec_check(rc, "", "");
skey[0].sk_attno = Anum_pg_partition_reltablespace;
skey[1].sk_attno = Anum_pg_partition_relfilenode;

View File

@ -44,6 +44,7 @@
#include <signal.h>
#include "access/skey.h"
#include "c.h"
#include "datatype/timestamp.h"
#include "gs_thread.h"
@ -1735,6 +1736,7 @@ typedef struct knl_u_relmap_context {
struct RelMapFile* pending_shared_updates;
struct RelMapFile* pending_local_updates;
struct ScanKeyData relfilenodeSkey[2];
/* Hash table for informations about each relfilenode <-> oid pair */
struct HTAB* RelfilenodeMapHash;
} knl_u_relmap_context;