Skip to content

Commit 3e256e5

Browse files
committed
Add SKIP_LOCKED option to RangeVarGetRelidExtended().
This will be used for VACUUM (SKIP LOCKED). Author: Nathan Bossart Reviewed-By: Michael Paquier and Andres Freund Discussion: https://postgr.es/m/20180306005349.b65whmvj7z6hbe2y@alap3.anarazel.de
1 parent d87510a commit 3e256e5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/backend/catalog/namespace.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ static bool MatchNamedCall(HeapTuple proctup, int nargs, List *argnames,
212212
* If flags contains RVR_NOWAIT, throw an error if we'd have to wait for a
213213
* lock.
214214
*
215+
* If flags contains RVR_SKIP_LOCKED, return InvalidOid if we'd have to wait
216+
* for a lock.
217+
*
218+
* flags cannot contain both RVR_NOWAIT and RVR_SKIP_LOCKED.
219+
*
220+
* Note that if RVR_MISSING_OK and RVR_SKIP_LOCKED are both specified, a
221+
* return value of InvalidOid could either mean the relation is missing or it
222+
* could not be locked.
223+
*
215224
* Callback allows caller to check permissions or acquire additional locks
216225
* prior to grabbing the relation lock.
217226
*/
@@ -226,6 +235,9 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
226235
bool retry = false;
227236
bool missing_ok = (flags & RVR_MISSING_OK) != 0;
228237

238+
/* verify that flags do no conflict */
239+
Assert(!((flags & RVR_NOWAIT) && (flags & RVR_SKIP_LOCKED)));
240+
229241
/*
230242
* We check the catalog name and then ignore it.
231243
*/
@@ -363,20 +375,24 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
363375
*/
364376
if (!OidIsValid(relId))
365377
AcceptInvalidationMessages();
366-
else if (!(flags & RVR_NOWAIT))
378+
else if (!(flags & (RVR_NOWAIT | RVR_SKIP_LOCKED)))
367379
LockRelationOid(relId, lockmode);
368380
else if (!ConditionalLockRelationOid(relId, lockmode))
369381
{
382+
int elevel = (flags & RVR_SKIP_LOCKED) ? DEBUG1 : ERROR;
383+
370384
if (relation->schemaname)
371-
ereport(ERROR,
385+
ereport(elevel,
372386
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
373387
errmsg("could not obtain lock on relation \"%s.%s\"",
374388
relation->schemaname, relation->relname)));
375389
else
376-
ereport(ERROR,
390+
ereport(elevel,
377391
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
378392
errmsg("could not obtain lock on relation \"%s\"",
379393
relation->relname)));
394+
395+
return InvalidOid;
380396
}
381397

382398
/*

src/include/catalog/namespace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ typedef struct OverrideSearchPath
5353
typedef enum RVROption
5454
{
5555
RVR_MISSING_OK = 1 << 0, /* don't error if relation doesn't exist */
56-
RVR_NOWAIT = 1 << 1 /* error if relation cannot be locked */
56+
RVR_NOWAIT = 1 << 1, /* error if relation cannot be locked */
57+
RVR_SKIP_LOCKED = 1 << 2 /* skip if relation cannot be locked */
5758
} RVROption;
5859

5960
typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy