On Fri, Apr 17, 2020 at 5:46 AM Andres Freund <and...@anarazel.de> wrote: > On 2020-04-16 13:34:39 -0400, Robert Haas wrote: > > On Thu, Apr 16, 2020 at 1:14 PM Andres Freund <and...@anarazel.de> wrote: > > > I still think we need a way to test this without waiting for hours to > > > hit various edge cases. You argued against a fixed binning of > > > old_snapshot_threshold/100 arguing its too coarse. How about a 1000 or > > > so? For 60 days, the current max for old_snapshot_threshold, that'd be a > > > granularity of 01:26:24, which seems fine. The best way I can think of > > > that'd keep current GUC values sensible is to change > > > old_snapshot_threshold to be float. Ugly, but ...? > > > > Yeah, 1000 would be a lot better. However, if we switch to a fixed > > number of bins, it's going to be a lot more code churn. > > Given the number of things that need to be addressed around the feature, > I am not too concerned about that. > > > > What did you think of my suggestion of making head_timestamp > > artificially move backward to simulate the passage of time? > > I don't think it allows to exercise the various cases well enough. We > need to be able to test this feature both interactively as well as in a > scripted manner. Edge cases like wrapping around in the time mapping imo > can not easily be tested by moving the head timestamp back.
What about a contrib function that lets you clobber oldSnapshotControl->current_timestamp? It looks like all times in this system come ultimately from GetSnapshotCurrentTimestamp(), which uses that variable to make sure that time never goes backwards. Perhaps you could abuse that, like so, from test scripts: postgres=# select * from pg_old_snapshot_time_mapping(); array_offset | end_timestamp | newest_xmin --------------+------------------------+------------- 0 | 3000-01-01 13:00:00+13 | 490 (1 row) postgres=# select pg_clobber_current_snapshot_timestamp('3000-01-01 00:01:00Z'); pg_clobber_current_snapshot_timestamp --------------------------------------- (1 row) postgres=# select * from pg_old_snapshot_time_mapping(); array_offset | end_timestamp | newest_xmin --------------+------------------------+------------- 0 | 3000-01-01 13:01:00+13 | 490 1 | 3000-01-01 13:02:00+13 | 490 (2 rows)
From 76fe56b732cdc420aeb7cb3b2adcc1e45343b0f7 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Fri, 17 Apr 2020 14:10:35 +1200 Subject: [PATCH 3/3] Add pg_clobber_current_snapshot_timestamp(). --- contrib/old_snapshot/old_snapshot--1.0.sql | 5 +++++ contrib/old_snapshot/time_mapping.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/contrib/old_snapshot/old_snapshot--1.0.sql b/contrib/old_snapshot/old_snapshot--1.0.sql index 9ebb8829e3..aacf1704b5 100644 --- a/contrib/old_snapshot/old_snapshot--1.0.sql +++ b/contrib/old_snapshot/old_snapshot--1.0.sql @@ -11,4 +11,9 @@ RETURNS SETOF record AS 'MODULE_PATHNAME', 'pg_old_snapshot_time_mapping' LANGUAGE C STRICT; +CREATE FUNCTION pg_clobber_current_snapshot_timestamp(now timestamptz) +RETURNS VOID +AS 'MODULE_PATHNAME', 'pg_clobber_current_snapshot_timestamp' +LANGUAGE C STRICT; + -- XXX. Do we want REVOKE commands here? diff --git a/contrib/old_snapshot/time_mapping.c b/contrib/old_snapshot/time_mapping.c index 37e0055a00..8728c4ddb5 100644 --- a/contrib/old_snapshot/time_mapping.c +++ b/contrib/old_snapshot/time_mapping.c @@ -36,6 +36,7 @@ typedef struct PG_MODULE_MAGIC; PG_FUNCTION_INFO_V1(pg_old_snapshot_time_mapping); +PG_FUNCTION_INFO_V1(pg_clobber_current_snapshot_timestamp); static OldSnapshotTimeMapping *GetOldSnapshotTimeMapping(void); static TupleDesc MakeOldSnapshotTimeMappingTupleDesc(void); @@ -157,3 +158,15 @@ MakeOldSnapshotTimeMappingTuple(TupleDesc tupdesc, OldSnapshotTimeMapping *mappi return heap_form_tuple(tupdesc, values, nulls); } + +Datum +pg_clobber_current_snapshot_timestamp(PG_FUNCTION_ARGS) +{ + TimestampTz new_current_timestamp = PG_GETARG_TIMESTAMPTZ(0); + + LWLockAcquire(OldSnapshotTimeMapLock, LW_EXCLUSIVE); + oldSnapshotControl->current_timestamp = new_current_timestamp; + LWLockRelease(OldSnapshotTimeMapLock); + + PG_RETURN_NULL(); +} -- 2.20.1