* IsCheckpointOnSchedule -- are we on schedule to finish this checkpoint * (or restartpoint) in time? * * Compares the current progress against the time/segments elapsed since last * checkpoint, and returns true if the progress we've made this far is greater * than the elapsed time/segments. */
| 774 | * than the elapsed time/segments. |
| 775 | */ |
| 776 | static bool |
| 777 | IsCheckpointOnSchedule(double progress) |
| 778 | { |
| 779 | XLogRecPtr recptr; |
| 780 | struct timeval now; |
| 781 | double elapsed_xlogs, |
| 782 | elapsed_time; |
| 783 | |
| 784 | Assert(ckpt_active); |
| 785 | |
| 786 | /* Scale progress according to checkpoint_completion_target. */ |
| 787 | progress *= CheckPointCompletionTarget; |
| 788 | |
| 789 | /* |
| 790 | * Check against the cached value first. Only do the more expensive |
| 791 | * calculations once we reach the target previously calculated. Since |
| 792 | * neither time or WAL insert pointer moves backwards, a freshly |
| 793 | * calculated value can only be greater than or equal to the cached value. |
| 794 | */ |
| 795 | if (progress < ckpt_cached_elapsed) |
| 796 | return false; |
| 797 | |
| 798 | /* |
| 799 | * Check progress against WAL segments written and CheckPointSegments. |
| 800 | * |
| 801 | * We compare the current WAL insert location against the location |
| 802 | * computed before calling CreateCheckPoint. The code in XLogInsert that |
| 803 | * actually triggers a checkpoint when CheckPointSegments is exceeded |
| 804 | * compares against RedoRecPtr, so this is not completely accurate. |
| 805 | * However, it's good enough for our purposes, we're only calculating an |
| 806 | * estimate anyway. |
| 807 | * |
| 808 | * During recovery, we compare last replayed WAL record's location with |
| 809 | * the location computed before calling CreateRestartPoint. That maintains |
| 810 | * the same pacing as we have during checkpoints in normal operation, but |
| 811 | * we might exceed max_wal_size by a fair amount. That's because there can |
| 812 | * be a large gap between a checkpoint's redo-pointer and the checkpoint |
| 813 | * record itself, and we only start the restartpoint after we've seen the |
| 814 | * checkpoint record. (The gap is typically up to CheckPointSegments * |
| 815 | * checkpoint_completion_target where checkpoint_completion_target is the |
| 816 | * value that was in effect when the WAL was generated). |
| 817 | */ |
| 818 | if (RecoveryInProgress()) |
| 819 | recptr = GetXLogReplayRecPtr(NULL); |
| 820 | else |
| 821 | recptr = GetInsertRecPtr(); |
| 822 | elapsed_xlogs = (((double) (recptr - ckpt_start_recptr)) / |
| 823 | wal_segment_size) / CheckPointSegments; |
| 824 | |
| 825 | if (progress < elapsed_xlogs) |
| 826 | { |
| 827 | ckpt_cached_elapsed = elapsed_xlogs; |
| 828 | return false; |
| 829 | } |
| 830 | |
| 831 | /* |
| 832 | * Check progress against time elapsed and checkpoint_timeout. |
| 833 | */ |
no test coverage detected