Fix incorrect calculation of LSN in bytes.
authorTatsuo Ishii <ishii at sraoss.co.jp>
Thu, 5 May 2011 02:39:14 +0000 (02:39 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Thu, 5 May 2011 02:39:14 +0000 (02:39 +0000)
Change pg_last_xlog_receive_location() to
pg_last_xlog_replay_location() because the latter respects actually
replayed location which will give less chance for clients to have
stale data in standby.

Fix suggested by Anton Yuzhaninov.

pool_worker_child.c

index 612cedaee955c3790b3c10197d3b316b2715a907..014190e661ddf02d5092d8a088bf37ecc736c39c 100644 (file)
@@ -233,7 +233,7 @@ static void check_replication_time_lag(void)
                }
                else
                {
-                       query = "SELECT pg_last_xlog_receive_location()";
+                       query = "SELECT pg_last_xlog_replay_location()";
                }
 
                sts = do_query(slots[i]->con, query, &res, PROTO_MAJOR_V3);
@@ -307,6 +307,12 @@ static void check_replication_time_lag(void)
  */
 static long text_to_lsn(char *text)
 {
+/*
+ * WAL segment size in bytes.  XXX We should fetch this from
+ * PostgreSQL, rather than having fixed value.
+ */
+#define WALSEGMENTSIZE 16 * 1024 * 1024
+
        unsigned int xlogid;
        unsigned int xrecoff;
        unsigned long long int lsn;
@@ -316,7 +322,10 @@ static long text_to_lsn(char *text)
                pool_error("text_to_lsn: wrong log location format: %s", text);
                return 0;
        }
-       lsn = xlogid * 16 * 1024 * 1024 * 255 + xrecoff;
+       lsn = xlogid * ((unsigned long long int)0xffffffff - WALSEGMENTSIZE) + xrecoff;
+#ifdef DEBUG
+       pool_log("lsn: %X %X %llX", xlogid, xrecoff, lsn);
+#endif
        return lsn;
 }