| 1745 | } |
| 1746 | |
| 1747 | GpParallelDSMEntry * |
| 1748 | GpInsertParallelDSMHash(PlanState *planstate) |
| 1749 | { |
| 1750 | GpParallelDSMEntry *entry; |
| 1751 | bool found = false; |
| 1752 | static bool init = false; |
| 1753 | |
| 1754 | int localSliceId = LocallyExecutingSliceIndex(planstate->state); |
| 1755 | int parallel_workers = 0; |
| 1756 | |
| 1757 | if (planstate->state->es_plannedstmt && planstate->state->es_plannedstmt->slices) |
| 1758 | { |
| 1759 | parallel_workers = planstate->state->es_plannedstmt->slices[localSliceId].parallel_workers; |
| 1760 | } |
| 1761 | |
| 1762 | if (parallel_workers <= 1) |
| 1763 | return NULL; |
| 1764 | |
| 1765 | ParallelEntryTag tag; |
| 1766 | INIT_PARALLELENTRYTAG(tag, gp_command_count, localSliceId, gp_session_id); |
| 1767 | |
| 1768 | LWLockAcquire(GpParallelDSMHashLock, LW_EXCLUSIVE); |
| 1769 | |
| 1770 | entry = (GpParallelDSMEntry *) |
| 1771 | hash_search(GpParallelDSMHash, |
| 1772 | &tag, |
| 1773 | HASH_ENTER_NULL, |
| 1774 | &found); |
| 1775 | |
| 1776 | if (!entry) |
| 1777 | ereport(ERROR, |
| 1778 | (errcode(ERRCODE_OUT_OF_MEMORY), |
| 1779 | errmsg("out of shared memory"), |
| 1780 | errhint("out of cross-slice SHARED_PARALLEL_DSM_TABLE_SIZE slots."))); |
| 1781 | |
| 1782 | if (!found) |
| 1783 | { |
| 1784 | shm_toc_estimator *estimator = NULL; |
| 1785 | ParallelContext context = { |
| 1786 | .nworkers = parallel_workers, |
| 1787 | }; |
| 1788 | |
| 1789 | Size dsa_minsize = dsa_minimum_size(); |
| 1790 | estimator = &context.estimator; |
| 1791 | shm_toc_initialize_estimator(estimator); |
| 1792 | |
| 1793 | /* Estimate space for parallel DSA area. */ |
| 1794 | shm_toc_estimate_chunk(estimator, dsa_minsize); |
| 1795 | shm_toc_estimate_keys(estimator, 1); |
| 1796 | |
| 1797 | EstimateGpParallelDSMEntrySize(planstate, &context); |
| 1798 | |
| 1799 | Size segsize = shm_toc_estimate(estimator); |
| 1800 | |
| 1801 | shm_toc *toc; |
| 1802 | dsm_segment* seg = dsm_create(segsize, DSM_CREATE_NULL_IF_MAXSEGMENTS); |
| 1803 | |
| 1804 | if (seg != NULL) |
no test coverage detected