PostgreSQL Source Code: src/backend/storage/ipc/procarray.c File Reference (original) (raw)
Go to the source code of this file.
Data Structures | |
---|---|
struct | ProcArrayStruct |
struct | GlobalVisState |
struct | ComputeXidHorizonsResult |
Macros | |
---|---|
#define | UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) |
#define | xc_by_recent_xmin_inc() ((void) 0) |
#define | xc_by_known_xact_inc() ((void) 0) |
#define | xc_by_my_xact_inc() ((void) 0) |
#define | xc_by_latest_xid_inc() ((void) 0) |
#define | xc_by_main_xid_inc() ((void) 0) |
#define | xc_by_child_xid_inc() ((void) 0) |
#define | xc_by_known_assigned_inc() ((void) 0) |
#define | xc_no_overflow_inc() ((void) 0) |
#define | xc_slow_answer_inc() ((void) 0) |
#define | PROCARRAY_MAXPROCS (MaxBackends + max_prepared_xacts) |
#define | TOTAL_MAX_CACHED_SUBXIDS ((PGPROC_MAX_CACHED_SUBXIDS + 1) * PROCARRAY_MAXPROCS) |
#define | MAXAUTOVACPIDS 10 /* max autovacs to SIGTERM per iteration */ |
#define | KAX_COMPRESS_FREQUENCY 128 /* in transactions */ |
#define | KAX_COMPRESS_IDLE_INTERVAL 1000 /* in ms */ |
Typedefs | |
---|---|
typedef struct ProcArrayStruct | ProcArrayStruct |
typedef struct ComputeXidHorizonsResult | ComputeXidHorizonsResult |
typedef enum GlobalVisHorizonKind | GlobalVisHorizonKind |
typedef enum KAXCompressReason | KAXCompressReason |
Variables | |
---|---|
static ProcArrayStruct * | procArray |
static PGPROC * | allProcs |
static TransactionId | cachedXidIsNotInProgress = InvalidTransactionId |
static TransactionId * | KnownAssignedXids |
static bool * | KnownAssignedXidsValid |
static TransactionId | latestObservedXid = InvalidTransactionId |
static TransactionId | standbySnapshotPendingXmin |
static GlobalVisState | GlobalVisSharedRels |
static GlobalVisState | GlobalVisCatalogRels |
static GlobalVisState | GlobalVisDataRels |
static GlobalVisState | GlobalVisTempRels |
static TransactionId | ComputeXidHorizonsResultLastXmin |
◆ KAX_COMPRESS_FREQUENCY
#define KAX_COMPRESS_FREQUENCY 128 /* in transactions */
◆ KAX_COMPRESS_IDLE_INTERVAL
#define KAX_COMPRESS_IDLE_INTERVAL 1000 /* in ms */
◆ MAXAUTOVACPIDS
#define MAXAUTOVACPIDS 10 /* max autovacs to SIGTERM per iteration */
◆ PROCARRAY_MAXPROCS
◆ TOTAL_MAX_CACHED_SUBXIDS
◆ UINT32_ACCESS_ONCE
| #define UINT32_ACCESS_ONCE | ( | | var | ) | ((uint32)(*((volatile uint32 *)&(var)))) | | ---------------------------- | - | | --- | - | -------------------------------------------------------------------------------------------------------------------------------------------- |
◆ xc_by_child_xid_inc
#define xc_by_child_xid_inc | ( | ) | ((void) 0) |
---|
◆ xc_by_known_assigned_inc
#define xc_by_known_assigned_inc | ( | ) | ((void) 0) |
---|
◆ xc_by_known_xact_inc
#define xc_by_known_xact_inc | ( | ) | ((void) 0) |
---|
◆ xc_by_latest_xid_inc
#define xc_by_latest_xid_inc | ( | ) | ((void) 0) |
---|
◆ xc_by_main_xid_inc
#define xc_by_main_xid_inc | ( | ) | ((void) 0) |
---|
◆ xc_by_my_xact_inc
#define xc_by_my_xact_inc | ( | ) | ((void) 0) |
---|
◆ xc_by_recent_xmin_inc
#define xc_by_recent_xmin_inc | ( | ) | ((void) 0) |
---|
◆ xc_no_overflow_inc
#define xc_no_overflow_inc | ( | ) | ((void) 0) |
---|
◆ xc_slow_answer_inc
#define xc_slow_answer_inc | ( | ) | ((void) 0) |
---|
◆ ComputeXidHorizonsResult
◆ GlobalVisHorizonKind
◆ KAXCompressReason
◆ ProcArrayStruct
◆ GlobalVisHorizonKind
Enumerator |
---|
VISHORIZON_SHARED |
VISHORIZON_CATALOG |
VISHORIZON_DATA |
VISHORIZON_TEMP |
Definition at line 249 of file procarray.c.
◆ KAXCompressReason
Enumerator |
---|
KAX_NO_SPACE |
KAX_PRUNE |
KAX_TRANSACTION_END |
KAX_STARTUP_PROCESS_IDLE |
Definition at line 260 of file procarray.c.
◆ BackendPidGetProc()
PGPROC * BackendPidGetProc | ( | int | pid | ) |
---|
Definition at line 3196 of file procarray.c.
3197{
3199
3200 if (pid == 0)
3201 return NULL;
3202
3204
3206
3208
3209 return result;
3210}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
PGPROC * BackendPidGetProcWithLock(int pid)
References BackendPidGetProcWithLock(), LW_SHARED, LWLockAcquire(), and LWLockRelease().
Referenced by IsBackendPid(), pg_isolation_test_session_is_blocked(), pg_log_backend_memory_contexts(), pg_signal_backend(), pg_stat_get_activity(), pg_stat_get_backend_wait_event(), pg_stat_get_backend_wait_event_type(), pg_stat_reset_backend_stats(), pgstat_fetch_stat_backend_by_pid(), TerminateOtherDBBackends(), and test_shm_mq_main().
◆ BackendPidGetProcWithLock()
PGPROC * BackendPidGetProcWithLock | ( | int | pid | ) |
---|
◆ BackendXidGetPid()
Definition at line 3256 of file procarray.c.
3257{
3258 int result = 0;
3262
3264 return 0;
3265
3267
3269 {
3270 if (other_xids[index] == xid)
3271 {
3274
3275 result = proc->pid;
3276 break;
3277 }
3278 }
3279
3281
3282 return result;
3283}
#define InvalidTransactionId
References allProcs, InvalidTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PGPROC::pid, procArray, ProcGlobal, and PROC_HDR::xids.
Referenced by pgrowlocks().
◆ CancelDBBackends()
Definition at line 3659 of file procarray.c.
3660{
3663
3664
3666
3668 {
3671
3673 {
3675 pid_t pid;
3676
3678
3680 pid = proc->pid;
3681 if (pid != 0)
3682 {
3683
3684
3685
3686
3688 }
3689 }
3690 }
3691
3693}
#define GET_VXID_FROM_PGPROC(vxid_dst, proc)
int SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
bool recoveryConflictPending
References allProcs, PGPROC::databaseId, GET_VXID_FROM_PGPROC, InvalidOid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PGPROC::pid, procArray, VirtualTransactionId::procNumber, PGPROC::recoveryConflictPending, and SendProcSignal().
Referenced by ResolveRecoveryConflictWithDatabase(), and SendRecoveryConflictWithBufferPin().
◆ CancelVirtualTransaction()
◆ ComputeXidHorizons()
Definition at line 1735 of file procarray.c.
1736{
1741
1742
1744
1746
1748
1749
1750
1751
1752
1753
1754
1755 {
1757
1761
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1780 else
1782 }
1783
1784
1785
1786
1787
1788
1791
1793 {
1799
1800
1803
1804
1805
1806
1807
1808
1809
1810
1812
1813
1815 continue;
1816
1817
1818
1819
1820
1821
1822
1825
1826
1827
1828
1829
1830
1832 continue;
1833
1834
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1860 in_recovery)
1861 {
1864 }
1865 }
1866
1867
1868
1869
1870
1871 if (in_recovery)
1873
1874
1875
1876
1877
1879
1880 if (in_recovery)
1881 {
1888
1889 }
1890
1895
1896
1897
1898
1903
1904
1905
1906
1907
1908
1909
1910
1919
1920
1921
1922
1923
1933
1934
1935
1936
1937
1942
1943
1944
1945
1946
1961
1962
1964}
Assert(PointerIsAligned(start, uint64))
#define PROC_IN_LOGICAL_DECODING
#define PROC_AFFECTS_ALL_HORIZONS
#define UINT32_ACCESS_ONCE(var)
static void GlobalVisUpdateApply(ComputeXidHorizonsResult *horizons)
static TransactionId KnownAssignedXidsGetOldestXmin(void)
TransactionId slot_catalog_xmin
TransactionId data_oldest_nonremovable
TransactionId temp_oldest_nonremovable
TransactionId shared_oldest_nonremovable
TransactionId oldest_considered_running
FullTransactionId latest_completed
TransactionId catalog_oldest_nonremovable
TransactionId shared_oldest_nonremovable_raw
TransactionId replication_slot_xmin
TransactionId replication_slot_catalog_xmin
FullTransactionId latestCompletedXid
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
#define XidFromFullTransactionId(x)
#define TransactionIdIsValid(xid)
#define TransactionIdAdvance(dest)
static TransactionId TransactionIdOlder(TransactionId a, TransactionId b)
TransamVariablesData * TransamVariables
bool RecoveryInProgress(void)
References allProcs, Assert(), ComputeXidHorizonsResult::catalog_oldest_nonremovable, ComputeXidHorizonsResult::data_oldest_nonremovable, PGPROC::databaseId, GlobalVisUpdateApply(), InvalidOid, InvalidTransactionId, KnownAssignedXidsGetOldestXmin(), ComputeXidHorizonsResult::latest_completed, TransamVariablesData::latestCompletedXid, LW_SHARED, LWLockAcquire(), LWLockRelease(), MyDatabaseId, MyProc, ProcArrayStruct::numProcs, ComputeXidHorizonsResult::oldest_considered_running, ProcArrayStruct::pgprocnos, PROC_AFFECTS_ALL_HORIZONS, PROC_IN_LOGICAL_DECODING, PROC_IN_VACUUM, procArray, ProcGlobal, RecoveryInProgress(), ProcArrayStruct::replication_slot_catalog_xmin, ProcArrayStruct::replication_slot_xmin, ComputeXidHorizonsResult::shared_oldest_nonremovable, ComputeXidHorizonsResult::shared_oldest_nonremovable_raw, ComputeXidHorizonsResult::slot_catalog_xmin, ComputeXidHorizonsResult::slot_xmin, PROC_HDR::statusFlags, ComputeXidHorizonsResult::temp_oldest_nonremovable, TransactionIdAdvance, TransactionIdIsValid, TransactionIdOlder(), TransactionIdPrecedesOrEquals(), TransamVariables, UINT32_ACCESS_ONCE, PGPROC::xid, XidFromFullTransactionId, PROC_HDR::xids, and PGPROC::xmin.
Referenced by GetOldestNonRemovableTransactionId(), GetOldestTransactionIdConsideredRunning(), GetReplicationHorizons(), and GlobalVisUpdate().
◆ CountDBBackends()
int CountDBBackends | ( | Oid | databaseid | ) |
---|
◆ CountDBConnections()
int CountDBConnections | ( | Oid | databaseid | ) |
---|
Definition at line 3628 of file procarray.c.
3629{
3631 int count = 0;
3633
3635
3637 {
3640
3641 if (proc->pid == 0)
3642 continue;
3644 continue;
3647 count++;
3648 }
3649
3651
3652 return count;
3653}
References allProcs, PGPROC::databaseId, PGPROC::isRegularBackend, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numProcs, OidIsValid, ProcArrayStruct::pgprocnos, PGPROC::pid, and procArray.
Referenced by CheckMyDatabase().
◆ CountOtherDBBackends()
bool CountOtherDBBackends | ( | Oid | databaseId, |
---|---|---|---|
int * | nbackends, | ||
int * | nprepared | ||
) |
Definition at line 3750 of file procarray.c.
3751{
3753
3754#define MAXAUTOVACPIDS 10
3756 int tries;
3757
3758
3759 for (tries = 0; tries < 50; tries++)
3760 {
3761 int nautovacs = 0;
3762 bool found = false;
3764
3766
3767 *nbackends = *nprepared = 0;
3768
3770
3772 {
3776
3778 continue;
3780 continue;
3781
3782 found = true;
3783
3784 if (proc->pid == 0)
3785 (*nprepared)++;
3786 else
3787 {
3788 (*nbackends)++;
3791 autovac_pids[nautovacs++] = proc->pid;
3792 }
3793 }
3794
3796
3797 if (!found)
3798 return false;
3799
3800
3801
3802
3803
3804
3805
3807 (void) kill(autovac_pids[index], SIGTERM);
3808
3809
3810 pg_usleep(100 * 1000L);
3811 }
3812
3813 return true;
3814}
#define CHECK_FOR_INTERRUPTS()
#define PROC_IS_AUTOVACUUM
void pg_usleep(long microsec)
References allProcs, CHECK_FOR_INTERRUPTS, PGPROC::databaseId, kill, LW_SHARED, LWLockAcquire(), LWLockRelease(), MAXAUTOVACPIDS, MyProc, ProcArrayStruct::numProcs, pg_usleep(), ProcArrayStruct::pgprocnos, PGPROC::pid, PROC_IS_AUTOVACUUM, procArray, ProcGlobal, and PROC_HDR::statusFlags.
Referenced by createdb(), dropdb(), movedb(), and RenameDatabase().
◆ CountUserBackends()
int CountUserBackends | ( | Oid | roleid | ) |
---|
◆ ExpireAllKnownAssignedTransactionIds()
void ExpireAllKnownAssignedTransactionIds | ( | void | ) |
---|
Definition at line 4498 of file procarray.c.
4499{
4501
4504
4505
4510
4511
4512
4513
4514
4516
4517
4518
4519
4520
4521
4524}
static void KnownAssignedXidsRemovePreceding(TransactionId removeXid)
TransactionId lastOverflowedXid
FullTransactionId nextXid
uint64 xactCompletionCount
static void FullTransactionIdRetreat(FullTransactionId *dest)
#define FullTransactionIdIsValid(x)
References Assert(), FullTransactionIdIsValid, FullTransactionIdRetreat(), InvalidTransactionId, KnownAssignedXidsRemovePreceding(), ProcArrayStruct::lastOverflowedXid, TransamVariablesData::latestCompletedXid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextXid, procArray, TransamVariables, and TransamVariablesData::xactCompletionCount.
Referenced by ShutdownRecoveryTransactionEnvironment().
◆ ExpireOldKnownAssignedTransactionIds()
Definition at line 4532 of file procarray.c.
4533{
4535
4537
4538
4539 latestXid = xid;
4542
4543
4545
4546
4547
4548
4549
4550
4551
4556}
static void MaintainLatestCompletedXidRecovery(TransactionId latestXid)
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
#define TransactionIdRetreat(dest)
References InvalidTransactionId, KnownAssignedXidsRemovePreceding(), ProcArrayStruct::lastOverflowedXid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaintainLatestCompletedXidRecovery(), procArray, TransactionIdPrecedes(), TransactionIdRetreat, TransamVariables, and TransamVariablesData::xactCompletionCount.
Referenced by ProcArrayApplyRecoveryInfo().
◆ ExpireTreeKnownAssignedTransactionIds()
Definition at line 4472 of file procarray.c.
4474{
4476
4477
4478
4479
4481
4483
4484
4486
4487
4489
4491}
static void KnownAssignedXidsRemoveTree(TransactionId xid, int nsubxids, TransactionId *subxids)
HotStandbyState standbyState
References Assert(), KnownAssignedXidsRemoveTree(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaintainLatestCompletedXidRecovery(), STANDBY_INITIALIZED, standbyState, TransamVariables, and TransamVariablesData::xactCompletionCount.
Referenced by xact_redo_abort(), and xact_redo_commit().
◆ FullXidRelativeTo()
◆ GetConflictingVirtualXIDs()
Definition at line 3417 of file procarray.c.
3418{
3421 int count = 0;
3423
3424
3425
3426
3427
3428
3429 if (vxids == NULL)
3430 {
3433 if (vxids == NULL)
3435 (errcode(ERRCODE_OUT_OF_MEMORY),
3436 errmsg("out of memory")));
3437 }
3438
3440
3442 {
3445
3446
3447 if (proc->pid == 0)
3448 continue;
3449
3452 {
3453
3455
3456
3457
3458
3459
3460
3461
3462
3463
3466 {
3468
3471 vxids[count++] = vxid;
3472 }
3473 }
3474 }
3475
3477
3478
3481
3482 return vxids;
3483}
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define VirtualTransactionIdIsValid(vxid)
#define InvalidLocalTransactionId
#define INVALID_PROC_NUMBER
LocalTransactionId localTransactionId
bool TransactionIdFollows(TransactionId id1, TransactionId id2)
References allProcs, PGPROC::databaseId, ereport, errcode(), errmsg(), ERROR, GET_VXID_FROM_PGPROC, INVALID_PROC_NUMBER, InvalidLocalTransactionId, VirtualTransactionId::localTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), malloc, ProcArrayStruct::maxProcs, ProcArrayStruct::numProcs, OidIsValid, ProcArrayStruct::pgprocnos, PGPROC::pid, procArray, VirtualTransactionId::procNumber, TransactionIdFollows(), TransactionIdIsValid, UINT32_ACCESS_ONCE, VirtualTransactionIdIsValid, and PGPROC::xmin.
Referenced by ResolveRecoveryConflictWithSnapshot(), and ResolveRecoveryConflictWithTablespace().
◆ GetCurrentVirtualXIDs()
Definition at line 3324 of file procarray.c.
3327{
3330 int count = 0;
3332
3333
3336
3338
3340 {
3344
3346 continue;
3347
3348 if (excludeVacuum & statusFlags)
3349 continue;
3350
3352 {
3353
3355
3357 continue;
3358
3359
3360
3361
3362
3365 {
3367
3370 vxids[count++] = vxid;
3371 }
3372 }
3373 }
3374
3376
3377 *nvxids = count;
3378 return vxids;
3379}
References allProcs, PGPROC::databaseId, GET_VXID_FROM_PGPROC, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::maxProcs, MyDatabaseId, MyProc, ProcArrayStruct::numProcs, palloc(), ProcArrayStruct::pgprocnos, procArray, ProcGlobal, PROC_HDR::statusFlags, TransactionIdIsValid, TransactionIdPrecedesOrEquals(), UINT32_ACCESS_ONCE, VirtualTransactionIdIsValid, and PGPROC::xmin.
Referenced by WaitForOlderSnapshots().
◆ GetMaxSnapshotSubxidCount()
int GetMaxSnapshotSubxidCount | ( | void | ) |
---|
◆ GetMaxSnapshotXidCount()
int GetMaxSnapshotXidCount | ( | void | ) |
---|
◆ GetOldestActiveTransactionId()
Definition at line 2880 of file procarray.c.
2881{
2886
2888
2889
2890
2891
2892
2893
2894
2895
2899
2900
2901
2902
2905 {
2907
2908
2910
2912 continue;
2913
2915 oldestRunningXid = xid;
2916
2917
2918
2919
2920
2921
2922 }
2924
2925 return oldestRunningXid;
2926}
#define TransactionIdIsNormal(xid)
References Assert(), LW_SHARED, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextXid, ProcArrayStruct::numProcs, procArray, ProcGlobal, RecoveryInProgress(), TransactionIdIsNormal, TransactionIdPrecedes(), TransamVariables, UINT32_ACCESS_ONCE, XidFromFullTransactionId, and PROC_HDR::xids.
Referenced by CreateCheckPoint().
◆ GetOldestNonRemovableTransactionId()
Definition at line 2005 of file procarray.c.
2006{
2008
2010
2012 {
2021 }
2022
2023
2025}
static void ComputeXidHorizons(ComputeXidHorizonsResult *h)
static GlobalVisHorizonKind GlobalVisHorizonKindForRel(Relation rel)
References ComputeXidHorizonsResult::catalog_oldest_nonremovable, ComputeXidHorizons(), ComputeXidHorizonsResult::data_oldest_nonremovable, GlobalVisHorizonKindForRel(), InvalidTransactionId, ComputeXidHorizonsResult::shared_oldest_nonremovable, ComputeXidHorizonsResult::temp_oldest_nonremovable, VISHORIZON_CATALOG, VISHORIZON_DATA, VISHORIZON_SHARED, and VISHORIZON_TEMP.
Referenced by _bt_pendingfsm_finalize(), acquire_sample_rows(), GetStrictOldestNonRemovableTransactionId(), heapam_index_build_range_scan(), removable_cutoff(), statapprox_heap(), vac_update_datfrozenxid(), and vacuum_get_cutoffs().
◆ GetOldestSafeDecodingTransactionId()
TransactionId GetOldestSafeDecodingTransactionId | ( | bool | catalogOnly | ) |
---|
Definition at line 2945 of file procarray.c.
2946{
2951
2953
2954
2955
2956
2957
2958
2959
2960
2961
2964
2965
2966
2967
2968
2969
2970
2971
2974 oldestSafeXid))
2976
2977 if (catalogOnly &&
2980 oldestSafeXid))
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995 if (!recovery_in_progress)
2996 {
2998
2999
3000
3001
3003 {
3005
3006
3008
3010 continue;
3011
3013 oldestSafeXid = xid;
3014 }
3015 }
3016
3018
3019 return oldestSafeXid;
3020}
bool LWLockHeldByMe(LWLock *lock)
References Assert(), LW_SHARED, LWLockAcquire(), LWLockHeldByMe(), LWLockRelease(), TransamVariablesData::nextXid, ProcArrayStruct::numProcs, procArray, ProcGlobal, RecoveryInProgress(), ProcArrayStruct::replication_slot_catalog_xmin, ProcArrayStruct::replication_slot_xmin, TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), TransamVariables, UINT32_ACCESS_ONCE, XidFromFullTransactionId, and PROC_HDR::xids.
Referenced by CreateInitDecodingContext(), SnapBuildInitialSnapshot(), and synchronize_one_slot().
◆ GetOldestTransactionIdConsideredRunning()
◆ GetReplicationHorizons()
◆ GetRunningTransactionData()
Definition at line 2689 of file procarray.c.
2690{
2691
2693
2702 int count;
2703 int subcount;
2704 bool suboverflowed;
2705
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717 if (CurrentRunningXacts->xids == NULL)
2718 {
2719
2720
2721
2724 if (CurrentRunningXacts->xids == NULL)
2726 (errcode(ERRCODE_OUT_OF_MEMORY),
2727 errmsg("out of memory")));
2728 }
2729
2730 xids = CurrentRunningXacts->xids;
2731
2732 count = subcount = 0;
2733 suboverflowed = false;
2734
2735
2736
2737
2738
2741
2742 latestCompletedXid =
2744 oldestDatabaseRunningXid = oldestRunningXid =
2746
2747
2748
2749
2751 {
2753
2754
2756
2757
2758
2759
2760
2762 continue;
2763
2764
2765
2766
2767
2768
2770 oldestRunningXid = xid;
2771
2772
2773
2774
2775
2776
2778 {
2781
2783 oldestDatabaseRunningXid = xid;
2784 }
2785
2787 suboverflowed = true;
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797 xids[count++] = xid;
2798 }
2799
2800
2801
2802
2803
2804 if (!suboverflowed)
2805 {
2807
2809 {
2812 int nsubxids;
2813
2814
2815
2816
2817
2818 nsubxids = other_subxidstates[index].count;
2819 if (nsubxids > 0)
2820 {
2821
2823
2824 memcpy(&xids[count], proc->subxids.xids,
2826 count += nsubxids;
2827 subcount += nsubxids;
2828
2829
2830
2831
2832
2833
2834 }
2835 }
2836 }
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847 CurrentRunningXacts->xcnt = count - subcount;
2848 CurrentRunningXacts->subxcnt = subcount;
2854
2858
2859
2860
2861 return CurrentRunningXacts;
2862}
#define pg_read_barrier()
XidCacheStatus * subxidStates
TransactionId oldestRunningXid
TransactionId oldestDatabaseRunningXid
TransactionId latestCompletedXid
subxids_array_status subxid_status
TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS]
References allProcs, Assert(), XidCacheStatus::count, PGPROC::databaseId, ereport, errcode(), errmsg(), ERROR, TransamVariablesData::latestCompletedXid, RunningTransactionsData::latestCompletedXid, LW_SHARED, LWLockAcquire(), malloc, MyDatabaseId, TransamVariablesData::nextXid, RunningTransactionsData::nextXid, ProcArrayStruct::numProcs, RunningTransactionsData::oldestDatabaseRunningXid, RunningTransactionsData::oldestRunningXid, XidCacheStatus::overflowed, pg_read_barrier, ProcArrayStruct::pgprocnos, procArray, ProcGlobal, RecoveryInProgress(), RunningTransactionsData::subxcnt, RunningTransactionsData::subxid_status, PGPROC::subxids, SUBXIDS_IN_ARRAY, SUBXIDS_IN_SUBTRANS, PROC_HDR::subxidStates, TOTAL_MAX_CACHED_SUBXIDS, TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), TransamVariables, UINT32_ACCESS_ONCE, RunningTransactionsData::xcnt, XidFromFullTransactionId, XidCache::xids, PROC_HDR::xids, and RunningTransactionsData::xids.
Referenced by GetStrictOldestNonRemovableTransactionId(), and LogStandbySnapshot().
◆ GetSnapshotData()
Definition at line 2175 of file procarray.c.
2176{
2181 int count = 0;
2182 int subcount = 0;
2183 bool suboverflowed = false;
2186 int mypgxactoff;
2188 uint64 curXactCompletionCount;
2189
2192
2193 Assert(snapshot != NULL);
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206 if (snapshot->xip == NULL)
2207 {
2208
2209
2210
2211
2214 if (snapshot->xip == NULL)
2216 (errcode(ERRCODE_OUT_OF_MEMORY),
2217 errmsg("out of memory")));
2221 if (snapshot->subxip == NULL)
2223 (errcode(ERRCODE_OUT_OF_MEMORY),
2224 errmsg("out of memory")));
2225 }
2226
2227
2228
2229
2230
2232
2234 {
2236 return snapshot;
2237 }
2238
2241 myxid = other_xids[mypgxactoff];
2243
2246
2247
2251
2252
2253 xmin = xmax;
2254
2255
2257 xmin = myxid;
2258
2260
2262 {
2263 int numProcs = arrayP->numProcs;
2265 int *pgprocnos = arrayP->pgprocnos;
2268
2269
2270
2271
2272
2273 for (int pgxactoff = 0; pgxactoff < numProcs; pgxactoff++)
2274 {
2275
2277 uint8 statusFlags;
2278
2280
2281
2282
2283
2284
2286 continue;
2287
2288
2289
2290
2291
2292
2293 if (pgxactoff == mypgxactoff)
2294 continue;
2295
2296
2297
2298
2299
2300
2301
2303
2304
2305
2306
2307
2308
2310 continue;
2311
2312
2313
2314
2315
2316 statusFlags = allStatusFlags[pgxactoff];
2318 continue;
2319
2321 xmin = xid;
2322
2323
2324 xip[count++] = xid;
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341 if (!suboverflowed)
2342 {
2343
2344 if (subxidStates[pgxactoff].overflowed)
2345 suboverflowed = true;
2346 else
2347 {
2348 int nsubxids = subxidStates[pgxactoff].count;
2349
2350 if (nsubxids > 0)
2351 {
2352 int pgprocno = pgprocnos[pgxactoff];
2354
2356
2357 memcpy(snapshot->subxip + subcount,
2360 subcount += nsubxids;
2361 }
2362 }
2363 }
2364 }
2365 }
2366 else
2367 {
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2398 xmax);
2399
2401 suboverflowed = true;
2402 }
2403
2404
2405
2406
2407
2408
2409
2412
2415
2417
2418
2419 {
2425
2426
2427
2428
2429
2430
2432
2433
2434 def_vis_xid_data =
2436
2437
2438
2439
2440
2441 def_vis_xid = def_vis_xid_data;
2442
2443
2444
2445
2446
2447 def_vis_xid =
2449
2450 def_vis_fxid = FullXidRelativeTo(latest_completed, def_vis_xid);
2451 def_vis_fxid_data = FullXidRelativeTo(latest_completed, def_vis_xid_data);
2452
2453
2454
2455
2456
2457
2467
2471 else
2472 {
2475 }
2476
2477
2478
2479
2480
2481
2482
2483
2484
2487 oldestfxid);
2490 oldestfxid);
2493 oldestfxid);
2494
2496 }
2497
2500
2501 snapshot->xmin = xmin;
2502 snapshot->xmax = xmax;
2503 snapshot->xcnt = count;
2504 snapshot->subxcnt = subcount;
2507
2509
2510
2511
2512
2513
2516 snapshot->copied = false;
2517
2518 return snapshot;
2519}
static GlobalVisState GlobalVisDataRels
static GlobalVisState GlobalVisSharedRels
static GlobalVisState GlobalVisCatalogRels
static FullTransactionId FullXidRelativeTo(FullTransactionId rel, TransactionId xid)
static int KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin, TransactionId xmax)
int GetMaxSnapshotSubxidCount(void)
static GlobalVisState GlobalVisTempRels
int GetMaxSnapshotXidCount(void)
static bool GetSnapshotDataReuse(Snapshot snapshot)
TransactionId TransactionXmin
FullTransactionId definitely_needed
FullTransactionId maybe_needed
uint64 snapXactCompletionCount
static FullTransactionId FullTransactionIdNewer(FullTransactionId a, FullTransactionId b)
#define NormalTransactionIdPrecedes(id1, id2)
static void FullTransactionIdAdvance(FullTransactionId *dest)
CommandId GetCurrentCommandId(bool used)
References SnapshotData::active_count, allProcs, Assert(), SnapshotData::copied, XidCacheStatus::count, SnapshotData::curcid, GlobalVisState::definitely_needed, ereport, errcode(), errmsg(), ERROR, FullTransactionIdAdvance(), FullTransactionIdNewer(), FullXidRelativeTo(), GetCurrentCommandId(), GetMaxSnapshotSubxidCount(), GetMaxSnapshotXidCount(), GetSnapshotDataReuse(), GlobalVisCatalogRels, GlobalVisDataRels, GlobalVisSharedRels, GlobalVisTempRels, InvalidTransactionId, KnownAssignedXidsGetAndSetXmin(), ProcArrayStruct::lastOverflowedXid, TransamVariablesData::latestCompletedXid, likely, LW_SHARED, LWLockAcquire(), LWLockRelease(), malloc, GlobalVisState::maybe_needed, MyProc, NormalTransactionIdPrecedes, ProcArrayStruct::numProcs, TransamVariablesData::oldestXid, pg_read_barrier, ProcArrayStruct::pgprocnos, PGPROC::pgxactoff, PROC_IN_LOGICAL_DECODING, PROC_IN_VACUUM, procArray, ProcGlobal, RecentXmin, RecoveryInProgress(), SnapshotData::regd_count, ProcArrayStruct::replication_slot_catalog_xmin, ProcArrayStruct::replication_slot_xmin, SnapshotData::snapXactCompletionCount, PROC_HDR::statusFlags, SnapshotData::suboverflowed, SnapshotData::subxcnt, PGPROC::subxids, PROC_HDR::subxidStates, SnapshotData::subxip, SnapshotData::takenDuringRecovery, TransactionIdAdvance, TransactionIdIsNormal, TransactionIdIsValid, TransactionIdOlder(), TransactionIdPrecedesOrEquals(), TransactionXmin, TransamVariables, UINT32_ACCESS_ONCE, TransamVariablesData::xactCompletionCount, SnapshotData::xcnt, PGPROC::xid, XidFromFullTransactionId, XidCache::xids, PROC_HDR::xids, SnapshotData::xip, SnapshotData::xmax, PGPROC::xmin, and SnapshotData::xmin.
Referenced by GetLatestSnapshot(), GetNonHistoricCatalogSnapshot(), GetSerializableTransactionSnapshotInt(), GetTransactionSnapshot(), and SetTransactionSnapshot().
◆ GetSnapshotDataReuse()
static bool GetSnapshotDataReuse ( Snapshot snapshot) | static |
---|
Definition at line 2095 of file procarray.c.
2096{
2097 uint64 curXactCompletionCount;
2098
2100
2102 return false;
2103
2106 return false;
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2130
2133
2137 snapshot->copied = false;
2138
2139 return true;
2140}
References SnapshotData::active_count, Assert(), SnapshotData::copied, SnapshotData::curcid, GetCurrentCommandId(), LWLockHeldByMe(), MyProc, RecentXmin, SnapshotData::regd_count, SnapshotData::snapXactCompletionCount, TransactionIdIsValid, TransactionIdPrecedesOrEquals(), TransactionXmin, TransamVariables, unlikely, TransamVariablesData::xactCompletionCount, PGPROC::xmin, and SnapshotData::xmin.
Referenced by GetSnapshotData().
◆ GetVirtualXIDsDelayingChkpt()
Definition at line 3043 of file procarray.c.
3044{
3047 int count = 0;
3049
3051
3052
3055
3057
3059 {
3062
3064 {
3066
3069 vxids[count++] = vxid;
3070 }
3071 }
3072
3074
3075 *nvxids = count;
3076 return vxids;
3077}
References allProcs, Assert(), PGPROC::delayChkptFlags, GET_VXID_FROM_PGPROC, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::maxProcs, ProcArrayStruct::numProcs, palloc(), ProcArrayStruct::pgprocnos, procArray, type, and VirtualTransactionIdIsValid.
Referenced by CreateCheckPoint().
◆ GlobalVisCheckRemovableFullXid()
◆ GlobalVisCheckRemovableXid()
◆ GlobalVisHorizonKindForRel()
Definition at line 1971 of file procarray.c.
1972{
1973
1974
1975
1976
1978 rel->rd_rel->relkind == RELKIND_RELATION ||
1979 rel->rd_rel->relkind == RELKIND_MATVIEW ||
1980 rel->rd_rel->relkind == RELKIND_TOASTVALUE);
1981
1989 else
1991}
bool IsCatalogRelation(Relation relation)
#define RELATION_IS_LOCAL(relation)
#define RelationIsAccessibleInLogicalDecoding(relation)
References Assert(), IsCatalogRelation(), RelationData::rd_rel, RecoveryInProgress(), RELATION_IS_LOCAL, RelationIsAccessibleInLogicalDecoding, VISHORIZON_CATALOG, VISHORIZON_DATA, VISHORIZON_SHARED, and VISHORIZON_TEMP.
Referenced by GetOldestNonRemovableTransactionId(), and GlobalVisTestFor().
◆ GlobalVisTestFor()
Definition at line 4107 of file procarray.c.
4108{
4110
4111
4113
4115 {
4118 break;
4121 break;
4124 break;
4127 break;
4128 }
4129
4132
4134}
References Assert(), FullTransactionIdIsValid, GlobalVisCatalogRels, GlobalVisDataRels, GlobalVisHorizonKindForRel(), GlobalVisSharedRels, GlobalVisTempRels, RecentXmin, VISHORIZON_CATALOG, VISHORIZON_DATA, VISHORIZON_SHARED, and VISHORIZON_TEMP.
Referenced by get_actual_variable_endpoint(), GlobalVisCheckRemovableFullXid(), GlobalVisCheckRemovableXid(), heap_hot_search_buffer(), heap_index_delete_tuples(), heap_page_prune_opt(), heap_vacuum_rel(), and vacuumRedirectAndPlaceholder().
◆ GlobalVisTestIsRemovableFullXid()
◆ GlobalVisTestIsRemovableXid()
◆ GlobalVisTestShouldUpdate()
static bool GlobalVisTestShouldUpdate ( GlobalVisState * state) | static |
---|
◆ GlobalVisUpdate()
static void GlobalVisUpdate ( void ) | static |
---|
◆ GlobalVisUpdateApply()
Definition at line 4166 of file procarray.c.
4167{
4180
4181
4182
4183
4184
4185
4196
4198}
References ComputeXidHorizonsResult::catalog_oldest_nonremovable, ComputeXidHorizonsResultLastXmin, ComputeXidHorizonsResult::data_oldest_nonremovable, GlobalVisState::definitely_needed, FullTransactionIdNewer(), FullXidRelativeTo(), GlobalVisCatalogRels, GlobalVisDataRels, GlobalVisSharedRels, GlobalVisTempRels, ComputeXidHorizonsResult::latest_completed, GlobalVisState::maybe_needed, RecentXmin, ComputeXidHorizonsResult::shared_oldest_nonremovable, and ComputeXidHorizonsResult::temp_oldest_nonremovable.
Referenced by ComputeXidHorizons().
◆ HaveVirtualXIDsDelayingChkpt()
Definition at line 3089 of file procarray.c.
3090{
3091 bool result = false;
3094
3096
3098
3100 {
3104
3106
3109 {
3110 int i;
3111
3112 for (i = 0; i < nvxids; i++)
3113 {
3115 {
3116 result = true;
3117 break;
3118 }
3119 }
3120 if (result)
3121 break;
3122 }
3123 }
3124
3126
3127 return result;
3128}
#define VirtualTransactionIdEquals(vxid1, vxid2)
References allProcs, Assert(), PGPROC::delayChkptFlags, GET_VXID_FROM_PGPROC, i, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, procArray, type, VirtualTransactionIdEquals, and VirtualTransactionIdIsValid.
Referenced by CreateCheckPoint().
◆ IsBackendPid()
bool IsBackendPid | ( | int | pid | ) |
---|
◆ KnownAssignedTransactionIdsIdleMaintenance()
void KnownAssignedTransactionIdsIdleMaintenance | ( | void | ) |
---|
◆ KnownAssignedXidExists()
◆ KnownAssignedXidsAdd()
Definition at line 4782 of file procarray.c.
4784{
4787 int head,
4788 tail;
4789 int nxids;
4790 int i;
4791
4793
4794
4795
4796
4797
4798
4799 if (to_xid >= from_xid)
4800 nxids = to_xid - from_xid + 1;
4801 else
4802 {
4803 nxids = 1;
4804 next_xid = from_xid;
4806 {
4807 nxids++;
4809 }
4810 }
4811
4812
4813
4814
4815
4818
4819 Assert(head >= 0 && head <= pArray->maxKnownAssignedXids);
4820 Assert(tail >= 0 && tail < pArray->maxKnownAssignedXids);
4821
4822
4823
4824
4825
4826
4827 if (head > tail &&
4829 {
4831 elog(ERROR, "out-of-order XID insertion in KnownAssignedXids");
4832 }
4833
4834
4835
4836
4838 {
4840
4842
4843
4844
4845
4846
4848 elog(ERROR, "too many KnownAssignedXids");
4849 }
4850
4851
4852 next_xid = from_xid;
4853 for (i = 0; i < nxids; i++)
4854 {
4858 head++;
4859 }
4860
4861
4863
4864
4865
4866
4867
4868
4869
4870 if (!exclusive_lock)
4872
4874}
#define pg_write_barrier()
static TransactionId * KnownAssignedXids
static bool * KnownAssignedXidsValid
static void KnownAssignedXidsDisplay(int trace_level)
int tailKnownAssignedXids
int headKnownAssignedXids
bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
References Assert(), elog, ERROR, ProcArrayStruct::headKnownAssignedXids, i, KAX_NO_SPACE, KnownAssignedXids, KnownAssignedXidsCompress(), KnownAssignedXidsDisplay(), KnownAssignedXidsValid, LOG, ProcArrayStruct::maxKnownAssignedXids, ProcArrayStruct::numKnownAssignedXids, pg_write_barrier, procArray, ProcArrayStruct::tailKnownAssignedXids, TransactionIdAdvance, TransactionIdFollowsOrEquals(), TransactionIdPrecedes(), and TransactionIdPrecedesOrEquals().
Referenced by ProcArrayApplyRecoveryInfo(), and RecordKnownAssignedTransactionIds().
◆ KnownAssignedXidsCompress()
static void KnownAssignedXidsCompress ( KAXCompressReason reason, bool haveLock ) | static |
---|
Definition at line 4665 of file procarray.c.
4666{
4668 int head,
4669 tail,
4670 nelements;
4671 int compress_index;
4672 int i;
4673
4674
4675 static unsigned int transactionEndsCounter;
4677
4678
4679#define KAX_COMPRESS_FREQUENCY 128
4680#define KAX_COMPRESS_IDLE_INTERVAL 1000
4681
4682
4683
4684
4685
4688 nelements = head - tail;
4689
4690
4691
4692
4693
4694
4695
4697 {
4698
4699
4700
4701
4702
4704 return;
4705 }
4707 {
4708
4709
4710
4711
4713 return;
4714
4715
4716
4717
4718
4719 if (nelements < 2 * pArray->numKnownAssignedXids)
4720 return;
4721 }
4723 {
4724
4725
4726
4727
4728
4729 if (lastCompressTs != 0)
4730 {
4732
4736 return;
4737 }
4738 }
4739
4740
4741 if (!haveLock)
4743
4744
4745
4746
4747
4748 compress_index = 0;
4749 for (i = tail; i < head; i++)
4750 {
4752 {
4755 compress_index++;
4756 }
4757 }
4759
4762
4763 if (!haveLock)
4765
4766
4768}
TimestampTz GetCurrentTimestamp(void)
#define KAX_COMPRESS_FREQUENCY
#define KAX_COMPRESS_IDLE_INTERVAL
#define TimestampTzPlusMilliseconds(tz, ms)
References Assert(), GetCurrentTimestamp(), ProcArrayStruct::headKnownAssignedXids, i, KAX_COMPRESS_FREQUENCY, KAX_COMPRESS_IDLE_INTERVAL, KAX_NO_SPACE, KAX_STARTUP_PROCESS_IDLE, KAX_TRANSACTION_END, KnownAssignedXids, KnownAssignedXidsValid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numKnownAssignedXids, procArray, ProcArrayStruct::tailKnownAssignedXids, and TimestampTzPlusMilliseconds.
Referenced by KnownAssignedTransactionIdsIdleMaintenance(), KnownAssignedXidsAdd(), KnownAssignedXidsRemovePreceding(), and KnownAssignedXidsRemoveTree().
◆ KnownAssignedXidsDisplay()
static void KnownAssignedXidsDisplay ( int trace_level) | static |
---|
Definition at line 5218 of file procarray.c.
5219{
5222 int head,
5223 tail,
5224 i;
5225 int nxids = 0;
5226
5229
5231
5232 for (i = tail; i < head; i++)
5233 {
5235 {
5236 nxids++;
5238 }
5239 }
5240
5241 elog(trace_level, "%d KnownAssignedXids (num=%d tail=%d head=%d) %s",
5242 nxids,
5246 buf.data);
5247
5249}
void pfree(void *pointer)
void appendStringInfo(StringInfo str, const char *fmt,...)
void initStringInfo(StringInfo str)
References appendStringInfo(), buf, elog, ProcArrayStruct::headKnownAssignedXids, i, initStringInfo(), KnownAssignedXids, KnownAssignedXidsValid, ProcArrayStruct::numKnownAssignedXids, pfree(), procArray, and ProcArrayStruct::tailKnownAssignedXids.
Referenced by KnownAssignedXidsAdd(), and ProcArrayApplyRecoveryInfo().
◆ KnownAssignedXidsGet()
◆ KnownAssignedXidsGetAndSetXmin()
Definition at line 5127 of file procarray.c.
5129{
5130 int count = 0;
5131 int head,
5132 tail;
5133 int i;
5134
5135
5136
5137
5138
5139
5140
5141
5144
5145 pg_read_barrier();
5146
5147 for (i = tail; i < head; i++)
5148 {
5149
5151 {
5153
5154
5155
5156
5157
5158 if (count == 0 &&
5160 *xmin = knownXid;
5161
5162
5163
5164
5165
5168 break;
5169
5170
5171 xarray[count++] = knownXid;
5172 }
5173 }
5174
5175 return count;
5176}
References ProcArrayStruct::headKnownAssignedXids, i, KnownAssignedXids, KnownAssignedXidsValid, pg_read_barrier, procArray, ProcArrayStruct::tailKnownAssignedXids, TransactionIdFollowsOrEquals(), TransactionIdIsValid, and TransactionIdPrecedes().
Referenced by GetSnapshotData(), and KnownAssignedXidsGet().
◆ KnownAssignedXidsGetOldestXmin()
static TransactionId KnownAssignedXidsGetOldestXmin ( void ) | static |
---|
◆ KnownAssignedXidsRemove()
◆ KnownAssignedXidsRemovePreceding()
static void KnownAssignedXidsRemovePreceding ( TransactionId removeXid) | static |
---|
Definition at line 5035 of file procarray.c.
5036{
5038 int count = 0;
5039 int head,
5040 tail,
5041 i;
5042
5044 {
5045 elog(DEBUG4, "removing all KnownAssignedXids");
5048 return;
5049 }
5050
5051 elog(DEBUG4, "prune KnownAssignedXids to %u", removeXid);
5052
5053
5054
5055
5056
5059
5060 for (i = tail; i < head; i++)
5061 {
5063 {
5065
5067 break;
5068
5070 {
5072 count++;
5073 }
5074 }
5075 }
5076
5079
5080
5081
5082
5083 for (i = tail; i < head; i++)
5084 {
5086 break;
5087 }
5088 if (i >= head)
5089 {
5090
5093 }
5094 else
5095 {
5097 }
5098
5099
5101}
bool StandbyTransactionIdIsPrepared(TransactionId xid)
References Assert(), DEBUG4, elog, ProcArrayStruct::headKnownAssignedXids, i, KAX_PRUNE, KnownAssignedXids, KnownAssignedXidsCompress(), KnownAssignedXidsValid, ProcArrayStruct::numKnownAssignedXids, procArray, StandbyTransactionIdIsPrepared(), ProcArrayStruct::tailKnownAssignedXids, TransactionIdFollowsOrEquals(), and TransactionIdIsValid.
Referenced by ExpireAllKnownAssignedTransactionIds(), and ExpireOldKnownAssignedTransactionIds().
◆ KnownAssignedXidsRemoveTree()
◆ KnownAssignedXidsReset()
static void KnownAssignedXidsReset ( void ) | static |
---|
◆ KnownAssignedXidsSearch()
static bool KnownAssignedXidsSearch ( TransactionId xid, bool remove ) | static |
---|
Definition at line 4886 of file procarray.c.
4887{
4889 int first,
4890 last;
4891 int head;
4892 int tail;
4893 int result_index = -1;
4894
4897
4898
4899
4900
4901
4902 if (!remove)
4903 pg_read_barrier();
4904
4905
4906
4907
4908
4909 first = tail;
4910 last = head - 1;
4911 while (first <= last)
4912 {
4913 int mid_index;
4915
4916 mid_index = (first + last) / 2;
4918
4919 if (xid == mid_xid)
4920 {
4921 result_index = mid_index;
4922 break;
4923 }
4925 last = mid_index - 1;
4926 else
4927 first = mid_index + 1;
4928 }
4929
4930 if (result_index < 0)
4931 return false;
4932
4934 return false;
4935
4936 if (remove)
4937 {
4939
4942
4943
4944
4945
4946
4947 if (result_index == tail)
4948 {
4949 tail++;
4951 tail++;
4952 if (tail >= head)
4953 {
4954
4957 }
4958 else
4959 {
4961 }
4962 }
4963 }
4964
4965 return true;
4966}
References Assert(), ProcArrayStruct::headKnownAssignedXids, KnownAssignedXids, KnownAssignedXidsValid, ProcArrayStruct::numKnownAssignedXids, pg_read_barrier, procArray, ProcArrayStruct::tailKnownAssignedXids, and TransactionIdPrecedes().
Referenced by KnownAssignedXidExists(), and KnownAssignedXidsRemove().
◆ MaintainLatestCompletedXid()
static void MaintainLatestCompletedXid ( TransactionId latestXid) | static |
---|
Definition at line 967 of file procarray.c.
968{
970
974
976 {
979 }
980
983}
#define IsBootstrapProcessingMode()
#define FullTransactionIdIsNormal(x)
References Assert(), FullTransactionIdIsNormal, FullTransactionIdIsValid, FullXidRelativeTo(), IsBootstrapProcessingMode, TransamVariablesData::latestCompletedXid, LWLockHeldByMe(), RecoveryInProgress(), TransactionIdPrecedes(), TransamVariables, and XidFromFullTransactionId.
Referenced by ProcArrayEndTransactionInternal(), ProcArrayRemove(), and XidCacheRemoveRunningXids().
◆ MaintainLatestCompletedXidRecovery()
static void MaintainLatestCompletedXidRecovery ( TransactionId latestXid) | static |
---|
Definition at line 989 of file procarray.c.
990{
993
996
997
998
999
1000
1001
1004
1007 {
1010 }
1011
1013}
#define AmStartupProcess()
References AmStartupProcess, Assert(), FullTransactionIdIsNormal, FullTransactionIdIsValid, FullXidRelativeTo(), IsUnderPostmaster, TransamVariablesData::latestCompletedXid, LWLockHeldByMe(), TransamVariablesData::nextXid, TransactionIdPrecedes(), TransamVariables, and XidFromFullTransactionId.
Referenced by ExpireOldKnownAssignedTransactionIds(), ExpireTreeKnownAssignedTransactionIds(), and ProcArrayApplyRecoveryInfo().
◆ MinimumActiveBackends()
bool MinimumActiveBackends | ( | int | min | ) |
---|
◆ ProcArrayAdd()
void ProcArrayAdd | ( | PGPROC * | proc | ) |
---|
Definition at line 468 of file procarray.c.
469{
473 int movecount;
474
475
478
480 {
481
482
483
484
485
487 (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
488 errmsg("sorry, too many clients already")));
489 }
490
491
492
493
494
495
496
497
498
499
501 {
503
506
507
508 if (this_procno > pgprocno)
509 break;
510 }
511
515 movecount * sizeof(*arrayP->pgprocnos));
525
531
533
534
537 {
539
542
544 }
545
546
547
548
549
552}
#define NUM_AUXILIARY_PROCS
#define GetNumberFromPGProc(proc)
XidCacheStatus subxidStatus
References allProcs, Assert(), ereport, errcode(), errmsg(), FATAL, GetNumberFromPGProc, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::maxProcs, NUM_AUXILIARY_PROCS, ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PGPROC::pgxactoff, procArray, ProcGlobal, PGPROC::statusFlags, PROC_HDR::statusFlags, PROC_HDR::subxidStates, PGPROC::subxidStatus, PGPROC::xid, and PROC_HDR::xids.
Referenced by InitProcessPhase2(), and MarkAsPrepared().
◆ ProcArrayApplyRecoveryInfo()
Definition at line 1054 of file procarray.c.
1055{
1058 int nxids;
1059 int i;
1060
1065
1066
1067
1068
1070
1071
1072
1073
1074
1075
1076 advanceNextXid = running->nextXid;
1080
1081
1082
1083
1085
1086
1087
1088
1090 return;
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1104 {
1105
1106
1107
1108
1110 {
1111
1112
1113
1114
1117 }
1118 else
1119 {
1122 {
1125 "recovery snapshots are now enabled");
1126 }
1127 else
1129 "recovery snapshot waiting for non-overflowed snapshot or "
1130 "until oldest active xid on standby is at least %u (now %u)",
1133 return;
1134 }
1135 }
1136
1138
1139
1140
1141
1142
1143
1144
1145
1146
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1166
1167
1168
1169
1170 nxids = 0;
1171 for (i = 0; i < running->xcnt + running->subxcnt; i++)
1172 {
1174
1175
1176
1177
1178
1179
1180
1182 continue;
1183
1184 xids[nxids++] = xid;
1185 }
1186
1187 if (nxids > 0)
1188 {
1190 {
1192 elog(ERROR, "KnownAssignedXids is not empty");
1193 }
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1205
1206
1207
1208
1209
1210
1211 for (i = 0; i < nxids; i++)
1212 {
1214 {
1216 "found duplicated transaction %u for KnownAssignedXids insertion",
1217 xids[i]);
1218 continue;
1219 }
1221 }
1222
1224 }
1225
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1241 {
1244 }
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1262 {
1264
1267 }
1268 else
1269 {
1271
1273
1274
1275
1276
1277
1280 else
1281 {
1284 }
1285 }
1286
1287
1288
1289
1290
1291
1292
1294
1295
1296
1297
1298
1299
1301
1304 elog(DEBUG1, "recovery snapshots are now enabled");
1305 else
1307 "recovery snapshot waiting for non-overflowed snapshot or "
1308 "until oldest active xid on standby is at least %u (now %u)",
1311}
#define qsort(a, b, c, d)
static TransactionId standbySnapshotPendingXmin
static TransactionId latestObservedXid
static void KnownAssignedXidsReset(void)
static void KnownAssignedXidsAdd(TransactionId from_xid, TransactionId to_xid, bool exclusive_lock)
void ExpireOldKnownAssignedTransactionIds(TransactionId xid)
void StandbyReleaseOldLocks(TransactionId oldxid)
void ExtendSUBTRANS(TransactionId newestXact)
bool TransactionIdDidCommit(TransactionId transactionId)
bool TransactionIdDidAbort(TransactionId transactionId)
#define TransactionIdEquals(id1, id2)
void AdvanceNextFullTransactionIdPastXid(TransactionId xid)
int xidLogicalComparator(const void *arg1, const void *arg2)
@ STANDBY_SNAPSHOT_PENDING
References AdvanceNextFullTransactionIdPastXid(), Assert(), DEBUG1, DEBUG3, elog, ERROR, ExpireOldKnownAssignedTransactionIds(), ExtendSUBTRANS(), FullTransactionIdIsValid, i, InvalidTransactionId, KnownAssignedXidsAdd(), KnownAssignedXidsDisplay(), KnownAssignedXidsReset(), ProcArrayStruct::lastOverflowedXid, RunningTransactionsData::latestCompletedXid, latestObservedXid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaintainLatestCompletedXidRecovery(), TransamVariablesData::nextXid, RunningTransactionsData::nextXid, ProcArrayStruct::numKnownAssignedXids, RunningTransactionsData::oldestRunningXid, palloc(), pfree(), procArray, qsort, STANDBY_INITIALIZED, STANDBY_SNAPSHOT_PENDING, STANDBY_SNAPSHOT_READY, StandbyReleaseOldLocks(), standbySnapshotPendingXmin, standbyState, RunningTransactionsData::subxcnt, RunningTransactionsData::subxid_status, SUBXIDS_IN_ARRAY, SUBXIDS_IN_SUBTRANS, SUBXIDS_MISSING, TransactionIdAdvance, TransactionIdDidAbort(), TransactionIdDidCommit(), TransactionIdEquals, TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), TransactionIdRetreat, TransamVariables, RunningTransactionsData::xcnt, xidLogicalComparator(), and RunningTransactionsData::xids.
Referenced by standby_redo(), StartupXLOG(), and xlog_redo().
◆ ProcArrayApplyXidAssignment()
Definition at line 1318 of file procarray.c.
1320{
1322 int i;
1323
1325
1327
1328
1329
1330
1331
1332
1333
1334
1335
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349 for (i = 0; i < nsubxids; i++)
1351
1352
1354 return;
1355
1356
1357
1358
1360
1361
1362
1363
1365
1366
1367
1368
1371
1373}
void RecordKnownAssignedTransactionIds(TransactionId xid)
void SubTransSetParent(TransactionId xid, TransactionId parent)
TransactionId TransactionIdLatest(TransactionId mainxid, int nxids, const TransactionId *xids)
References Assert(), i, InvalidTransactionId, KnownAssignedXidsRemoveTree(), ProcArrayStruct::lastOverflowedXid, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), procArray, RecordKnownAssignedTransactionIds(), STANDBY_INITIALIZED, standbyState, SubTransSetParent(), TransactionIdLatest(), and TransactionIdPrecedes().
Referenced by xact_redo().
◆ ProcArrayClearTransaction()
void ProcArrayClearTransaction | ( | PGPROC * | proc | ) |
---|
Definition at line 907 of file procarray.c.
908{
909 int pgxactoff;
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
926
928
931
935
938
939
940
941
942
943
944
945
947
948
952 {
957 }
958
960}
#define PROC_VACUUM_STATE_MASK
References Assert(), XidCacheStatus::count, PGPROC::delayChkptFlags, InvalidLocalTransactionId, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PGPROC::lxid, XidCacheStatus::overflowed, PGPROC::pgxactoff, PROC_VACUUM_STATE_MASK, ProcGlobal, PGPROC::recoveryConflictPending, PGPROC::statusFlags, PROC_HDR::subxidStates, PGPROC::subxidStatus, TransamVariables, PGPROC::vxid, TransamVariablesData::xactCompletionCount, PGPROC::xid, PROC_HDR::xids, and PGPROC::xmin.
Referenced by PrepareTransaction().
◆ ProcArrayEndTransaction()
Definition at line 667 of file procarray.c.
668{
670 {
671
672
673
674
675
676
678
679
680
681
682
683
685 {
688 }
689 else
691 }
692 else
693 {
694
695
696
697
698
702
705
706
708
710
711
712
714 {
718 proc->statusFlags &= ~PROC_VACUUM_STATE_MASK;
721 }
722 }
723}
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
static void ProcArrayEndTransactionInternal(PGPROC *proc, TransactionId latestXid)
static void ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
References Assert(), XidCacheStatus::count, PGPROC::delayChkptFlags, InvalidLocalTransactionId, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockHeldByMe(), LWLockRelease(), PGPROC::lxid, XidCacheStatus::overflowed, PGPROC::pgxactoff, PROC_VACUUM_STATE_MASK, ProcArrayEndTransactionInternal(), ProcArrayGroupClearXid(), ProcGlobal, PGPROC::recoveryConflictPending, PGPROC::statusFlags, PROC_HDR::statusFlags, PGPROC::subxidStatus, TransactionIdIsValid, PGPROC::vxid, PGPROC::xid, and PGPROC::xmin.
Referenced by AbortTransaction(), and CommitTransaction().
◆ ProcArrayEndTransactionInternal()
static void ProcArrayEndTransactionInternal ( PGPROC * proc, TransactionId latestXid ) | inlinestatic |
---|
Definition at line 731 of file procarray.c.
732{
734
735
736
737
738
742
747
748
750
752
753
754
756 {
757 proc->statusFlags &= ~PROC_VACUUM_STATE_MASK;
759 }
760
761
765 {
770 }
771
772
774
775
777}
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
static void MaintainLatestCompletedXid(TransactionId latestXid)
References Assert(), XidCacheStatus::count, PGPROC::delayChkptFlags, InvalidLocalTransactionId, InvalidTransactionId, LW_EXCLUSIVE, LWLockHeldByMeInMode(), PGPROC::lxid, MaintainLatestCompletedXid(), XidCacheStatus::overflowed, PGPROC::pgxactoff, PROC_VACUUM_STATE_MASK, ProcGlobal, PGPROC::recoveryConflictPending, PGPROC::statusFlags, PROC_HDR::statusFlags, PROC_HDR::subxidStates, PGPROC::subxidStatus, TransactionIdIsValid, TransamVariables, PGPROC::vxid, TransamVariablesData::xactCompletionCount, PGPROC::xid, PROC_HDR::xids, and PGPROC::xmin.
Referenced by ProcArrayEndTransaction(), and ProcArrayGroupClearXid().
◆ ProcArrayGetReplicationSlotXmin()
◆ ProcArrayGroupClearXid()
Definition at line 792 of file procarray.c.
793{
798
799
801
802
806 while (true)
807 {
809
811 &nextidx,
813 break;
814 }
815
816
817
818
819
820
821
823 {
824 int extraWaits = 0;
825
826
828 for (;;)
829 {
830
833 break;
834 extraWaits++;
835 }
837
839
840
841 while (extraWaits-- > 0)
843 return;
844 }
845
846
848
849
850
851
852
853
856
857
858 wakeidx = nextidx;
859
860
862 {
864
866
867
869 }
870
871
873
874
875
876
877
878
879
880
882 {
884
887
888
890
892
893 if (nextproc != MyProc)
895 }
896}
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
void PGSemaphoreUnlock(PGSemaphore sema)
void PGSemaphoreLock(PGSemaphore sema)
bool procArrayGroupMember
pg_atomic_uint32 procArrayGroupNext
TransactionId procArrayGroupMemberXid
pg_atomic_uint32 procArrayGroupFirst
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
References allProcs, Assert(), GetNumberFromPGProc, INVALID_PROC_NUMBER, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProc, pg_atomic_compare_exchange_u32(), pg_atomic_exchange_u32(), pg_atomic_read_u32(), pg_atomic_write_u32(), pg_write_barrier, PGSemaphoreLock(), PGSemaphoreUnlock(), pgstat_report_wait_end(), pgstat_report_wait_start(), ProcArrayEndTransactionInternal(), PROC_HDR::procArrayGroupFirst, PGPROC::procArrayGroupMember, PGPROC::procArrayGroupMemberXid, PGPROC::procArrayGroupNext, ProcGlobal, PGPROC::sem, TransactionIdIsValid, and PGPROC::xid.
Referenced by ProcArrayEndTransaction().
◆ ProcArrayInitRecovery()
◆ ProcArrayInstallImportedXmin()
Definition at line 2532 of file procarray.c.
2534{
2535 bool result = false;
2538
2540 if (!sourcevxid)
2541 return false;
2542
2543
2545
2546
2547
2548
2549
2550
2552 {
2557
2558
2560 continue;
2561
2562
2564 continue;
2566 continue;
2567
2568
2569
2570
2571
2572
2573
2575 continue;
2576
2577
2578
2579
2583 continue;
2584
2585
2586
2587
2588
2589
2590
2592
2593 result = true;
2594 break;
2595 }
2596
2598
2599 return result;
2600}
References allProcs, Assert(), PGPROC::databaseId, VirtualTransactionId::localTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), PGPROC::lxid, MyDatabaseId, MyProc, ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PROC_IN_VACUUM, procArray, ProcGlobal, VirtualTransactionId::procNumber, PGPROC::procNumber, PROC_HDR::statusFlags, TransactionIdIsNormal, TransactionIdPrecedesOrEquals(), TransactionXmin, UINT32_ACCESS_ONCE, PGPROC::vxid, and PGPROC::xmin.
Referenced by GetSerializableTransactionSnapshotInt(), and SetTransactionSnapshot().
◆ ProcArrayInstallRestoredXmin()
Definition at line 2616 of file procarray.c.
2617{
2618 bool result = false;
2620
2622 Assert(proc != NULL);
2623
2624
2625
2626
2628
2629
2630
2631
2632
2633
2634
2639 {
2640
2641
2642
2643
2648
2649 result = true;
2650 }
2651
2653
2654 return result;
2655}
References Assert(), PGPROC::databaseId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyDatabaseId, MyProc, PGPROC::pgxactoff, PROC_XMIN_FLAGS, ProcGlobal, PGPROC::statusFlags, PROC_HDR::statusFlags, TransactionIdIsNormal, TransactionIdPrecedesOrEquals(), TransactionXmin, UINT32_ACCESS_ONCE, and PGPROC::xmin.
Referenced by SetTransactionSnapshot().
◆ ProcArrayRemove()
Definition at line 565 of file procarray.c.
566{
568 int myoff;
569 int movecount;
570
571#ifdef XIDCACHE_DEBUG
572
573 if (proc->pid != 0)
574 DisplayXidCache();
575#endif
576
577
580
582
583 Assert(myoff >= 0 && myoff < arrayP->numProcs);
585
587 {
589
590
592
593
595
599 }
600 else
601 {
602
604 }
605
609
611
612
613 movecount = arrayP->numProcs - myoff - 1;
614 memmove(&arrayP->pgprocnos[myoff],
616 movecount * sizeof(*arrayP->pgprocnos));
626
627 arrayP->pgprocnos[arrayP->numProcs - 1] = -1;
629
630
631
632
633
635 {
637
640
642 }
643
644
645
646
647
650}
References allProcs, PROC_HDR::allProcs, Assert(), XidCacheStatus::count, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaintainLatestCompletedXid(), ProcArrayStruct::maxProcs, NUM_AUXILIARY_PROCS, ProcArrayStruct::numProcs, XidCacheStatus::overflowed, ProcArrayStruct::pgprocnos, PGPROC::pgxactoff, PGPROC::pid, procArray, ProcGlobal, PROC_HDR::statusFlags, PROC_HDR::subxidStates, TransactionIdIsValid, TransamVariables, TransamVariablesData::xactCompletionCount, and PROC_HDR::xids.
Referenced by FinishPreparedTransaction(), and RemoveProcFromArray().
◆ ProcArraySetReplicationSlotXmin()
Definition at line 3943 of file procarray.c.
3945{
3947
3948 if (!already_locked)
3950
3953
3954 if (!already_locked)
3956
3957 elog(DEBUG1, "xmin required by slots: data %u, catalog %u",
3958 xmin, catalog_xmin);
3959}
References Assert(), DEBUG1, elog, LW_EXCLUSIVE, LWLockAcquire(), LWLockHeldByMe(), LWLockRelease(), procArray, ProcArrayStruct::replication_slot_catalog_xmin, and ProcArrayStruct::replication_slot_xmin.
Referenced by ReplicationSlotsComputeRequiredXmin().
◆ ProcArrayShmemInit()
void ProcArrayShmemInit | ( | void | ) |
---|
Definition at line 418 of file procarray.c.
419{
420 bool found;
421
422
428 &found);
429
430 if (!found)
431 {
432
433
434
445 }
446
448
449
451 {
456 &found);
460 &found);
461 }
462}
#define PROCARRAY_MAXPROCS
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
References add_size(), allProcs, PROC_HDR::allProcs, EnableHotStandby, ProcArrayStruct::headKnownAssignedXids, InvalidTransactionId, KnownAssignedXids, KnownAssignedXidsValid, ProcArrayStruct::lastOverflowedXid, ProcArrayStruct::maxKnownAssignedXids, ProcArrayStruct::maxProcs, mul_size(), ProcArrayStruct::numKnownAssignedXids, ProcArrayStruct::numProcs, procArray, PROCARRAY_MAXPROCS, ProcGlobal, ProcArrayStruct::replication_slot_catalog_xmin, ProcArrayStruct::replication_slot_xmin, ShmemInitStruct(), ProcArrayStruct::tailKnownAssignedXids, TOTAL_MAX_CACHED_SUBXIDS, TransamVariables, and TransamVariablesData::xactCompletionCount.
Referenced by CreateOrAttachShmemStructs().
◆ ProcArrayShmemSize()
Size ProcArrayShmemSize | ( | void | ) |
---|
◆ ProcNumberGetProc()
◆ ProcNumberGetTransactionIds()
Definition at line 3160 of file procarray.c.
3162{
3164
3167 *nsubxid = 0;
3168 *overflowed = false;
3169
3171 return;
3173
3174
3176
3177 if (proc->pid != 0)
3178 {
3179 *xid = proc->xid;
3180 *xmin = proc->xmin;
3183 }
3184
3186}
References PROC_HDR::allProcCount, XidCacheStatus::count, GetPGProcByNumber, InvalidTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), XidCacheStatus::overflowed, PGPROC::pid, ProcGlobal, PGPROC::subxidStatus, PGPROC::xid, and PGPROC::xmin.
Referenced by pgstat_read_current_status().
◆ RecordKnownAssignedTransactionIds()
Definition at line 4403 of file procarray.c.
4404{
4408
4409 elog(DEBUG4, "record known xact %u latestObservedXid %u",
4411
4412
4413
4414
4415
4416
4418 {
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4432 {
4435 }
4436 Assert(next_expected_xid == xid);
4437
4438
4439
4440
4441
4443 {
4445 return;
4446 }
4447
4448
4449
4450
4454
4455
4456
4457
4459
4460
4462 }
4463}
References AdvanceNextFullTransactionIdPastXid(), Assert(), DEBUG4, elog, ExtendSUBTRANS(), KnownAssignedXidsAdd(), latestObservedXid, STANDBY_INITIALIZED, standbyState, TransactionIdAdvance, TransactionIdFollows(), TransactionIdIsValid, and TransactionIdPrecedes().
Referenced by ApplyWalRecord(), ProcArrayApplyXidAssignment(), xact_redo_abort(), and xact_redo_commit().
◆ SignalVirtualTransaction()
Definition at line 3497 of file procarray.c.
3499{
3502 pid_t pid = 0;
3503
3505
3507 {
3511
3513
3516 {
3518 pid = proc->pid;
3519 if (pid != 0)
3520 {
3521
3522
3523
3524
3526 }
3527 break;
3528 }
3529 }
3530
3532
3533 return pid;
3534}
References allProcs, GET_VXID_FROM_PGPROC, VirtualTransactionId::localTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PGPROC::pid, procArray, VirtualTransactionId::procNumber, PGPROC::recoveryConflictPending, and SendProcSignal().
Referenced by CancelVirtualTransaction(), and ResolveRecoveryConflictWithLock().
◆ TerminateOtherDBBackends()
void TerminateOtherDBBackends | ( | Oid | databaseId | ) |
---|
Definition at line 3828 of file procarray.c.
3829{
3832 int nprepared = 0;
3833 int i;
3834
3836
3838 {
3839 int pgprocno = arrayP->pgprocnos[i];
3841
3843 continue;
3845 continue;
3846
3847 if (proc->pid != 0)
3849 else
3850 nprepared++;
3851 }
3852
3854
3855 if (nprepared > 0)
3857 (errcode(ERRCODE_OBJECT_IN_USE),
3858 errmsg("database \"%s\" is being used by prepared transactions",
3860 errdetail_plural("There is %d prepared transaction using the database.",
3861 "There are %d prepared transactions using the database.",
3862 nprepared,
3863 nprepared)));
3864
3865 if (pids)
3866 {
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884 foreach(lc, pids)
3885 {
3888
3889 if (proc != NULL)
3890 {
3893 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3894 errmsg("permission denied to terminate process"),
3895 errdetail("Only roles with the %s attribute may terminate processes of roles with the %s attribute.",
3896 "SUPERUSER", "SUPERUSER")));
3897
3901 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3902 errmsg("permission denied to terminate process"),
3903 errdetail("Only roles with privileges of the role whose process is being terminated or with privileges of the \"%s\" role may terminate this process.",
3904 "pg_signal_backend")));
3905 }
3906 }
3907
3908
3909
3910
3911
3912
3913
3914 foreach(lc, pids)
3915 {
3918
3919 if (proc != NULL)
3920 {
3921
3922
3923
3924
3925#ifdef HAVE_SETSID
3926 (void) kill(-pid, SIGTERM);
3927#else
3928 (void) kill(pid, SIGTERM);
3929#endif
3930 }
3931 }
3932 }
3933}
bool has_privs_of_role(Oid member, Oid role)
char * get_database_name(Oid dbid)
int errdetail(const char *fmt,...)
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
List * lappend_int(List *list, int datum)
bool superuser_arg(Oid roleid)
References allProcs, BackendPidGetProc(), PGPROC::databaseId, ereport, errcode(), errdetail(), errdetail_plural(), errmsg(), ERROR, get_database_name(), GetUserId(), has_privs_of_role(), i, kill, lappend_int(), lfirst_int, LW_SHARED, LWLockAcquire(), LWLockRelease(), MyProc, NIL, ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PGPROC::pid, procArray, PGPROC::roleId, superuser(), and superuser_arg().
Referenced by dropdb().
◆ TransactionIdIsActive()
Definition at line 1634 of file procarray.c.
1635{
1636 bool result = false;
1639 int i;
1640
1641
1642
1643
1644
1646 return false;
1647
1649
1651 {
1652 int pgprocno = arrayP->pgprocnos[i];
1655
1656
1658
1660 continue;
1661
1662 if (proc->pid == 0)
1663 continue;
1664
1666 {
1667 result = true;
1668 break;
1669 }
1670 }
1671
1673
1674 return result;
1675}
References allProcs, i, LW_SHARED, LWLockAcquire(), LWLockRelease(), ProcArrayStruct::numProcs, ProcArrayStruct::pgprocnos, PGPROC::pid, procArray, ProcGlobal, RecentXmin, TransactionIdEquals, TransactionIdIsValid, TransactionIdPrecedes(), UINT32_ACCESS_ONCE, and PROC_HDR::xids.
◆ TransactionIdIsInProgress()
Definition at line 1402 of file procarray.c.
1403{
1407 int nxids = 0;
1411 int mypgxactoff;
1412 int numProcs;
1413 int j;
1414
1415
1416
1417
1418
1419
1420
1422 {
1424 return false;
1425 }
1426
1427
1428
1429
1430
1431
1433 {
1435 return false;
1436 }
1437
1438
1439
1440
1441
1443 {
1445 return true;
1446 }
1447
1448
1449
1450
1451
1452 if (xids == NULL)
1453 {
1454
1455
1456
1457
1458
1460
1462 if (xids == NULL)
1464 (errcode(ERRCODE_OUT_OF_MEMORY),
1465 errmsg("out of memory")));
1466 }
1467
1470
1472
1473
1474
1475
1476
1477 latestCompletedXid =
1480 {
1483 return true;
1484 }
1485
1486
1488 numProcs = arrayP->numProcs;
1489 for (int pgxactoff = 0; pgxactoff < numProcs; pgxactoff++)
1490 {
1491 int pgprocno;
1494 int pxids;
1495
1496
1497 if (pgxactoff == mypgxactoff)
1498 continue;
1499
1500
1502
1504 continue;
1505
1506
1507
1508
1510 {
1513 return true;
1514 }
1515
1516
1517
1518
1519
1521 continue;
1522
1523
1524
1525
1526 pxids = other_subxidstates[pgxactoff].count;
1527 pg_read_barrier();
1528 pgprocno = arrayP->pgprocnos[pgxactoff];
1530 for (j = pxids - 1; j >= 0; j--)
1531 {
1532
1534
1536 {
1539 return true;
1540 }
1541 }
1542
1543
1544
1545
1546
1547
1548
1549
1550 if (other_subxidstates[pgxactoff].overflowed)
1551 xids[nxids++] = pxid;
1552 }
1553
1554
1555
1556
1557
1559 {
1560
1562
1564 {
1567 return true;
1568 }
1569
1570
1571
1572
1573
1574
1575
1576
1579 }
1580
1582
1583
1584
1585
1586
1587 if (nxids == 0)
1588 {
1591 return false;
1592 }
1593
1594
1595
1596
1597
1598
1599
1600
1601
1603
1605 {
1607 return false;
1608 }
1609
1610
1611
1612
1613
1614
1619 return true;
1620
1622 return false;
1623}
static bool pg_lfind32(uint32 key, const uint32 *base, uint32 nelem)
#define xc_no_overflow_inc()
#define xc_by_recent_xmin_inc()
static int KnownAssignedXidsGet(TransactionId *xarray, TransactionId xmax)
#define xc_by_my_xact_inc()
#define xc_by_known_assigned_inc()
#define xc_by_child_xid_inc()
#define xc_slow_answer_inc()
#define xc_by_main_xid_inc()
static bool KnownAssignedXidExists(TransactionId xid)
#define xc_by_latest_xid_inc()
#define xc_by_known_xact_inc()
static TransactionId cachedXidIsNotInProgress
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
References allProcs, Assert(), cachedXidIsNotInProgress, XidCacheStatus::count, ereport, errcode(), errmsg(), ERROR, j, KnownAssignedXidExists(), KnownAssignedXidsGet(), ProcArrayStruct::lastOverflowedXid, TransamVariablesData::latestCompletedXid, LW_SHARED, LWLockAcquire(), LWLockRelease(), malloc, ProcArrayStruct::maxProcs, MyProc, ProcArrayStruct::numProcs, pg_lfind32(), pg_read_barrier, ProcArrayStruct::pgprocnos, PGPROC::pgxactoff, procArray, ProcGlobal, RecentXmin, RecoveryInProgress(), SubTransGetTopmostTransaction(), PGPROC::subxids, PROC_HDR::subxidStates, TOTAL_MAX_CACHED_SUBXIDS, TransactionIdDidAbort(), TransactionIdEquals, TransactionIdIsCurrentTransactionId(), TransactionIdIsValid, TransactionIdPrecedes(), TransactionIdPrecedesOrEquals(), TransamVariables, UINT32_ACCESS_ONCE, xc_by_child_xid_inc, xc_by_known_assigned_inc, xc_by_known_xact_inc, xc_by_latest_xid_inc, xc_by_main_xid_inc, xc_by_my_xact_inc, xc_by_recent_xmin_inc, xc_no_overflow_inc, xc_slow_answer_inc, XidFromFullTransactionId, XidCache::xids, and PROC_HDR::xids.
Referenced by check_safe_enum_use(), compute_new_xmax_infomask(), ConditionalXactLockTableWait(), Do_MultiXactIdWait(), DoesMultiXactIdConflict(), FreezeMultiXactId(), get_xid_status(), HandleConcurrentAbort(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuumHorizon(), MultiXactIdExpand(), MultiXactIdIsRunning(), pg_xact_status(), ReorderBufferCheckAndTruncateAbortedTXN(), test_lockmode_for_conflict(), verify_heapam(), and XactLockTableWait().
◆ XidCacheRemoveRunningXids()
Definition at line 3991 of file procarray.c.
3994{
3995 int i,
3996 j;
3998
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4014
4016
4017
4018
4019
4020
4021
4022 for (i = nxids - 1; i >= 0; i--)
4023 {
4025
4027 {
4029 {
4032 mysubxidstat->count--;
4034 break;
4035 }
4036 }
4037
4038
4039
4040
4041
4042
4043
4044
4045 if (j < 0 && !MyProc->subxidStatus.overflowed)
4046 elog(WARNING, "did not find subXID %u in MyProc", anxid);
4047 }
4048
4050 {
4052 {
4055 mysubxidstat->count--;
4057 break;
4058 }
4059 }
4060
4061 if (j < 0 && !MyProc->subxidStatus.overflowed)
4062 elog(WARNING, "did not find subXID %u in MyProc", xid);
4063
4064
4066
4067
4069
4071}
References Assert(), XidCacheStatus::count, elog, i, j, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaintainLatestCompletedXid(), MyProc, pg_write_barrier, PGPROC::pgxactoff, ProcGlobal, PGPROC::subxids, PROC_HDR::subxidStates, PGPROC::subxidStatus, TransactionIdEquals, TransactionIdIsValid, TransamVariables, WARNING, TransamVariablesData::xactCompletionCount, and XidCache::xids.
Referenced by RecordTransactionAbort().
◆ allProcs
Definition at line 271 of file procarray.c.
Referenced by BackendPidGetProcWithLock(), BackendXidGetPid(), CancelDBBackends(), ComputeXidHorizons(), CountDBBackends(), CountDBConnections(), CountOtherDBBackends(), CountUserBackends(), GetConflictingVirtualXIDs(), GetCurrentVirtualXIDs(), GetRunningTransactionData(), GetSnapshotData(), GetVirtualXIDsDelayingChkpt(), HaveVirtualXIDsDelayingChkpt(), MinimumActiveBackends(), ProcArrayAdd(), ProcArrayGroupClearXid(), ProcArrayInstallImportedXmin(), ProcArrayRemove(), ProcArrayShmemInit(), SignalVirtualTransaction(), TerminateOtherDBBackends(), TransactionIdIsActive(), and TransactionIdIsInProgress().
◆ cachedXidIsNotInProgress
◆ ComputeXidHorizonsResultLastXmin
◆ GlobalVisCatalogRels
◆ GlobalVisDataRels
◆ GlobalVisSharedRels
◆ GlobalVisTempRels
◆ KnownAssignedXids
◆ KnownAssignedXidsValid
bool* KnownAssignedXidsValid | static |
---|
◆ latestObservedXid
Definition at line 269 of file procarray.c.
Referenced by BackendPidGetProcWithLock(), BackendXidGetPid(), CancelDBBackends(), ComputeXidHorizons(), CountDBBackends(), CountDBConnections(), CountOtherDBBackends(), CountUserBackends(), ExpireAllKnownAssignedTransactionIds(), ExpireOldKnownAssignedTransactionIds(), GetConflictingVirtualXIDs(), GetCurrentVirtualXIDs(), GetMaxSnapshotXidCount(), GetOldestActiveTransactionId(), GetOldestSafeDecodingTransactionId(), GetRunningTransactionData(), GetSnapshotData(), GetVirtualXIDsDelayingChkpt(), HaveVirtualXIDsDelayingChkpt(), KnownAssignedXidsAdd(), KnownAssignedXidsCompress(), KnownAssignedXidsDisplay(), KnownAssignedXidsGetAndSetXmin(), KnownAssignedXidsGetOldestXmin(), KnownAssignedXidsRemovePreceding(), KnownAssignedXidsReset(), KnownAssignedXidsSearch(), MinimumActiveBackends(), ProcArrayAdd(), ProcArrayApplyRecoveryInfo(), ProcArrayApplyXidAssignment(), ProcArrayGetReplicationSlotXmin(), ProcArrayInstallImportedXmin(), ProcArrayRemove(), ProcArraySetReplicationSlotXmin(), ProcArrayShmemInit(), SignalVirtualTransaction(), TerminateOtherDBBackends(), TransactionIdIsActive(), and TransactionIdIsInProgress().