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

taosdata / TDengine / #4875

09 Dec 2025 01:22AM UTC coverage: 64.472% (-0.2%) from 64.623%
#4875

push

travis-ci

guanshengliang
fix: temporarily disable memory leak detection for UDF tests (#33856)

162014 of 251293 relevant lines covered (64.47%)

104318075.66 hits per line

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

81.88
/source/dnode/mgmt/mgmt_mnode/src/mmInt.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
#define _DEFAULT_SOURCE
17
#include "mmInt.h"
18
#include "wal.h"
19

20
static bool mmDeployRequired(const SMgmtInputOpt *pInput) {
585,675✔
21
  if (pInput->pData->dnodeId > 0) return false;
585,675✔
22
  if (pInput->pData->clusterId > 0) return false;
520,780✔
23
  if (strcmp(tsLocalEp, tsFirst) != 0) return false;
520,780✔
24
  return true;
329,616✔
25
}
26

27
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
708,517✔
28
  int32_t   code = 0;
708,517✔
29
  SMnodeOpt option = {0};
708,517✔
30
  if ((code = mmReadFile(pInput->path, &option)) != 0) {
708,517✔
31
    return code;
×
32
  }
33

34
  if (!option.deploy) {
708,517✔
35
    *required = mmDeployRequired(pInput);
585,675✔
36
    if (*required) {
585,675✔
37
      dInfo("deploy mnode required. dnodeId:%d<=0, clusterId:0x%" PRIx64 "<=0, localEp:%s==firstEp",
329,616✔
38
            pInput->pData->dnodeId, pInput->pData->clusterId, tsLocalEp);
39
    }
40
  } else {
41
    *required = true;
122,842✔
42
    dInfo("deploy mnode required. option deploy:%d", option.deploy);
122,842✔
43
  }
44

45
  return code;
708,517✔
46
}
47

48
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
329,324✔
49
  pOption->deploy = true;
329,324✔
50
  pOption->msgCb = pMgmt->msgCb;
329,324✔
51
  pOption->dnodeId = pMgmt->pData->dnodeId;
329,324✔
52
  pOption->selfIndex = 0;
329,324✔
53
  pOption->numOfReplicas = 1;
329,324✔
54
  pOption->numOfTotalReplicas = 1;
329,324✔
55
  pOption->replicas[0].id = 1;
329,324✔
56
  pOption->replicas[0].port = tsServerPort;
329,324✔
57
  tstrncpy(pOption->replicas[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
329,324✔
58
  pOption->lastIndex = SYNC_INDEX_INVALID;
329,324✔
59
}
329,324✔
60

61
static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
175,406✔
62
  pOption->deploy = false;
175,406✔
63
  pOption->msgCb = pMgmt->msgCb;
175,406✔
64
  pOption->dnodeId = pMgmt->pData->dnodeId;
175,406✔
65
}
175,406✔
66

67
static void mmClose(SMnodeMgmt *pMgmt) {
504,730✔
68
  if (pMgmt->pMnode != NULL) {
504,730✔
69
    mmStopWorker(pMgmt);
504,730✔
70
    mndClose(pMgmt->pMnode);
504,730✔
71
    (void)taosThreadRwlockDestroy(&pMgmt->lock);
504,730✔
72
    pMgmt->pMnode = NULL;
504,730✔
73
  }
74

75
  taosMemoryFree(pMgmt);
504,730✔
76
}
504,730✔
77
static int32_t mndOpenWrapper(const char *path, SMnodeOpt *opt, SMnode **pMnode) {
504,730✔
78
  int32_t code = 0;
504,730✔
79
  *pMnode = mndOpen(path, opt);
504,730✔
80
  if (*pMnode == NULL) {
504,730✔
81
    code = terrno;
×
82
  }
83
  ///*pMnode = pNode;
84
  return code;
504,730✔
85
}
86
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
504,730✔
87
  int32_t code = 0;
504,730✔
88
  if ((code = walInit(pInput->stopDnodeFp)) != 0) {
504,730✔
89
    dError("failed to init wal since %s", tstrerror(code));
×
90
    return code;
×
91
  }
92

93
  if ((code = syncInit()) != 0) {
504,730✔
94
    dError("failed to init sync since %s", tstrerror(code));
×
95
    return code;
×
96
  }
97

98
  SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
504,730✔
99
  if (pMgmt == NULL) {
504,730✔
100
    code = terrno;
×
101
    return code;
×
102
  }
103

104
  pMgmt->pData = pInput->pData;
504,730✔
105
  pMgmt->path = pInput->path;
504,730✔
106
  pMgmt->name = pInput->name;
504,730✔
107
  pMgmt->msgCb = pInput->msgCb;
504,730✔
108
  pMgmt->msgCb.putToQueueFp = (PutToQueueFp)mmPutMsgToQueue;
504,730✔
109
  pMgmt->msgCb.mgmt = pMgmt;
504,730✔
110
  (void)taosThreadRwlockInit(&pMgmt->lock, NULL);
504,730✔
111

112
  SMnodeOpt option = {0};
504,730✔
113
  if ((code = mmReadFile(pMgmt->path, &option)) != 0) {
504,730✔
114
    dError("failed to read file since %s", tstrerror(code));
×
115
    mmClose(pMgmt);
×
116
    return code;
×
117
  }
118

119
  if (!option.deploy) {
504,730✔
120
    dInfo("mnode start to deploy");
329,324✔
121
    pMgmt->pData->dnodeId = 1;
329,324✔
122
    mmBuildOptionForDeploy(pMgmt, pInput, &option);
329,324✔
123
  } else {
124
    dInfo("mnode start to open");
175,406✔
125
    mmBuildOptionForOpen(pMgmt, &option);
175,406✔
126
  }
127

128
  code = mndOpenWrapper(pMgmt->path, &option, &pMgmt->pMnode);
504,730✔
129
  if (code != 0) {
504,730✔
130
    dError("failed to open mnode since %s", tstrerror(code));
×
131
    mmClose(pMgmt);
×
132
    return code;
×
133
  }
134
  tmsgReportStartup("mnode-impl", "initialized");
504,730✔
135

136
  if ((code = mmStartWorker(pMgmt)) != 0) {
504,730✔
137
    dError("failed to start mnode worker since %s", tstrerror(code));
×
138
    mmClose(pMgmt);
×
139
    return code;
×
140
  }
141
  tmsgReportStartup("mnode-worker", "initialized");
504,730✔
142

143
  if (option.numOfTotalReplicas > 0) {
504,730✔
144
    option.deploy = true;
390,278✔
145
    option.numOfReplicas = 0;
390,278✔
146
    option.numOfTotalReplicas = 0;
390,278✔
147
    if ((code = mmWriteFile(pMgmt->path, &option)) != 0) {
390,278✔
148
      dError("failed to write mnode file since %s", tstrerror(code));
×
149
      return code;
×
150
    }
151
  }
152

153
  pInput->pData->dnodeId = pMgmt->pData->dnodeId;
504,730✔
154
  pOutput->pMgmt = pMgmt;
504,730✔
155
  return 0;
504,730✔
156
}
157

158
static int32_t mmStart(SMnodeMgmt *pMgmt) {
504,730✔
159
  int32_t code = 0;
504,730✔
160
  dDebug("mnode-mgmt start to run");
504,730✔
161
  SMnodeOpt option = {0};
504,730✔
162
  if ((code = mmReadFile(pMgmt->path, &option)) != 0) {
504,730✔
163
    dError("failed to read file since %s", tstrerror(code));
×
164
    mmClose(pMgmt);
×
165
    return code;
×
166
  }
167
  if ((code = mndStart(pMgmt->pMnode)) != 0) {
504,730✔
168
    return code;
×
169
  }
170
  if (mndNeedUpgrade(pMgmt->pMnode, option.version)) {
504,730✔
171
    option.version = mndGetVersion(pMgmt->pMnode);
390,278✔
172
    if ((code = mmWriteFile(pMgmt->path, &option)) != 0) {
390,278✔
173
      dError("failed to write mnode file since %s", tstrerror(code));
×
174
      return code;
×
175
    }
176
  }
177
  return code;
504,730✔
178
}
179

180
static void mmStop(SMnodeMgmt *pMgmt) {
504,730✔
181
  dDebug("mnode-mgmt start to stop");
504,730✔
182
  mndPreClose(pMgmt->pMnode);
504,730✔
183
  (void)taosThreadRwlockWrlock(&pMgmt->lock);
504,730✔
184
  pMgmt->stopped = 1;
504,730✔
185
  (void)taosThreadRwlockUnlock(&pMgmt->lock);
504,730✔
186

187
  mndStop(pMgmt->pMnode);
504,730✔
188
}
504,730✔
189

190
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) { return mndIsCatchUp(pMgmt->pMnode); }
370,709✔
191

192
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) { return mndGetRole(pMgmt->pMnode); }
370,709✔
193

194
SMgmtFunc mmGetMgmtFunc() {
708,517✔
195
  SMgmtFunc mgmtFunc = {0};
708,517✔
196
  mgmtFunc.openFp = mmOpen;
708,517✔
197
  mgmtFunc.closeFp = (NodeCloseFp)mmClose;
708,517✔
198
  mgmtFunc.startFp = (NodeStartFp)mmStart;
708,517✔
199
  mgmtFunc.stopFp = (NodeStopFp)mmStop;
708,517✔
200
  mgmtFunc.createFp = (NodeCreateFp)mmProcessCreateReq;
708,517✔
201
  mgmtFunc.dropFp = (NodeDropFp)mmProcessDropReq;
708,517✔
202
  mgmtFunc.requiredFp = mmRequire;
708,517✔
203
  mgmtFunc.getHandlesFp = mmGetMsgHandles;
708,517✔
204
  mgmtFunc.isCatchUpFp = (NodeIsCatchUpFp)mmSyncIsCatchUp;
708,517✔
205
  mgmtFunc.nodeRoleFp = (NodeRole)mmSyncGetRole;
708,517✔
206

207
  return mgmtFunc;
708,517✔
208
}
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