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

Commit59273a7

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 parent984aca4 commit59273a7

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
@@ -188,8 +188,6 @@ static void reportDependentObjects(const ObjectAddresses *targetObjects,
188188
staticvoiddeleteOneObject(constObjectAddress*object,
189189
Relation*depRel,int32flags);
190190
staticvoiddoDeletion(constObjectAddress*object,intflags);
191-
staticvoidAcquireDeletionLock(constObjectAddress*object,intflags);
192-
staticvoidReleaseDeletionLock(constObjectAddress*object);
193191
staticboolfind_expr_references_walker(Node*node,
194192
find_expr_references_context*context);
195193
staticvoideliminate_duplicate_dependencies(ObjectAddresses*addrs);
@@ -1326,11 +1324,14 @@ doDeletion(const ObjectAddress *object, int flags)
13261324
/*
13271325
* AcquireDeletionLock - acquire a suitable lock for deleting an object
13281326
*
1327+
* Accepts the same flags as performDeletion (though currently only
1328+
* PERFORM_DELETION_CONCURRENTLY does anything).
1329+
*
13291330
* We use LockRelation for relations, LockDatabaseObject for everything
1330-
* else.Note that dependency.c isnotconcerned with deleting any kind of
1331-
*shared-across-databases object, so we have no need for LockSharedObject.
1331+
* else.Shared-across-databases objects arenotcurrently supported
1332+
*because no caller cares, but could be modified to use LockSharedObject.
13321333
*/
1333-
staticvoid
1334+
void
13341335
AcquireDeletionLock(constObjectAddress*object,intflags)
13351336
{
13361337
if (object->classId==RelationRelationId)
@@ -1356,8 +1357,10 @@ AcquireDeletionLock(const ObjectAddress *object, int flags)
13561357

13571358
/*
13581359
* ReleaseDeletionLock - release an object deletion lock
1360+
*
1361+
* Companion to AcquireDeletionLock.
13591362
*/
1360-
staticvoid
1363+
void
13611364
ReleaseDeletionLock(constObjectAddress*object)
13621365
{
13631366
if (object->classId==RelationRelationId)

‎src/backend/catalog/pg_shdepend.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,14 +1240,29 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
12401240
sdepForm->objid);
12411241
break;
12421242
caseSHARED_DEPENDENCY_POLICY:
1243-
/* If unable to remove role from policy, remove policy. */
1243+
/*
1244+
* Try to remove role from policy; if unable to, remove
1245+
* policy.
1246+
*/
12441247
if (!RemoveRoleFromObjectPolicy(roleid,
12451248
sdepForm->classid,
12461249
sdepForm->objid))
12471250
{
12481251
obj.classId=sdepForm->classid;
12491252
obj.objectId=sdepForm->objid;
12501253
obj.objectSubId=sdepForm->objsubid;
1254+
/*
1255+
* Acquire lock on object, then verify this dependency
1256+
* is still relevant. If not, the object might have
1257+
* been dropped or the policy modified. Ignore the
1258+
* object in that case.
1259+
*/
1260+
AcquireDeletionLock(&obj,0);
1261+
if (!systable_recheck_tuple(scan,tuple))
1262+
{
1263+
ReleaseDeletionLock(&obj);
1264+
break;
1265+
}
12511266
add_exact_object_address(&obj,deleteobjs);
12521267
}
12531268
break;
@@ -1258,6 +1273,13 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
12581273
obj.classId=sdepForm->classid;
12591274
obj.objectId=sdepForm->objid;
12601275
obj.objectSubId=sdepForm->objsubid;
1276+
/* as above */
1277+
AcquireDeletionLock(&obj,0);
1278+
if (!systable_recheck_tuple(scan,tuple))
1279+
{
1280+
ReleaseDeletionLock(&obj);
1281+
break;
1282+
}
12611283
add_exact_object_address(&obj,deleteobjs);
12621284
}
12631285
break;

‎src/backend/commands/subscriptioncmds.c

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

902-
903902
ObjectAddressSet(myself,SubscriptionRelationId,subid);
904903
EventTriggerSQLDropAddObject(&myself, true, true);
905904

‎src/include/catalog/dependency.h

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

196196
/* in dependency.c */
197197

198+
externvoidAcquireDeletionLock(constObjectAddress*object,intflags);
199+
200+
externvoidReleaseDeletionLock(constObjectAddress*object);
201+
198202
externvoidperformDeletion(constObjectAddress*object,
199203
DropBehaviorbehavior,intflags);
200204

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp