public inbox for [email protected]help / color / mirror / Atom feed
[PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations 5+ messages / 3 participants [nested] [flat]
* [PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations @ 2019-05-29 14:03 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Kyotaro Horiguchi @ 2019-05-29 14:03 UTC (permalink / raw) The function longer does only deletions but also syncs. Rename the function to refect that. smgrGetPendingDeletes is not renamed since it does not change behavior. --- src/backend/access/transam/xact.c | 4 +-- src/backend/catalog/storage.c | 57 ++++++++++++++++++++------------------- src/include/catalog/storage.h | 2 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d7930c077d..cc0c43b2dd 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2228,7 +2228,7 @@ CommitTransaction(void) * Other backends will observe the attendant catalog changes and not * attempt to access affected files. */ - smgrDoPendingDeletes(true); + smgrDoPendingOperations(true); AtCommit_Notify(); AtEOXact_GUC(true, 1); @@ -2716,7 +2716,7 @@ AbortTransaction(void) ResourceOwnerRelease(TopTransactionResourceOwner, RESOURCE_RELEASE_AFTER_LOCKS, false, true); - smgrDoPendingDeletes(false); + smgrDoPendingOperations(false); AtEOXact_GUC(false, 1); AtEOXact_SPI(false); diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index e4bcdc390f..6ebe75aa37 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -53,17 +53,17 @@ * but I'm being paranoid. */ -typedef struct PendingRelDelete +typedef struct PendingRelOps { RelFileNode relnode; /* relation that may need to be deleted */ BackendId backend; /* InvalidBackendId if not a temp rel */ bool atCommit; /* T=work at commit; F=work at abort */ bool dosync; /* T=work is sync; F=work is delete */ int nestLevel; /* xact nesting level of request */ - struct PendingRelDelete *next; /* linked-list link */ -} PendingRelDelete; + struct PendingRelOps *next; /* linked-list link */ +} PendingRelOps; -static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ +static PendingRelOps *pendingDeletes = NULL; /* head of linked list */ /* * RelationCreateStorage @@ -79,7 +79,7 @@ static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ SMgrRelation RelationCreateStorage(RelFileNode rnode, char relpersistence) { - PendingRelDelete *pending; + PendingRelOps *pending; SMgrRelation srel; BackendId backend; bool needs_wal; @@ -110,8 +110,8 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence) log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM); /* Add the relation to the list of stuff to delete at abort */ - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOps *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOps)); pending->relnode = rnode; pending->backend = backend; pending->atCommit = false; /* delete if abort */ @@ -127,8 +127,8 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence) */ if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded()) { - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOps *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOps)); pending->relnode = rnode; pending->backend = backend; pending->atCommit = true; @@ -167,11 +167,11 @@ log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum) void RelationDropStorage(Relation rel) { - PendingRelDelete *pending; + PendingRelOps *pending; /* Add the relation to the list of stuff to delete at commit */ - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOps *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOps)); pending->relnode = rel->rd_node; pending->backend = rel->rd_backend; pending->atCommit = true; /* delete if commit */ @@ -185,9 +185,9 @@ RelationDropStorage(Relation rel) * present in the pending-delete list twice, once with atCommit true and * once with atCommit false. Hence, it will be physically deleted at end * of xact in either case (and the other entry will be ignored by - * smgrDoPendingDeletes, so no error will occur). We could instead remove - * the existing list entry and delete the physical file immediately, but - * for now I'll keep the logic simple. + * smgrDoPendingOperations, so no error will occur). We could instead + * remove the existing list entry and delete the physical file + * immediately, but for now I'll keep the logic simple. */ RelationCloseSmgr(rel); @@ -213,9 +213,9 @@ RelationDropStorage(Relation rel) void RelationPreserveStorage(RelFileNode rnode, bool atCommit) { - PendingRelDelete *pending; - PendingRelDelete *prev; - PendingRelDelete *next; + PendingRelOps *pending; + PendingRelOps *prev; + PendingRelOps *next; prev = NULL; for (pending = pendingDeletes; pending != NULL; pending = next) @@ -406,7 +406,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, } /* - * smgrDoPendingDeletes() -- Take care of relation deletes at end of xact. + * smgrDoPendingOperations() -- Take care of relation deletes and syncs at + * end of xact. * * This also runs when aborting a subxact; we want to clean up a failed * subxact immediately. @@ -417,12 +418,12 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, * already recovered the physical storage. */ void -smgrDoPendingDeletes(bool isCommit) +smgrDoPendingOperations(bool isCommit) { int nestLevel = GetCurrentTransactionNestLevel(); - PendingRelDelete *pending; - PendingRelDelete *prev; - PendingRelDelete *next; + PendingRelOps *pending; + PendingRelOps *prev; + PendingRelOps *next; int nrels = 0, i = 0, maxrels = 0; @@ -518,7 +519,7 @@ smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr) int nestLevel = GetCurrentTransactionNestLevel(); int nrels; RelFileNode *rptr; - PendingRelDelete *pending; + PendingRelOps *pending; nrels = 0; for (pending = pendingDeletes; pending != NULL; pending = pending->next) @@ -558,8 +559,8 @@ smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr) void PostPrepare_smgr(void) { - PendingRelDelete *pending; - PendingRelDelete *next; + PendingRelOps *pending; + PendingRelOps *next; for (pending = pendingDeletes; pending != NULL; pending = next) { @@ -580,7 +581,7 @@ void AtSubCommit_smgr(void) { int nestLevel = GetCurrentTransactionNestLevel(); - PendingRelDelete *pending; + PendingRelOps *pending; for (pending = pendingDeletes; pending != NULL; pending = pending->next) { @@ -599,7 +600,7 @@ AtSubCommit_smgr(void) void AtSubAbort_smgr(void) { - smgrDoPendingDeletes(false); + smgrDoPendingOperations(false); } void diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h index 3579d3f3eb..43836cf11c 100644 --- a/src/include/catalog/storage.h +++ b/src/include/catalog/storage.h @@ -30,7 +30,7 @@ extern void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, * These functions used to be in storage/smgr/smgr.c, which explains the * naming */ -extern void smgrDoPendingDeletes(bool isCommit); +extern void smgrDoPendingOperations(bool isCommit); extern int smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr); extern void AtSubCommit_smgr(void); extern void AtSubAbort_smgr(void); -- 2.16.3 ----Next_Part(Wed_Jul_10_13_19_14_2019_952)---- ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations @ 2019-05-29 14:03 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Kyotaro Horiguchi @ 2019-05-29 14:03 UTC (permalink / raw) The function longer does only deletions but also syncs. Rename the function to refect that. smgrGetPendingDeletes is not renamed since it does not change behavior. --- src/backend/access/transam/xact.c | 4 +-- src/backend/catalog/storage.c | 57 ++++++++++++++++++++------------------- src/include/catalog/storage.h | 2 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d7930c077d..cc0c43b2dd 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2228,7 +2228,7 @@ CommitTransaction(void) * Other backends will observe the attendant catalog changes and not * attempt to access affected files. */ - smgrDoPendingDeletes(true); + smgrDoPendingOperations(true); AtCommit_Notify(); AtEOXact_GUC(true, 1); @@ -2716,7 +2716,7 @@ AbortTransaction(void) ResourceOwnerRelease(TopTransactionResourceOwner, RESOURCE_RELEASE_AFTER_LOCKS, false, true); - smgrDoPendingDeletes(false); + smgrDoPendingOperations(false); AtEOXact_GUC(false, 1); AtEOXact_SPI(false); diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index e4bcdc390f..6ebe75aa37 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -53,17 +53,17 @@ * but I'm being paranoid. */ -typedef struct PendingRelDelete +typedef struct PendingRelOps { RelFileNode relnode; /* relation that may need to be deleted */ BackendId backend; /* InvalidBackendId if not a temp rel */ bool atCommit; /* T=work at commit; F=work at abort */ bool dosync; /* T=work is sync; F=work is delete */ int nestLevel; /* xact nesting level of request */ - struct PendingRelDelete *next; /* linked-list link */ -} PendingRelDelete; + struct PendingRelOps *next; /* linked-list link */ +} PendingRelOps; -static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ +static PendingRelOps *pendingDeletes = NULL; /* head of linked list */ /* * RelationCreateStorage @@ -79,7 +79,7 @@ static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ SMgrRelation RelationCreateStorage(RelFileNode rnode, char relpersistence) { - PendingRelDelete *pending; + PendingRelOps *pending; SMgrRelation srel; BackendId backend; bool needs_wal; @@ -110,8 +110,8 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence) log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM); /* Add the relation to the list of stuff to delete at abort */ - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOps *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOps)); pending->relnode = rnode; pending->backend = backend; pending->atCommit = false; /* delete if abort */ @@ -127,8 +127,8 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence) */ if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded()) { - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOps *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOps)); pending->relnode = rnode; pending->backend = backend; pending->atCommit = true; @@ -167,11 +167,11 @@ log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum) void RelationDropStorage(Relation rel) { - PendingRelDelete *pending; + PendingRelOps *pending; /* Add the relation to the list of stuff to delete at commit */ - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOps *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOps)); pending->relnode = rel->rd_node; pending->backend = rel->rd_backend; pending->atCommit = true; /* delete if commit */ @@ -185,9 +185,9 @@ RelationDropStorage(Relation rel) * present in the pending-delete list twice, once with atCommit true and * once with atCommit false. Hence, it will be physically deleted at end * of xact in either case (and the other entry will be ignored by - * smgrDoPendingDeletes, so no error will occur). We could instead remove - * the existing list entry and delete the physical file immediately, but - * for now I'll keep the logic simple. + * smgrDoPendingOperations, so no error will occur). We could instead + * remove the existing list entry and delete the physical file + * immediately, but for now I'll keep the logic simple. */ RelationCloseSmgr(rel); @@ -213,9 +213,9 @@ RelationDropStorage(Relation rel) void RelationPreserveStorage(RelFileNode rnode, bool atCommit) { - PendingRelDelete *pending; - PendingRelDelete *prev; - PendingRelDelete *next; + PendingRelOps *pending; + PendingRelOps *prev; + PendingRelOps *next; prev = NULL; for (pending = pendingDeletes; pending != NULL; pending = next) @@ -406,7 +406,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, } /* - * smgrDoPendingDeletes() -- Take care of relation deletes at end of xact. + * smgrDoPendingOperations() -- Take care of relation deletes and syncs at + * end of xact. * * This also runs when aborting a subxact; we want to clean up a failed * subxact immediately. @@ -417,12 +418,12 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, * already recovered the physical storage. */ void -smgrDoPendingDeletes(bool isCommit) +smgrDoPendingOperations(bool isCommit) { int nestLevel = GetCurrentTransactionNestLevel(); - PendingRelDelete *pending; - PendingRelDelete *prev; - PendingRelDelete *next; + PendingRelOps *pending; + PendingRelOps *prev; + PendingRelOps *next; int nrels = 0, i = 0, maxrels = 0; @@ -518,7 +519,7 @@ smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr) int nestLevel = GetCurrentTransactionNestLevel(); int nrels; RelFileNode *rptr; - PendingRelDelete *pending; + PendingRelOps *pending; nrels = 0; for (pending = pendingDeletes; pending != NULL; pending = pending->next) @@ -558,8 +559,8 @@ smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr) void PostPrepare_smgr(void) { - PendingRelDelete *pending; - PendingRelDelete *next; + PendingRelOps *pending; + PendingRelOps *next; for (pending = pendingDeletes; pending != NULL; pending = next) { @@ -580,7 +581,7 @@ void AtSubCommit_smgr(void) { int nestLevel = GetCurrentTransactionNestLevel(); - PendingRelDelete *pending; + PendingRelOps *pending; for (pending = pendingDeletes; pending != NULL; pending = pending->next) { @@ -599,7 +600,7 @@ AtSubCommit_smgr(void) void AtSubAbort_smgr(void) { - smgrDoPendingDeletes(false); + smgrDoPendingOperations(false); } void diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h index 3579d3f3eb..43836cf11c 100644 --- a/src/include/catalog/storage.h +++ b/src/include/catalog/storage.h @@ -30,7 +30,7 @@ extern void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, * These functions used to be in storage/smgr/smgr.c, which explains the * naming */ -extern void smgrDoPendingDeletes(bool isCommit); +extern void smgrDoPendingOperations(bool isCommit); extern int smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr); extern void AtSubCommit_smgr(void); extern void AtSubAbort_smgr(void); -- 2.16.3 ----Next_Part(Fri_Jul_12_17_37_25_2019_721)---- ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations @ 2019-05-29 14:03 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Kyotaro Horiguchi @ 2019-05-29 14:03 UTC (permalink / raw) The function longer does only deletions but also syncs. Rename the function to reflect that. smgrGetPendingDeletes is not renamed since it does not change behavior. --- src/backend/access/transam/xact.c | 4 +- src/backend/catalog/storage.c | 91 ++++++++++++++++++++------------------- src/include/catalog/storage.h | 2 +- 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index f594d33e7a..0123fb0f7f 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2228,7 +2228,7 @@ CommitTransaction(void) * Other backends will observe the attendant catalog changes and not * attempt to access affected files. */ - smgrDoPendingDeletes(true); + smgrDoPendingOperations(true); AtCommit_Notify(); AtEOXact_GUC(true, 1); @@ -2716,7 +2716,7 @@ AbortTransaction(void) ResourceOwnerRelease(TopTransactionResourceOwner, RESOURCE_RELEASE_AFTER_LOCKS, false, true); - smgrDoPendingDeletes(false); + smgrDoPendingOperations(false); AtEOXact_GUC(false, 1); AtEOXact_SPI(false); diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index 354a74c27c..544ef3aa55 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -54,18 +54,18 @@ * but I'm being paranoid. */ -/* entry type of pendingDeletes */ -typedef struct PendingRelDelete +/* entry type of pendingOperations */ +typedef struct PendingRelOp { RelFileNode relnode; /* relation that may need to be deleted */ BackendId backend; /* InvalidBackendId if not a temp rel */ bool atCommit; /* T=work at commit; F=work at abort */ PendingOpType op; /* type of operation to do */ int nestLevel; /* xact nesting level of request */ - struct PendingRelDelete *next; /* linked-list link */ -} PendingRelDelete; + struct PendingRelOp *next; /* linked-list link */ +} PendingRelOp; -static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ +static PendingRelOp *pendingOperations = NULL; /* head of linked list */ /* * RelationCreateStorage @@ -81,7 +81,7 @@ static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ SMgrRelation RelationCreateStorage(RelFileNode rnode, char relpersistence) { - PendingRelDelete *pending; + PendingRelOp *pending; SMgrRelation srel; BackendId backend; bool needs_wal; @@ -112,15 +112,15 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence) log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM); /* Add the relation to the list of stuff to delete at abort */ - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOp *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOp)); pending->relnode = rnode; pending->backend = backend; pending->atCommit = false; /* delete if abort */ pending->op = PENDING_DELETE; pending->nestLevel = GetCurrentTransactionNestLevel(); - pending->next = pendingDeletes; - pendingDeletes = pending; + pending->next = pendingOperations; + pendingOperations = pending; /* * We are going to skip WAL-logging for storage of persistent relations @@ -129,15 +129,15 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence) */ if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded()) { - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOp *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOp)); pending->relnode = rnode; pending->backend = backend; pending->atCommit = true; pending->op = PENDING_SYNC; pending->nestLevel = GetCurrentTransactionNestLevel(); - pending->next = pendingDeletes; - pendingDeletes = pending; + pending->next = pendingOperations; + pendingOperations = pending; } return srel; @@ -169,27 +169,27 @@ log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum) void RelationDropStorage(Relation rel) { - PendingRelDelete *pending; + PendingRelOp *pending; /* Add the relation to the list of stuff to delete at commit */ - pending = (PendingRelDelete *) - MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete)); + pending = (PendingRelOp *) + MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelOp)); pending->relnode = rel->rd_node; pending->backend = rel->rd_backend; pending->atCommit = true; /* delete if commit */ pending->op = PENDING_DELETE; pending->nestLevel = GetCurrentTransactionNestLevel(); - pending->next = pendingDeletes; - pendingDeletes = pending; + pending->next = pendingOperations; + pendingOperations = pending; /* * NOTE: if the relation was created in this transaction, it will now be * present in the pending-delete list twice, once with atCommit true and * once with atCommit false. Hence, it will be physically deleted at end * of xact in either case (and the other entry will be ignored by - * smgrDoPendingDeletes, so no error will occur). We could instead remove - * the existing list entry and delete the physical file immediately, but - * for now I'll keep the logic simple. + * smgrDoPendingOperations, so no error will occur). We could instead + * remove the existing list entry and delete the physical file + * immediately, but for now I'll keep the logic simple. */ RelationCloseSmgr(rel); @@ -215,12 +215,12 @@ RelationDropStorage(Relation rel) void RelationPreserveStorage(RelFileNode rnode, bool atCommit) { - PendingRelDelete *pending; - PendingRelDelete *prev; - PendingRelDelete *next; + PendingRelOp *pending; + PendingRelOp *prev; + PendingRelOp *next; prev = NULL; - for (pending = pendingDeletes; pending != NULL; pending = next) + for (pending = pendingOperations; pending != NULL; pending = next) { next = pending->next; if (RelFileNodeEquals(rnode, pending->relnode) @@ -231,7 +231,7 @@ RelationPreserveStorage(RelFileNode rnode, bool atCommit) if (prev) prev->next = next; else - pendingDeletes = next; + pendingOperations = next; pfree(pending); /* prev does not change */ } @@ -409,7 +409,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, } /* - * smgrDoPendingDeletes() -- Take care of relation deletes at end of xact. + * smgrDoPendingOperations() -- Take care of relation deletes and syncs at + * end of xact. * * This also runs when aborting a subxact; we want to clean up a failed * subxact immediately. @@ -420,12 +421,12 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, * already recovered the physical storage. */ void -smgrDoPendingDeletes(bool isCommit) +smgrDoPendingOperations(bool isCommit) { int nestLevel = GetCurrentTransactionNestLevel(); - PendingRelDelete *pending; - PendingRelDelete *prev; - PendingRelDelete *next; + PendingRelOp *pending; + PendingRelOp *prev; + PendingRelOp *next; int nrels = 0, i = 0, maxrels = 0; @@ -433,7 +434,7 @@ smgrDoPendingDeletes(bool isCommit) struct HTAB *synchash = NULL; prev = NULL; - for (pending = pendingDeletes; pending != NULL; pending = next) + for (pending = pendingOperations; pending != NULL; pending = next) { next = pending->next; if (pending->nestLevel < nestLevel) @@ -447,7 +448,7 @@ smgrDoPendingDeletes(bool isCommit) if (prev) prev->next = next; else - pendingDeletes = next; + pendingOperations = next; /* do deletion if called for */ if (pending->atCommit == isCommit) { @@ -576,10 +577,10 @@ smgrGetPendingOperations(PendingOpType op, bool forCommit, RelFileNode **ptr) int nestLevel = GetCurrentTransactionNestLevel(); int nrels; RelFileNode *rptr; - PendingRelDelete *pending; + PendingRelOp *pending; nrels = 0; - for (pending = pendingDeletes; pending != NULL; pending = pending->next) + for (pending = pendingOperations; pending != NULL; pending = pending->next) { if (pending->nestLevel >= nestLevel && pending->atCommit == forCommit && pending->backend == InvalidBackendId @@ -593,7 +594,7 @@ smgrGetPendingOperations(PendingOpType op, bool forCommit, RelFileNode **ptr) } rptr = (RelFileNode *) palloc(nrels * sizeof(RelFileNode)); *ptr = rptr; - for (pending = pendingDeletes; pending != NULL; pending = pending->next) + for (pending = pendingOperations; pending != NULL; pending = pending->next) { if (pending->nestLevel >= nestLevel && pending->atCommit == forCommit && pending->backend == InvalidBackendId @@ -630,13 +631,13 @@ smgrGetPendingSyncs(bool forCommit, RelFileNode **ptr) void PostPrepare_smgr(void) { - PendingRelDelete *pending; - PendingRelDelete *next; + PendingRelOp *pending; + PendingRelOp *next; - for (pending = pendingDeletes; pending != NULL; pending = next) + for (pending = pendingOperations; pending != NULL; pending = next) { next = pending->next; - pendingDeletes = next; + pendingOperations = next; /* must explicitly free the list entry */ pfree(pending); } @@ -646,15 +647,15 @@ PostPrepare_smgr(void) /* * AtSubCommit_smgr() --- Take care of subtransaction commit. * - * Reassign all items in the pending-deletes list to the parent transaction. + * Reassign all items in the pending-operations list to the parent transaction. */ void AtSubCommit_smgr(void) { int nestLevel = GetCurrentTransactionNestLevel(); - PendingRelDelete *pending; + PendingRelOp *pending; - for (pending = pendingDeletes; pending != NULL; pending = pending->next) + for (pending = pendingOperations; pending != NULL; pending = pending->next) { if (pending->nestLevel >= nestLevel) pending->nestLevel = nestLevel - 1; @@ -671,7 +672,7 @@ AtSubCommit_smgr(void) void AtSubAbort_smgr(void) { - smgrDoPendingDeletes(false); + smgrDoPendingOperations(false); } void diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h index 1de6f1655c..dcb3bc4b69 100644 --- a/src/include/catalog/storage.h +++ b/src/include/catalog/storage.h @@ -37,7 +37,7 @@ extern void RelationCopyStorage(SMgrRelation src, SMgrRelation dst, * These functions used to be in storage/smgr/smgr.c, which explains the * naming */ -extern void smgrDoPendingDeletes(bool isCommit); +extern void smgrDoPendingOperations(bool isCommit); extern int smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr); extern int smgrGetPendingSyncs(bool forCommit, RelFileNode **ptr); extern void AtSubCommit_smgr(void); -- 2.16.3 ----Next_Part(Wed_Aug_21_16_32_38_2019_483)---- ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v1 2/9] Use "template" initdb in tests @ 2023-02-03 05:51 Andres Freund <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Andres Freund @ 2023-02-03 05:51 UTC (permalink / raw) Discussion: https://postgr.es/m/[email protected] --- meson.build | 30 ++++++++++ .cirrus.yml | 3 +- src/test/perl/PostgreSQL/Test/Cluster.pm | 46 ++++++++++++++- src/test/regress/pg_regress.c | 74 ++++++++++++++++++------ src/Makefile.global.in | 52 +++++++++-------- 5 files changed, 161 insertions(+), 44 deletions(-) diff --git a/meson.build b/meson.build index 0a11efc97a1..0e8a72b12b9 100644 --- a/meson.build +++ b/meson.build @@ -3048,8 +3048,10 @@ testport = 40000 test_env = environment() temp_install_bindir = test_install_location / get_option('bindir') +test_initdb_template = meson.build_root() / 'tmp_install' / 'initdb-template' test_env.set('PG_REGRESS', pg_regress.full_path()) test_env.set('REGRESS_SHLIB', regress_module.full_path()) +test_env.set('INITDB_TEMPLATE', test_initdb_template) # Test suites that are not safe by default but can be run if selected # by the user via the whitespace-separated list in variable PG_TEST_EXTRA. @@ -3064,6 +3066,34 @@ if library_path_var != '' endif +# Create (and remove old) initdb template directory. Tests use that, where +# possible, to make it cheaper to run tests. +# +# Use python to remove the old cached initdb, as we cannot rely on a working +# 'rm' binary on windows. +test('initdb_cache', + python, + args: [ + '-c', ''' +import shutil +import sys +import subprocess + +shutil.rmtree(sys.argv[1], ignore_errors=True) +sp = subprocess.run(sys.argv[2:] + [sys.argv[1]]) +sys.exit(sp.returncode) +''', + test_initdb_template, + temp_install_bindir / 'initdb', + '-A', 'trust', '-N', '--no-instructions' + ], + priority: setup_tests_priority - 1, + timeout: 300, + is_parallel: false, + env: test_env, + suite: ['setup']) + + ############################################################### # Test Generation diff --git a/.cirrus.yml b/.cirrus.yml index e9cfc542cfe..f08da65ed76 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -115,8 +115,9 @@ task: test_minimal_script: | su postgres <<-EOF ulimit -c unlimited + meson test $MTEST_ARGS --suite setup meson test $MTEST_ARGS --num-processes ${TEST_JOBS} \ - tmp_install cube/regress pg_ctl/001_start_stop + cube/regress pg_ctl/001_start_stop EOF on_failure: diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index 5e161dbee60..4d449c35de9 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -522,8 +522,50 @@ sub init mkdir $self->backup_dir; mkdir $self->archive_dir; - PostgreSQL::Test::Utils::system_or_bail('initdb', '-D', $pgdata, '-A', - 'trust', '-N', @{ $params{extra} }); + # If available and if there aren't any parameters, use a previously + # initdb'd cluster as a template by copying it. For a lot of tests, that's + # substantially cheaper. Do so only if there aren't parameters, it doesn't + # seem worth figuring out whether they affect compatibility. + # + # There's very similar code in pg_regress.c, but we can't easily + # deduplicate it until we require perl at build time. + if (defined $params{extra} or !defined $ENV{INITDB_TEMPLATE}) + { + note("initializing database system by running initdb"); + PostgreSQL::Test::Utils::system_or_bail('initdb', '-D', $pgdata, '-A', + 'trust', '-N', @{ $params{extra} }); + } + else + { + my @copycmd; + my $expected_exitcode; + + note("initializing database system by copying initdb template"); + + if ($PostgreSQL::Test::Utils::windows_os) + { + @copycmd = qw(robocopy /E /NJS /NJH /NFL /NDL /NP); + $expected_exitcode = 1; # 1 denotes files were copied + } + else + { + @copycmd = qw(cp -a); + $expected_exitcode = 0; + } + + @copycmd = (@copycmd, $ENV{INITDB_TEMPLATE}, $pgdata); + + my $ret = PostgreSQL::Test::Utils::system_log(@copycmd); + + # See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR + if ($ret & 127 or $ret >> 8 != $expected_exitcode) + { + BAIL_OUT( + sprintf("failed to execute command \"%s\": $ret", + join(" ", @copycmd))); + } + } + PostgreSQL::Test::Utils::system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata, @{ $params{auth_extra} }); diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index b68632320a7..407e3915cec 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -2295,6 +2295,7 @@ regression_main(int argc, char *argv[], FILE *pg_conf; const char *env_wait; int wait_seconds; + const char *initdb_template_dir; /* * Prepare the temp instance @@ -2316,25 +2317,64 @@ regression_main(int argc, char *argv[], if (!directory_exists(buf)) make_directory(buf); - /* initdb */ initStringInfo(&cmd); - appendStringInfo(&cmd, - "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync", - bindir ? bindir : "", - bindir ? "/" : "", - temp_instance); - if (debug) - appendStringInfo(&cmd, " --debug"); - if (nolocale) - appendStringInfo(&cmd, " --no-locale"); - appendStringInfo(&cmd, " > \"%s/log/initdb.log\" 2>&1", outputdir); - fflush(NULL); - if (system(cmd.data)) + + /* + * Create data directory. + * + * If available, use a previously initdb'd cluster as a template by + * copying it. For a lot of tests, that's substantially cheaper. + * + * There's very similar code in Cluster.pm, but we can't easily de + * duplicate it until we require perl at build time. + */ + initdb_template_dir = getenv("INITDB_TEMPLATE"); + if (initdb_template_dir == NULL || nolocale || debug) { - bail("initdb failed\n" - "# Examine \"%s/log/initdb.log\" for the reason.\n" - "# Command was: %s", - outputdir, cmd.data); + note("initializing database system by running initdb"); + + appendStringInfo(&cmd, + "\"%s%sinitdb\" -D \"%s/data\" --no-clean --no-sync", + bindir ? bindir : "", + bindir ? "/" : "", + temp_instance); + if (debug) + appendStringInfo(&cmd, " --debug"); + if (nolocale) + appendStringInfo(&cmd, " --no-locale"); + appendStringInfo(&cmd, " > \"%s/log/initdb.log\" 2>&1", outputdir); + fflush(NULL); + if (system(cmd.data)) + { + bail("initdb failed\n" + "# Examine \"%s/log/initdb.log\" for the reason.\n" + "# Command was: %s", + outputdir, cmd.data); + } + } + else + { +#ifndef WIN32 + const char *copycmd = "cp -a \"%s\" \"%s/data\""; + int expected_exitcode = 0; +#else + const char *copycmd = "robocopy /E /NJS /NJH /NFL /NDL /NP \"%s\" \"%s/data\""; + int expected_exitcode = 1; /* 1 denotes files were copied */ +#endif + + note("initializing database system by copying initdb template"); + + appendStringInfo(&cmd, + copycmd, + initdb_template_dir, + temp_instance); + if (system(cmd.data) != expected_exitcode) + { + bail("copying of initdb template failed\n" + "# Examine \"%s/log/initdb.log\" for the reason.\n" + "# Command was: %s", + outputdir, cmd.data); + } } pfree(cmd.data); diff --git a/src/Makefile.global.in b/src/Makefile.global.in index df9f721a41a..0b4ca0eb6ae 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -397,30 +397,6 @@ check: temp-install .PHONY: temp-install -temp-install: | submake-generated-headers -ifndef NO_TEMP_INSTALL -ifneq ($(abs_top_builddir),) -ifeq ($(MAKELEVEL),0) - rm -rf '$(abs_top_builddir)'/tmp_install - $(MKDIR_P) '$(abs_top_builddir)'/tmp_install/log - $(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1 - $(MAKE) -j1 $(if $(CHECKPREP_TOP),-C $(CHECKPREP_TOP),) checkprep >>'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1 -endif -endif -endif - -# Tasks to run serially at the end of temp-install. Some EXTRA_INSTALL -# entries appear more than once in the tree, and parallel installs of the same -# file can fail with EEXIST. -checkprep: - $(if $(EXTRA_INSTALL),for extra in $(EXTRA_INSTALL); do $(MAKE) -C '$(top_builddir)'/$$extra DESTDIR='$(abs_top_builddir)'/tmp_install install || exit; done) - -PROVE = @PROVE@ -# There are common routines in src/test/perl, and some test suites have -# extra perl modules in their own directory. -PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir) -# User-supplied prove flags such as --verbose can be provided in PROVE_FLAGS. -PROVE_FLAGS = # prepend to path if already set, else just set it define add_to_path @@ -437,8 +413,36 @@ ld_library_path_var = LD_LIBRARY_PATH with_temp_install = \ PATH="$(abs_top_builddir)/tmp_install$(bindir):$(CURDIR):$$PATH" \ $(call add_to_path,$(strip $(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir)) \ + INITDB_TEMPLATE='$(abs_top_builddir)'/tmp_install/initdb-template \ $(with_temp_install_extra) +temp-install: | submake-generated-headers +ifndef NO_TEMP_INSTALL +ifneq ($(abs_top_builddir),) +ifeq ($(MAKELEVEL),0) + rm -rf '$(abs_top_builddir)'/tmp_install + $(MKDIR_P) '$(abs_top_builddir)'/tmp_install/log + $(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1 + $(MAKE) -j1 $(if $(CHECKPREP_TOP),-C $(CHECKPREP_TOP),) checkprep >>'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1 + + $(with_temp_install) initdb -A trust -N --no-instructions '$(abs_top_builddir)'/tmp_install/initdb-template >>'$(abs_top_builddir)'/tmp_install/log/initdb-template.log 2>&1 +endif +endif +endif + +# Tasks to run serially at the end of temp-install. Some EXTRA_INSTALL +# entries appear more than once in the tree, and parallel installs of the same +# file can fail with EEXIST. +checkprep: + $(if $(EXTRA_INSTALL),for extra in $(EXTRA_INSTALL); do $(MAKE) -C '$(top_builddir)'/$$extra DESTDIR='$(abs_top_builddir)'/tmp_install install || exit; done) + +PROVE = @PROVE@ +# There are common routines in src/test/perl, and some test suites have +# extra perl modules in their own directory. +PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir) +# User-supplied prove flags such as --verbose can be provided in PROVE_FLAGS. +PROVE_FLAGS = + ifeq ($(enable_tap_tests),yes) ifndef PGXS -- 2.38.0 --uu4yojthqnm7ulmd Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0003-ci-macos-Remove-use-of-DRANDOMIZE_ALLOCATED_MEMOR.patch" ^ permalink raw reply [nested|flat] 5+ messages in thread
* [PATCH v3 4/7] Handle pg_get_indexdef default args in system_functions.sql @ 2025-12-09 18:02 Mark Wong <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Mark Wong @ 2025-12-09 18:02 UTC (permalink / raw) Modernize pg_get_indexdef to use CREATE OR REPLACE FUNCTION to handle the optional column and pretty argument. --- src/backend/catalog/system_functions.sql | 7 +++++++ src/backend/utils/adt/ruleutils.c | 20 -------------------- src/include/catalog/pg_proc.dat | 5 +---- src/include/catalog/pg_retired.dat | 3 ++- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql index 4ddbf194fa8..72f5fdc06f9 100644 --- a/src/backend/catalog/system_functions.sql +++ b/src/backend/catalog/system_functions.sql @@ -678,6 +678,13 @@ LANGUAGE INTERNAL PARALLEL RESTRICTED AS 'pg_get_viewdef'; +CREATE OR REPLACE FUNCTION + pg_get_indexdef(view oid, "column" int DEFAULT 0, pretty bool DEFAULT false) +RETURNS TEXT +LANGUAGE INTERNAL +PARALLEL SAFE +AS 'pg_get_indexdef'; + -- -- The default permissions for functions mean that anyone can execute them. -- A number of functions shouldn't be executable by just anyone, but rather diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 29557f3c9d2..d8b8d7b4d38 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -1114,26 +1114,6 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) */ Datum pg_get_indexdef(PG_FUNCTION_ARGS) -{ - Oid indexrelid = PG_GETARG_OID(0); - int prettyFlags; - char *res; - - prettyFlags = PRETTYFLAG_INDENT; - - res = pg_get_indexdef_worker(indexrelid, 0, NULL, - false, false, - false, false, - prettyFlags, true); - - if (res == NULL) - PG_RETURN_NULL(); - - PG_RETURN_TEXT_P(string_to_text(res)); -} - -Datum -pg_get_indexdef_ext(PG_FUNCTION_ARGS) { Oid indexrelid = PG_GETARG_OID(0); int32 colno = PG_GETARG_INT32(1); diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 531d0dea7db..fee5efca41e 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -3964,9 +3964,6 @@ { oid => '1642', descr => 'role name by OID (with fallback)', proname => 'pg_get_userbyid', provolatile => 's', prorettype => 'name', proargtypes => 'oid', prosrc => 'pg_get_userbyid' }, -{ oid => '1643', descr => 'index description', - proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text', - proargtypes => 'oid', prosrc => 'pg_get_indexdef' }, { oid => '3415', descr => 'extended statistics object description', proname => 'pg_get_statisticsobjdef', provolatile => 's', prorettype => 'text', proargtypes => 'oid', @@ -8517,7 +8514,7 @@ { oid => '2507', descr => 'index description (full create statement or single expression) with pretty-print option', proname => 'pg_get_indexdef', provolatile => 's', prorettype => 'text', - proargtypes => 'oid int4 bool', prosrc => 'pg_get_indexdef_ext' }, + proargtypes => 'oid int4 bool', prosrc => 'pg_get_indexdef' }, { oid => '2508', descr => 'constraint description with pretty-print option', proname => 'pg_get_constraintdef', provolatile => 's', prorettype => 'text', proargtypes => 'oid bool', prosrc => 'pg_get_constraintdef_ext' }, diff --git a/src/include/catalog/pg_retired.dat b/src/include/catalog/pg_retired.dat index d5d51ddb3e8..768ce980a1d 100644 --- a/src/include/catalog/pg_retired.dat +++ b/src/include/catalog/pg_retired.dat @@ -19,6 +19,7 @@ { oid => '1573', proname => 'pg_get_ruledef' }, { oid => '1640', proname => 'pg_get_viewdef' }, -{ oid => '1641', proname => 'pg_get_viewdef' } +{ oid => '1641', proname => 'pg_get_viewdef' }, +{ oid => '1643', proname => 'pg_get_indexdef' } ] -- 2.43.0 --zd8Z8rlPOcTi77n/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0005-Handle-pg_get_constraintdef-default-args-in-syste.patch" ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2025-12-09 18:02 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-05-29 14:03 [PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations Kyotaro Horiguchi <[email protected]> 2019-05-29 14:03 [PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations Kyotaro Horiguchi <[email protected]> 2019-05-29 14:03 [PATCH 3/3] Rename smgrDoPendingDeletes to smgrDoPendingOperations Kyotaro Horiguchi <[email protected]> 2023-02-03 05:51 [PATCH v1 2/9] Use "template" initdb in tests Andres Freund <[email protected]> 2025-12-09 18:02 [PATCH v3 4/7] Handle pg_get_indexdef default args in system_functions.sql Mark Wong <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox