Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit55b7e2f

Browse files
committed
Fix two bugs in MaintainOldSnapshotTimeMapping.
The previous coding was confused about whether head_timestamp wasintended to represent the timestamp for the newest bucket in themapping or the oldest timestamp for the oldest bucket in the mapping.Decide that it's intended to be the oldest one, and repairaccordingly.To do that, we need to do two things. First, when advancing to anew bucket, don't categorically set head_timestamp to the newtimestamp. Do this only if we're blowing out the map completelybecause a lot of time has passed since we last maintained it. Ifwe're replacing entries one by one, advance head_timestamp by1 minute for each; if we're filling in unused entries, don'tadvance head_timestamp at all.Second, fix the computation of how many buckets we need to advance.The previous formula would be correct if head_timestamp were thetimestamp for the new bucket, but we're now making all the codeagree that it's the timestamp for the oldest bucket, so adjust theformula accordingly.This is certainly a bug fix, but I don't feel good aboutback-patching it without the introspection tools added by commitaecf5ee, and perhaps also someactual tests. Since back-patching the introspection tools mightnot attract sufficient support and since there are no automatedtests of these fixes yet, I'm just committing this to master fornow.Patch by me, reviewed by Thomas Munro, Dilip Kumar, Hamid Akhtar.Discussion:http://postgr.es/m/CA+TgmoY=aqf0zjTD+3dUWYkgMiNDegDLFjo+6ze=Wtpik+3XqA@mail.gmail.com
1 parentc005eb0 commit55b7e2f

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

‎src/backend/utils/time/snapmgr.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,17 +1949,40 @@ MaintainOldSnapshotTimeMapping(TimestampTz whenTaken, TransactionId xmin)
19491949
else
19501950
{
19511951
/* We need a new bucket, but it might not be the very next one. */
1952-
intadvance= ((ts-oldSnapshotControl->head_timestamp)
1953-
/USECS_PER_MINUTE);
1952+
intdistance_to_new_tail;
1953+
intdistance_to_current_tail;
1954+
intadvance;
19541955

1955-
oldSnapshotControl->head_timestamp=ts;
1956+
/*
1957+
* Our goal is for the new "tail" of the mapping, that is, the entry
1958+
* which is newest and thus furthest from the "head" entry, to
1959+
* correspond to "ts". Since there's one entry per minute, the
1960+
* distance between the current head and the new tail is just the
1961+
* number of minutes of difference between ts and the current
1962+
* head_timestamp.
1963+
*
1964+
* The distance from the current head to the current tail is one
1965+
* less than the number of entries in the mapping, because the
1966+
* entry at the head_offset is for 0 minutes after head_timestamp.
1967+
*
1968+
* The difference between these two values is the number of minutes
1969+
* by which we need to advance the mapping, either adding new entries
1970+
* or rotating old ones out.
1971+
*/
1972+
distance_to_new_tail=
1973+
(ts-oldSnapshotControl->head_timestamp) /USECS_PER_MINUTE;
1974+
distance_to_current_tail=
1975+
oldSnapshotControl->count_used-1;
1976+
advance=distance_to_new_tail-distance_to_current_tail;
1977+
Assert(advance>0);
19561978

19571979
if (advance >=OLD_SNAPSHOT_TIME_MAP_ENTRIES)
19581980
{
19591981
/* Advance is so far that all old data is junk; start over. */
19601982
oldSnapshotControl->head_offset=0;
19611983
oldSnapshotControl->count_used=1;
19621984
oldSnapshotControl->xid_by_minute[0]=xmin;
1985+
oldSnapshotControl->head_timestamp=ts;
19631986
}
19641987
else
19651988
{
@@ -1978,6 +2001,7 @@ MaintainOldSnapshotTimeMapping(TimestampTz whenTaken, TransactionId xmin)
19782001
else
19792002
oldSnapshotControl->head_offset=old_head+1;
19802003
oldSnapshotControl->xid_by_minute[old_head]=xmin;
2004+
oldSnapshotControl->head_timestamp+=USECS_PER_MINUTE;
19812005
}
19822006
else
19832007
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp