• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3562

20 Dec 2024 09:57AM UTC coverage: 26.655% (-32.2%) from 58.812%
#3562

push

travis-ci

web-flow
Merge pull request #29229 from taosdata/enh/TS-5749-3.0

enh: seperate tsdb async tasks to different thread pools

21498 of 109421 branches covered (19.65%)

Branch coverage included in aggregate %.

66 of 96 new or added lines in 7 files covered. (68.75%)

39441 existing lines in 157 files now uncovered.

35007 of 102566 relevant lines covered (34.13%)

53922.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.79
/source/dnode/vnode/src/tq/tqPush.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "tq.h"
17
#include "vnd.h"
18

19
int32_t tqProcessSubmitReqForSubscribe(STQ* pTq) {
44,980✔
20
  if (pTq == NULL) {
44,980!
21
    return TSDB_CODE_INVALID_MSG;
×
22
  }
23
  if (taosHashGetSize(pTq->pPushMgr) <= 0) {
44,980!
24
    return 0;
44,980✔
25
  }
UNCOV
26
  SRpcMsg msg = {.msgType = TDMT_VND_TMQ_CONSUME_PUSH};
×
UNCOV
27
  msg.pCont = rpcMallocCont(sizeof(SMsgHead));
×
UNCOV
28
  if (msg.pCont == NULL) {
×
29
    return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
30
  }
UNCOV
31
  msg.contLen = sizeof(SMsgHead);
×
UNCOV
32
  SMsgHead *pHead = msg.pCont;
×
UNCOV
33
  pHead->vgId = TD_VID(pTq->pVnode);
×
UNCOV
34
  pHead->contLen = msg.contLen;
×
UNCOV
35
  int32_t code = tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
×
UNCOV
36
  if (code != 0){
×
37
    tqError("vgId:%d failed to push msg to queue, code:%d", TD_VID(pTq->pVnode), code);
×
38
    rpcFreeCont(msg.pCont);
×
39
  }
UNCOV
40
  return code;
×
41
}
42

43
int32_t tqPushMsg(STQ* pTq, tmsg_t msgType) {
51,347✔
44
  int32_t code = 0;
51,347✔
45
  if (msgType == TDMT_VND_SUBMIT) {
51,347✔
46
    code = tqProcessSubmitReqForSubscribe(pTq);
44,980✔
47
    if (code != 0){
44,980!
48
      tqError("vgId:%d failed to process submit request for subscribe, code:%d", TD_VID(pTq->pVnode), code);
×
49
    }
50
  }
51

52
  streamMetaRLock(pTq->pStreamMeta);
51,347✔
53
  int32_t numOfTasks = streamMetaGetNumOfTasks(pTq->pStreamMeta);
51,350✔
54
  streamMetaRUnLock(pTq->pStreamMeta);
51,350✔
55

56
//  tqTrace("vgId:%d handle submit, restore:%d, numOfTasks:%d", TD_VID(pTq->pVnode), pTq->pVnode->restored, numOfTasks);
57

58
  // push data for stream processing:
59
  // 1. the vnode has already been restored.
60
  // 2. the vnode should be the leader.
61
  // 3. the stream is not suspended yet.
62
  if ((!tsDisableStream) && (numOfTasks > 0)) {
51,350!
UNCOV
63
    code = tqScanWalAsync(pTq, true);
×
64
  }
65

66
  return code;
51,350✔
67
}
68

UNCOV
69
int32_t tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg) {
×
UNCOV
70
  if (pTq == NULL || handle == NULL || pMsg == NULL) {
×
71
    return TSDB_CODE_INVALID_MSG;
×
72
  }
UNCOV
73
  int32_t    vgId = TD_VID(pTq->pVnode);
×
UNCOV
74
  STqHandle* pHandle = (STqHandle*)handle;
×
75

UNCOV
76
  if (pHandle->msg == NULL) {
×
UNCOV
77
    pHandle->msg = taosMemoryCalloc(1, sizeof(SRpcMsg));
×
UNCOV
78
    if (pHandle->msg == NULL) {
×
79
      return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
80
    }
UNCOV
81
    (void)memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
×
UNCOV
82
    pHandle->msg->pCont = rpcMallocCont(pMsg->contLen);
×
UNCOV
83
    if (pHandle->msg->pCont == NULL) {
×
84
      taosMemoryFree(pHandle->msg);
×
85
      pHandle->msg = NULL;
×
86
      return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
87
    }
88
  } else {
89
    tqPushEmptyDataRsp(pHandle, vgId);
×
90

91
    void* tmp = pHandle->msg->pCont;
×
92
    (void)memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
×
93
    pHandle->msg->pCont = tmp;
×
94
  }
95

UNCOV
96
  (void)memcpy(pHandle->msg->pCont, pMsg->pCont, pMsg->contLen);
×
UNCOV
97
  pHandle->msg->contLen = pMsg->contLen;
×
UNCOV
98
  int32_t ret = taosHashPut(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey), &pHandle, POINTER_BYTES);
×
UNCOV
99
  tqDebug("vgId:%d data is over, ret:%d, consumerId:0x%" PRIx64 ", register to pHandle:%p, pCont:%p, len:%d", vgId, ret,
×
100
          pHandle->consumerId, pHandle, pHandle->msg->pCont, pHandle->msg->contLen);
UNCOV
101
  if (ret != 0) {
×
102
    rpcFreeCont(pHandle->msg->pCont);
×
103
    taosMemoryFree(pHandle->msg);
×
104
    pHandle->msg = NULL;
×
105
  }
UNCOV
106
  return ret;
×
107
}
108

UNCOV
109
void tqUnregisterPushHandle(STQ* pTq, void *handle) {
×
UNCOV
110
  if (pTq == NULL || handle == NULL) {
×
111
    return;
×
112
  }
UNCOV
113
  STqHandle *pHandle = (STqHandle*)handle;
×
UNCOV
114
  int32_t    vgId = TD_VID(pTq->pVnode);
×
115

UNCOV
116
  if(taosHashGetSize(pTq->pPushMgr) <= 0) {
×
UNCOV
117
    return;
×
118
  }
UNCOV
119
  int32_t ret = taosHashRemove(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey));
×
UNCOV
120
  tqInfo("vgId:%d remove pHandle:%p,ret:%d consumer Id:0x%" PRIx64, vgId, pHandle, ret, pHandle->consumerId);
×
121

UNCOV
122
  if(ret == 0 && pHandle->msg != NULL) {
×
UNCOV
123
    tqPushEmptyDataRsp(pHandle, vgId);
×
124

UNCOV
125
    rpcFreeCont(pHandle->msg->pCont);
×
UNCOV
126
    taosMemoryFree(pHandle->msg);
×
UNCOV
127
    pHandle->msg = NULL;
×
128
  }
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc