pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hari Babu <haribabu.kommi@huawei.com>
To: 'Boszormenyi Zoltan' <zb@cybertec.at>
Cc: 'Fujii Masao' <masao.fujii@gmail.com>
Cc: 'Heikki Linnakangas' <hlinnakangas@vmware.com>
Cc: pgsql-hackers@postgresql.org
Cc: 'Amit kapila' <amit.kapila@huawei.com>
Subject: Re: Review of "pg_basebackup and pg_receivexlog to use non-blocking socket communication", was: Re: Re: [BUGS] BUG #7534: walreceiver takes long time to detect n/w breakdown
Date: Fri, 4 Jan 2013 18:13:08 +0530
Message-ID: <007701cdea79$0cf35b30$26da1190$@kommi@huawei.com> (raw)
References: <E1TBlX1-0003OA-SB@wrigleys.postgresql.org>
	<CAHGQGwG2cWJ+Fr+AroXEA3=26Yrc_C4yMW6HJ8rhX9nKm7Z0NA@mail.gmail.com>
	<6C0B27F7206C9E4CA54AE035729E9C38285337FF@szxeml509-mbs>
	<506972B9.6060104@vmware.com>
	<6C0B27F7206C9E4CA54AE035729E9C38285358F7@szxeml509-mbs>
	<506AA530.30106@vmware.com>
	<6C0B27F7206C9E4CA54AE035729E9C382853645A@szxeml509-mbs>
	<507597E2.8090701@vmware.com>
	<5076DD38.8020804@vmware.com>
	<CAHGQGwHyMwP8YqmcDynrsGbOax=dL7HmxAnZ68Azr36_7wJ0WQ@mail.gmail.com>
	<507BE1AD.2060709@vmware.com>
	<507e9adc.43db440a.5351.fffff4d0SMTPIN_ADDED@mx.google.com>
	<CAHGQGwHcYME6VdGwwfOrbA27A5ju+MyL4WwaUDK_tPtZ2_uNoQ@mail.gmail.com>
	<6C0B27F7206C9E4CA54AE035729E9C382853BBED@szxeml509-mbs>
	<509B6E66.9070408@vmware.com>
	<CAHGQGwGdYJ1tJDHH+FURgaJhRR1kmpvKatpBdmgLsk7ZMhYKPA@mail.gmail.com>
	<509c9cd1.494f420a.3fc7.4362SMTPIN_ADDED@mx.google.com>
	<CAHGQGwHxvOUPrtXDBMtDGHc7+7dEsF7G4GmfN2_CTPKeQXqe_Q@mail.gmail.com>
	<6C0B27F7206C9E4CA54AE035729E9C38285499FA@szxeml509-mbx>
	<50E31370.5030405@cybertec.at>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>


On January 02, 2013 12:41 PM Hari Babu wrote:
>On January 01, 2013 10:19 PM Boszormenyi Zoltan wrote:
>>I am reviewing your patch.
>>• Is the patch in context diff format? 
>>Yes.
>
>Thanks for reviewing the patch.
>
>>• Does it apply cleanly to the current git master?
>>Not quite cleanly but it doesn't produce rejects or fuzz, only offset
warnings:
>
>Will rebase the patch to head.
>
>>• Does it include reasonable tests, necessary doc patches, etc? 
>>The test cases are not applicable. There is no test framework for
>>testing network outage in "make check".
>>
>>There are no documentation patches for the new --recvtimeout=INTERVAL
>>and --conntimeout=INTERVAL options for either pg_basebackup or
>>pg_receivexlog.
>
>I will add the documentation for the same.
>
>>Per the previous comment, no. But those are for the backend
>>to notice network breakdowns and as such, they need a
>>separate patch. 
>
>I also think it is better to handle it as a separate patch for walsender.
>
>>• Are the comments sufficient and accurate?
>>This chunk below removes a comment which seems obvious enough
>>so it's not needed:
>>***************
>>*** 518,524 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos,
uint32 timeline,
>>                        goto error;
>>                }
>>  
>>!               /* Check the message type. */
>>                if (copybuf[0] == 'k')
>>                {
>>                        int             pos;
>>--- 559,568 ----
>>                        goto error;
>>                }
>>  
>>!               /* Set the last reply timestamp */
>>!               last_recv_timestamp = localGetCurrentTimestamp();
>>!               ping_sent = false;
>>!               
>>                if (copybuf[0] == 'k')
>>                {
>>                        int             pos;
>>***************
>>
>>Other comments are sufficient and accurate.
>
>I will fix and update the patch.

The attached V2 patch in the mail handles all the review comments identified
above.

Regards,
Hari babu.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

pg_basebkup_recvxlog_noblock_comm_v2.patch (application/octet-stream, 24.3K) download *** a/doc/src/sgml/ref/pg_basebackup.sgml --- b/doc/src/sgml/ref/pg_basebackup.sgml *************** *** 386,391 **** PostgreSQL documentation --- 386,411 ---- </varlistentry> <varlistentry> + <term><option>-r <replaceable class="parameter">interval</replaceable></option></term> + <term><option>--recvtimeout=<replaceable class="parameter">interval</replaceable></option></term> + <listitem> + <para> + time that receiver waits for communication from server (in seconds). + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-t <replaceable class="parameter">interval</replaceable></option></term> + <term><option>--conntimeout=<replaceable class="parameter">interval</replaceable></option></term> + <listitem> + <para> + time that client wait for connection to establish with server (in seconds). + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-U <replaceable>username</replaceable></option></term> <term><option>--username=<replaceable class="parameter">username</replaceable></option></term> <listitem> *** a/doc/src/sgml/ref/pg_receivexlog.sgml --- b/doc/src/sgml/ref/pg_receivexlog.sgml *************** *** 164,169 **** PostgreSQL documentation --- 164,189 ---- </varlistentry> <varlistentry> + <term><option>-r <replaceable class="parameter">interval</replaceable></option></term> + <term><option>--recvtimeout=<replaceable class="parameter">interval</replaceable></option></term> + <listitem> + <para> + time that receiver waits for communication from server (in seconds). + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-t <replaceable class="parameter">interval</replaceable></option></term> + <term><option>--conntimeout=<replaceable class="parameter">interval</replaceable></option></term> + <listitem> + <para> + time that client wait for connection to establish with server (in seconds). + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-U <replaceable>username</replaceable></option></term> <term><option>--username=<replaceable class="parameter">username</replaceable></option></term> <listitem> *** a/src/bin/pg_basebackup/pg_basebackup.c --- b/src/bin/pg_basebackup/pg_basebackup.c *************** *** 41,46 **** bool includewal = false; --- 41,50 ---- bool streamwal = false; bool fastcheckpoint = false; int standby_message_timeout = 10 * 1000; /* 10 sec = default */ + int standby_recv_timeout = 60*1000; /* 60 sec = default */ + char *standby_connect_timeout = NULL; + + #define NAPTIME_PER_CYCLE 100 /* max sleep time between cycles (100ms) */ /* Progress counters */ static uint64 totalsize; *************** *** 119,124 **** usage(void) --- 123,132 ---- printf(_(" -p, --port=PORT database server port number\n")); printf(_(" -s, --status-interval=INTERVAL\n" " time between status packets sent to server (in seconds)\n")); + printf(_(" -r, --recvtimeout=INTERVAL time that receiver waits for communication from\n" + " server (in seconds)\n")); + printf(_(" -t, --conntimeout=INTERVAL time that client wait for connection to establish\n" + " with server (in seconds)\n")); printf(_(" -U, --username=NAME connect as specified database user\n")); printf(_(" -w, --no-password never prompt for password\n")); printf(_(" -W, --password force password prompt (should happen automatically)\n")); *************** *** 231,238 **** LogStreamerMain(logstreamer_param *param) { if (!ReceiveXlogStream(param->bgconn, param->startptr, param->timeline, param->sysidentifier, param->xlogdir, ! reached_end_position, standby_message_timeout, ! true)) /* * Any errors will already have been reported in the function process, --- 239,246 ---- { if (!ReceiveXlogStream(param->bgconn, param->startptr, param->timeline, param->sysidentifier, param->xlogdir, ! reached_end_position, standby_message_timeout, ! standby_recv_timeout, true)) /* * Any errors will already have been reported in the function process, *************** *** 284,291 **** StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier) } #endif ! /* Get a second connection */ ! param->bgconn = GetConnection(); if (!param->bgconn) /* Error message already written in GetConnection() */ exit(1); --- 292,300 ---- } #endif ! /* Get a second connection. Sending connect_timeout ! * as configured, there is no need for rw_timeout.*/ ! param->bgconn = GetConnection(standby_connect_timeout); if (!param->bgconn) /* Error message already written in GetConnection() */ exit(1); *************** *** 461,466 **** ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) --- 470,476 ---- char filename[MAXPGPATH]; char *copybuf = NULL; FILE *tarfile = NULL; + int64 last_recv_timestamp; #ifdef HAVE_LIBZ gzFile ztarfile = NULL; *************** *** 578,586 **** ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) --- 588,599 ---- disconnect_and_exit(1); } + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); while (1) { int r; + int64 now; if (copybuf != NULL) { *************** *** 588,594 **** ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) copybuf = NULL; } ! r = PQgetCopyData(conn, &copybuf, 0); if (r == -1) { /* --- 601,662 ---- copybuf = NULL; } ! r = PQgetCopyData(conn, &copybuf, 1); ! if (r == 0) ! { ! /* ! * In async mode, and no data available. We block on reading but ! * not more than the specified timeout, so that we can send a ! * response back to the client. ! */ ! fd_set input_mask; ! struct timeval timeout; ! ! FD_ZERO(&input_mask); ! FD_SET(PQsocket(conn), &input_mask); ! timeout.tv_sec = 0; ! timeout.tv_usec = NAPTIME_PER_CYCLE*1000; ! ! r = select(PQsocket(conn) + 1, &input_mask, NULL, NULL, &timeout); ! if (r == 0 || (r < 0 && errno == EINTR)) ! { ! /* ! * Got a timeout or signal. Before Continuing the loop, check for timeout. ! */ ! if (standby_recv_timeout > 0) ! { ! now = localGetCurrentTimestamp(); ! if (localTimestampDifferenceExceeds(last_recv_timestamp, now, standby_recv_timeout)) ! { ! fprintf(stderr, _("%s: terminating DB File receive due to timeout\n"), ! progname); ! disconnect_and_exit(1); ! } ! } ! ! continue; ! } ! else if (r < 0) ! { ! fprintf(stderr, _("%s: select() failed: %s\n"), ! progname, strerror(errno)); ! disconnect_and_exit(1); ! } ! /* Else there is actually data on the socket */ ! if (PQconsumeInput(conn) == 0) ! { ! fprintf(stderr, ! _("%s: could not receive data from WAL Sender: %s"), ! progname, PQerrorMessage(conn)); ! disconnect_and_exit(1); ! } ! ! /* Set the last reply timestamp */ ! last_recv_timestamp = localGetCurrentTimestamp(); ! ! /* Some data is received, so go back read them in buffer*/ ! continue; ! } if (r == -1) { /* *************** *** 659,664 **** ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) --- 727,735 ---- disconnect_and_exit(1); } + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); + #ifdef HAVE_LIBZ if (ztarfile != NULL) { *************** *** 708,713 **** ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) --- 779,785 ---- int current_padding = 0; char *copybuf = NULL; FILE *file = NULL; + int64 last_recv_timestamp; if (PQgetisnull(res, rownum, 0)) strcpy(current_path, basedir); *************** *** 725,733 **** ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) --- 797,809 ---- disconnect_and_exit(1); } + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); while (1) { int r; + int64 now; + if (copybuf != NULL) { *************** *** 735,742 **** ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) copybuf = NULL; } ! r = PQgetCopyData(conn, &copybuf, 0); if (r == -1) { /* --- 811,872 ---- copybuf = NULL; } ! r = PQgetCopyData(conn, &copybuf, 1); ! if (r == 0) ! { ! /* ! * In async mode, and no data available. We block on reading but ! * not more than the specified timeout, so that we can send a ! * response back to the client. ! */ ! fd_set input_mask; ! struct timeval timeout; ! ! FD_ZERO(&input_mask); ! FD_SET(PQsocket(conn), &input_mask); ! timeout.tv_sec = 0; ! timeout.tv_usec = NAPTIME_PER_CYCLE*1000; + r = select(PQsocket(conn) + 1, &input_mask, NULL, NULL, &timeout); + if (r == 0 || (r < 0 && errno == EINTR)) + { + /* + * Got a timeout or signal. Before Continuing the loop, check for timeout. + */ + if (standby_recv_timeout > 0) + { + now = localGetCurrentTimestamp(); + if (localTimestampDifferenceExceeds(last_recv_timestamp, now, standby_recv_timeout)) + { + fprintf(stderr, _("%s: terminating DB File receive due to timeout\n"), + progname); + disconnect_and_exit(1); + } + } + + continue; + } + else if (r < 0) + { + fprintf(stderr, _("%s: select() failed: %s\n"), + progname, strerror(errno)); + disconnect_and_exit(1); + } + /* Else there is actually data on the socket */ + if (PQconsumeInput(conn) == 0) + { + fprintf(stderr, + _("%s: could not receive data from WAL Sender: %s"), + progname, PQerrorMessage(conn)); + disconnect_and_exit(1); + } + + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); + + /* Some data is received, so go back read them in buffer*/ + continue; + } if (r == -1) { /* *************** *** 749,759 **** ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) } else if (r == -2) { fprintf(stderr, _("%s: could not read COPY data: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } ! if (file == NULL) { int filemode; --- 879,892 ---- } else if (r == -2) { + fprintf(stderr, "\n"); fprintf(stderr, _("%s: could not read COPY data: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } ! ! /* Set the last reply timestamp */ ! last_recv_timestamp = localGetCurrentTimestamp(); if (file == NULL) { int filemode; *************** *** 947,955 **** BaseBackup(void) char xlogend[64]; /* ! * Connect in replication mode to the server */ ! conn = GetConnection(); if (!conn) /* Error message already written in GetConnection() */ exit(1); --- 1080,1088 ---- char xlogend[64]; /* ! * Connect in replication mode to the server. Sending connect_timeout. */ ! conn = GetConnection(standby_connect_timeout); if (!conn) /* Error message already written in GetConnection() */ exit(1); *************** *** 1248,1253 **** main(int argc, char **argv) --- 1381,1388 ---- {"no-password", no_argument, NULL, 'w'}, {"password", no_argument, NULL, 'W'}, {"status-interval", required_argument, NULL, 's'}, + {"recvtimeout", required_argument, NULL, 'r'}, + {"conntimeout", required_argument, NULL, 't'}, {"verbose", no_argument, NULL, 'v'}, {"progress", no_argument, NULL, 'P'}, {NULL, 0, NULL, 0} *************** *** 1274,1280 **** main(int argc, char **argv) } } ! while ((c = getopt_long(argc, argv, "D:F:xX:l:zZ:c:h:p:U:s:wWvP", long_options, &option_index)) != -1) { switch (c) --- 1409,1415 ---- } } ! while ((c = getopt_long(argc, argv, "D:F:xX:l:zZ:c:h:p:U:s:r:t:wWvP", long_options, &option_index)) != -1) { switch (c) *************** *** 1386,1391 **** main(int argc, char **argv) --- 1521,1546 ---- exit(1); } break; + case 'r': + standby_recv_timeout = atoi(optarg)*1000; + if (standby_recv_timeout < 0) + { + fprintf(stderr, _("%s: invalid recv timeout \"%s\"\n"), + progname, optarg); + exit(1); + } + + break; + case 't': + if (atoi(optarg) < 0) + { + fprintf(stderr, _("%s: invalid connect timeout \"%s\"\n"), + progname, optarg); + exit(1); + } + + standby_connect_timeout = pg_strdup(optarg); + break; case 'v': verbose++; break; *** a/src/bin/pg_basebackup/pg_receivexlog.c --- b/src/bin/pg_basebackup/pg_receivexlog.c *************** *** 35,40 **** char *basedir = NULL; --- 35,42 ---- int verbose = 0; int noloop = 0; int standby_message_timeout = 10 * 1000; /* 10 sec = default */ + int standby_recv_timeout = 60*1000; /* 60 sec = default */ + char *standby_connect_timeout = NULL; volatile bool time_to_abort = false; *************** *** 63,68 **** usage(void) --- 65,74 ---- printf(_(" -p, --port=PORT database server port number\n")); printf(_(" -s, --status-interval=INTERVAL\n" " time between status packets sent to server (in seconds)\n")); + printf(_(" -r, --recvtimeout=INTERVAL time that receiver waits for communication from\n" + " server (in seconds)\n")); + printf(_(" -t, --conntimeout=INTERVAL time that client wait for connection to establish\n" + " with server (in seconds)\n")); printf(_(" -U, --username=NAME connect as specified database user\n")); printf(_(" -w, --no-password never prompt for password\n")); printf(_(" -W, --password force password prompt (should happen automatically)\n")); *************** *** 218,226 **** StreamLog(void) lo; /* ! * Connect in replication mode to the server */ ! conn = GetConnection(); if (!conn) /* Error message already written in GetConnection() */ return; --- 224,233 ---- lo; /* ! * Connect in replication mode to the server, Sending connect_timeout ! * as configured, there is no need for rw_timeout. */ ! conn = GetConnection(standby_connect_timeout); if (!conn) /* Error message already written in GetConnection() */ return; *************** *** 274,280 **** StreamLog(void) timeline); ReceiveXlogStream(conn, startpos, timeline, NULL, basedir, ! stop_streaming, standby_message_timeout, false); PQfinish(conn); } --- 281,288 ---- timeline); ReceiveXlogStream(conn, startpos, timeline, NULL, basedir, ! stop_streaming, standby_message_timeout, ! standby_recv_timeout, false); PQfinish(conn); } *************** *** 306,311 **** main(int argc, char **argv) --- 314,321 ---- {"no-password", no_argument, NULL, 'w'}, {"password", no_argument, NULL, 'W'}, {"status-interval", required_argument, NULL, 's'}, + {"recvtimeout", required_argument, NULL, 'r'}, + {"conntimeout", required_argument, NULL, 't'}, {"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; *************** *** 331,337 **** main(int argc, char **argv) } } ! while ((c = getopt_long(argc, argv, "D:h:p:U:s:nwWv", long_options, &option_index)) != -1) { switch (c) --- 341,347 ---- } } ! while ((c = getopt_long(argc, argv, "D:h:p:U:s:r:t:nwWv", long_options, &option_index)) != -1) { switch (c) *************** *** 369,374 **** main(int argc, char **argv) --- 379,404 ---- exit(1); } break; + case 'r': + standby_recv_timeout = atoi(optarg)*1000; + if (standby_recv_timeout < 0) + { + fprintf(stderr, _("%s: invalid recv timeout \"%s\"\n"), + progname, optarg); + exit(1); + } + break; + case 't': + if (atoi(optarg) < 0) + { + fprintf(stderr, _("%s: invalid connect timeout \"%s\"\n"), + progname, optarg); + exit(1); + } + + standby_connect_timeout = pg_strdup(optarg); + break; + case 'n': noloop = 1; break; *** a/src/bin/pg_basebackup/receivelog.c --- b/src/bin/pg_basebackup/receivelog.c *************** *** 181,187 **** close_walfile(char *basedir, char *walname, bool segment_complete) * backend code. The protocol always uses integer timestamps, regardless of * server setting. */ ! static int64 localGetCurrentTimestamp(void) { int64 result; --- 181,187 ---- * backend code. The protocol always uses integer timestamps, regardless of * server setting. */ ! int64 localGetCurrentTimestamp(void) { int64 result; *************** *** 201,207 **** localGetCurrentTimestamp(void) * Local version of TimestampDifference(), since we are not linked with * backend code. */ ! static void localTimestampDifference(int64 start_time, int64 stop_time, long *secs, int *microsecs) { --- 201,207 ---- * Local version of TimestampDifference(), since we are not linked with * backend code. */ ! void localTimestampDifference(int64 start_time, int64 stop_time, long *secs, int *microsecs) { *************** *** 223,229 **** localTimestampDifference(int64 start_time, int64 stop_time, * Local version of TimestampDifferenceExceeds(), since we are not * linked with backend code. */ ! static bool localTimestampDifferenceExceeds(int64 start_time, int64 stop_time, int msec) --- 223,229 ---- * Local version of TimestampDifferenceExceeds(), since we are not * linked with backend code. */ ! bool localTimestampDifferenceExceeds(int64 start_time, int64 stop_time, int msec) *************** *** 333,339 **** bool ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysidentifier, char *basedir, stream_stop_callback stream_stop, ! int standby_message_timeout, bool rename_partial) { char query[128]; char current_walfile_name[MAXPGPATH]; --- 333,340 ---- ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysidentifier, char *basedir, stream_stop_callback stream_stop, ! int standby_message_timeout, ! int standby_recv_timeout, bool rename_partial) { char query[128]; char current_walfile_name[MAXPGPATH]; *************** *** 341,346 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, --- 342,349 ---- char *copybuf = NULL; int64 last_status = -1; XLogRecPtr blockpos = InvalidXLogRecPtr; + int64 last_recv_timestamp; + bool ping_sent = false; if (sysidentifier != NULL) { *************** *** 394,399 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, --- 397,406 ---- } PQclear(res); + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); + ping_sent = false; + /* * Receive the actual xlog data */ *************** *** 477,486 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, if (r == 0 || (r < 0 && errno == EINTR)) { /* ! * Got a timeout or signal. Continue the loop and either ! * deliver a status packet to the server or just go back into * blocking. */ continue; } else if (r < 0) --- 484,522 ---- if (r == 0 || (r < 0 && errno == EINTR)) { /* ! * Got a timeout or signal. Before Continuing the loop, check for timeout. ! * and then either deliver a status packet to the server or just go back into * blocking. */ + if (standby_recv_timeout > 0) + { + now = localGetCurrentTimestamp(); + if (localTimestampDifferenceExceeds(last_recv_timestamp, now, standby_recv_timeout)) + { + fprintf(stderr, _("%s: terminating XLogStream receiver due to timeout\n"), + progname); + goto error; + } + + /* + * We didn't receive anything new, for half of receiver + * replication timeout. Ping the server, if not already done. + */ + if (!ping_sent) + { + if (localTimestampDifferenceExceeds(last_recv_timestamp, now, (standby_recv_timeout/2))) + { + if (!sendFeedback(conn, blockpos, now, true)) + { + goto error; + } + + last_status = now; + ping_sent = true; + } + } + } + continue; } else if (r < 0) *************** *** 497,502 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, --- 533,543 ---- progname, PQerrorMessage(conn)); goto error; } + + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); + ping_sent = false; + continue; } if (r == -1) *************** *** 509,514 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, --- 550,559 ---- goto error; } + /* Set the last reply timestamp */ + last_recv_timestamp = localGetCurrentTimestamp(); + ping_sent = false; + /* Check the message type. */ if (copybuf[0] == 'k') { *** a/src/bin/pg_basebackup/receivelog.h --- b/src/bin/pg_basebackup/receivelog.h *************** *** 7,16 **** typedef bool (*stream_stop_callback) (XLogRecPtr segendpos, uint32 timeline, bool segment_finished); extern bool ReceiveXlogStream(PGconn *conn, ! XLogRecPtr startpos, ! uint32 timeline, ! char *sysidentifier, ! char *basedir, ! stream_stop_callback stream_stop, ! int standby_message_timeout, ! bool rename_partial); --- 7,24 ---- typedef bool (*stream_stop_callback) (XLogRecPtr segendpos, uint32 timeline, bool segment_finished); extern bool ReceiveXlogStream(PGconn *conn, ! XLogRecPtr startpos, ! uint32 timeline, ! char *sysidentifier, ! char *basedir, ! stream_stop_callback stream_stop, ! int standby_message_timeout, ! int standby_recv_timeout, ! bool rename_partial); ! ! extern int64 localGetCurrentTimestamp(void); ! extern void localTimestampDifference(int64 start_time, int64 stop_time, ! long *secs, int *microsecs); ! extern bool localTimestampDifferenceExceeds(int64 start_time, ! int64 stop_time, ! int msec); *** a/src/bin/pg_basebackup/streamutil.c --- b/src/bin/pg_basebackup/streamutil.c *************** *** 66,74 **** pg_malloc0(size_t size) * Connect to the server. Returns a valid PGconn pointer if connected, * or NULL on non-permanent error. On permanent error, the function will * call exit(1) directly. */ PGconn * ! GetConnection(void) { PGconn *tmpconn; int argcount = 4; /* dbname, replication, fallback_app_name, --- 66,76 ---- * Connect to the server. Returns a valid PGconn pointer if connected, * or NULL on non-permanent error. On permanent error, the function will * call exit(1) directly. + * Set conn_timeout to PGconn structure if their value + * is not NULL. */ PGconn * ! GetConnection(char *conn_timeout) { PGconn *tmpconn; int argcount = 4; /* dbname, replication, fallback_app_name, *************** *** 85,90 **** GetConnection(void) --- 87,94 ---- argcount++; if (dbport) argcount++; + if (conn_timeout) + argcount++; keywords = pg_malloc0((argcount + 1) * sizeof(*keywords)); values = pg_malloc0((argcount + 1) * sizeof(*values)); *************** *** 114,119 **** GetConnection(void) --- 118,129 ---- values[i] = dbport; i++; } + if (conn_timeout != NULL) + { + keywords[i] = "connect_timeout"; + values[i] = conn_timeout; + i++; + } while (true) { *** a/src/bin/pg_basebackup/streamutil.h --- b/src/bin/pg_basebackup/streamutil.h *************** *** 19,22 **** extern PGconn *conn; extern char *pg_strdup(const char *s); extern void *pg_malloc0(size_t size); ! extern PGconn *GetConnection(void); --- 19,22 ---- extern char *pg_strdup(const char *s); extern void *pg_malloc0(size_t size); ! PGconn *GetConnection(char *conn_timeout); =

view thread (11+ messages)  latest in thread

Message-ID: <007701cdea79$0cf35b30$26da1190$@kommi@huawei.com>
Permalink:  ../007701cdea79$0cf35b30$26da1190$@kommi@huawei.com/
Also on:    postgresql.org/message-id/007701cdea79$0cf35b30$26da1190$@kommi@huawei.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: haribabu.kommi@huawei.com, zb@cybertec.at, masao.fujii@gmail.com, hlinnakangas@vmware.com, pgsql-hackers@postgresql.org, amit.kapila@huawei.com
  Subject: Re: Review of "pg_basebackup and pg_receivexlog to use non-blocking socket communication", was: Re: Re: [BUGS] BUG #7534: walreceiver takes long time to detect n/w breakdown
  In-Reply-To: <007701cdea79$0cf35b30$26da1190$@kommi@huawei.com>
  References: <E1TBlX1-0003OA-SB@wrigleys.postgresql.org> <6C0B27F7206C9E4CA54AE035729E9C38285337FF@szxeml509-mbs> <506972B9.6060104@vmware.com> <6C0B27F7206C9E4CA54AE035729E9C38285358F7@szxeml509-mbs> <506AA530.30106@vmware.com> <6C0B27F7206C9E4CA54AE035729E9C382853645A@szxeml509-mbs> <507597E2.8090701@vmware.com> <5076DD38.8020804@vmware.com> <CAHGQGwHyMwP8YqmcDynrsGbOax=dL7HmxAnZ68Azr36_7wJ0WQ@mail.gmail.com> <507BE1AD.2060709@vmware.com> <507e9adc.43db440a.5351.fffff4d0SMTPIN_ADDED@mx.google.com> <CAHGQGwHcYME6VdGwwfOrbA27A5ju+MyL4WwaUDK_tPtZ2_uNoQ@mail.gmail.com> <6C0B27F7206C9E4CA54AE035729E9C382853BBED@szxeml509-mbs> <509B6E66.9070408@vmware.com> <CAHGQGwGdYJ1tJDHH+FURgaJhRR1kmpvKatpBdmgLsk7ZMhYKPA@mail.gmail.com> <509c9cd1.494f420a.3fc7.4362SMTPIN_ADDED@mx.google.com> <CAHGQGwHxvOUPrtXDBMtDGHc7+7dEsF7G4GmfN2_CTPKeQXqe_Q@mail.gmail.com> <6C0B27F7206C9E4CA54AE035729E9C38285499FA@szxeml509-mbx> <50E31370.5030405@cybertec.at> <007701cdea79$0cf35b30$26da1190$@kommi@huawei.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox