Skip to content

Commit a7fd03e

Browse files
committed
Handle clog structure in shared memory in exec() case, for Win32.
1 parent 36fa297 commit a7fd03e

File tree

7 files changed

+90
-29
lines changed

7 files changed

+90
-29
lines changed

src/backend/access/transam/clog.c

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.14 2003/05/02 21:59:31 momjian Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.15 2003/05/03 03:52:07 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -157,7 +157,7 @@ static ClogCtlData *ClogCtl = NULL;
157157
* The value is automatically inherited by backends via fork, and
158158
* doesn't need to be in shared memory.
159159
*/
160-
static LWLockId ClogBufferLocks[NUM_CLOG_BUFFERS]; /* Per-buffer I/O locks */
160+
static LWLockId *ClogBufferLocks; /* Per-buffer I/O locks */
161161

162162
/*
163163
* ClogDir is set during CLOGShmemInit and does not change thereafter.
@@ -271,41 +271,67 @@ TransactionIdGetStatus(TransactionId xid)
271271
/*
272272
* Initialization of shared memory for CLOG
273273
*/
274-
275274
int
276275
CLOGShmemSize(void)
277276
{
278-
return MAXALIGN(sizeof(ClogCtlData) + CLOG_BLCKSZ * NUM_CLOG_BUFFERS);
277+
return MAXALIGN(sizeof(ClogCtlData) + CLOG_BLCKSZ * NUM_CLOG_BUFFERS)
278+
#ifdef EXEC_BACKEND
279+
+ MAXALIGN(NUM_CLOG_BUFFERS * sizeof(LWLockId))
280+
#endif
281+
;
279282
}
280283

284+
281285
void
282286
CLOGShmemInit(void)
283287
{
284288
bool found;
285-
char *bufptr;
286289
int slotno;
287290

291+
/* Handle ClogCtl */
292+
288293
/* this must agree with space requested by CLOGShmemSize() */
289-
ClogCtl = (ClogCtlData *)
290-
ShmemInitStruct("CLOG Ctl",
291-
MAXALIGN(sizeof(ClogCtlData) +
292-
CLOG_BLCKSZ * NUM_CLOG_BUFFERS),
293-
&found);
294-
Assert(!found);
294+
ClogCtl = (ClogCtlData *) ShmemInitStruct("CLOG Ctl",
295+
MAXALIGN(sizeof(ClogCtlData) +
296+
CLOG_BLCKSZ * NUM_CLOG_BUFFERS), &found);
295297

296-
memset(ClogCtl, 0, sizeof(ClogCtlData));
298+
if (!IsUnderPostmaster)
299+
/* Initialize ClogCtl shared memory area */
300+
{
301+
char *bufptr;
297302

298-
bufptr = ((char *) ClogCtl) + sizeof(ClogCtlData);
303+
Assert(!found);
299304

300-
for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
301-
{
302-
ClogCtl->page_buffer[slotno] = bufptr;
303-
ClogCtl->page_status[slotno] = CLOG_PAGE_EMPTY;
304-
ClogBufferLocks[slotno] = LWLockAssign();
305-
bufptr += CLOG_BLCKSZ;
306-
}
305+
memset(ClogCtl, 0, sizeof(ClogCtlData));
306+
307+
bufptr = (char *)ClogCtl + sizeof(ClogCtlData);
308+
309+
for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
310+
{
311+
ClogCtl->page_buffer[slotno] = bufptr;
312+
ClogCtl->page_status[slotno] = CLOG_PAGE_EMPTY;
313+
bufptr += CLOG_BLCKSZ;
314+
}
307315

308-
/* ClogCtl->latest_page_number will be set later */
316+
/* ClogCtl->latest_page_number will be set later */
317+
}
318+
else
319+
Assert(found);
320+
321+
/* Handle ClogBufferLocks */
322+
323+
#ifdef EXEC_BACKEND
324+
ClogBufferLocks = (LWLockId *) ShmemInitStruct("CLOG Buffer Locks",
325+
NUM_CLOG_BUFFERS * sizeof(LWLockId), &found);
326+
Assert((!found && !IsUnderPostmaster) || (found && IsUnderPostmaster));
327+
#else
328+
ClogBufferLocks = malloc(NUM_CLOG_BUFFERS * sizeof(LWLockId));
329+
Assert(ClogBufferLocks);
330+
#endif
331+
332+
if (!IsUnderPostmaster)
333+
for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
334+
ClogBufferLocks[slotno] = LWLockAssign();
309335

310336
/* Init CLOG directory path */
311337
snprintf(ClogDir, MAXPGPATH, "%s/pg_clog", DataDir);

src/backend/bootstrap/bootstrap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.150 2003/05/02 21:59:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.151 2003/05/03 03:52:07 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -301,6 +301,11 @@ BootstrapMain(int argc, char *argv[])
301301

302302
Assert(dbName);
303303

304+
if (IsUnderPostmaster && ExecBackend && MyProc /* ordinary backend */)
305+
{
306+
AttachSharedMemoryAndSemaphores();
307+
}
308+
304309
if (!IsUnderPostmaster)
305310
{
306311
if (!potential_DataDir)

src/backend/postmaster/postmaster.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.319 2003/05/02 22:02:47 momjian Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.320 2003/05/03 03:52:07 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -172,6 +172,13 @@ static int ServerSock_INET = INVALID_SOCK; /* stream socket server */
172172
static int ServerSock_UNIX = INVALID_SOCK; /* stream socket server */
173173
#endif
174174

175+
/* Used to reduce macros tests */
176+
#ifdef EXEC_BACKEND
177+
const bool ExecBackend = true;
178+
#else
179+
const bool ExecBackend = false;
180+
#endif
181+
175182
/*
176183
* Set by the -o option
177184
*/
@@ -1407,7 +1414,11 @@ processCancelRequest(Port *port, void *pkt)
14071414
elog(DEBUG1, "processCancelRequest: CheckPointPID in cancel request for process %d", backendPID);
14081415
return;
14091416
}
1410-
1417+
else if (ExecBackend)
1418+
{
1419+
AttachSharedMemoryAndSemaphores();
1420+
}
1421+
14111422
/* See if we have a matching backend */
14121423

14131424
for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))

src/backend/storage/ipc/ipci.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.51 2003/05/02 21:59:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.52 2003/05/03 03:52:07 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -134,3 +134,16 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
134134
*/
135135
PMSignalInit();
136136
}
137+
138+
139+
/*
140+
* AttachSharedMemoryAndSemaphores
141+
* Attaches to the existing shared resources when exec()'d off
142+
* by the postmaster.
143+
*/
144+
void
145+
AttachSharedMemoryAndSemaphores(void)
146+
{
147+
CLOGShmemInit();
148+
}
149+

src/backend/tcop/postgres.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.329 2003/05/02 21:59:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.330 2003/05/03 03:52:07 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1453,6 +1453,7 @@ PostgresMain(int argc, char *argv[], const char *username)
14531453
break;
14541454
}
14551455

1456+
14561457
/*
14571458
* -d is not the same as setting
14581459
* log_min_messages because it enables other
@@ -1577,6 +1578,9 @@ PostgresMain(int argc, char *argv[], const char *username)
15771578
* restart... */
15781579
}
15791580
BaseInit();
1581+
#ifdef EXECBACKEND
1582+
AttachSharedMemoryAndSemaphores();
1583+
#endif
15801584
}
15811585
else
15821586
{
@@ -1672,7 +1676,7 @@ PostgresMain(int argc, char *argv[], const char *username)
16721676
if (!IsUnderPostmaster)
16731677
{
16741678
puts("\nPOSTGRES backend interactive interface ");
1675-
puts("$Revision: 1.329 $ $Date: 2003/05/02 21:59:31 $\n");
1679+
puts("$Revision: 1.330 $ $Date: 2003/05/03 03:52:07 $\n");
16761680
}
16771681

16781682
/*

src/include/miscadmin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.120 2003/05/02 21:59:31 momjian Exp $
15+
* $Id: miscadmin.h,v 1.121 2003/05/03 03:52:07 momjian Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file should be moved to
@@ -106,6 +106,7 @@ extern void ProcessInterrupts(void);
106106
*/
107107
extern bool IsUnderPostmaster;
108108
extern bool ClientAuthInProgress;
109+
extern const bool ExecBackend;
109110

110111
extern int PostmasterMain(int argc, char *argv[]);
111112
extern void ClosePostmasterPorts(bool pgstat_too);

src/include/storage/ipc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $Id: ipc.h,v 1.59 2003/05/02 21:59:31 momjian Exp $
14+
* $Id: ipc.h,v 1.60 2003/05/03 03:52:07 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -32,5 +32,6 @@ extern void on_exit_reset(void);
3232
extern void CreateSharedMemoryAndSemaphores(bool makePrivate,
3333
int maxBackends,
3434
int port);
35+
extern void AttachSharedMemoryAndSemaphores(void);
3536

3637
#endif /* IPC_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy