Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2eea494

Browse files
committed
Heed lock protocol in DROP OWNED BY
We were acquiring object locks then deleting objects one by one, insteadof acquiring all object locks first, ignoring those that did not exist,and then deleting all objects together. The latter is the correctprotocol to use, and what this commits changes to code to do. Failingto follow that leads to "cache lookup failed for relation XYZ" errorreports when DROP OWNED runs concurrently with other DDL -- for example,a session termination that removes some temp tables.Author: Álvaro HerreraReported-by: Mithun Chicklore Yogendra (Mithun CY)Reviewed-by: Ahsan Hadi, Tom LaneDiscussion:https://postgr.es/m/CADq3xVZTbzK4ZLKq+dn_vB4QafXXbmMgDP3trY-GuLnib2Ai1w@mail.gmail.com
1 parent8c0939d commit2eea494

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

‎src/backend/catalog/dependency.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ static void reportDependentObjects(const ObjectAddresses *targetObjects,
199199
staticvoiddeleteOneObject(constObjectAddress*object,
200200
Relation*depRel,int32flags);
201201
staticvoiddoDeletion(constObjectAddress*object,intflags);
202-
staticvoidAcquireDeletionLock(constObjectAddress*object,intflags);
203-
staticvoidReleaseDeletionLock(constObjectAddress*object);
204202
staticboolfind_expr_references_walker(Node*node,
205203
find_expr_references_context*context);
206204
staticvoideliminate_duplicate_dependencies(ObjectAddresses*addrs);
@@ -1526,11 +1524,14 @@ doDeletion(const ObjectAddress *object, int flags)
15261524
/*
15271525
* AcquireDeletionLock - acquire a suitable lock for deleting an object
15281526
*
1527+
* Accepts the same flags as performDeletion (though currently only
1528+
* PERFORM_DELETION_CONCURRENTLY does anything).
1529+
*
15291530
* We use LockRelation for relations, LockDatabaseObject for everything
1530-
* else.Note that dependency.c isnotconcerned with deleting any kind of
1531-
*shared-across-databases object, so we have no need for LockSharedObject.
1531+
* else.Shared-across-databases objects arenotcurrently supported
1532+
*because no caller cares, but could be modified to use LockSharedObject.
15321533
*/
1533-
staticvoid
1534+
void
15341535
AcquireDeletionLock(constObjectAddress*object,intflags)
15351536
{
15361537
if (object->classId==RelationRelationId)
@@ -1556,8 +1557,10 @@ AcquireDeletionLock(const ObjectAddress *object, int flags)
15561557

15571558
/*
15581559
* ReleaseDeletionLock - release an object deletion lock
1560+
*
1561+
* Companion to AcquireDeletionLock.
15591562
*/
1560-
staticvoid
1563+
void
15611564
ReleaseDeletionLock(constObjectAddress*object)
15621565
{
15631566
if (object->classId==RelationRelationId)

‎src/backend/catalog/pg_shdepend.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,14 +1325,29 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
13251325
sdepForm->objid);
13261326
break;
13271327
caseSHARED_DEPENDENCY_POLICY:
1328-
/* If unable to remove role from policy, remove policy. */
1328+
/*
1329+
* Try to remove role from policy; if unable to, remove
1330+
* policy.
1331+
*/
13291332
if (!RemoveRoleFromObjectPolicy(roleid,
13301333
sdepForm->classid,
13311334
sdepForm->objid))
13321335
{
13331336
obj.classId=sdepForm->classid;
13341337
obj.objectId=sdepForm->objid;
13351338
obj.objectSubId=sdepForm->objsubid;
1339+
/*
1340+
* Acquire lock on object, then verify this dependency
1341+
* is still relevant. If not, the object might have
1342+
* been dropped or the policy modified. Ignore the
1343+
* object in that case.
1344+
*/
1345+
AcquireDeletionLock(&obj,0);
1346+
if (!systable_recheck_tuple(scan,tuple))
1347+
{
1348+
ReleaseDeletionLock(&obj);
1349+
break;
1350+
}
13361351
add_exact_object_address(&obj,deleteobjs);
13371352
}
13381353
break;
@@ -1343,6 +1358,13 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
13431358
obj.classId=sdepForm->classid;
13441359
obj.objectId=sdepForm->objid;
13451360
obj.objectSubId=sdepForm->objsubid;
1361+
/* as above */
1362+
AcquireDeletionLock(&obj,0);
1363+
if (!systable_recheck_tuple(scan,tuple))
1364+
{
1365+
ReleaseDeletionLock(&obj);
1366+
break;
1367+
}
13461368
add_exact_object_address(&obj,deleteobjs);
13471369
}
13481370
break;

‎src/backend/commands/subscriptioncmds.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,6 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
928928
if (slotname)
929929
PreventInTransactionBlock(isTopLevel,"DROP SUBSCRIPTION");
930930

931-
932931
ObjectAddressSet(myself,SubscriptionRelationId,subid);
933932
EventTriggerSQLDropAddObject(&myself, true, true);
934933

‎src/include/catalog/dependency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ typedef enum ObjectClass
142142

143143
/* in dependency.c */
144144

145+
externvoidAcquireDeletionLock(constObjectAddress*object,intflags);
146+
147+
externvoidReleaseDeletionLock(constObjectAddress*object);
148+
145149
externvoidperformDeletion(constObjectAddress*object,
146150
DropBehaviorbehavior,intflags);
147151

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp