Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8892eaa

Browse files
knizhnikkelvich
authored andcommitted
Optimize sending replication of relation information
1 parent cf3e9c5 commit 8892eaa

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

pglogical_proto.c

+28-13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static int MtmTransactionRecords;
4242
static bool MtmIsFilteredTxn;
4343
static TransactionId MtmCurrentXid;
4444
static bool DDLInProgress = false;
45+
static Oid MtmSenderTID; /* transaction identifier for WAL sender */
4546

4647
static void pglogical_write_rel(StringInfo out, PGLogicalOutputData *data, Relation rel);
4748

@@ -80,6 +81,7 @@ pglogical_write_rel(StringInfo out, PGLogicalOutputData *data, Relation rel)
8081
const char *relname;
8182
uint8 relnamelen;
8283
Oid relid;
84+
Oid tid;
8385

8486
if (MtmIsFilteredTxn) {
8587
MTM_LOG2("%d: pglogical_write_message filtered", MyProcPid);
@@ -92,23 +94,32 @@ pglogical_write_rel(StringInfo out, PGLogicalOutputData *data, Relation rel)
9294
}
9395

9496
relid = RelationGetRelid(rel);
97+
9598
pq_sendbyte(out, 'R'); /* sending RELATION */
9699
pq_sendint(out, relid, sizeof relid); /* use Oid as relation identifier */
97100

98-
nspname = get_namespace_name(rel->rd_rel->relnamespace);
99-
if (nspname == NULL)
100-
elog(ERROR, "cache lookup failed for namespace %u",
101+
Assert(MtmSenderTID != InvalidOid);
102+
tid = pglogical_relid_map_get(relid);
103+
if (tid == MtmSenderTID) { /* this relation was already sent in this transaction */
104+
pq_sendbyte(out, 0); /* do not need to send relation namespace and name in this case */
105+
pq_sendbyte(out, 0);
106+
} else {
107+
pglogical_relid_map_put(relid, MtmSenderTID);
108+
nspname = get_namespace_name(rel->rd_rel->relnamespace);
109+
if (nspname == NULL)
110+
elog(ERROR, "cache lookup failed for namespace %u",
101111
rel->rd_rel->relnamespace);
102-
nspnamelen = strlen(nspname) + 1;
103-
104-
relname = NameStr(rel->rd_rel->relname);
105-
relnamelen = strlen(relname) + 1;
106-
107-
pq_sendbyte(out, nspnamelen); /* schema name length */
108-
pq_sendbytes(out, nspname, nspnamelen);
109-
110-
pq_sendbyte(out, relnamelen); /* table name length */
111-
pq_sendbytes(out, relname, relnamelen);
112+
nspnamelen = strlen(nspname) + 1;
113+
114+
relname = NameStr(rel->rd_rel->relname);
115+
relnamelen = strlen(relname) + 1;
116+
117+
pq_sendbyte(out, nspnamelen); /* schema name length */
118+
pq_sendbytes(out, nspname, nspnamelen);
119+
120+
pq_sendbyte(out, relnamelen); /* table name length */
121+
pq_sendbytes(out, relname, relnamelen);
122+
}
112123
}
113124

114125
/*
@@ -128,6 +139,10 @@ pglogical_write_begin(StringInfo out, PGLogicalOutputData *data,
128139
MtmIsFilteredTxn = true;
129140
MTM_LOG2("%d: pglogical_write_begin XID=%lld filtered", MyProcPid, (long64)txn->xid);
130141
} else {
142+
if (++MtmSenderTID == InvalidOid) {
143+
pglogical_relid_map_reset();
144+
MtmSenderTID += 1; /* skip InvalidOid */
145+
}
131146
MtmCurrentXid = txn->xid;
132147
MtmIsFilteredTxn = false;
133148
MTM_LOG3("%d: pglogical_write_begin XID=%d node=%d CSN=%lld recovery=%d restart_decoding_lsn=%llx first_lsn=%llx end_lsn=%llx confirmed_flush=%llx",

pglogical_relid_map.c

+8
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@ bool pglogical_relid_map_put(Oid remote_relid, Oid local_relid)
6464
entry->local_relid = local_relid;
6565
return true;
6666
}
67+
68+
void pglogical_relid_map_reset(void)
69+
{
70+
if (relid_map != NULL) {
71+
hash_destroy(relid_map);
72+
relid_map = NULL;
73+
}
74+
}

pglogical_relid_map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ typedef struct PGLRelidMapEntry {
1010

1111
extern Oid pglogical_relid_map_get(Oid relid);
1212
extern bool pglogical_relid_map_put(Oid remote_relid, Oid local_relid);
13-
13+
extern void pglogical_relid_map_reset(void);
1414
#endif

0 commit comments

Comments
 (0)