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

Commit9bcf350

Browse files
committed
Apply Bryan's IPC Patches
From: Bryan Henderson <bryanh@giraffe.netgate.net>
1 parent930bce3 commit9bcf350

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.61 1997/11/10 05:10:21 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.62 1997/11/17 03:47:28 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -123,6 +123,32 @@ static Dllist *PortList;
123123

124124
staticshortPostPortName=-1;
125125
staticshortActiveBackends= FALSE;
126+
/* This is a boolean indicating that there is at least one backend
127+
that is accessing the current shared memory and semaphores.
128+
Between the time that we start up, or throw away shared memory
129+
segments and start over, and the time we generate the next
130+
backend (because we received a connection request), it is false.
131+
Other times, it is true.
132+
*/
133+
staticshortshmem_seq=0;
134+
/* This is a sequence number that indicates how many times we've had
135+
to throw away the shared memory and start over because we doubted
136+
its integrity. It starts off at zero and is incremented every
137+
time we start over. We use this to ensure that we use a new
138+
IPC shared memory key for the new shared memory segment in case
139+
the old segment isn't entirely gone yet.
140+
141+
The sequence actually cycles back to 0 after 9, so pathologically
142+
there could be an IPC failure if 10 sets of backends are all stuck
143+
and won't release IPC resources.
144+
*/
145+
146+
staticIpcMemoryKeyipc_key;
147+
/* This is the base IPC shared memory key. Other keys are generated by
148+
adding to this.
149+
*/
150+
151+
126152
staticintNextBackendId=MAXINT;/* XXX why? */
127153
staticchar*progname= (char*)NULL;
128154

@@ -904,11 +930,11 @@ ConnCreate(int serverFd, int *newFdP)
904930
staticvoid
905931
reset_shared(shortport)
906932
{
907-
IPCKeykey;
908-
909-
key=SystemPortAddressCreateIPCKey((SystemPortAddress)port);
910-
CreateSharedMemoryAndSemaphores(key);
911-
ActiveBackends= FALSE;
933+
ipc_key=port*1000+shmem_seq*100;
934+
CreateSharedMemoryAndSemaphores(ipc_key);
935+
ActiveBackends= FALSE;
936+
shmem_seq+=1;
937+
if (shmem_seq >=10)shmem_seq-=10;
912938
}
913939

914940
/*
@@ -1079,9 +1105,10 @@ BackendStartup(StartupInfo *packet,/* client's startup packet */
10791105
Backend*bn;/* for backend cleanup */
10801106
intpid,
10811107
i;
1082-
staticcharenvEntry[4][2*ARGV_SIZE];
1108+
#defineNR_ENVIRONMENT_VBL 5
1109+
staticcharenvEntry[NR_ENVIRONMENT_VBL][2*ARGV_SIZE];
10831110

1084-
for (i=0;i<4;++i)
1111+
for (i=0;i<NR_ENVIRONMENT_VBL;++i)
10851112
{
10861113
MemSet(envEntry[i],0,2*ARGV_SIZE);
10871114
}
@@ -1101,6 +1128,9 @@ BackendStartup(StartupInfo *packet,/* client's startup packet */
11011128
sprintf(envEntry[3],"PGDATA=%s",DataDir);
11021129
putenv(envEntry[3]);
11031130
}
1131+
sprintf(envEntry[4],"IPC_KEY=%d",ipc_key);
1132+
putenv(envEntry[4]);
1133+
11041134
if (DebugLvl>2)
11051135
{
11061136
char**p;

‎src/backend/utils/init/postinit.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.17 1997/11/10 15:15:40 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.18 1997/11/17 03:47:31 scrappy Exp $
1111
*
1212
* NOTES
1313
*InitPostgres() is the function called from PostgresMain
@@ -281,8 +281,9 @@ InitUserid()
281281
staticvoid
282282
InitCommunication()
283283
{
284-
char*postid;
285-
char*postport;
284+
char*postid;/* value of environment variable */
285+
char*postport;/* value of environment variable */
286+
char*ipc_key;/* value of environemnt variable */
286287
IPCKeykey=0;
287288

288289
/* ----------------
@@ -302,10 +303,15 @@ InitCommunication()
302303
Assert(MyBackendTag >=0);
303304
}
304305

305-
/* ----------------
306-
*try and get the ipc key from POSTPORT
307-
* ----------------
308-
*/
306+
307+
ipc_key=getenv("IPC_KEY");
308+
if (!PointerIsValid(ipc_key)) {
309+
key=-1;
310+
}else {
311+
key=atoi(ipc_key);
312+
Assert(MyBackendTag >=0);
313+
}
314+
309315
postport=getenv("POSTPORT");
310316

311317
if (PointerIsValid(postport))
@@ -315,8 +321,6 @@ InitCommunication()
315321
if (MyBackendTag==-1)
316322
elog(FATAL,"InitCommunication: missing POSTID");
317323

318-
key=SystemPortAddressCreateIPCKey(address);
319-
320324
/*
321325
* Enable this if you are trying to force the backend to run as if
322326
* it is running under the postmaster.
@@ -328,8 +332,11 @@ InitCommunication()
328332
* To enable emulation, run the following shell commands (in addition
329333
* to enabling this goto)
330334
*
331-
* % setenv POSTID 1 % setenv POSTPORT 4321 % postmaster & % kill -9
332-
* %1
335+
* % setenv POSTID 1
336+
* % setenv POSTPORT 4321
337+
* % setenv IPC_KEY 4321000
338+
* % postmaster &
339+
* % kill -9 %1
333340
*
334341
* Upon doing this, Postmaster will have allocated the shared memory
335342
* resources that Postgres will attach to if you enable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp