27
27
28
28
#include "access/tupdesc.h"
29
29
#include "catalog/pg_type_d.h"
30
+ #include "executor/executor.h"
30
31
#include "libpq/libpq.h"
31
32
#include "libpq/pqformat.h"
32
33
#include "replication/basebackup.h"
33
34
#include "replication/basebackup_sink.h"
34
35
#include "tcop/dest.h"
36
+ #include "utils/builtins.h"
35
37
#include "utils/timestamp.h"
36
38
37
39
typedef struct bbsink_copystream
@@ -86,7 +88,6 @@ static void SendCopyOutResponse(void);
86
88
static void SendCopyDone (void );
87
89
static void SendXlogRecPtrResult (XLogRecPtr ptr , TimeLineID tli );
88
90
static void SendTablespaceList (List * tablespaces );
89
- static void send_int8_string (StringInfoData * buf , int64 intval );
90
91
91
92
static const bbsink_ops bbsink_copystream_ops = {
92
93
.begin_backup = bbsink_copystream_begin_backup ,
@@ -339,10 +340,10 @@ static void
339
340
SendXlogRecPtrResult (XLogRecPtr ptr , TimeLineID tli )
340
341
{
341
342
DestReceiver * dest ;
343
+ TupOutputState * tstate ;
342
344
TupleDesc tupdesc ;
343
- StringInfoData buf ;
344
- char str [MAXFNAMELEN ];
345
- Size len ;
345
+ Datum values [2 ];
346
+ bool nulls [2 ] = {0 };
346
347
347
348
dest = CreateDestReceiver (DestRemoteSimple );
348
349
@@ -355,22 +356,14 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
355
356
TupleDescInitBuiltinEntry (tupdesc , (AttrNumber ) 2 , "tli" , INT8OID , -1 , 0 );
356
357
357
358
/* send RowDescription */
358
- dest -> rStartup (dest , CMD_SELECT , tupdesc );
359
+ tstate = begin_tup_output_tupdesc (dest , tupdesc , & TTSOpsVirtual );
359
360
360
361
/* 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 );
368
365
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 );
374
367
375
368
/* Send a CommandComplete message */
376
369
pq_puttextmessage ('C' , "SELECT" );
@@ -383,8 +376,8 @@ static void
383
376
SendTablespaceList (List * tablespaces )
384
377
{
385
378
DestReceiver * dest ;
379
+ TupOutputState * tstate ;
386
380
TupleDesc tupdesc ;
387
- StringInfoData buf ;
388
381
ListCell * lc ;
389
382
390
383
dest = CreateDestReceiver (DestRemoteSimple );
@@ -395,51 +388,33 @@ SendTablespaceList(List *tablespaces)
395
388
TupleDescInitBuiltinEntry (tupdesc , (AttrNumber ) 3 , "size" , INT8OID , -1 , 0 );
396
389
397
390
/* send RowDescription */
398
- dest -> rStartup (dest , CMD_SELECT , tupdesc );
391
+ tstate = begin_tup_output_tupdesc (dest , tupdesc , & TTSOpsVirtual );
399
392
400
393
/* Construct and send the directory information */
401
394
foreach (lc , tablespaces )
402
395
{
403
396
tablespaceinfo * ti = lfirst (lc );
397
+ Datum values [3 ];
398
+ bool nulls [3 ] = {0 };
404
399
405
400
/* Send one datarow message */
406
- pq_beginmessage (& buf , 'D' );
407
- pq_sendint16 (& buf , 3 ); /* number of columns */
408
401
if (ti -> path == NULL )
409
402
{
410
- pq_sendint32 ( & buf , -1 ); /* Length = -1 ==> NULL */
411
- pq_sendint32 ( & buf , -1 ) ;
403
+ nulls [ 0 ] = true;
404
+ nulls [ 1 ] = true ;
412
405
}
413
406
else
414
407
{
415
- Size len ;
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 );
424
410
}
425
411
if (ti -> size >= 0 )
426
- send_int8_string ( & buf , ti -> size / 1024 );
412
+ values [ 2 ] = Int64GetDatum ( ti -> size / 1024 );
427
413
else
428
- pq_sendint32 ( & buf , -1 ); /* NULL */
414
+ nulls [ 2 ] = true;
429
415
430
- pq_endmessage ( & buf );
416
+ do_tup_output ( tstate , values , nulls );
431
417
}
432
- }
433
-
434
- /*
435
- * Send a 64-bit integer as a string via the wire protocol.
436
- */
437
- static void
438
- send_int8_string (StringInfoData * buf , int64 intval )
439
- {
440
- char is [32 ];
441
418
442
- sprintf (is , INT64_FORMAT , intval );
443
- pq_sendint32 (buf , strlen (is ));
444
- pq_sendbytes (buf , is , strlen (is ));
419
+ end_tup_output (tstate );
445
420
}
0 commit comments