Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac7d6f5

Browse files
committed
Make use of initReadOnlyStringInfo() in more places
f0efa5a introduced the concept of "read-only" StringInfos which makesuse of an existing, possibly not NUL terminated, buffer.Here we adjust two places that make use of StringInfos to receive datato avoid using appendBinaryStringInfo() in cases where a NUL terminationcharacter is not required. This saves a possible palloc() and saveshaving to needlessly memcpy() from one buffer to another.Here we adjust two places which were using appendBinaryStringInfo().Neither of these cases seem particularly performance-critical. In thecase of XLogWalRcvProcessMsg(), the appendBinaryStringInfo() was onlyappending 24 bytes. The change made here does mean that we can get ridof the incoming_message global variable and make that local instead.The apply_spooled_messages() case applies in logical decoding whenapplying (possibly large) changes which have been serialized to a file.Reviewed-by: Amit KapilaDiscussion:https://postgr.es/m/CAApHDvoxYUDHwqPf-ShvchsERf1RzmkGoLwg63JNvHCkDCuyKQ@mail.gmail.com
1 parent18b5851 commitac7d6f5

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

‎src/backend/replication/logical/worker.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,6 @@ void
20192019
apply_spooled_messages(FileSet*stream_fileset,TransactionIdxid,
20202020
XLogRecPtrlsn)
20212021
{
2022-
StringInfoDatas2;
20232022
intnchanges;
20242023
charpath[MAXPGPATH];
20252024
char*buffer=NULL;
@@ -2057,7 +2056,6 @@ apply_spooled_messages(FileSet *stream_fileset, TransactionId xid,
20572056
CurrentResourceOwner=oldowner;
20582057

20592058
buffer=palloc(BLCKSZ);
2060-
initStringInfo(&s2);
20612059

20622060
MemoryContextSwitchTo(oldcxt);
20632061

@@ -2079,6 +2077,7 @@ apply_spooled_messages(FileSet *stream_fileset, TransactionId xid,
20792077
nchanges=0;
20802078
while (true)
20812079
{
2080+
StringInfoDatas2;
20822081
size_tnbytes;
20832082
intlen;
20842083

@@ -2104,9 +2103,8 @@ apply_spooled_messages(FileSet *stream_fileset, TransactionId xid,
21042103

21052104
BufFileTell(stream_fd,&fileno,&offset);
21062105

2107-
/* copy the buffer to the stringinfo and call apply_dispatch */
2108-
resetStringInfo(&s2);
2109-
appendBinaryStringInfo(&s2,buffer,len);
2106+
/* init a stringinfo using the buffer and call apply_dispatch */
2107+
initReadOnlyStringInfo(&s2,buffer,len);
21102108

21112109
/* Ensure we are reading the data into our memory context. */
21122110
oldcxt=MemoryContextSwitchTo(ApplyMessageContext);

‎src/backend/replication/walreceiver.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ typedef enum WalRcvWakeupReason
132132
staticTimestampTzwakeup[NUM_WALRCV_WAKEUPS];
133133

134134
staticStringInfoDatareply_message;
135-
staticStringInfoDataincoming_message;
136135

137136
/* Prototypes for private functions */
138137
staticvoidWalRcvFetchTimeLineHistoryFiles(TimeLineIDfirst,TimeLineIDlast);
@@ -425,7 +424,6 @@ WalReceiverMain(void)
425424
/* Initialize LogstreamResult and buffers for processing messages */
426425
LogstreamResult.Write=LogstreamResult.Flush=GetXLogReplayRecPtr(NULL);
427426
initStringInfo(&reply_message);
428-
initStringInfo(&incoming_message);
429427

430428
/* Initialize nap wakeup times. */
431429
now=GetCurrentTimestamp();
@@ -843,19 +841,20 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len, TimeLineID tli)
843841
TimestampTzsendTime;
844842
boolreplyRequested;
845843

846-
resetStringInfo(&incoming_message);
847-
848844
switch (type)
849845
{
850846
case'w':/* WAL records */
851847
{
852-
/* copy message to StringInfo */
848+
StringInfoDataincoming_message;
849+
853850
hdrlen=sizeof(int64)+sizeof(int64)+sizeof(int64);
854851
if (len<hdrlen)
855852
ereport(ERROR,
856853
(errcode(ERRCODE_PROTOCOL_VIOLATION),
857854
errmsg_internal("invalid WAL message received from primary")));
858-
appendBinaryStringInfo(&incoming_message,buf,hdrlen);
855+
856+
/* initialize a StringInfo with the given buffer */
857+
initReadOnlyStringInfo(&incoming_message,buf,hdrlen);
859858

860859
/* read the fields */
861860
dataStart=pq_getmsgint64(&incoming_message);
@@ -870,13 +869,16 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len, TimeLineID tli)
870869
}
871870
case'k':/* Keepalive */
872871
{
873-
/* copy message to StringInfo */
872+
StringInfoDataincoming_message;
873+
874874
hdrlen=sizeof(int64)+sizeof(int64)+sizeof(char);
875875
if (len!=hdrlen)
876876
ereport(ERROR,
877877
(errcode(ERRCODE_PROTOCOL_VIOLATION),
878878
errmsg_internal("invalid keepalive message received from primary")));
879-
appendBinaryStringInfo(&incoming_message,buf,hdrlen);
879+
880+
/* initialize a StringInfo with the given buffer */
881+
initReadOnlyStringInfo(&incoming_message,buf,hdrlen);
880882

881883
/* read the fields */
882884
walEnd=pq_getmsgint64(&incoming_message);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp