Skip to content

Commit 15916ff

Browse files
committed
Initialize ShmemVariableCache like other shmem areas
For sake of consistency. Reviewed-by: Tristan Partin, Richard Guo Discussion: https://www.postgresql.org/message-id/6537d63d-4bb5-46f8-9b5d-73a8ba4720ab@iki.fi
1 parent 049ef33 commit 15916ff

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

src/backend/access/transam/varsup.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@
3434
VariableCache ShmemVariableCache = NULL;
3535

3636

37+
/*
38+
* Initialization of shared memory for ShmemVariableCache.
39+
*/
40+
Size
41+
VarsupShmemSize(void)
42+
{
43+
return sizeof(VariableCacheData);
44+
}
45+
46+
void
47+
VarsupShmemInit(void)
48+
{
49+
bool found;
50+
51+
/* Initialize our shared state struct */
52+
ShmemVariableCache = ShmemInitStruct("ShmemVariableCache",
53+
sizeof(VariableCacheData),
54+
&found);
55+
if (!IsUnderPostmaster)
56+
{
57+
Assert(!found);
58+
memset(ShmemVariableCache, 0, sizeof(VariableCacheData));
59+
}
60+
else
61+
Assert(found);
62+
}
63+
3764
/*
3865
* Allocate the next FullTransactionId for a new transaction or
3966
* subtransaction.

src/backend/postmaster/postmaster.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
#include <pthread.h>
9090
#endif
9191

92-
#include "access/transam.h"
9392
#include "access/xlog.h"
9493
#include "access/xlogrecovery.h"
9594
#include "catalog/pg_control.h"
@@ -513,7 +512,6 @@ typedef struct
513512
#endif
514513
void *UsedShmemSegAddr;
515514
slock_t *ShmemLock;
516-
VariableCache ShmemVariableCache;
517515
Backend *ShmemBackendArray;
518516
#ifndef HAVE_SPINLOCKS
519517
PGSemaphore *SpinlockSemaArray;
@@ -6034,7 +6032,6 @@ save_backend_variables(BackendParameters *param, Port *port, BackgroundWorker *w
60346032
param->UsedShmemSegAddr = UsedShmemSegAddr;
60356033

60366034
param->ShmemLock = ShmemLock;
6037-
param->ShmemVariableCache = ShmemVariableCache;
60386035
param->ShmemBackendArray = ShmemBackendArray;
60396036

60406037
#ifndef HAVE_SPINLOCKS
@@ -6280,7 +6277,6 @@ restore_backend_variables(BackendParameters *param, Port **port, BackgroundWorke
62806277
UsedShmemSegAddr = param->UsedShmemSegAddr;
62816278

62826279
ShmemLock = param->ShmemLock;
6283-
ShmemVariableCache = param->ShmemVariableCache;
62846280
ShmemBackendArray = param->ShmemBackendArray;
62856281

62866282
#ifndef HAVE_SPINLOCKS

src/backend/storage/ipc/ipci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "access/nbtree.h"
2222
#include "access/subtrans.h"
2323
#include "access/syncscan.h"
24+
#include "access/transam.h"
2425
#include "access/twophase.h"
2526
#include "access/xlogprefetcher.h"
2627
#include "access/xlogrecovery.h"
@@ -118,6 +119,7 @@ CalculateShmemSize(int *num_semaphores)
118119
size = add_size(size, PredicateLockShmemSize());
119120
size = add_size(size, ProcGlobalShmemSize());
120121
size = add_size(size, XLogPrefetchShmemSize());
122+
size = add_size(size, VarsupShmemSize());
121123
size = add_size(size, XLOGShmemSize());
122124
size = add_size(size, XLogRecoveryShmemSize());
123125
size = add_size(size, CLOGShmemSize());
@@ -289,6 +291,7 @@ CreateOrAttachShmemStructs(void)
289291
/*
290292
* Set up xlog, clog, and buffers
291293
*/
294+
VarsupShmemInit();
292295
XLOGShmemInit();
293296
XLogPrefetchShmemInit();
294297
XLogRecoveryShmemInit();

src/backend/storage/ipc/shmem.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,6 @@ InitShmemAllocation(void)
140140
/* ShmemIndex can't be set up yet (need LWLocks first) */
141141
shmhdr->index = NULL;
142142
ShmemIndex = (HTAB *) NULL;
143-
144-
/*
145-
* Initialize ShmemVariableCache for transaction manager. (This doesn't
146-
* really belong here, but not worth moving.)
147-
*/
148-
ShmemVariableCache = (VariableCache)
149-
ShmemAlloc(sizeof(*ShmemVariableCache));
150-
memset(ShmemVariableCache, 0, sizeof(*ShmemVariableCache));
151143
}
152144

153145
/*

src/include/access/transam.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ extern TransactionId TransactionIdLatest(TransactionId mainxid,
285285
extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
286286

287287
/* in transam/varsup.c */
288+
extern Size VarsupShmemSize(void);
289+
extern void VarsupShmemInit(void);
288290
extern FullTransactionId GetNewTransactionId(bool isSubXact);
289291
extern void AdvanceNextFullTransactionIdPastXid(TransactionId xid);
290292
extern FullTransactionId ReadNextFullTransactionId(void);

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