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

Commitead49eb

Browse files
author
Amit Kapila
committed
Fix parallel operations that prevent oldest xmin from advancing.
While determining xid horizons, we skip over backends that are runningVacuum. We also ignore Create Index Concurrently, or Reindex Concurrentlyfor the purposes of computing Xmin for Vacuum. But we were not setting theflags corresponding to these operations when they are performed inparallel which was preventing Xid horizon from advancing.The optimization related to skipping Create Index Concurrently, or ReindexConcurrently operations was implemented in PG-14 but the fix is the samefor the Parallel Vacuum as well so back-patched till PG-13.Author: Masahiko SawadaReviewed-by: Amit KapilaBackpatch-through: 13Discussion:https://postgr.es/m/CAD21AoCLQqgM1sXh9BrDFq0uzd3RBFKi=Vfo6cjjKODm0Onr5w@mail.gmail.com
1 parented1c261 commitead49eb

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,6 +4161,12 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
41614161
LVRelStatevacrel;
41624162
ErrorContextCallbackerrcallback;
41634163

4164+
/*
4165+
* A parallel vacuum worker must have only PROC_IN_VACUUM flag since we
4166+
* don't support parallel vacuum for autovacuum as of now.
4167+
*/
4168+
Assert(MyProc->statusFlags==PROC_IN_VACUUM);
4169+
41644170
lvshared= (LVShared*)shm_toc_lookup(toc,PARALLEL_VACUUM_KEY_SHARED,
41654171
false);
41664172
elevel=lvshared->elevel;

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,13 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
18141814
ResetUsage();
18151815
#endif/* BTREE_BUILD_STATS */
18161816

1817+
/*
1818+
* The only possible status flag that can be set to the parallel worker is
1819+
* PROC_IN_SAFE_IC.
1820+
*/
1821+
Assert((MyProc->statusFlags==0)||
1822+
(MyProc->statusFlags==PROC_IN_SAFE_IC));
1823+
18171824
/* Set debug_query_string for individual workers first */
18181825
sharedquery=shm_toc_lookup(toc,PARALLEL_KEY_QUERY_TEXT, true);
18191826
debug_query_string=sharedquery;

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,10 @@ ProcArrayInstallImportedXmin(TransactionId xmin,
26372637
* PGPROC of the transaction from which we imported the snapshot, rather than
26382638
* an XID.
26392639
*
2640+
* Note that this function also copies statusFlags from the source `proc` in
2641+
* order to avoid the case where MyProc's xmin needs to be skipped for
2642+
* computing xid horizon.
2643+
*
26402644
* Returns true if successful, false if source xact is no longer running.
26412645
*/
26422646
bool
@@ -2648,8 +2652,10 @@ ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc)
26482652
Assert(TransactionIdIsNormal(xmin));
26492653
Assert(proc!=NULL);
26502654

2651-
/* Get lock so source xact can't end while we're doing this */
2652-
LWLockAcquire(ProcArrayLock,LW_SHARED);
2655+
/*
2656+
* Get an exclusive lock so that we can copy statusFlags from source proc.
2657+
*/
2658+
LWLockAcquire(ProcArrayLock,LW_EXCLUSIVE);
26532659

26542660
/*
26552661
* Be certain that the referenced PGPROC has an advertised xmin which is
@@ -2662,7 +2668,14 @@ ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc)
26622668
TransactionIdIsNormal(xid)&&
26632669
TransactionIdPrecedesOrEquals(xid,xmin))
26642670
{
2671+
/* Install xmin */
26652672
MyProc->xmin=TransactionXmin=xmin;
2673+
2674+
/* Flags being copied must be valid copy-able flags. */
2675+
Assert((proc->statusFlags& (~PROC_COPYABLE_FLAGS))==0);
2676+
MyProc->statusFlags=proc->statusFlags;
2677+
ProcGlobal->statusFlags[MyProc->pgxactoff]=MyProc->statusFlags;
2678+
26662679
result= true;
26672680
}
26682681

‎src/include/storage/proc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ struct XidCache
6565
#definePROC_VACUUM_STATE_MASK \
6666
(PROC_IN_VACUUM | PROC_IN_SAFE_IC | PROC_VACUUM_FOR_WRAPAROUND)
6767

68+
/*
69+
* Flags that are valid to copy from another proc, the parallel leader
70+
* process in practice. Currently, flags that are set during parallel
71+
* vacuum and parallel index creation are allowed.
72+
*/
73+
#definePROC_COPYABLE_FLAGS (PROC_IN_VACUUM | PROC_IN_SAFE_IC)
74+
6875
/*
6976
* We allow a small number of "weak" relation locks (AccessShareLock,
7077
* RowShareLock, RowExclusiveLock) to be recorded in the PGPROC structure

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp