Skip to content

Commit 424954a

Browse files
Chao Li (Evan)hackorum
authored andcommitted
Use simple struct for table sync COPY buffer state
copy_read_data() only needs to track the COPY buffer's data pointer, length, and cursor position. Replace the StringInfo with a small local struct containing just those fields. Author: Chao Li <lic@highgo.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/5B2C9B4C-EAE6-4F21-AF99-613A561D26DC@gmail.com
1 parent 086f6f1 commit 424954a

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/backend/replication/logical/tablesync.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@
126126

127127
List *table_states_not_ready = NIL;
128128

129-
static StringInfo copybuf = NULL;
129+
typedef struct CopyBuf
130+
{
131+
char *data;
132+
int len;
133+
int cursor;
134+
} CopyBuf;
135+
136+
static CopyBuf copybuf;
130137

131138
/*
132139
* Wait until the relation sync state is set in the catalog to the expected
@@ -649,13 +656,13 @@ copy_read_data(void *outbuf, int minread, int maxread)
649656
int avail;
650657

651658
/* If there are some leftover data from previous read, use it. */
652-
avail = copybuf->len - copybuf->cursor;
659+
avail = copybuf.len - copybuf.cursor;
653660
if (avail)
654661
{
655662
if (avail > maxread)
656663
avail = maxread;
657-
memcpy(outbuf, &copybuf->data[copybuf->cursor], avail);
658-
copybuf->cursor += avail;
664+
memcpy(outbuf, &copybuf.data[copybuf.cursor], avail);
665+
copybuf.cursor += avail;
659666
maxread -= avail;
660667
bytesread += avail;
661668
}
@@ -680,16 +687,16 @@ copy_read_data(void *outbuf, int minread, int maxread)
680687
else
681688
{
682689
/* Process the data */
683-
copybuf->data = buf;
684-
copybuf->len = len;
685-
copybuf->cursor = 0;
690+
copybuf.data = buf;
691+
copybuf.len = len;
692+
copybuf.cursor = 0;
686693

687-
avail = copybuf->len - copybuf->cursor;
694+
avail = copybuf.len - copybuf.cursor;
688695
if (avail > maxread)
689696
avail = maxread;
690-
memcpy(outbuf, &copybuf->data[copybuf->cursor], avail);
697+
memcpy(outbuf, &copybuf.data[copybuf.cursor], avail);
691698
outbuf = (char *) outbuf + avail;
692-
copybuf->cursor += avail;
699+
copybuf.cursor += avail;
693700
maxread -= avail;
694701
bytesread += avail;
695702
}
@@ -1199,7 +1206,7 @@ copy_table(Relation rel)
11991206
lrel.nspname, lrel.relname, res->err)));
12001207
walrcv_clear_result(res);
12011208

1202-
copybuf = makeStringInfo();
1209+
memset(&copybuf, 0, sizeof(copybuf));
12031210

12041211
pstate = make_parsestate(NULL);
12051212
(void) addRangeTableEntryForRelation(pstate, rel, AccessShareLock,

0 commit comments

Comments
 (0)