* Establish the dynamic shared memory segment for a parallel context and * copy state and other bookkeeping information that will be needed by * parallel workers into it. */
| 236 | * parallel workers into it. |
| 237 | */ |
| 238 | void |
| 239 | InitializeParallelDSM(ParallelContext *pcxt) |
| 240 | { |
| 241 | MemoryContext oldcontext; |
| 242 | Size library_len = 0; |
| 243 | Size guc_len = 0; |
| 244 | Size combocidlen = 0; |
| 245 | Size tsnaplen = 0; |
| 246 | Size asnaplen = 0; |
| 247 | Size tstatelen = 0; |
| 248 | Size pendingsyncslen = 0; |
| 249 | Size reindexlen = 0; |
| 250 | Size relmapperlen = 0; |
| 251 | Size uncommittedenumslen = 0; |
| 252 | Size segsize = 0; |
| 253 | int i; |
| 254 | FixedParallelState *fps; |
| 255 | dsm_handle session_dsm_handle = DSM_HANDLE_INVALID; |
| 256 | Snapshot transaction_snapshot = GetTransactionSnapshot(); |
| 257 | Snapshot active_snapshot = GetActiveSnapshot(); |
| 258 | |
| 259 | if (gp_select_invisible) |
| 260 | active_snapshot = transaction_snapshot; |
| 261 | |
| 262 | /* We might be running in a very short-lived memory context. */ |
| 263 | oldcontext = MemoryContextSwitchTo(TopTransactionContext); |
| 264 | |
| 265 | /* Allow space to store the fixed-size parallel state. */ |
| 266 | shm_toc_estimate_chunk(&pcxt->estimator, sizeof(FixedParallelState)); |
| 267 | shm_toc_estimate_keys(&pcxt->estimator, 1); |
| 268 | |
| 269 | /* |
| 270 | * Normally, the user will have requested at least one worker process, but |
| 271 | * if by chance they have not, we can skip a bunch of things here. |
| 272 | */ |
| 273 | if (pcxt->nworkers > 0) |
| 274 | { |
| 275 | /* Get (or create) the per-session DSM segment's handle. */ |
| 276 | session_dsm_handle = GetSessionDsmHandle(); |
| 277 | |
| 278 | /* |
| 279 | * If we weren't able to create a per-session DSM segment, then we can |
| 280 | * continue but we can't safely launch any workers because their |
| 281 | * record typmods would be incompatible so they couldn't exchange |
| 282 | * tuples. |
| 283 | */ |
| 284 | if (session_dsm_handle == DSM_HANDLE_INVALID) |
| 285 | pcxt->nworkers = 0; |
| 286 | } |
| 287 | |
| 288 | if (pcxt->nworkers > 0) |
| 289 | { |
| 290 | /* Estimate space for various kinds of state sharing. */ |
| 291 | library_len = EstimateLibraryStateSpace(); |
| 292 | shm_toc_estimate_chunk(&pcxt->estimator, library_len); |
| 293 | guc_len = EstimateGUCStateSpace(); |
| 294 | shm_toc_estimate_chunk(&pcxt->estimator, guc_len); |
| 295 | combocidlen = EstimateComboCIDStateSpace(); |
no test coverage detected