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

Commit3d0a463

Browse files
committed
Deduplicate choice of horizon for a relation procarray.c.
5a1e1d8 was a minimal bug fix fordc7420c. To avoid future bugs ofthat kind, deduplicate the choice of a relation's horizon into a new helper,GlobalVisHorizonKindForRel().As the code in question was only introduced indc7420c it seems worthbackpatching this change as well, otherwise 14 will look different from allother branches.A different approach to this was suggested by Matthias van de Meent.Author: Andres FreundDiscussion:https://postgr.es/m/20210621122919.2qhu3pfugxxp3cji@alap3.anarazel.deBackpatch: 14, like5a1e1d8
1 parent712ba6b commit3d0a463

File tree

1 file changed

+64
-34
lines changed

1 file changed

+64
-34
lines changed

‎src/backend/storage/ipc/procarray.c

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ typedef struct ComputeXidHorizonsResult
246246

247247
}ComputeXidHorizonsResult;
248248

249+
/*
250+
* Return value for GlobalVisHorizonKindForRel().
251+
*/
252+
typedefenumGlobalVisHorizonKind
253+
{
254+
VISHORIZON_SHARED,
255+
VISHORIZON_CATALOG,
256+
VISHORIZON_DATA,
257+
VISHORIZON_TEMP
258+
}GlobalVisHorizonKind;
259+
249260

250261
staticProcArrayStruct*procArray;
251262

@@ -1952,6 +1963,33 @@ ComputeXidHorizons(ComputeXidHorizonsResult *h)
19521963
GlobalVisUpdateApply(h);
19531964
}
19541965

1966+
/*
1967+
* Determine what kind of visibility horizon needs to be used for a
1968+
* relation. If rel is NULL, the most conservative horizon is used.
1969+
*/
1970+
staticinlineGlobalVisHorizonKind
1971+
GlobalVisHorizonKindForRel(Relationrel)
1972+
{
1973+
/*
1974+
* Other relkkinds currently don't contain xids, nor always the necessary
1975+
* logical decoding markers.
1976+
*/
1977+
Assert(!rel||
1978+
rel->rd_rel->relkind==RELKIND_RELATION||
1979+
rel->rd_rel->relkind==RELKIND_MATVIEW||
1980+
rel->rd_rel->relkind==RELKIND_TOASTVALUE);
1981+
1982+
if (rel==NULL||rel->rd_rel->relisshared||RecoveryInProgress())
1983+
returnVISHORIZON_SHARED;
1984+
elseif (IsCatalogRelation(rel)||
1985+
RelationIsAccessibleInLogicalDecoding(rel))
1986+
returnVISHORIZON_CATALOG;
1987+
elseif (!RELATION_IS_LOCAL(rel))
1988+
returnVISHORIZON_DATA;
1989+
else
1990+
returnVISHORIZON_TEMP;
1991+
}
1992+
19551993
/*
19561994
* Return the oldest XID for which deleted tuples must be preserved in the
19571995
* passed table.
@@ -1970,16 +2008,19 @@ GetOldestNonRemovableTransactionId(Relation rel)
19702008

19712009
ComputeXidHorizons(&horizons);
19722010

1973-
/* select horizon appropriate for relation */
1974-
if (rel==NULL||rel->rd_rel->relisshared||RecoveryInProgress())
1975-
returnhorizons.shared_oldest_nonremovable;
1976-
elseif (IsCatalogRelation(rel)||
1977-
RelationIsAccessibleInLogicalDecoding(rel))
1978-
returnhorizons.catalog_oldest_nonremovable;
1979-
elseif (RELATION_IS_LOCAL(rel))
1980-
returnhorizons.temp_oldest_nonremovable;
1981-
else
1982-
returnhorizons.data_oldest_nonremovable;
2011+
switch (GlobalVisHorizonKindForRel(rel))
2012+
{
2013+
caseVISHORIZON_SHARED:
2014+
returnhorizons.shared_oldest_nonremovable;
2015+
caseVISHORIZON_CATALOG:
2016+
returnhorizons.catalog_oldest_nonremovable;
2017+
caseVISHORIZON_DATA:
2018+
returnhorizons.data_oldest_nonremovable;
2019+
caseVISHORIZON_TEMP:
2020+
returnhorizons.temp_oldest_nonremovable;
2021+
}
2022+
2023+
returnInvalidTransactionId;
19832024
}
19842025

19852026
/*
@@ -3986,38 +4027,27 @@ DisplayXidCache(void)
39864027
GlobalVisState*
39874028
GlobalVisTestFor(Relationrel)
39884029
{
3989-
boolneed_shared;
3990-
boolneed_catalog;
39914030
GlobalVisState*state;
39924031

39934032
/* XXX: we should assert that a snapshot is pushed or registered */
39944033
Assert(RecentXmin);
39954034

3996-
if (!rel)
3997-
need_shared=need_catalog= true;
3998-
else
4035+
switch (GlobalVisHorizonKindForRel(rel))
39994036
{
4000-
/*
4001-
* Other kinds currently don't contain xids, nor always the necessary
4002-
* logical decoding markers.
4003-
*/
4004-
Assert(rel->rd_rel->relkind==RELKIND_RELATION||
4005-
rel->rd_rel->relkind==RELKIND_MATVIEW||
4006-
rel->rd_rel->relkind==RELKIND_TOASTVALUE);
4007-
4008-
need_shared=rel->rd_rel->relisshared||RecoveryInProgress();
4009-
need_catalog=IsCatalogRelation(rel)||RelationIsAccessibleInLogicalDecoding(rel);
4037+
caseVISHORIZON_SHARED:
4038+
state=&GlobalVisSharedRels;
4039+
break;
4040+
caseVISHORIZON_CATALOG:
4041+
state=&GlobalVisCatalogRels;
4042+
break;
4043+
caseVISHORIZON_DATA:
4044+
state=&GlobalVisDataRels;
4045+
break;
4046+
caseVISHORIZON_TEMP:
4047+
state=&GlobalVisTempRels;
4048+
break;
40104049
}
40114050

4012-
if (need_shared)
4013-
state=&GlobalVisSharedRels;
4014-
elseif (need_catalog)
4015-
state=&GlobalVisCatalogRels;
4016-
elseif (RELATION_IS_LOCAL(rel))
4017-
state=&GlobalVisTempRels;
4018-
else
4019-
state=&GlobalVisDataRels;
4020-
40214051
Assert(FullTransactionIdIsValid(state->definitely_needed)&&
40224052
FullTransactionIdIsValid(state->maybe_needed));
40234053

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp