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

Commit9d9b9d4

Browse files
committed
Move cancel key generation to after forking the backend
Move responsibility of generating the cancel key to the backendprocess. The cancel key is now generated after forking, and thebackend advertises it in the ProcSignal array. When a cancel requestarrives, the backend handling it scans the ProcSignal array to findthe target pid and cancel key. This is similar to how this previouslyworked in the EXEC_BACKEND case with the ShmemBackendArray, justreusing the ProcSignal array.One notable change is that we no longer generate cancellation keys fornon-backend processes. We generated them before just to prevent amalicious user from canceling them; the keys for non-backend processeswere never actually given to anyone. There is now an explicit flagindicating whether a process has a valid key or not.I wrote this originally in preparation for supporting longer cancelkeys, but it's a nice cleanup on its own.Reviewed-by: Jelte Fennema-NioDiscussion:https://www.postgresql.org/message-id/508d0505-8b7a-4864-a681-e7e5edfe32aa@iki.fi
1 parent19de089 commit9d9b9d4

File tree

12 files changed

+193
-262
lines changed

12 files changed

+193
-262
lines changed

‎src/backend/postmaster/auxprocess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ AuxiliaryProcessMainCommon(void)
7171

7272
BaseInit();
7373

74-
ProcSignalInit();
74+
ProcSignalInit(false,0);
7575

7676
/*
7777
* Auxiliary processes don't run transactions, but they may need a

‎src/backend/postmaster/launch_backend.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include"storage/pg_shmem.h"
5959
#include"storage/pmsignal.h"
6060
#include"storage/proc.h"
61+
#include"storage/procsignal.h"
6162
#include"tcop/backend_startup.h"
6263
#include"tcop/tcopprot.h"
6364
#include"utils/builtins.h"
@@ -94,7 +95,6 @@ typedef int InheritableSocket;
9495
typedefstruct
9596
{
9697
charDataDir[MAXPGPATH];
97-
int32MyCancelKey;
9898
intMyPMChildSlot;
9999
#ifndefWIN32
100100
unsigned longUsedShmemSegID;
@@ -104,7 +104,6 @@ typedef struct
104104
#endif
105105
void*UsedShmemSegAddr;
106106
slock_t*ShmemLock;
107-
structbkend*ShmemBackendArray;
108107
#ifdefUSE_INJECTION_POINTS
109108
structInjectionPointsCtl*ActiveInjectionPoints;
110109
#endif
@@ -119,6 +118,7 @@ typedef struct
119118
PGPROC*AuxiliaryProcs;
120119
PGPROC*PreparedXactProcs;
121120
volatilePMSignalData*PMSignalState;
121+
ProcSignalHeader*ProcSignal;
122122
pid_tPostmasterPid;
123123
TimestampTzPgStartTime;
124124
TimestampTzPgReloadTime;
@@ -702,7 +702,6 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
702702

703703
strlcpy(param->DataDir,DataDir,MAXPGPATH);
704704

705-
param->MyCancelKey=MyCancelKey;
706705
param->MyPMChildSlot=MyPMChildSlot;
707706

708707
#ifdefWIN32
@@ -712,7 +711,6 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
712711
param->UsedShmemSegAddr=UsedShmemSegAddr;
713712

714713
param->ShmemLock=ShmemLock;
715-
param->ShmemBackendArray=ShmemBackendArray;
716714

717715
#ifdefUSE_INJECTION_POINTS
718716
param->ActiveInjectionPoints=ActiveInjectionPoints;
@@ -729,6 +727,7 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
729727
param->AuxiliaryProcs=AuxiliaryProcs;
730728
param->PreparedXactProcs=PreparedXactProcs;
731729
param->PMSignalState=PMSignalState;
730+
param->ProcSignal=ProcSignal;
732731

733732
param->PostmasterPid=PostmasterPid;
734733
param->PgStartTime=PgStartTime;
@@ -965,7 +964,6 @@ restore_backend_variables(BackendParameters *param)
965964

966965
SetDataDir(param->DataDir);
967966

968-
MyCancelKey=param->MyCancelKey;
969967
MyPMChildSlot=param->MyPMChildSlot;
970968

971969
#ifdefWIN32
@@ -975,7 +973,6 @@ restore_backend_variables(BackendParameters *param)
975973
UsedShmemSegAddr=param->UsedShmemSegAddr;
976974

977975
ShmemLock=param->ShmemLock;
978-
ShmemBackendArray=param->ShmemBackendArray;
979976

980977
#ifdefUSE_INJECTION_POINTS
981978
ActiveInjectionPoints=param->ActiveInjectionPoints;
@@ -992,6 +989,7 @@ restore_backend_variables(BackendParameters *param)
992989
AuxiliaryProcs=param->AuxiliaryProcs;
993990
PreparedXactProcs=param->PreparedXactProcs;
994991
PMSignalState=param->PMSignalState;
992+
ProcSignal=param->ProcSignal;
995993

996994
PostmasterPid=param->PostmasterPid;
997995
PgStartTime=param->PgStartTime;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp