37
37
*
38
38
*
39
39
* 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 $
41
41
*
42
42
*-------------------------------------------------------------------------
43
43
*/
@@ -135,8 +135,6 @@ static void DisplayXidCache(void);
135
135
#endif /* XIDCACHE_DEBUG */
136
136
137
137
/* Primitives for KnownAssignedXids array handling for standby */
138
- static Size KnownAssignedXidsShmemSize (int size );
139
- static void KnownAssignedXidsInit (int size );
140
138
static int KnownAssignedXidsGet (TransactionId * xarray , TransactionId xmax );
141
139
static int KnownAssignedXidsGetAndSetXmin (TransactionId * xarray , TransactionId * xmin ,
142
140
TransactionId xmax );
@@ -161,16 +159,19 @@ ProcArrayShmemSize(void)
161
159
size = add_size (size , mul_size (sizeof (PGPROC * ), PROCARRAY_MAXPROCS ));
162
160
163
161
/*
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.
170
169
*/
171
170
#define TOTAL_MAX_CACHED_SUBXIDS ((PGPROC_MAX_CACHED_SUBXIDS + 1) * PROCARRAY_MAXPROCS)
172
171
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 )));
174
175
175
176
return size ;
176
177
}
@@ -186,8 +187,8 @@ CreateSharedProcArray(void)
186
187
/* Create or attach to the ProcArray shared structure */
187
188
procArray = (ProcArrayStruct * )
188
189
ShmemInitStruct ("Proc Array" ,
189
- mul_size (sizeof (PGPROC * ), PROCARRAY_MAXPROCS ),
190
- & found );
190
+ mul_size (sizeof (PGPROC * ), PROCARRAY_MAXPROCS ),
191
+ & found );
191
192
192
193
if (!found )
193
194
{
@@ -197,9 +198,28 @@ CreateSharedProcArray(void)
197
198
/* Normal processing */
198
199
procArray -> numProcs = 0 ;
199
200
procArray -> maxProcs = PROCARRAY_MAXPROCS ;
201
+ procArray -> numKnownAssignedXids = 0 ;
202
+ procArray -> maxKnownAssignedXids = TOTAL_MAX_CACHED_SUBXIDS ;
203
+ procArray -> lastOverflowedXid = InvalidTransactionId ;
204
+ }
200
205
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" );
203
223
}
204
224
}
205
225
@@ -2291,36 +2311,6 @@ ExpireOldKnownAssignedTransactionIds(TransactionId xid)
2291
2311
* high availability. So we choose to implement as a hash table.
2292
2312
*/
2293
2313
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
-
2324
2314
/*
2325
2315
* Add xids into KnownAssignedXids.
2326
2316
*
0 commit comments