1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-15 19:21:59 +03:00

During transaction cleanup, release locks before deleting files.

There's no need to hold onto the locks until the files are needed,
and by doing it this way, we reduce the impact on other backends who
may be awaiting locks we hold.

Noah Misch
This commit is contained in:
Robert Haas
2012-06-14 10:19:33 -04:00
parent 6cd015bea3
commit cd80073445

View File

@ -1944,14 +1944,6 @@ CommitTransaction(void)
*/ */
AtEOXact_Inval(true); AtEOXact_Inval(true);
/*
* Likewise, dropping of files deleted during the transaction is best done
* after releasing relcache and buffer pins. (This is not strictly
* necessary during commit, since such pins should have been released
* already, but this ordering is definitely critical during abort.)
*/
smgrDoPendingDeletes(true);
AtEOXact_MultiXact(); AtEOXact_MultiXact();
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
@ -1961,6 +1953,17 @@ CommitTransaction(void)
RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_AFTER_LOCKS,
true, true); true, true);
/*
* Likewise, dropping of files deleted during the transaction is best done
* after releasing relcache and buffer pins. (This is not strictly
* necessary during commit, since such pins should have been released
* already, but this ordering is definitely critical during abort.) Since
* this may take many seconds, also delay until after releasing locks.
* Other backends will observe the attendant catalog changes and not
* attempt to access affected files.
*/
smgrDoPendingDeletes(true);
/* Check we've released all catcache entries */ /* Check we've released all catcache entries */
AtEOXact_CatCache(true); AtEOXact_CatCache(true);
@ -2354,7 +2357,6 @@ AbortTransaction(void)
AtEOXact_Buffers(false); AtEOXact_Buffers(false);
AtEOXact_RelationCache(false); AtEOXact_RelationCache(false);
AtEOXact_Inval(false); AtEOXact_Inval(false);
smgrDoPendingDeletes(false);
AtEOXact_MultiXact(); AtEOXact_MultiXact();
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_LOCKS,
@ -2362,6 +2364,7 @@ AbortTransaction(void)
ResourceOwnerRelease(TopTransactionResourceOwner, ResourceOwnerRelease(TopTransactionResourceOwner,
RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_AFTER_LOCKS,
false, true); false, true);
smgrDoPendingDeletes(false);
AtEOXact_CatCache(false); AtEOXact_CatCache(false);
AtEOXact_GUC(false, 1); AtEOXact_GUC(false, 1);
@ -4238,13 +4241,13 @@ AbortSubTransaction(void)
AtEOSubXact_RelationCache(false, s->subTransactionId, AtEOSubXact_RelationCache(false, s->subTransactionId,
s->parent->subTransactionId); s->parent->subTransactionId);
AtEOSubXact_Inval(false); AtEOSubXact_Inval(false);
AtSubAbort_smgr();
ResourceOwnerRelease(s->curTransactionOwner, ResourceOwnerRelease(s->curTransactionOwner,
RESOURCE_RELEASE_LOCKS, RESOURCE_RELEASE_LOCKS,
false, false); false, false);
ResourceOwnerRelease(s->curTransactionOwner, ResourceOwnerRelease(s->curTransactionOwner,
RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_AFTER_LOCKS,
false, false); false, false);
AtSubAbort_smgr();
AtEOXact_GUC(false, s->gucNestLevel); AtEOXact_GUC(false, s->gucNestLevel);
AtEOSubXact_SPI(false, s->subTransactionId); AtEOSubXact_SPI(false, s->subTransactionId);