OSDN Git Service

Introduce replication timeout for synchronous replication.
authorMasaoFujii <masao.fujii@gmail.com>
Fri, 3 Dec 2010 02:53:06 +0000 (11:53 +0900)
committerMasaoFujii <masao.fujii@gmail.com>
Fri, 3 Dec 2010 02:53:06 +0000 (11:53 +0900)
src/backend/replication/walsender.c

index 5513e53..3b86bd7 100644 (file)
@@ -583,15 +583,24 @@ WalSndLoop(void)
                                 */
 
                                /*
-                                * Check for replication timeout if it's enabled and we need to
-                                * wait for the socket to be writable to flush pending WAL in
-                                * output buffer.
+                                * Check for replication timeout if it's enabled and we need
+                                * to wait until the socket has become writable to flush
+                                * pending WAL in output buffer or until the Ack message
+                                * from the standby has become available.
                                 */
-                               check_timeout = replication_timeout > 0 && pending;
-                               if (check_timeout)
+                               if (replication_timeout > 0 &&
+                                       (pending ||
+                                        (rplMode != REPLICATION_MODE_ASYNC &&
+                                         XLByteLT(ackdPtr, sentPtr))))
+                               {
                                        sleeptime = replication_timeout;
+                                       check_timeout = true;
+                               }
                                else
+                               {
                                        sleeptime = WalSndDelay;
+                                       check_timeout = false;
+                               }
 
                                /* Sleep */
                                res = WaitLatchOrSocket(&MyWalSnd->latch, MyProcPort->sock,