yjhjstz commented on code in PR #1357: URL: https://github.com/apache/cloudberry/pull/1357#discussion_r2488676947
########## contrib/udp2/ic_udp2.c: ########## @@ -0,0 +1,989 @@ +/*------------------------------------------------------------------------- + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * ic_udp2.c + * + * IDENTIFICATION + * contrib/udp2/ic_udp2.c + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "cdb/cdbdisp.h" +#include "cdb/cdbgang.h" +#include "cdb/cdbmotion.h" +#include "cdb/cdbvars.h" +#include "cdb/tupchunklist.h" +#include "postmaster/bgworker.h" +#include "postmaster/postmaster.h" +#include "storage/latch.h" +#include "storage/pmsignal.h" +#include "tcop/tcopprot.h" +#include "utils/wait_event.h" +#include "utils/memutils.h" + +/* local interconnect */ +#include "ic_udp2.h" + +/* from ic_common packeage */ +#include "ic_types.h" +#include "udp2/ic_udp2.h" + + +#define HandleLastError() \ +do { \ + ICError *error = GetLastError(); \ + Assert(error); \ + if (error->level == LEVEL_ERROR) \ + { \ + Assert(error->msg); \ + elog(ERROR, "%s", error->msg); \ + } \ + if (error->level == LEVEL_FATAL) \ + { \ + Assert(error->msg); \ + elog(FATAL, "%s", error->msg); \ + } \ +} while (0) + +#define ML_CHECK_FOR_INTERRUPTS(teardownActive) \ + do {if (!teardownActive && InterruptPending) CHECK_FOR_INTERRUPTS(); } while (0) + +/* + * Resource manager + */ +typedef void (*TeardownInterconnectCallBack)(ChunkTransportState *transportStates, bool hasErrors); +typedef struct interconnect_handle_t +{ + ChunkTransportState *interconnect_context; /* Interconnect state */ + + // callback for interconnect been abort + TeardownInterconnectCallBack teardown_cb; + + ResourceOwner owner; /* owner of this handle */ + struct interconnect_handle_t *next; + struct interconnect_handle_t *prev; +} interconnect_handle_t; + +static interconnect_handle_t * open_interconnect_handles; +static bool interconnect_resowner_callback_registered; + +static void destroy_interconnect_handle(interconnect_handle_t *h); +static interconnect_handle_t * allocate_interconnect_handle(TeardownInterconnectCallBack callback); +static interconnect_handle_t * find_interconnect_handle(ChunkTransportState *icContext); + + +static void SetupGlobalMotionLayerIPCParam(GlobalMotionLayerIPCParam *param); +static void SetupSessionMotionLayerIPCParam(SessionMotionLayerIPCParam *param); +static bool CheckPostmasterIsAlive(void); +static void CheckCancelOnQD(ICChunkTransportState *pTransportStates); +static void CheckInterrupts(int teardownActive); +static void SimpleFaultInjector(const char *faultname); +static void *CreateOpaqueData(void); +static void DestroyOpaqueData(void **opaque); +static ICSliceTable* ConvertToICSliceTable(SliceTable *tbl); +static TupleChunkListItem ConvertToTupleChunk(ChunkTransportState *transportStates, DataBlock *data); +static ChunkTransportState *CreateChunkTransportState(EState *estate, ICChunkTransportState *udp2_state); + + +int +GetMaxTupleChunkSizeUDP2(void) +{ + int header_size = UDP2_GetICHeaderSizeUDP(); + return Gp_max_packet_size - header_size - TUPLE_CHUNK_HEADER_SIZE; +} + +int32 +GetListenPortUDP2(void) +{ + return UDP2_GetListenPortUDP(); +} + +void +InitMotionIPCLayerUDP2(void) +{ + GlobalMotionLayerIPCParam param; + SetupGlobalMotionLayerIPCParam(¶m); + + param.checkPostmasterIsAliveCallback = CheckPostmasterIsAlive; + param.checkInterruptsCallback = CheckInterrupts; + param.simpleFaultInjectorCallback = SimpleFaultInjector; + + param.createOpaqueDataCallback = CreateOpaqueData; + param.destroyOpaqueDataCallback = DestroyOpaqueData; + + param.checkCancelOnQDCallback = CheckCancelOnQD; + + ResetLastError(); + UDP2_InitUDPIFC(¶m); + HandleLastError(); +} + +void +CleanUpMotionLayerIPCUDP2(void) +{ + if (gp_log_interconnect >= GPVARS_VERBOSITY_DEBUG) + elog(DEBUG3, "Cleaning Up Motion Layer IPC..."); + + ResetLastError(); + UDP2_CleanUpUDPIFC(); + HandleLastError(); +} + +void +WaitInterconnectQuitUDPIFC2(void) +{ + ResetLastError(); + UDP2_WaitQuitUDPIFC(); + HandleLastError(); +} + +void +SetupInterconnectUDP2(EState *estate) +{ + if (estate->interconnect_context) + elog(ERROR, "SetupInterconnectUDP: already initialized."); + + if (!estate->es_sliceTable) + elog(ERROR, "SetupInterconnectUDP: no slice table ?"); + + SessionMotionLayerIPCParam param; + SetupSessionMotionLayerIPCParam(¶m); + + interconnect_handle_t *h; + h = allocate_interconnect_handle(TeardownInterconnectUDP2); + + ICSliceTable *tbl = ConvertToICSliceTable(estate->es_sliceTable); Review Comment: when free tbl ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
