MCPcopy Create free account
hub / github.com/apache/cloudberry / processCancelRequest

Function processCancelRequest

src/backend/postmaster/postmaster.c:2891–2960  ·  view source on GitHub ↗

* The client has sent a cancel request packet, not a normal * start-a-new-connection packet. Perform the necessary processing. * Nothing is sent back to the client. */

Source from the content-addressed store, hash-verified

2889 * Nothing is sent back to the client.
2890 */
2891static void
2892processCancelRequest(Port *port, void *pkt, MsgType code)
2893{
2894 CancelRequestPacket *canc = (CancelRequestPacket *) pkt;
2895 int backendPID;
2896 int32 cancelAuthCode;
2897 Backend *bp;
2898
2899#ifndef EXEC_BACKEND
2900 dlist_iter iter;
2901#else
2902 int i;
2903#endif
2904
2905 backendPID = (int) pg_ntoh32(canc->backendPID);
2906 cancelAuthCode = (int32) pg_ntoh32(canc->cancelAuthCode);
2907
2908 /*
2909 * See if we have a matching backend. In the EXEC_BACKEND case, we can no
2910 * longer access the postmaster's own backend list, and must rely on the
2911 * duplicate array in shared memory.
2912 */
2913#ifndef EXEC_BACKEND
2914 dlist_foreach(iter, &BackendList)
2915 {
2916 bp = dlist_container(Backend, elem, iter.cur);
2917#else
2918 for (i = MaxLivePostmasterChildren() - 1; i >= 0; i--)
2919 {
2920 bp = (Backend *) &ShmemBackendArray[i];
2921#endif
2922 if (bp->pid == backendPID)
2923 {
2924 if (bp->cancel_key == cancelAuthCode)
2925 {
2926 /* Found a match; signal that backend to cancel current op */
2927 if (code == FINISH_REQUEST_CODE)
2928 {
2929 ereport(LOG,
2930 (errmsg_internal("query finish request to process %d",
2931 backendPID)));
2932 SendProcSignal(bp->pid, PROCSIG_QUERY_FINISH,
2933 InvalidBackendId);
2934 }
2935 else
2936 {
2937 ereport(DEBUG2,
2938 (errmsg_internal("processing cancel request: sending SIGINT to process %d",
2939 backendPID)));
2940 signal_child(bp->pid, SIGINT);
2941 }
2942 }
2943 else
2944 /* Right PID, wrong key: no way, Jose */
2945 ereport(LOG,
2946 (errmsg("wrong key in cancel request for process %d",
2947 backendPID)));
2948 return;

Callers 1

ProcessStartupPacketFunction · 0.85

Calls 5

SendProcSignalFunction · 0.85
signal_childFunction · 0.85
errmsg_internalFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected