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

taosdata / TDengine / #4911

04 Jan 2026 09:05AM UTC coverage: 65.028% (-0.8%) from 65.864%
#4911

push

travis-ci

web-flow
merge: from main to 3.0 branch #34156

1206 of 4524 new or added lines in 22 files covered. (26.66%)

1517 existing lines in 134 files now uncovered.

195276 of 300296 relevant lines covered (65.03%)

116931714.52 hits per line

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

73.13
/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) {
612,132,551✔
20
  if (pTq == NULL) {
612,132,551✔
21
    return TSDB_CODE_INVALID_MSG;
×
22
  }
23
  if (taosHashGetSize(pTq->pPushMgr) <= 0) {
612,132,551✔
24
    return 0;
604,476,700✔
25
  }
26
  SRpcMsg msg = {.msgType = TDMT_VND_TMQ_CONSUME_PUSH};
7,656,603✔
27
  msg.pCont = rpcMallocCont(sizeof(SMsgHead));
7,656,603✔
28
  if (msg.pCont == NULL) {
7,656,603✔
29
    return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
30
  }
31
  msg.contLen = sizeof(SMsgHead);
7,656,603✔
32
  SMsgHead *pHead = msg.pCont;
7,656,603✔
33
  pHead->vgId = TD_VID(pTq->pVnode);
7,656,603✔
34
  pHead->contLen = msg.contLen;
7,656,603✔
35
  int32_t code = tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
7,656,603✔
36
  if (code != 0){
7,656,603✔
UNCOV
37
    tqError("vgId:%d failed to push msg to queue, code:%d", TD_VID(pTq->pVnode), code);
×
UNCOV
38
    rpcFreeCont(msg.pCont);
×
39
  }
40
  return code;
7,656,603✔
41
}
42

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

52
  return code;
699,982,307✔
53
}
54

55
int32_t tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg) {
8,554,362✔
56
  if (pTq == NULL || handle == NULL || pMsg == NULL) {
8,554,362✔
57
    return TSDB_CODE_INVALID_MSG;
×
58
  }
59
  int32_t    vgId = TD_VID(pTq->pVnode);
8,554,362✔
60
  STqHandle* pHandle = (STqHandle*)handle;
8,554,362✔
61

62
  if (pHandle->msg == NULL) {
8,554,362✔
63
    pHandle->msg = taosMemoryCalloc(1, sizeof(SRpcMsg));
8,554,362✔
64
    if (pHandle->msg == NULL) {
8,554,362✔
65
      return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
66
    }
67
    (void)memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
8,554,362✔
68
    pHandle->msg->pCont = rpcMallocCont(pMsg->contLen);
8,554,362✔
69
    if (pHandle->msg->pCont == NULL) {
8,554,362✔
70
      taosMemoryFree(pHandle->msg);
×
71
      pHandle->msg = NULL;
×
72
      return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
×
73
    }
74
  } else {
75
    tqPushEmptyDataRsp(pHandle, vgId);
×
76

77
    void* tmp = pHandle->msg->pCont;
×
78
    (void)memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
×
79
    pHandle->msg->pCont = tmp;
×
80
  }
81

82
  (void)memcpy(pHandle->msg->pCont, pMsg->pCont, pMsg->contLen);
8,554,362✔
83
  pHandle->msg->contLen = pMsg->contLen;
8,554,362✔
84
  int32_t ret = taosHashPut(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey), &pHandle, POINTER_BYTES);
8,554,362✔
85
  tqDebug("vgId:%d data is over, ret:%d, consumerId:0x%" PRIx64 ", register to pHandle:%p, pCont:%p, len:%d", vgId, ret,
8,554,362✔
86
          pHandle->consumerId, pHandle, pHandle->msg->pCont, pHandle->msg->contLen);
87
  if (ret != 0) {
8,554,362✔
88
    rpcFreeCont(pHandle->msg->pCont);
×
89
    taosMemoryFree(pHandle->msg);
×
90
    pHandle->msg = NULL;
×
91
  }
92
  return ret;
8,554,362✔
93
}
94

95
void tqUnregisterPushHandle(STQ* pTq, void *handle) {
1,091,841✔
96
  if (pTq == NULL || handle == NULL) {
1,091,841✔
97
    return;
×
98
  }
99
  STqHandle *pHandle = (STqHandle*)handle;
1,091,841✔
100
  int32_t    vgId = TD_VID(pTq->pVnode);
1,091,841✔
101

102
  if(taosHashGetSize(pTq->pPushMgr) <= 0) {
1,091,841✔
103
    return;
952,550✔
104
  }
105
  int32_t ret = taosHashRemove(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey));
139,291✔
106
  tqInfo("vgId:%d remove pHandle:%p,ret:%d consumer Id:0x%" PRIx64, vgId, pHandle, ret, pHandle->consumerId);
139,291✔
107

108
  if(ret == 0 && pHandle->msg != NULL) {
139,291✔
109
    tqPushEmptyDataRsp(pHandle, vgId);
136,731✔
110

111
    rpcFreeCont(pHandle->msg->pCont);
136,731✔
112
    taosMemoryFree(pHandle->msg);
136,731✔
113
    pHandle->msg = NULL;
136,731✔
114
  }
115
}
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