3030 *
3131 *
3232 * IDENTIFICATION
33- * $PostgreSQL: pgsql/src/backend/replication/walsender.c,v 1.2 2010/01/15 11:47:15 heikki Exp $
33+ * $PostgreSQL: pgsql/src/backend/replication/walsender.c,v 1.3 2010/01/21 08:19:57 heikki Exp $
3434 *
3535 *-------------------------------------------------------------------------
3636 */
@@ -602,26 +602,18 @@ XLogSend(StringInfo outMsg)
602602 sentPtr .xrecoff == 0 )
603603 return true;
604604
605- /* Attempt to send all the records which were written to the disk */
605+ /* Attempt to send all records flushed to the disk already */
606606 SendRqstPtr = GetWriteRecPtr ();
607607
608608 /* Quick exit if nothing to do */
609609 if (!XLByteLT (sentPtr , SendRqstPtr ))
610610 return true;
611611
612612 /*
613- * Since successive pages in a segment are consecutively written,
614- * we can gather multiple records together by issuing just one
615- * read() call, and send them as one CopyData message at one time;
616- * nmsgs is the number of CopyData messages sent in this XLogSend;
617- * npages is the number of pages we have determined can be read and
618- * sent together; startpos is the starting position of reading and
619- * sending in the first page, startoff is the file offset at which
620- * it should go and endpos is the end position of reading and
621- * sending in the last page. We must initialize all of them to
622- * keep the compiler quiet.
613+ * We gather multiple records together by issuing just one read() of
614+ * a suitable size, and send them as one CopyData message. Repeat
615+ * until we've sent everything we can.
623616 */
624-
625617 while (XLByteLT (sentPtr , SendRqstPtr ))
626618 {
627619 XLogRecPtr startptr ;
@@ -631,31 +623,30 @@ XLogSend(StringInfo outMsg)
631623 /*
632624 * Figure out how much to send in one message. If there's less than
633625 * MAX_SEND_SIZE bytes to send, send everything. Otherwise send
634- * MAX_SEND_SIZE bytes, but round to page boundary for efficiency.
626+ * MAX_SEND_SIZE bytes, but round to page boundary.
627+ *
628+ * The rounding is not only for performance reasons. Walreceiver
629+ * relies on the fact that we never split a WAL record across two
630+ * messages. Since a long WAL record is split at page boundary into
631+ * continuation records, page boundary is alwayssafe cut-off point.
632+ * We also assume that SendRqstPtr never points in the middle of a
633+ * WAL record.
635634 */
636635 startptr = sentPtr ;
637636 endptr = startptr ;
638637 XLByteAdvance (endptr , MAX_SEND_SIZE );
639-
640- /*
641- * Round down to page boundary. This is not only for performance
642- * reasons, walreceiver relies on the fact that we never split a WAL
643- * record across two messages. Since a long WAL record is split at
644- * page boundary into continuation records, page boundary is always
645- * safe cut-off point. We also assume that SendRqstPtr never points
646- * in the middle of a WAL record.
647- */
638+ /* round down to page boundary. */
648639 endptr .xrecoff -= (endptr .xrecoff % XLOG_BLCKSZ );
649-
640+ /* if we went beyond SendRqstPtr, back off */
650641 if (XLByteLT (SendRqstPtr , endptr ))
651642 endptr = SendRqstPtr ;
652643
653644 /*
654- * OK to read and send the log .
645+ * OK to read and send the slice .
655646 *
656647 * We don't need to convert the xlogid/xrecoff from host byte order
657648 * to network byte order because the both server can be expected to
658- * have the same byte order. If they have the different order, we
649+ * have the same byte order. If they have different byte order, we
659650 * don't reach here.
660651 */
661652 pq_sendbytes (outMsg , (char * ) & startptr , sizeof (startptr ));
@@ -671,7 +662,7 @@ XLogSend(StringInfo outMsg)
671662 sentPtr = endptr ;
672663
673664 /*
674- * Read the log into the output buffer directly to prevent
665+ * Read the log directly into the output buffer to prevent
675666 * extra memcpy calls.
676667 */
677668 enlargeStringInfo (outMsg , nbytes );
0 commit comments