3737 *
3838 *
3939 * IDENTIFICATION
40- * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.56 2010/01/1610:05:50 sriggs Exp $
40+ * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.57 2010/01/1617: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 );
140138static int KnownAssignedXidsGet (TransactionId * xarray ,TransactionId xmax );
141139static int KnownAssignedXidsGetAndSetXmin (TransactionId * xarray ,TransactionId * xmin ,
142140TransactionId xmax );
@@ -161,16 +159,19 @@ ProcArrayShmemSize(void)
161159size = 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)
172171if (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
175176return size ;
176177}
@@ -186,8 +187,8 @@ CreateSharedProcArray(void)
186187/* Create or attach to the ProcArray shared structure */
187188procArray = (ProcArrayStruct * )
188189ShmemInitStruct ("Proc Array" ,
189- mul_size (sizeof (PGPROC * ),PROCARRAY_MAXPROCS ),
190- & found );
190+ mul_size (sizeof (PGPROC * ),PROCARRAY_MAXPROCS ),
191+ & found );
191192
192193if (!found )
193194{
@@ -197,9 +198,28 @@ CreateSharedProcArray(void)
197198/* Normal processing */
198199procArray -> numProcs = 0 ;
199200procArray -> 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 *