Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b607484

Browse files
Simplify vacuum_set_xid_limits() signature.
Pass VACUUM parameters (VacuumParams state) to vacuum_set_xid_limits() directly, rather than passing most individual VacuumParams fields as separate arguments. Also make vacuum_set_xid_limits() output parameter symbol names match those used by its vacuumlazy.c caller. Author: Peter Geoghegan <pg@bowt.ie> Discussion: https://postgr.es/m/CAH2-Wz=TE7gW5DgSahDkf0UEZigFGAoHNNN6EvSrdzC=Kn+hrA@mail.gmail.com
1 parent 02d647b commit b607484

File tree

4 files changed

+58
-61
lines changed

4 files changed

+58
-61
lines changed

src/backend/access/heap/vacuumlazy.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
360360
* an aggressive VACUUM then lazy_scan_heap cannot leave behind unfrozen
361361
* XIDs < FreezeLimit (all MXIDs < MultiXactCutoff also need to go away).
362362
*/
363-
aggressive = vacuum_set_xid_limits(rel,
364-
params->freeze_min_age,
365-
params->multixact_freeze_min_age,
366-
params->freeze_table_age,
367-
params->multixact_freeze_table_age,
368-
&OldestXmin, &OldestMxact,
363+
aggressive = vacuum_set_xid_limits(rel, params, &OldestXmin, &OldestMxact,
369364
&FreezeLimit, &MultiXactCutoff);
370365

371366
skipwithvm = true;

src/backend/commands/cluster.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
823823
Form_pg_class relform;
824824
TupleDesc oldTupDesc PG_USED_FOR_ASSERTS_ONLY;
825825
TupleDesc newTupDesc PG_USED_FOR_ASSERTS_ONLY;
826+
VacuumParams params;
826827
TransactionId OldestXmin,
827828
FreezeXid;
828829
MultiXactId OldestMxact,
@@ -914,7 +915,8 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
914915
* Since we're going to rewrite the whole table anyway, there's no reason
915916
* not to be aggressive about this.
916917
*/
917-
vacuum_set_xid_limits(OldHeap, 0, 0, 0, 0, &OldestXmin, &OldestMxact,
918+
memset(&params, 0, sizeof(VacuumParams));
919+
vacuum_set_xid_limits(OldHeap, &params, &OldestXmin, &OldestMxact,
918920
&FreezeXid, &MultiXactCutoff);
919921

920922
/*

src/backend/commands/vacuum.c

+49-45
Original file line numberDiff line numberDiff line change
@@ -929,51 +929,55 @@ get_all_vacuum_rels(int options)
929929
}
930930

931931
/*
932-
* vacuum_set_xid_limits() -- compute oldestXmin and freeze cutoff points
932+
* vacuum_set_xid_limits() -- compute OldestXmin and freeze cutoff points
933933
*
934-
* Input parameters are the target relation, applicable freeze age settings.
934+
* The target relation and VACUUM parameters are our inputs.
935935
*
936-
* The output parameters are:
937-
* - oldestXmin is the Xid below which tuples deleted by any xact (that
936+
* Our output parameters are:
937+
* - OldestXmin is the Xid below which tuples deleted by any xact (that
938938
* committed) should be considered DEAD, not just RECENTLY_DEAD.
939-
* - oldestMxact is the Mxid below which MultiXacts are definitely not
939+
* - OldestMxact is the Mxid below which MultiXacts are definitely not
940940
* seen as visible by any running transaction.
941-
* - freezeLimit is the Xid below which all Xids are definitely replaced by
942-
* FrozenTransactionId during aggressive vacuums.
943-
* - multiXactCutoff is the value below which all MultiXactIds are definitely
941+
* - FreezeLimit is the Xid below which all Xids are definitely frozen or
942+
* removed during aggressive vacuums.
943+
* - MultiXactCutoff is the value below which all MultiXactIds are definitely
944944
* removed from Xmax during aggressive vacuums.
945945
*
946946
* Return value indicates if vacuumlazy.c caller should make its VACUUM
947947
* operation aggressive. An aggressive VACUUM must advance relfrozenxid up to
948-
* FreezeLimit (at a minimum), and relminmxid up to multiXactCutoff (at a
948+
* FreezeLimit (at a minimum), and relminmxid up to MultiXactCutoff (at a
949949
* minimum).
950950
*
951-
* oldestXmin and oldestMxact are the most recent values that can ever be
951+
* OldestXmin and OldestMxact are the most recent values that can ever be
952952
* passed to vac_update_relstats() as frozenxid and minmulti arguments by our
953953
* vacuumlazy.c caller later on. These values should be passed when it turns
954954
* out that VACUUM will leave no unfrozen XIDs/MXIDs behind in the table.
955955
*/
956956
bool
957-
vacuum_set_xid_limits(Relation rel,
958-
int freeze_min_age,
959-
int multixact_freeze_min_age,
960-
int freeze_table_age,
961-
int multixact_freeze_table_age,
962-
TransactionId *oldestXmin,
963-
MultiXactId *oldestMxact,
964-
TransactionId *freezeLimit,
965-
MultiXactId *multiXactCutoff)
957+
vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
958+
TransactionId *OldestXmin, MultiXactId *OldestMxact,
959+
TransactionId *FreezeLimit, MultiXactId *MultiXactCutoff)
966960
{
961+
int freeze_min_age,
962+
multixact_freeze_min_age,
963+
freeze_table_age,
964+
multixact_freeze_table_age,
965+
effective_multixact_freeze_max_age;
967966
TransactionId nextXID,
968967
safeOldestXmin,
969968
aggressiveXIDCutoff;
970969
MultiXactId nextMXID,
971970
safeOldestMxact,
972971
aggressiveMXIDCutoff;
973-
int effective_multixact_freeze_max_age;
972+
973+
/* Use mutable copies of freeze age parameters */
974+
freeze_min_age = params->freeze_min_age;
975+
multixact_freeze_min_age = params->multixact_freeze_min_age;
976+
freeze_table_age = params->freeze_table_age;
977+
multixact_freeze_table_age = params->multixact_freeze_table_age;
974978

975979
/*
976-
* Acquire oldestXmin.
980+
* Acquire OldestXmin.
977981
*
978982
* We can always ignore processes running lazy vacuum. This is because we
979983
* use these values only for deciding which tuples we must keep in the
@@ -983,14 +987,14 @@ vacuum_set_xid_limits(Relation rel,
983987
* that only one vacuum process can be working on a particular table at
984988
* any time, and that each vacuum is always an independent transaction.
985989
*/
986-
*oldestXmin = GetOldestNonRemovableTransactionId(rel);
990+
*OldestXmin = GetOldestNonRemovableTransactionId(rel);
987991

988992
if (OldSnapshotThresholdActive())
989993
{
990994
TransactionId limit_xmin;
991995
TimestampTz limit_ts;
992996

993-
if (TransactionIdLimitedForOldSnapshots(*oldestXmin, rel,
997+
if (TransactionIdLimitedForOldSnapshots(*OldestXmin, rel,
994998
&limit_xmin, &limit_ts))
995999
{
9961000
/*
@@ -1000,15 +1004,15 @@ vacuum_set_xid_limits(Relation rel,
10001004
* frequency), but would still be a significant improvement.
10011005
*/
10021006
SetOldSnapshotThresholdTimestamp(limit_ts, limit_xmin);
1003-
*oldestXmin = limit_xmin;
1007+
*OldestXmin = limit_xmin;
10041008
}
10051009
}
10061010

1007-
Assert(TransactionIdIsNormal(*oldestXmin));
1011+
Assert(TransactionIdIsNormal(*OldestXmin));
10081012

1009-
/* Acquire oldestMxact */
1010-
*oldestMxact = GetOldestMultiXactId();
1011-
Assert(MultiXactIdIsValid(*oldestMxact));
1013+
/* Acquire OldestMxact */
1014+
*OldestMxact = GetOldestMultiXactId();
1015+
Assert(MultiXactIdIsValid(*OldestMxact));
10121016

10131017
/* Acquire next XID/next MXID values used to apply age-based settings */
10141018
nextXID = ReadNextTransactionId();
@@ -1025,13 +1029,13 @@ vacuum_set_xid_limits(Relation rel,
10251029
freeze_min_age = Min(freeze_min_age, autovacuum_freeze_max_age / 2);
10261030
Assert(freeze_min_age >= 0);
10271031

1028-
/* Compute freezeLimit, being careful to generate a normal XID */
1029-
*freezeLimit = nextXID - freeze_min_age;
1030-
if (!TransactionIdIsNormal(*freezeLimit))
1031-
*freezeLimit = FirstNormalTransactionId;
1032-
/* freezeLimit must always be <= oldestXmin */
1033-
if (TransactionIdPrecedes(*oldestXmin, *freezeLimit))
1034-
*freezeLimit = *oldestXmin;
1032+
/* Compute FreezeLimit, being careful to generate a normal XID */
1033+
*FreezeLimit = nextXID - freeze_min_age;
1034+
if (!TransactionIdIsNormal(*FreezeLimit))
1035+
*FreezeLimit = FirstNormalTransactionId;
1036+
/* FreezeLimit must always be <= OldestXmin */
1037+
if (TransactionIdPrecedes(*OldestXmin, *FreezeLimit))
1038+
*FreezeLimit = *OldestXmin;
10351039

10361040
/*
10371041
* Compute the multixact age for which freezing is urgent. This is
@@ -1052,16 +1056,16 @@ vacuum_set_xid_limits(Relation rel,
10521056
effective_multixact_freeze_max_age / 2);
10531057
Assert(multixact_freeze_min_age >= 0);
10541058

1055-
/* Compute multiXactCutoff, being careful to generate a valid value */
1056-
*multiXactCutoff = nextMXID - multixact_freeze_min_age;
1057-
if (*multiXactCutoff < FirstMultiXactId)
1058-
*multiXactCutoff = FirstMultiXactId;
1059-
/* multiXactCutoff must always be <= oldestMxact */
1060-
if (MultiXactIdPrecedes(*oldestMxact, *multiXactCutoff))
1061-
*multiXactCutoff = *oldestMxact;
1059+
/* Compute MultiXactCutoff, being careful to generate a valid value */
1060+
*MultiXactCutoff = nextMXID - multixact_freeze_min_age;
1061+
if (*MultiXactCutoff < FirstMultiXactId)
1062+
*MultiXactCutoff = FirstMultiXactId;
1063+
/* MultiXactCutoff must always be <= OldestMxact */
1064+
if (MultiXactIdPrecedes(*OldestMxact, *MultiXactCutoff))
1065+
*MultiXactCutoff = *OldestMxact;
10621066

10631067
/*
1064-
* Done setting output parameters; check if oldestXmin or oldestMxact are
1068+
* Done setting output parameters; check if OldestXmin or OldestMxact are
10651069
* held back to an unsafe degree in passing
10661070
*/
10671071
safeOldestXmin = nextXID - autovacuum_freeze_max_age;
@@ -1070,12 +1074,12 @@ vacuum_set_xid_limits(Relation rel,
10701074
safeOldestMxact = nextMXID - effective_multixact_freeze_max_age;
10711075
if (safeOldestMxact < FirstMultiXactId)
10721076
safeOldestMxact = FirstMultiXactId;
1073-
if (TransactionIdPrecedes(*oldestXmin, safeOldestXmin))
1077+
if (TransactionIdPrecedes(*OldestXmin, safeOldestXmin))
10741078
ereport(WARNING,
10751079
(errmsg("cutoff for removing and freezing tuples is far in the past"),
10761080
errhint("Close open transactions soon to avoid wraparound problems.\n"
10771081
"You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
1078-
if (MultiXactIdPrecedes(*oldestMxact, safeOldestMxact))
1082+
if (MultiXactIdPrecedes(*OldestMxact, safeOldestMxact))
10791083
ereport(WARNING,
10801084
(errmsg("cutoff for freezing multixacts is far in the past"),
10811085
errhint("Close open transactions soon to avoid wraparound problems.\n"

src/include/commands/vacuum.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,11 @@ extern void vac_update_relstats(Relation relation,
286286
bool *frozenxid_updated,
287287
bool *minmulti_updated,
288288
bool in_outer_xact);
289-
extern bool vacuum_set_xid_limits(Relation rel,
290-
int freeze_min_age,
291-
int multixact_freeze_min_age,
292-
int freeze_table_age,
293-
int multixact_freeze_table_age,
294-
TransactionId *oldestXmin,
295-
MultiXactId *oldestMxact,
296-
TransactionId *freezeLimit,
297-
MultiXactId *multiXactCutoff);
289+
extern bool vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
290+
TransactionId *OldestXmin,
291+
MultiXactId *OldestMxact,
292+
TransactionId *FreezeLimit,
293+
MultiXactId *MultiXactCutoff);
298294
extern bool vacuum_xid_failsafe_check(TransactionId relfrozenxid,
299295
MultiXactId relminmxid);
300296
extern void vac_update_datfrozenxid(void);

0 commit comments

Comments
 (0)