Skip to content

Commit e319e67

Browse files
committed
Fix bogus initialization of KnownAssignedXids shared memory state ---
didn't work in EXEC_BACKEND case.
1 parent 8bfd1a8 commit e319e67

File tree

1 file changed

+34
-44
lines changed

1 file changed

+34
-44
lines changed

src/backend/storage/ipc/procarray.c

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.56 2010/01/16 10:05:50 sriggs Exp $
40+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.57 2010/01/16 17:17:26 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -135,8 +135,6 @@ static void DisplayXidCache(void);
135135
#endif /* XIDCACHE_DEBUG */
136136

137137
/* Primitives for KnownAssignedXids array handling for standby */
138-
static Size KnownAssignedXidsShmemSize(int size);
139-
static void KnownAssignedXidsInit(int size);
140138
static int KnownAssignedXidsGet(TransactionId *xarray, TransactionId xmax);
141139
static int KnownAssignedXidsGetAndSetXmin(TransactionId *xarray, TransactionId *xmin,
142140
TransactionId xmax);
@@ -161,16 +159,19 @@ ProcArrayShmemSize(void)
161159
size = add_size(size, mul_size(sizeof(PGPROC *), PROCARRAY_MAXPROCS));
162160

163161
/*
164-
* During recovery processing we have a data structure called KnownAssignedXids,
165-
* created in shared memory. Local data structures are also created in various
166-
* backends during GetSnapshotData(), TransactionIdIsInProgress() and
167-
* GetRunningTransactionData(). All of the main structures created in those
168-
* functions must be identically sized, since we may at times copy the whole
169-
* of the data structures around. We refer to this as TOTAL_MAX_CACHED_SUBXIDS.
162+
* During recovery processing we have a data structure called
163+
* KnownAssignedXids, created in shared memory. Local data structures are
164+
* also created in various backends during GetSnapshotData(),
165+
* TransactionIdIsInProgress() and GetRunningTransactionData(). All of the
166+
* main structures created in those functions must be identically sized,
167+
* since we may at times copy the whole of the data structures around. We
168+
* refer to this size as TOTAL_MAX_CACHED_SUBXIDS.
170169
*/
171170
#define TOTAL_MAX_CACHED_SUBXIDS ((PGPROC_MAX_CACHED_SUBXIDS + 1) * PROCARRAY_MAXPROCS)
172171
if (XLogRequestRecoveryConnections)
173-
size = add_size(size, KnownAssignedXidsShmemSize(TOTAL_MAX_CACHED_SUBXIDS));
172+
size = add_size(size,
173+
hash_estimate_size(TOTAL_MAX_CACHED_SUBXIDS,
174+
sizeof(TransactionId)));
174175

175176
return size;
176177
}
@@ -186,8 +187,8 @@ CreateSharedProcArray(void)
186187
/* Create or attach to the ProcArray shared structure */
187188
procArray = (ProcArrayStruct *)
188189
ShmemInitStruct("Proc Array",
189-
mul_size(sizeof(PGPROC *), PROCARRAY_MAXPROCS),
190-
&found);
190+
mul_size(sizeof(PGPROC *), PROCARRAY_MAXPROCS),
191+
&found);
191192

192193
if (!found)
193194
{
@@ -197,9 +198,28 @@ CreateSharedProcArray(void)
197198
/* Normal processing */
198199
procArray->numProcs = 0;
199200
procArray->maxProcs = PROCARRAY_MAXPROCS;
201+
procArray->numKnownAssignedXids = 0;
202+
procArray->maxKnownAssignedXids = TOTAL_MAX_CACHED_SUBXIDS;
203+
procArray->lastOverflowedXid = InvalidTransactionId;
204+
}
200205

201-
if (XLogRequestRecoveryConnections)
202-
KnownAssignedXidsInit(TOTAL_MAX_CACHED_SUBXIDS);
206+
if (XLogRequestRecoveryConnections)
207+
{
208+
/* Create or attach to the KnownAssignedXids hash table */
209+
HASHCTL info;
210+
211+
MemSet(&info, 0, sizeof(info));
212+
info.keysize = sizeof(TransactionId);
213+
info.entrysize = sizeof(TransactionId);
214+
info.hash = tag_hash;
215+
216+
KnownAssignedXidsHash = ShmemInitHash("KnownAssignedXids Hash",
217+
TOTAL_MAX_CACHED_SUBXIDS,
218+
TOTAL_MAX_CACHED_SUBXIDS,
219+
&info,
220+
HASH_ELEM | HASH_FUNCTION);
221+
if (!KnownAssignedXidsHash)
222+
elog(FATAL, "could not initialize known assigned xids hash table");
203223
}
204224
}
205225

@@ -2291,36 +2311,6 @@ ExpireOldKnownAssignedTransactionIds(TransactionId xid)
22912311
* high availability. So we choose to implement as a hash table.
22922312
*/
22932313

2294-
static Size
2295-
KnownAssignedXidsShmemSize(int size)
2296-
{
2297-
return hash_estimate_size(size, sizeof(TransactionId));
2298-
}
2299-
2300-
static void
2301-
KnownAssignedXidsInit(int size)
2302-
{
2303-
HASHCTL info;
2304-
2305-
/* assume no locking is needed yet */
2306-
2307-
info.keysize = sizeof(TransactionId);
2308-
info.entrysize = sizeof(TransactionId);
2309-
info.hash = tag_hash;
2310-
2311-
KnownAssignedXidsHash = ShmemInitHash("KnownAssignedXids Hash",
2312-
size, size,
2313-
&info,
2314-
HASH_ELEM | HASH_FUNCTION);
2315-
2316-
if (!KnownAssignedXidsHash)
2317-
elog(FATAL, "could not initialize known assigned xids hash table");
2318-
2319-
procArray->numKnownAssignedXids = 0;
2320-
procArray->maxKnownAssignedXids = TOTAL_MAX_CACHED_SUBXIDS;
2321-
procArray->lastOverflowedXid = InvalidTransactionId;
2322-
}
2323-
23242314
/*
23252315
* Add xids into KnownAssignedXids.
23262316
*

0 commit comments

Comments
 (0)