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

Commit267c6ce

Browse files
committed
[refer #PGPRO-4197] Fix shm_mq access sycnhronization
1 parent1b095a1 commit267c6ce

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

‎pg_query_state.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ typedef struct
8686
slock_tmutex;/* protect concurrent access to `userid` */
8787
Oiduserid;
8888
Latch*caller;
89+
pg_atomic_uint32n_peers;
8990
}RemoteUserIdResult;
9091

9192
staticvoidSendCurrentUserId(void);
@@ -150,6 +151,7 @@ pg_qs_shmem_startup(void)
150151
counterpart_userid=shm_toc_allocate(toc,sizeof(RemoteUserIdResult));
151152
shm_toc_insert(toc,num_toc++,counterpart_userid);
152153
SpinLockInit(&counterpart_userid->mutex);
154+
pg_atomic_init_u32(&counterpart_userid->n_peers,0);
153155

154156
params=shm_toc_allocate(toc,sizeof(pg_qs_params));
155157
shm_toc_insert(toc,num_toc++,params);
@@ -481,6 +483,7 @@ pg_query_state(PG_FUNCTION_ARGS)
481483
shm_mq_msg*msg;
482484
List*bg_worker_procs=NIL;
483485
List*msgs;
486+
inti;
484487

485488
if (!module_initialized)
486489
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -513,6 +516,13 @@ pg_query_state(PG_FUNCTION_ARGS)
513516
init_lock_tag(&tag,PG_QUERY_STATE_KEY);
514517
LockAcquire(&tag,ExclusiveLock, false, false);
515518

519+
for (i=0;pg_atomic_read_u32(&counterpart_userid->n_peers)!=0&&i<MIN_TIMEOUT/1000;i++)
520+
{
521+
pg_usleep(1000000);/* wait one second */
522+
CHECK_FOR_INTERRUPTS();
523+
}
524+
pg_atomic_write_u32(&counterpart_userid->n_peers,1);
525+
516526
counterpart_user_id=GetRemoteBackendUserId(proc);
517527
if (!(superuser()||GetUserId()==counterpart_user_id))
518528
ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
@@ -970,6 +980,7 @@ GetRemoteBackendQueryStates(PGPROC *leader,
970980
continue;
971981
}
972982

983+
pg_atomic_add_fetch_u32(&counterpart_userid->n_peers,1);
973984
alive_procs=lappend(alive_procs,proc);
974985
}
975986

@@ -1023,7 +1034,6 @@ GetRemoteBackendQueryStates(PGPROC *leader,
10231034
shm_mq_detach(mqh);
10241035
#endif
10251036
}
1026-
10271037
returnresult;
10281038

10291039
signal_error:
@@ -1033,3 +1043,12 @@ GetRemoteBackendQueryStates(PGPROC *leader,
10331043
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
10341044
errmsg("error in message queue data transmitting")));
10351045
}
1046+
1047+
void
1048+
DetachPeer(void)
1049+
{
1050+
intn_peers=pg_atomic_fetch_sub_u32(&counterpart_userid->n_peers,1);
1051+
if (n_peers <=0)
1052+
ereport(LOG, (errcode(ERRCODE_INTERNAL_ERROR),
1053+
errmsg("pg_query_state peer is not responding")));
1054+
}

‎pg_query_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ extern shm_mq *mq;
6969

7070
/* signal_handler.c */
7171
externvoidSendQueryState(void);
72+
externvoidDetachPeer(void);
7273

7374
#endif

‎signal_handler.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,5 @@ SendQueryState(void)
214214
serialize_stack(msg->stack,qs_stack);
215215
shm_mq_send(mqh,msglen,msg, false);
216216
}
217+
DetachPeer();
217218
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp