* Get a reference to slot in shared memory for this shared scan. * * If the slot doesn't exist yet, it is created and initialized into * "not ready" state. * * The reference is tracked by the current ResourceOwner, and will be * automatically released on abort. */
| 798 | * automatically released on abort. |
| 799 | */ |
| 800 | static shareinput_Xslice_reference * |
| 801 | get_shareinput_reference(int share_id) |
| 802 | { |
| 803 | shareinput_tag tag; |
| 804 | shareinput_Xslice_state *xslice_state; |
| 805 | bool found; |
| 806 | shareinput_Xslice_reference *ref; |
| 807 | |
| 808 | /* Register our resource owner callback to clean up on first call. */ |
| 809 | if (!shareinput_resowner_callback_registered) |
| 810 | { |
| 811 | RegisterResourceReleaseCallback(shareinput_release_callback, NULL); |
| 812 | shareinput_resowner_callback_registered = true; |
| 813 | } |
| 814 | |
| 815 | ref = MemoryContextAllocZero(TopMemoryContext, |
| 816 | sizeof(shareinput_Xslice_reference)); |
| 817 | |
| 818 | LWLockAcquire(ShareInputScanLock, LW_EXCLUSIVE); |
| 819 | |
| 820 | tag.session_id = gp_session_id; |
| 821 | tag.command_count = gp_command_count; |
| 822 | tag.share_id = share_id; |
| 823 | xslice_state = hash_search(shareinput_Xslice_hash, |
| 824 | &tag, |
| 825 | HASH_ENTER_NULL, |
| 826 | &found); |
| 827 | if (!found) |
| 828 | { |
| 829 | if (xslice_state == NULL) |
| 830 | { |
| 831 | pfree(ref); |
| 832 | ereport(ERROR, |
| 833 | (errcode(ERRCODE_OUT_OF_MEMORY), |
| 834 | errmsg("out of cross-slice ShareInputScan slots"))); |
| 835 | } |
| 836 | |
| 837 | xslice_state->refcount = 0; |
| 838 | pg_atomic_init_u32(&xslice_state->ready, 0); |
| 839 | pg_atomic_init_u32(&xslice_state->ndone, 0); |
| 840 | |
| 841 | ConditionVariableInit(&xslice_state->ready_done_cv); |
| 842 | elog((Debug_shareinput_xslice ? LOG : DEBUG1), "SISC (shareid=%d, slice=%d): initialized xslice state", |
| 843 | share_id, currentSliceId); |
| 844 | } |
| 845 | |
| 846 | xslice_state->refcount++; |
| 847 | |
| 848 | ref->share_id = share_id; |
| 849 | ref->xslice_state = xslice_state; |
| 850 | ref->owner = CurrentResourceOwner; |
| 851 | dlist_push_head(&shareinput_Xslice_refs, &ref->node); |
| 852 | |
| 853 | LWLockRelease(ShareInputScanLock); |
| 854 | |
| 855 | return ref; |
| 856 | } |
| 857 |
no test coverage detected