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

Commit8b7ae5a

Browse files
committed
Stabilize the results of pg_notification_queue_usage().
This function wasn't touched in commit51004c7, but that turns outto be a bad idea, because its results now include any dead spacethat exists in the NOTIFY queue on account of our being lazy aboutadvancing the queue tail. Notably, the isolation tests now failif run twice without a server restart between, because async-notify'sfirst test of the function will already show a positive value.It seems likely that end users would be equally unhappy about theresult's instability. To fix, just make the function callasyncQueueAdvanceTail before computing its result. That should endin producing the same value as before, and it's hard to believe thatthere's any practical use-case where pg_notification_queue_usage()is called so often as to create a performance degradation, especiallycompared to what we did before.Out of paranoia, also mark this function parallel-restricted (itwas volatile, but parallel-safe by default, before). Although thecode seems to work fine when run in a parallel worker, that's outsidethe design scope of async.c, and it's a bit scary to have intentionalside-effects happening in a parallel worker. There seems no plausibleuse-case where it'd be important to try to parallelize this, so let'snot take any risk of introducing new bugs.In passing, re-pgindent async.c and run reformat-dat-files onpg_proc.dat, just because I'm a neatnik.Discussion:https://postgr.es/m/13881.1574557302@sss.pgh.pa.us
1 parent91da65f commit8b7ae5a

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

‎src/backend/commands/async.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ typedef struct
347347
typedefstructActionList
348348
{
349349
intnestingLevel;/* current transaction nesting depth */
350-
List*actions;/* list of ListenAction structs */
350+
List*actions;/* list of ListenAction structs */
351351
structActionList*upper;/* details for upper transaction levels */
352352
}ActionList;
353353

@@ -393,7 +393,7 @@ typedef struct NotificationList
393393
intnestingLevel;/* current transaction nesting depth */
394394
List*events;/* list of Notification structs */
395395
HTAB*hashtab;/* hash of NotificationHash structs, or NULL */
396-
structNotificationList*upper;/* details for upper transaction levels */
396+
structNotificationList*upper;/* details for upper transaction levels */
397397
}NotificationList;
398398

399399
#defineMIN_HASHABLE_NOTIFIES 16/* threshold to build hashtab */
@@ -1554,6 +1554,9 @@ pg_notification_queue_usage(PG_FUNCTION_ARGS)
15541554
{
15551555
doubleusage;
15561556

1557+
/* Advance the queue tail so we don't report a too-large result */
1558+
asyncQueueAdvanceTail();
1559+
15571560
LWLockAcquire(AsyncQueueLock,LW_SHARED);
15581561
usage=asyncQueueUsage();
15591562
LWLockRelease(AsyncQueueLock);
@@ -1834,9 +1837,8 @@ AtSubAbort_Notify(void)
18341837
* those are allocated in TopTransactionContext.
18351838
*
18361839
* Note that there might be no entries at all, or no entries for the
1837-
* current subtransaction level, either because none were ever created,
1838-
* or because we reentered this routine due to trouble during subxact
1839-
* abort.
1840+
* current subtransaction level, either because none were ever created, or
1841+
* because we reentered this routine due to trouble during subxact abort.
18401842
*/
18411843
while (pendingActions!=NULL&&
18421844
pendingActions->nestingLevel >=my_level)
@@ -2400,9 +2402,9 @@ ClearPendingActionsAndNotifies(void)
24002402
{
24012403
/*
24022404
* Everything's allocated in either TopTransactionContext or the context
2403-
* for the subtransaction to which it corresponds. So, there's nothing
2404-
*todo here exceptrest the pointers; the space will be reclaimed when
2405-
*thecontexts are deleted.
2405+
* for the subtransaction to which it corresponds.So, there's nothing to
2406+
* do here exceptreset the pointers; the space will be reclaimed when the
2407+
* contexts are deleted.
24062408
*/
24072409
pendingActions=NULL;
24082410
pendingNotifies=NULL;

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201911212
56+
#defineCATALOG_VERSION_NO201911241
5757

5858
#endif

‎src/include/catalog/pg_proc.dat

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7653,7 +7653,7 @@
76537653
{ oid => '3296',
76547654
descr => 'get the fraction of the asynchronous notification queue currently in use',
76557655
proname => 'pg_notification_queue_usage', provolatile => 'v',
7656-
prorettype => 'float8', proargtypes => '',
7656+
proparallel => 'r',prorettype => 'float8', proargtypes => '',
76577657
prosrc => 'pg_notification_queue_usage' },
76587658

76597659
# non-persistent series generator
@@ -9333,14 +9333,13 @@
93339333
proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_match' },
93349334

93359335
{ oid => '1177', descr => 'jsonpath exists test with timezone',
9336-
proname => 'jsonb_path_exists_tz', provolatile => 's',
9337-
prorettype => 'bool',proargtypes => 'jsonb jsonpath jsonb bool',
9336+
proname => 'jsonb_path_exists_tz', provolatile => 's', prorettype => 'bool',
9337+
proargtypes => 'jsonb jsonpath jsonb bool',
93389338
prosrc => 'jsonb_path_exists_tz' },
93399339
{ oid => '1179', descr => 'jsonpath query with timezone',
9340-
proname => 'jsonb_path_query_tz', provolatile => 's',
9341-
prorows => '1000', proretset => 't',
9342-
prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
9343-
prosrc => 'jsonb_path_query_tz' },
9340+
proname => 'jsonb_path_query_tz', prorows => '1000', proretset => 't',
9341+
provolatile => 's', prorettype => 'jsonb',
9342+
proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_query_tz' },
93449343
{ oid => '1180', descr => 'jsonpath query wrapped into array with timezone',
93459344
proname => 'jsonb_path_query_array_tz', provolatile => 's',
93469345
prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
@@ -9350,9 +9349,8 @@
93509349
prorettype => 'jsonb', proargtypes => 'jsonb jsonpath jsonb bool',
93519350
prosrc => 'jsonb_path_query_first_tz' },
93529351
{ oid => '2030', descr => 'jsonpath match with timezone',
9353-
proname => 'jsonb_path_match_tz', provolatile => 's',
9354-
prorettype => 'bool', proargtypes => 'jsonb jsonpath jsonb bool',
9355-
prosrc => 'jsonb_path_match_tz' },
9352+
proname => 'jsonb_path_match_tz', provolatile => 's', prorettype => 'bool',
9353+
proargtypes => 'jsonb jsonpath jsonb bool', prosrc => 'jsonb_path_match_tz' },
93569354

93579355
{ oid => '4010', descr => 'implementation of @? operator',
93589356
proname => 'jsonb_path_exists_opr', prorettype => 'bool',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp