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

Commit16d52fc

Browse files
committed
Refactor sending of DataRow messages in replication protocol
Some routines open-coded the construction of DataRow messages. UseTupOutputState struct and associated functions instead, which wasalready done in some places.SendTimeLineHistory() is a bit more complicated and isn't converted bythis.Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/7e4fdbdc-699c-4cd0-115d-fb78a957fc22@enterprisedb.com
1 parentb55f62a commit16d52fc

File tree

2 files changed

+33
-47
lines changed

2 files changed

+33
-47
lines changed

‎src/backend/access/common/printsimple.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ printsimple(TupleTableSlot *slot, DestReceiver *self)
121121
}
122122
break;
123123

124+
caseOIDOID:
125+
{
126+
Oidnum=ObjectIdGetDatum(value);
127+
charstr[10];/* 10 digits */
128+
intlen;
129+
130+
len=pg_ultoa_n(num,str);
131+
pq_sendcountedtext(&buf,str,len, false);
132+
}
133+
break;
134+
124135
default:
125136
elog(ERROR,"unsupported type OID: %u",attr->atttypid);
126137
}

‎src/backend/replication/basebackup_copy.c

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727

2828
#include"access/tupdesc.h"
2929
#include"catalog/pg_type_d.h"
30+
#include"executor/executor.h"
3031
#include"libpq/libpq.h"
3132
#include"libpq/pqformat.h"
3233
#include"replication/basebackup.h"
3334
#include"replication/basebackup_sink.h"
3435
#include"tcop/dest.h"
36+
#include"utils/builtins.h"
3537
#include"utils/timestamp.h"
3638

3739
typedefstructbbsink_copystream
@@ -86,7 +88,6 @@ static void SendCopyOutResponse(void);
8688
staticvoidSendCopyDone(void);
8789
staticvoidSendXlogRecPtrResult(XLogRecPtrptr,TimeLineIDtli);
8890
staticvoidSendTablespaceList(List*tablespaces);
89-
staticvoidsend_int8_string(StringInfoData*buf,int64intval);
9091

9192
staticconstbbsink_opsbbsink_copystream_ops= {
9293
.begin_backup=bbsink_copystream_begin_backup,
@@ -339,10 +340,10 @@ static void
339340
SendXlogRecPtrResult(XLogRecPtrptr,TimeLineIDtli)
340341
{
341342
DestReceiver*dest;
343+
TupOutputState*tstate;
342344
TupleDesctupdesc;
343-
StringInfoDatabuf;
344-
charstr[MAXFNAMELEN];
345-
Sizelen;
345+
Datumvalues[2];
346+
boolnulls[2]= {0};
346347

347348
dest=CreateDestReceiver(DestRemoteSimple);
348349

@@ -355,22 +356,14 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
355356
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber)2,"tli",INT8OID,-1,0);
356357

357358
/* send RowDescription */
358-
dest->rStartup(dest,CMD_SELECT,tupdesc);
359+
tstate=begin_tup_output_tupdesc(dest,tupdesc,&TTSOpsVirtual);
359360

360361
/* Data row */
361-
pq_beginmessage(&buf,'D');
362-
pq_sendint16(&buf,2);/* number of columns */
363-
364-
len=snprintf(str,sizeof(str),
365-
"%X/%X",LSN_FORMAT_ARGS(ptr));
366-
pq_sendint32(&buf,len);
367-
pq_sendbytes(&buf,str,len);
362+
values[0]=CStringGetTextDatum(psprintf("%X/%X",LSN_FORMAT_ARGS(ptr)));
363+
values[1]=Int64GetDatum(tli);
364+
do_tup_output(tstate,values,nulls);
368365

369-
len=snprintf(str,sizeof(str),"%u",tli);
370-
pq_sendint32(&buf,len);
371-
pq_sendbytes(&buf,str,len);
372-
373-
pq_endmessage(&buf);
366+
end_tup_output(tstate);
374367

375368
/* Send a CommandComplete message */
376369
pq_puttextmessage('C',"SELECT");
@@ -383,8 +376,8 @@ static void
383376
SendTablespaceList(List*tablespaces)
384377
{
385378
DestReceiver*dest;
379+
TupOutputState*tstate;
386380
TupleDesctupdesc;
387-
StringInfoDatabuf;
388381
ListCell*lc;
389382

390383
dest=CreateDestReceiver(DestRemoteSimple);
@@ -395,51 +388,33 @@ SendTablespaceList(List *tablespaces)
395388
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber)3,"size",INT8OID,-1,0);
396389

397390
/* send RowDescription */
398-
dest->rStartup(dest,CMD_SELECT,tupdesc);
391+
tstate=begin_tup_output_tupdesc(dest,tupdesc,&TTSOpsVirtual);
399392

400393
/* Construct and send the directory information */
401394
foreach(lc,tablespaces)
402395
{
403396
tablespaceinfo*ti=lfirst(lc);
397+
Datumvalues[3];
398+
boolnulls[3]= {0};
404399

405400
/* Send one datarow message */
406-
pq_beginmessage(&buf,'D');
407-
pq_sendint16(&buf,3);/* number of columns */
408401
if (ti->path==NULL)
409402
{
410-
pq_sendint32(&buf,-1);/* Length = -1 ==> NULL */
411-
pq_sendint32(&buf,-1);
403+
nulls[0]= true;
404+
nulls[1]= true;
412405
}
413406
else
414407
{
415-
Sizelen;
416-
417-
len=strlen(ti->oid);
418-
pq_sendint32(&buf,len);
419-
pq_sendbytes(&buf,ti->oid,len);
420-
421-
len=strlen(ti->path);
422-
pq_sendint32(&buf,len);
423-
pq_sendbytes(&buf,ti->path,len);
408+
values[0]=ObjectIdGetDatum(strtoul(ti->oid,NULL,10));
409+
values[1]=CStringGetTextDatum(ti->path);
424410
}
425411
if (ti->size >=0)
426-
send_int8_string(&buf,ti->size /1024);
412+
values[2]=Int64GetDatum(ti->size /1024);
427413
else
428-
pq_sendint32(&buf,-1);/* NULL */
414+
nulls[2]= true;
429415

430-
pq_endmessage(&buf);
416+
do_tup_output(tstate,values,nulls);
431417
}
432-
}
433-
434-
/*
435-
* Send a 64-bit integer as a string via the wire protocol.
436-
*/
437-
staticvoid
438-
send_int8_string(StringInfoData*buf,int64intval)
439-
{
440-
charis[32];
441418

442-
sprintf(is,INT64_FORMAT,intval);
443-
pq_sendint32(buf,strlen(is));
444-
pq_sendbytes(buf,is,strlen(is));
419+
end_tup_output(tstate);
445420
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp