Miscalculation in IsCheckpointOnSchedule() - Mailing list pgsql-patches

From ITAGAKI Takahiro
Subject Miscalculation in IsCheckpointOnSchedule()
Date
Msg-id 20071114132759.30E4.ITAGAKI.TAKAHIRO@oss.ntt.co.jp
Whole thread Raw
Responses Re: Miscalculation in IsCheckpointOnSchedule()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
I run long DBT-2 with 8.3beta2 and saw checkpoint spikes periodically.
The progress against WAL segments consumption *jumped up* in such cases.

It seems to be a miscalculation in IsCheckpointOnSchedule().
xrecoff is uint32, therefore the difference of two xrecoffs could
be between -4G and +4G. We should not cast it to int32, that domain
is [-2G, +2G).

Here is a patch to fix it, casting xrecoff to double directly.

Index: src/backend/postmaster/bgwriter.c
===================================================================
--- src/backend/postmaster/bgwriter.c    (HEAD)
+++ src/backend/postmaster/bgwriter.c    (working copy)
@@ -718,7 +718,7 @@
     recptr = GetInsertRecPtr();
     elapsed_xlogs =
         (((double) (int32) (recptr.xlogid - ckpt_start_recptr.xlogid)) * XLogSegsPerFile +
-         ((double) (int32) (recptr.xrecoff - ckpt_start_recptr.xrecoff)) / XLogSegSize) /
+         ((double) recptr.xrecoff - (double) ckpt_start_recptr.xrecoff) / XLogSegSize) /
         CheckPointSegments;

     if (progress < elapsed_xlogs)

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: Better default_statistics_target
Next
From: Tom Lane
Date:
Subject: Re: Miscalculation in IsCheckpointOnSchedule()