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

Commit3e256e5

Browse files
committed
Add SKIP_LOCKED option to RangeVarGetRelidExtended().
This will be used for VACUUM (SKIP LOCKED).Author: Nathan BossartReviewed-By: Michael Paquier and Andres FreundDiscussion:https://postgr.es/m/20180306005349.b65whmvj7z6hbe2y@alap3.anarazel.de
1 parentd87510a commit3e256e5

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
boolretry= false;
227236
boolmissing_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-
elseif (!(flags&RVR_NOWAIT))
378+
elseif (!(flags&(RVR_NOWAIT |RVR_SKIP_LOCKED)))
367379
LockRelationOid(relId,lockmode);
368380
elseif (!ConditionalLockRelationOid(relId,lockmode))
369381
{
382+
intelevel= (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+
returnInvalidOid;
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
typedefenumRVROption
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
typedefvoid (*RangeVarGetRelidCallback) (constRangeVar*relation,OidrelId,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp