From 54f8a816b55198bcc79bb3405210f4fe7079c573 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 6 Dec 2023 14:01:32 +0800 Subject: [PATCH 1/3] add http fast quit --- source/libs/transport/src/thttp.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 2723a11709..52c763372f 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -32,6 +32,7 @@ typedef struct SHttpModule { uv_loop_t* loop; SAsyncPool* asyncPool; TdThread thread; + int8_t quit; } SHttpModule; typedef struct SHttpMsg { @@ -186,6 +187,27 @@ static void httpDestroyMsg(SHttpMsg* msg) { taosMemoryFree(msg->cont); taosMemoryFree(msg); } + +static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) { + SHttpMsg *msg = NULL, *quitMsg = NULL; + if (atomic_load_8(&http->quit) == 0) { + return; + } + + while (!QUEUE_IS_EMPTY(&item->qmsg)) { + queue* h = QUEUE_HEAD(&item->qmsg); + QUEUE_REMOVE(h); + msg = QUEUE_DATA(h, SHttpMsg, q); + if (!msg->quit) { + httpDestroyMsg(msg); + } else { + quitMsg = msg; + } + } + if (quitMsg != NULL) { + QUEUE_PUSH(&item->qmsg, &quitMsg->q); + } +} static void httpAsyncCb(uv_async_t* handle) { SAsyncItem* item = handle->data; SHttpModule* http = item->pThrd; @@ -194,6 +216,8 @@ static void httpAsyncCb(uv_async_t* handle) { queue wq; taosThreadMutexLock(&item->mtx); + httpMayDiscardMsg(http, item); + QUEUE_MOVE(&item->qmsg, &wq); taosThreadMutexUnlock(&item->mtx); @@ -466,6 +490,10 @@ void transHttpEnvDestroy() { return; } SHttpModule* load = taosAcquireRef(httpRefMgt, httpRef); + if (load == NULL) return; + + atomic_store_8(&load->quit, 1); + httpSendQuit(); taosThreadJoin(load->thread, NULL); From 5cc67ca9f6f3255f2a6f5c5a538800652f0193b6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 6 Dec 2023 15:51:05 +0800 Subject: [PATCH 2/3] refactor code --- source/libs/transport/src/thttp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 52c763372f..378bd47864 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -464,6 +464,8 @@ static void transHttpEnvInit() { httpRefMgt = taosOpenRef(1, transHttpDestroyHandle); SHttpModule* http = taosMemoryMalloc(sizeof(SHttpModule)); + + http->quit = 0; http->loop = taosMemoryMalloc(sizeof(uv_loop_t)); uv_loop_init(http->loop); From 35e948ecfa4a52fbce38322da67e764c0e768d2d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 6 Dec 2023 16:05:44 +0800 Subject: [PATCH 3/3] refactor code --- source/libs/transport/src/thttp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 378bd47864..ab4c8facfb 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -163,7 +163,7 @@ _OVER: static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, struct sockaddr_in* dest) { uint32_t ip = taosGetIpv4FromFqdn(server); if (ip == 0xffffffff) { - tError("http-report failed to get http server:%s since %s", server, errno == 0 ? "invalid http server" : terrstr()); + tError("http-report failed to resolving domain names: %s", server); return -1; } char buf[128] = {0};