From f7b2413b716ae93bd5f2b7b3abb892c8a936f271 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sun, 23 Oct 2016 21:33:02 +0900 Subject: [PATCH 2/2] Rename pg_subtrans to pg_subxact pg_upgrade is updated to handle the transfer correctly to post-10 clusters. --- doc/src/sgml/func.sgml | 2 +- doc/src/sgml/storage.sgml | 2 +- doc/src/sgml/wal.sgml | 2 +- src/backend/access/transam/README | 18 +++++++++--------- src/backend/access/transam/subtrans.c | 8 ++++---- src/backend/access/transam/transam.c | 10 +++++----- src/backend/access/transam/twophase.c | 6 +++--- src/backend/access/transam/varsup.c | 6 +++--- src/backend/access/transam/xact.c | 2 +- src/backend/access/transam/xlog.c | 8 ++++---- src/backend/replication/basebackup.c | 2 +- src/backend/replication/logical/snapbuild.c | 2 +- src/backend/storage/ipc/procarray.c | 14 +++++++------- src/backend/utils/time/tqual.c | 2 +- src/bin/initdb/initdb.c | 2 +- src/bin/pg_basebackup/t/010_pg_basebackup.pl | 2 +- src/bin/pg_upgrade/exec.c | 7 ++++++- src/include/access/slru.h | 4 ++-- src/include/storage/proc.h | 2 +- 19 files changed, 53 insertions(+), 48 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index e9cfb06..74ccb77 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -15330,7 +15330,7 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n); pg_wal | 16 pg_hba.conf | 17 pg_stat_tmp | 18 - pg_subtrans | 19 + pg_subxact | 19 (19 rows) diff --git a/doc/src/sgml/storage.sgml b/doc/src/sgml/storage.sgml index 56aef3c..e72331d 100644 --- a/doc/src/sgml/storage.sgml +++ b/doc/src/sgml/storage.sgml @@ -121,7 +121,7 @@ Item - pg_subtrans + pg_subxact Subdirectory containing subtransaction status data diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index 1f9fac9..aa0eccb 100644 --- a/doc/src/sgml/wal.sgml +++ b/doc/src/sgml/wal.sgml @@ -201,7 +201,7 @@ - Internal data structures such as pg_xact, pg_subtrans, pg_multixact, + Internal data structures such as pg_xact, pg_subxact, pg_multixact, pg_serial, pg_notify, pg_stat, pg_snapshots are not directly checksummed, nor are pages protected by full page writes. However, where such data structures are persistent, WAL records are written that allow diff --git a/src/backend/access/transam/README b/src/backend/access/transam/README index e7dd19f..94553f1 100644 --- a/src/backend/access/transam/README +++ b/src/backend/access/transam/README @@ -198,7 +198,7 @@ parent. This maintains the invariant that child transactions have XIDs later than their parents, which is assumed in a number of places. The subsidiary actions of obtaining a lock on the XID and entering it into -pg_subtrans and PG_PROC are done at the time it is assigned. +pg_subxact and PG_PROC are done at the time it is assigned. A transaction that has no XID still needs to be identified for various purposes, notably holding locks. For this purpose we assign a "virtual @@ -331,10 +331,10 @@ of the xid fields is atomic, so assuming it for xmin as well is no extra risk. -pg_xact and pg_subtrans +pg_xact and pg_subxact ----------------------- -pg_xact and pg_subtrans are permanent (on-disk) storage of transaction related +pg_xact and pg_subxact are permanent (on-disk) storage of transaction related information. There is a limited number of pages of each kept in memory, so in many cases there is no need to actually read from disk. However, if there's a long running transaction or a backend sitting idle with an open @@ -367,24 +367,24 @@ allow unlimited transaction nesting depth, so any particular subtransaction's commit state is dependent on the commit status of each and every ancestor transaction. -The "subtransaction parent" (pg_subtrans) mechanism records, for each +The "subtransaction parent" (pg_subxact) mechanism records, for each transaction with an XID, the TransactionId of its parent transaction. This information is stored as soon as the subtransaction is assigned an XID. -Top-level transactions do not have a parent, so they leave their pg_subtrans +Top-level transactions do not have a parent, so they leave their pg_subxact entries set to the default value of zero (InvalidTransactionId). -pg_subtrans is used to check whether the transaction in question is still +pg_subxact is used to check whether the transaction in question is still running --- the main Xid of a transaction is recorded in the PGXACT struct, but since we allow arbitrary nesting of subtransactions, we can't fit all Xids in shared memory, so we have to store them on disk. Note, however, that for each transaction we keep a "cache" of Xids that are known to be part of the -transaction tree, so we can skip looking at pg_subtrans unless we know the +transaction tree, so we can skip looking at pg_subxact unless we know the cache has been overflowed. See storage/ipc/procarray.c for the gory details. -slru.c is the supporting mechanism for both pg_xact and pg_subtrans. It +slru.c is the supporting mechanism for both pg_xact and pg_subxact. It implements the LRU policy for in-memory buffer pages. The high-level routines for pg_xact are implemented in transam.c, while the low-level functions are in -clog.c. pg_subtrans is contained completely in subtrans.c. +clog.c. pg_subxact is contained completely in subtrans.c. Write-Ahead Log Coding diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c index 6871239..e0f0395 100644 --- a/src/backend/access/transam/subtrans.c +++ b/src/backend/access/transam/subtrans.c @@ -3,7 +3,7 @@ * subtrans.c * PostgreSQL subtransaction-log manager * - * The pg_subtrans manager is a pg_xact-like manager that stores the parent + * The pg_subxact manager is a pg_xact-like manager that stores the parent * transaction Id for each transaction. It is a fundamental part of the * nested transactions implementation. A main transaction has a parent * of InvalidTransactionId, and each subtransaction has its immediate parent. @@ -11,7 +11,7 @@ * opposite direction. * * are completely different from pg_xact, because we only need to remember - * pg_subtrans information for currently-open transactions. Thus, there is + * pg_subxact information for currently-open transactions. Thus, there is * no need to preserve data over a crash and restart. * * There are no XLOG interactions since we do not care about preserving @@ -179,7 +179,7 @@ SUBTRANSShmemInit(void) { SubTransCtl->PagePrecedes = SubTransPagePrecedes; SimpleLruInit(SubTransCtl, "subtrans", NUM_SUBTRANS_BUFFERS, 0, - SubtransControlLock, "pg_subtrans", + SubtransControlLock, "pg_subxact", LWTRANCHE_SUBTRANS_BUFFERS); /* Override default assumption that writes should be fsync'd */ SubTransCtl->do_fsync = false; @@ -240,7 +240,7 @@ StartupSUBTRANS(TransactionId oldestActiveXID) int endPage; /* - * Since we don't expect pg_subtrans to be valid across crashes, we + * Since we don't expect pg_subxact to be valid across crashes, we * initialize the currently-active page(s) to zeroes during startup. * Whenever we advance into a new page, ExtendSUBTRANS will likewise zero * the new page without regard to whatever was previously on disk. diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c index 0a103c3..9f11dfd 100644 --- a/src/backend/access/transam/transam.c +++ b/src/backend/access/transam/transam.c @@ -137,13 +137,13 @@ TransactionIdDidCommit(TransactionId transactionId) /* * If it's marked subcommitted, we have to check the parent recursively. * However, if it's older than TransactionXmin, we can't look at - * pg_subtrans; instead assume that the parent crashed without cleaning up + * pg_subxact; instead assume that the parent crashed without cleaning up * its children. * * Originally we Assert'ed that the result of SubTransGetParent was not * zero. However with the introduction of prepared transactions, there can * be a window just after database startup where we do not have complete - * knowledge in pg_subtrans of the transactions after TransactionXmin. + * knowledge in pg_subxact of the transactions after TransactionXmin. * StartupSUBTRANS() has ensured that any missing information will be * zeroed. Since this case should not happen under normal conditions, it * seems reasonable to emit a WARNING for it. @@ -157,7 +157,7 @@ TransactionIdDidCommit(TransactionId transactionId) parentXid = SubTransGetParent(transactionId); if (!TransactionIdIsValid(parentXid)) { - elog(WARNING, "no pg_subtrans entry for subcommitted XID %u", + elog(WARNING, "no pg_subxact entry for subcommitted XID %u", transactionId); return false; } @@ -193,7 +193,7 @@ TransactionIdDidAbort(TransactionId transactionId) /* * If it's marked subcommitted, we have to check the parent recursively. * However, if it's older than TransactionXmin, we can't look at - * pg_subtrans; instead assume that the parent crashed without cleaning up + * pg_subxact; instead assume that the parent crashed without cleaning up * its children. */ if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED) @@ -206,7 +206,7 @@ TransactionIdDidAbort(TransactionId transactionId) if (!TransactionIdIsValid(parentXid)) { /* see notes in TransactionIdDidCommit */ - elog(WARNING, "no pg_subtrans entry for subcommitted XID %u", + elog(WARNING, "no pg_subxact entry for subcommitted XID %u", transactionId); return true; } diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 8bed3f5..5b3831a 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1674,7 +1674,7 @@ CheckPointTwoPhase(XLogRecPtr redo_horizon) * * Our other responsibility is to determine and return the oldest valid XID * among the prepared xacts (if none, return ShmemVariableCache->nextXid). - * This is needed to synchronize pg_subtrans startup properly. + * This is needed to synchronize pg_subxact startup properly. * * If xids_p and nxids_p are not NULL, pointer to a palloc'd array of all * top-level xids is stored in *xids_p. The number of entries in the array @@ -1819,7 +1819,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p) * * Currently we simply call SubTransSetParent() for any subxids of prepared * transactions. If overwriteOK is true, it's OK if some XIDs have already - * been marked in pg_subtrans. + * been marked in pg_subxact. */ void StandbyRecoverPreparedTransactions(bool overwriteOK) @@ -1976,7 +1976,7 @@ RecoverPreparedTransactions(void) /* * Reconstruct subtrans state for the transaction --- needed - * because pg_subtrans is not preserved over a restart. Note that + * because pg_subxact is not preserved over a restart. Note that * we are linking all the subtransactions directly to the * top-level XID; there may originally have been a more complex * hierarchy, but there's no need to restore that exactly. diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 2f7e645..8703eea 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -166,7 +166,7 @@ GetNewTransactionId(bool isSubXact) * XID before we zero the page. Fortunately, a page of the commit log * holds 32K or more transactions, so we don't have to do this very often. * - * Extend pg_subtrans and pg_commit_ts too. + * Extend pg_subxact and pg_commit_ts too. */ ExtendCLOG(xid); ExtendCommitTs(xid); @@ -203,9 +203,9 @@ GetNewTransactionId(bool isSubXact) * * If there's no room to fit a subtransaction XID into PGPROC, set the * cache-overflowed flag instead. This forces readers to look in - * pg_subtrans to map subtransaction XIDs up to top-level XIDs. There is a + * pg_subxact to map subtransaction XIDs up to top-level XIDs. There is a * race-condition window, in that the new XID will not appear as running - * until its parent link has been placed into pg_subtrans. However, that + * until its parent link has been placed into pg_subxact. However, that * will happen before anyone could possibly have a reason to inquire about * the status of the XID, so it seems OK. (Snapshots taken during this * window *will* include the parent XID, so they will deliver the correct diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 0dc4d43..5703234 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -544,7 +544,7 @@ AssignTransactionId(TransactionState s) log_unknown_top = true; /* - * Generate a new Xid and record it in PG_PROC and pg_subtrans. + * Generate a new Xid and record it in PG_PROC and pg_subxact. * * NB: we must make the subtrans entry BEFORE the Xid appears anywhere in * shared storage other than PG_PROC; because if there's no room for it in diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ba1bce2..c21362d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8640,9 +8640,9 @@ CreateCheckPoint(int flags) PreallocXlogFiles(recptr); /* - * Truncate pg_subtrans if possible. We can throw away all data before + * Truncate pg_subxact if possible. We can throw away all data before * the oldest XMIN of any running transaction. No future transaction will - * attempt to reference any pg_subtrans entry older than that (see Asserts + * attempt to reference any pg_subxact entry older than that (see Asserts * in subtrans.c). During recovery, though, we mustn't do this because * StartupSUBTRANS hasn't been called yet. */ @@ -8979,9 +8979,9 @@ CreateRestartPoint(int flags) } /* - * Truncate pg_subtrans if possible. We can throw away all data before + * Truncate pg_subxact if possible. We can throw away all data before * the oldest XMIN of any running transaction. No future transaction will - * attempt to reference any pg_subtrans entry older than that (see Asserts + * attempt to reference any pg_subxact entry older than that (see Asserts * in subtrans.c). When hot standby is disabled, though, we mustn't do * this because StartupSUBTRANS hasn't been called yet. */ diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index ffc7e58..32c1998 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -134,7 +134,7 @@ static const char *excludeDirContents[] = "pg_snapshots", /* Contents zeroed on startup, see StartupSUBTRANS(). */ - "pg_subtrans", + "pg_subxact", /* end of list */ NULL diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index 8b59fc5..2d73734 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -20,7 +20,7 @@ * tables since the data we decode is wholly contained in the WAL * records. Also, our snapshots need to be different in comparison to normal * MVCC ones because in contrast to those we cannot fully rely on the clog and - * pg_subtrans for information about committed transactions because they might + * pg_subxact for information about committed transactions because they might * commit in the future from the POV of the WAL entry we're currently * decoding. This definition has the advantage that we only need to prevent * removal of catalog rows, while normal table's rows can still be diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index d41a79f..e4e88a9 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -935,7 +935,7 @@ ProcArrayApplyXidAssignment(TransactionId topxid, RecordKnownAssignedTransactionIds(max_xid); /* - * Notice that we update pg_subtrans with the top-level xid, rather than + * Notice that we update pg_subxact with the top-level xid, rather than * the parent xid. This is a difference between normal processing and * recovery, yet is still correct in all cases. The reason is that * subtransaction commit is not marked in clog until commit processing, so @@ -1152,7 +1152,7 @@ TransactionIdIsInProgress(TransactionId xid) } /* - * If the KnownAssignedXids overflowed, we have to check pg_subtrans + * If the KnownAssignedXids overflowed, we have to check pg_subxact * too. Fetch all xids from KnownAssignedXids that are lower than * xid, since if xid is a subtransaction its parent will always have a * lower value. Note we will collect both main and subXIDs here, but @@ -1166,7 +1166,7 @@ TransactionIdIsInProgress(TransactionId xid) /* * If none of the relevant caches overflowed, we know the Xid is not - * running without even looking at pg_subtrans. + * running without even looking at pg_subxact. */ if (nxids == 0) { @@ -1175,7 +1175,7 @@ TransactionIdIsInProgress(TransactionId xid) } /* - * Step 4: have to check pg_subtrans. + * Step 4: have to check pg_subxact. * * At this point, we know it's either a subtransaction of one of the Xids * in xids[], or it's not running. If it's an already-failed @@ -1276,7 +1276,7 @@ TransactionIdIsActive(TransactionId xid) * ignore concurrently running lazy VACUUMs because (a) they must be working * on other tables, and (b) they don't need to do snapshot-based lookups. * - * This is also used to determine where to truncate pg_subtrans. For that + * This is also used to determine where to truncate pg_subxact. For that * backends in all databases have to be considered, so rel = NULL has to be * passed in. * @@ -3081,14 +3081,14 @@ DisplayXidCache(void) * KnownAssignedXids list. In backends, this is copied into snapshots in * GetSnapshotData(), taking advantage of the fact that XidInMVCCSnapshot() * doesn't care about the distinction either. Subtransaction XIDs are - * effectively treated as top-level XIDs and in the typical case pg_subtrans + * effectively treated as top-level XIDs and in the typical case pg_subxact * links are *not* maintained (which does not affect visibility). * * We have room in KnownAssignedXids and in snapshots to hold maxProcs * * (1 + PGPROC_MAX_CACHED_SUBXIDS) XIDs, so every master transaction must * report its subtransaction XIDs in a WAL XLOG_XACT_ASSIGNMENT record at * least every PGPROC_MAX_CACHED_SUBXIDS. When we receive one of these - * records, we mark the subXIDs as children of the top XID in pg_subtrans, + * records, we mark the subXIDs as children of the top XID in pg_subxact, * and then remove them from KnownAssignedXids. This prevents overflow of * KnownAssignedXids and snapshots, at the cost that status checks for these * subXIDs will take a slower path through TransactionIdIsInProgress(). diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 41e89e1..5cfa917 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -1490,7 +1490,7 @@ XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot) * If the snapshot contains full subxact data, the fastest way to * check things is just to compare the given XID against both subxact * XIDs and top-level XIDs. If the snapshot overflowed, we have to - * use pg_subtrans to convert a subxact XID to its parent XID, but + * use pg_subxact to convert a subxact XID to its parent XID, but * then we need only look at top-level XIDs not subxacts. */ if (!snapshot->suboverflowed) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 9b82622..8f0460d 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -201,7 +201,7 @@ static const char *const subdirs[] = { "pg_notify", "pg_serial", "pg_snapshots", - "pg_subtrans", + "pg_subxact", "pg_twophase", "pg_multixact", "pg_multixact/members", diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index 579d7a1..61a1491 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -74,7 +74,7 @@ is_deeply( 'no WAL files copied'); # Contents of these directories should not be copied. -foreach my $dirname (qw(pg_dynshmem pg_notify pg_replslot pg_serial pg_snapshots pg_stat_tmp pg_subtrans)) +foreach my $dirname (qw(pg_dynshmem pg_notify pg_replslot pg_serial pg_snapshots pg_stat_tmp pg_subxact)) { is_deeply( [ sort(slurp_dir("$tempdir/backup/$dirname/")) ], diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index b242e30..c6633c9 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -300,7 +300,6 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "base"); check_single_dir(pg_data, "global"); check_single_dir(pg_data, "pg_multixact"); - check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, "pg_tblspc"); check_single_dir(pg_data, "pg_twophase"); @@ -315,6 +314,12 @@ check_data_dir(ClusterInfo *cluster) check_single_dir(pg_data, "pg_clog"); else check_single_dir(pg_data, "pg_xact"); + + /* pg_clog has been renamed to pg_xact in post-10 cluster */ + if (GET_MAJOR_VERSION(cluster->major_version) < 1000) + check_single_dir(pg_data, "pg_subtrans"); + else + check_single_dir(pg_data, "pg_subxact"); } diff --git a/src/include/access/slru.h b/src/include/access/slru.h index 96a1e44..54ad056 100644 --- a/src/include/access/slru.h +++ b/src/include/access/slru.h @@ -76,7 +76,7 @@ typedef struct SlruSharedData /* * Optional array of WAL flush LSNs associated with entries in the SLRU * pages. If not zero/NULL, we must flush WAL before writing pages (true - * for pg_xact, false for multixact, pg_subtrans, pg_notify). group_lsn[] + * for pg_xact, false for multixact, pg_subxact, pg_notify). group_lsn[] * has lsn_groups_per_page entries per buffer slot, each containing the * highest LSN known for a contiguous group of SLRU entries on that slot's * page. @@ -121,7 +121,7 @@ typedef struct SlruCtlData /* * This flag tells whether to fsync writes (true for pg_xact and multixact - * stuff, false for pg_subtrans and pg_notify). + * stuff, false for pg_subxact and pg_notify). */ bool do_fsync; diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 7dc8dac..08c2d68 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -30,7 +30,7 @@ * generated at least one subtransaction that didn't fit in the cache). * If none of the caches have overflowed, we can assume that an XID that's not * listed anywhere in the PGPROC array is not a running transaction. Else we - * have to look at pg_subtrans. + * have to look at pg_subxact. */ #define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */ -- 2.10.1