Thread
-
[PATCH v35 09/21] Remove code related to at-abort pending deletes
Kyotaro Horiguchi <horikyota.ntt@gmail.com> — 2024-10-25T02:52:39Z
This is the second step in a series of three commits to modify pendingDeletes. With abort-time processing now managed by the storage UNDO log, the pendingDeletes system no longer handles these deletions. Consequently, the abort and prepare code paths no longer explicitly handle file deletions. Remove the outdated code from these paths. --- src/backend/access/rmgrdesc/xactdesc.c | 4 --- src/backend/access/transam/twophase.c | 34 ++++---------------------- src/backend/access/transam/xact.c | 23 ----------------- src/backend/catalog/storage.c | 27 ++++++-------------- src/include/access/xact.h | 2 -- 5 files changed, 13 insertions(+), 77 deletions(-) diff --git a/src/backend/access/rmgrdesc/xactdesc.c b/src/backend/access/rmgrdesc/xactdesc.c index 889cb955c18..08172df83fd 100644 --- a/src/backend/access/rmgrdesc/xactdesc.c +++ b/src/backend/access/rmgrdesc/xactdesc.c @@ -251,7 +251,6 @@ ParsePrepareRecord(uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *p parsed->dbId = xlrec->database; parsed->nsubxacts = xlrec->nsubxacts; parsed->nrels = xlrec->ncommitrels; - parsed->nabortrels = xlrec->nabortrels; parsed->nmsgs = xlrec->ninvalmsgs; strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen); @@ -263,9 +262,6 @@ ParsePrepareRecord(uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *p parsed->xlocators = (RelFileLocator *) bufptr; bufptr += MAXALIGN(xlrec->ncommitrels * sizeof(RelFileLocator)); - parsed->abortlocators = (RelFileLocator *) bufptr; - bufptr += MAXALIGN(xlrec->nabortrels * sizeof(RelFileLocator)); - parsed->stats = (xl_xact_stats_item *) bufptr; bufptr += MAXALIGN(xlrec->ncommitstats * sizeof(xl_xact_stats_item)); diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 8455ceb057a..d3dac67d8cd 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -212,8 +212,6 @@ static void RecordTransactionCommitPrepared(TransactionId xid, static void RecordTransactionAbortPrepared(TransactionId xid, int nchildren, TransactionId *children, - int nrels, - RelFileLocator *rels, int nstats, xl_xact_stats_item *stats, const char *gid); @@ -1089,7 +1087,7 @@ StartPrepare(GlobalTransaction gxact) TwoPhaseFileHeader hdr; TransactionId *children; RelFileLocator *commitrels; - RelFileLocator *abortrels; + xl_xact_stats_item *abortstats = NULL; xl_xact_stats_item *commitstats = NULL; SharedInvalidationMessage *invalmsgs; @@ -1116,7 +1114,6 @@ StartPrepare(GlobalTransaction gxact) hdr.owner = gxact->owner; hdr.nsubxacts = xactGetCommittedChildren(&children); hdr.ncommitrels = smgrGetPendingDeletes(true, &commitrels); - hdr.nabortrels = smgrGetPendingDeletes(false, &abortrels); hdr.ncommitstats = pgstat_get_transactional_drops(true, &commitstats); hdr.nabortstats = @@ -1146,11 +1143,6 @@ StartPrepare(GlobalTransaction gxact) save_state_data(commitrels, hdr.ncommitrels * sizeof(RelFileLocator)); pfree(commitrels); } - if (hdr.nabortrels > 0) - { - save_state_data(abortrels, hdr.nabortrels * sizeof(RelFileLocator)); - pfree(abortrels); - } if (hdr.ncommitstats > 0) { save_state_data(commitstats, @@ -1532,9 +1524,6 @@ FinishPreparedTransaction(const char *gid, bool isCommit) TransactionId latestXid; TransactionId *children; RelFileLocator *commitrels; - RelFileLocator *abortrels; - RelFileLocator *delrels; - int ndelrels; xl_xact_stats_item *commitstats; xl_xact_stats_item *abortstats; SharedInvalidationMessage *invalmsgs; @@ -1569,8 +1558,6 @@ FinishPreparedTransaction(const char *gid, bool isCommit) bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId)); commitrels = (RelFileLocator *) bufptr; bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileLocator)); - abortrels = (RelFileLocator *) bufptr; - bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileLocator)); commitstats = (xl_xact_stats_item *) bufptr; bufptr += MAXALIGN(hdr->ncommitstats * sizeof(xl_xact_stats_item)); abortstats = (xl_xact_stats_item *) bufptr; @@ -1603,7 +1590,6 @@ FinishPreparedTransaction(const char *gid, bool isCommit) else RecordTransactionAbortPrepared(xid, hdr->nsubxacts, children, - hdr->nabortrels, abortrels, hdr->nabortstats, abortstats, gid); @@ -1627,21 +1613,15 @@ FinishPreparedTransaction(const char *gid, bool isCommit) * consistency with the regular xact.c code paths, must do this before * releasing locks, so do it before running the callbacks. * + * Deletion at abort is handled by undo logs. + * * NB: this code knows that we couldn't be dropping any temp rels ... */ if (isCommit) { - delrels = commitrels; - ndelrels = hdr->ncommitrels; + /* Make sure files supposed to be dropped are dropped */ + DropRelationFiles(commitrels, hdr->ncommitrels, false); } - else - { - delrels = abortrels; - ndelrels = hdr->nabortrels; - } - - /* Make sure files supposed to be dropped are dropped */ - DropRelationFiles(delrels, ndelrels, false); if (isCommit) pgstat_execute_transactional_drops(hdr->ncommitstats, commitstats, false); @@ -2152,7 +2132,6 @@ RecoverPreparedTransactions(void) subxids = (TransactionId *) bufptr; bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId)); bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileLocator)); - bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileLocator)); bufptr += MAXALIGN(hdr->ncommitstats * sizeof(xl_xact_stats_item)); bufptr += MAXALIGN(hdr->nabortstats * sizeof(xl_xact_stats_item)); bufptr += MAXALIGN(hdr->ninvalmsgs * sizeof(SharedInvalidationMessage)); @@ -2433,8 +2412,6 @@ static void RecordTransactionAbortPrepared(TransactionId xid, int nchildren, TransactionId *children, - int nrels, - RelFileLocator *rels, int nstats, xl_xact_stats_item *stats, const char *gid) @@ -2466,7 +2443,6 @@ RecordTransactionAbortPrepared(TransactionId xid, */ recptr = XactLogAbortRecord(GetCurrentTimestamp(), nchildren, children, - nrels, rels, nstats, stats, MyXactFlags | XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xid, gid); diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 5739ef3b7f5..1a691c7a30e 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -1756,8 +1756,6 @@ RecordTransactionAbort(bool isSubXact) { TransactionId xid = GetCurrentTransactionIdIfAny(); TransactionId latestXid; - int nrels; - RelFileLocator *rels; int ndroppedstats = 0; xl_xact_stats_item *droppedstats = NULL; int nchildren; @@ -1802,7 +1800,6 @@ RecordTransactionAbort(bool isSubXact) replorigin_session_origin != DoNotReplicateId); /* Fetch the data we need for the abort record */ - nrels = smgrGetPendingDeletes(false, &rels); nchildren = xactGetCommittedChildren(&children); ndroppedstats = pgstat_get_transactional_drops(false, &droppedstats); @@ -1819,7 +1816,6 @@ RecordTransactionAbort(bool isSubXact) XactLogAbortRecord(xact_time, nchildren, children, - nrels, rels, ndroppedstats, droppedstats, MyXactFlags, InvalidTransactionId, NULL); @@ -1870,8 +1866,6 @@ RecordTransactionAbort(bool isSubXact) XactLastRecEnd = 0; /* And clean up local data */ - if (rels) - pfree(rels); if (ndroppedstats) pfree(droppedstats); @@ -6009,7 +6003,6 @@ XactLogCommitRecord(TimestampTz commit_time, XLogRecPtr XactLogAbortRecord(TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, - int nrels, RelFileLocator *rels, int ndroppedstats, xl_xact_stats_item *droppedstats, int xactflags, TransactionId twophase_xid, const char *twophase_gid) @@ -6017,7 +6010,6 @@ XactLogAbortRecord(TimestampTz abort_time, xl_xact_abort xlrec; xl_xact_xinfo xl_xinfo; xl_xact_subxacts xl_subxacts; - xl_xact_relfilelocators xl_relfilelocators; xl_xact_stats_items xl_dropped_stats; xl_xact_twophase xl_twophase; xl_xact_dbinfo xl_dbinfo; @@ -6049,13 +6041,6 @@ XactLogAbortRecord(TimestampTz abort_time, xl_subxacts.nsubxacts = nsubxacts; } - if (nrels > 0) - { - xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILELOCATORS; - xl_relfilelocators.nrels = nrels; - info |= XLR_SPECIAL_REL_UPDATE; - } - if (ndroppedstats > 0) { xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS; @@ -6114,14 +6099,6 @@ XactLogAbortRecord(TimestampTz abort_time, nsubxacts * sizeof(TransactionId)); } - if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS) - { - XLogRegisterData((char *) (&xl_relfilelocators), - MinSizeOfXactRelfileLocators); - XLogRegisterData((char *) rels, - nrels * sizeof(RelFileLocator)); - } - if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS) { XLogRegisterData((char *) (&xl_dropped_stats), diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index e3b0aa8983c..db9cdad25f8 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -47,19 +47,14 @@ int wal_skip_threshold = 2048; /* in kilobytes */ /* - * We keep a list of all relations (represented as RelFileLocator values) - * that have been created or deleted in the current transaction. When - * a relation is created, we create the physical file immediately, but - * remember it so that we can delete the file again if the current - * transaction is aborted. Conversely, a deletion request is NOT - * executed immediately, but is just entered in the list. When and if - * the transaction commits, we can delete the physical file. + * We keep a list of all deletion requests (represented as RelFileLocator + * values) that are NOT executed immediately. When and if the transaction + * commits, we can delete the physical file. * * To handle subtransactions, every entry is marked with its transaction - * nesting level. At subtransaction commit, we reassign the subtransaction's - * entries to the parent nesting level. At subtransaction abort, we can - * immediately execute the abort-time actions for all entries of the current - * nesting level. + * nesting level. At subtransaction commit, we reassign the subtransaction's + * entries to the parent nesting level. At subtransaction abort, we discard the + * commit-time actions for all entries of the current nesting level. * * NOTE: the list is kept in TopMemoryContext to be sure it won't disappear * unbetimes. It'd probably be OK to keep it in TopTransactionContext, @@ -895,11 +890,7 @@ smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr) RelFileLocator *rptr; PendingRelDelete *pending; - if (!forCommit) - { - *ptr = NULL; - return 0; - } + Assert(forCommit); nrels = 0; for (pending = pendingDeletes; pending != NULL; pending = pending->next) @@ -971,9 +962,7 @@ AtSubCommit_smgr(void) /* * AtSubAbort_smgr() --- Take care of subtransaction abort. * - * Delete created relations and forget about deleted relations. - * We can execute these operations immediately because we know this - * subtransaction will not commit. + * Drop pending deletes registered during the subtransaction. */ void AtSubAbort_smgr(void) diff --git a/src/include/access/xact.h b/src/include/access/xact.h index fb64d7413a2..a1ceb846ac3 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -359,7 +359,6 @@ typedef struct xl_xact_prepare Oid owner; /* user running the transaction */ int32 nsubxacts; /* number of following subxact XIDs */ int32 ncommitrels; /* number of delete-on-commit rels */ - int32 nabortrels; /* number of delete-on-abort rels */ int32 ncommitstats; /* number of stats to drop on commit */ int32 nabortstats; /* number of stats to drop on abort */ int32 ninvalmsgs; /* number of cache invalidation messages */ @@ -513,7 +512,6 @@ extern XLogRecPtr XactLogCommitRecord(TimestampTz commit_time, extern XLogRecPtr XactLogAbortRecord(TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, - int nrels, RelFileLocator *rels, int ndroppedstats, xl_xact_stats_item *droppedstats, int xactflags, TransactionId twophase_xid, -- 2.43.5 ----Next_Part(Thu_Oct_31_17_01_30_2024_620)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="v35-0010-Rename-confusing-function-names.patch"