-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpglogical_relid_map.c
76 lines (66 loc) · 1.55 KB
/
pglogical_relid_map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*-------------------------------------------------------------------------
*
* pglogical_relid_map.c
* Logical Replication map of local Oids to to remote
*
* Portions Copyright (c) 2015-2021, Postgres Professional
* Portions Copyright (c) 2015-2020, PostgreSQL Global Development Group
*
*
* IDENTIFICATION
* pglogical_relid_map.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/hsearch.h"
#include "pglogical_relid_map.h"
static HTAB *relid_map;
static void
pglogical_relid_map_init(void)
{
HASHCTL ctl;
Assert(relid_map == NULL);
MemSet(&ctl, 0, sizeof(ctl));
ctl.keysize = sizeof(Oid);
ctl.entrysize = sizeof(PGLRelidMapEntry);
relid_map = hash_create("pglogical_relid_map", PGL_INIT_RELID_MAP_SIZE, &ctl, HASH_ELEM | HASH_BLOBS);
Assert(relid_map != NULL);
}
Oid
pglogical_relid_map_get(Oid relid)
{
if (relid_map != NULL)
{
PGLRelidMapEntry *entry = (PGLRelidMapEntry *) hash_search(relid_map, &relid, HASH_FIND, NULL);
return entry ? entry->local_relid : InvalidOid;
}
return InvalidOid;
}
bool
pglogical_relid_map_put(Oid remote_relid, Oid local_relid)
{
bool found;
PGLRelidMapEntry *entry;
if (relid_map == NULL)
{
pglogical_relid_map_init();
}
entry = hash_search(relid_map, &remote_relid, HASH_ENTER, &found);
if (found)
{
entry->local_relid = local_relid;
return false;
}
entry->local_relid = local_relid;
return true;
}
void
pglogical_relid_map_reset(void)
{
if (relid_map != NULL)
{
hash_destroy(relid_map);
relid_map = NULL;
}
}