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

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

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

62.83
/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) {
9✔
21
  if (pInput->pData->dnodeId > 0) return false;
9!
22
  if (pInput->pData->clusterId > 0) return false;
9!
23
  if (strcmp(tsLocalEp, tsFirst) != 0) return false;
9!
24
  return true;
9✔
25
}
26

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

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

45
  return code;
9✔
46
}
47

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

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

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

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

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

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

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

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

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

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

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

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

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

158
static int32_t mmStart(SMnodeMgmt *pMgmt) {
9✔
159
  dDebug("mnode-mgmt start to run");
9!
160
  return mndStart(pMgmt->pMnode);
9✔
161
}
162

163
static void mmStop(SMnodeMgmt *pMgmt) {
9✔
164
  dDebug("mnode-mgmt start to stop");
9!
165
  mndPreClose(pMgmt->pMnode);
9✔
166
  (void)taosThreadRwlockWrlock(&pMgmt->lock);
9✔
167
  pMgmt->stopped = 1;
9✔
168
  (void)taosThreadRwlockUnlock(&pMgmt->lock);
9✔
169

170
  mndStop(pMgmt->pMnode);
9✔
171
}
9✔
172

173
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) { return mndIsCatchUp(pMgmt->pMnode); }
×
174

175
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) { return mndGetRole(pMgmt->pMnode); }
×
176

177
SMgmtFunc mmGetMgmtFunc() {
9✔
178
  SMgmtFunc mgmtFunc = {0};
9✔
179
  mgmtFunc.openFp = mmOpen;
9✔
180
  mgmtFunc.closeFp = (NodeCloseFp)mmClose;
9✔
181
  mgmtFunc.startFp = (NodeStartFp)mmStart;
9✔
182
  mgmtFunc.stopFp = (NodeStopFp)mmStop;
9✔
183
  mgmtFunc.createFp = (NodeCreateFp)mmProcessCreateReq;
9✔
184
  mgmtFunc.dropFp = (NodeDropFp)mmProcessDropReq;
9✔
185
  mgmtFunc.requiredFp = mmRequire;
9✔
186
  mgmtFunc.getHandlesFp = mmGetMsgHandles;
9✔
187
  mgmtFunc.isCatchUpFp = (NodeIsCatchUpFp)mmSyncIsCatchUp;
9✔
188
  mgmtFunc.nodeRoleFp = (NodeRole)mmSyncGetRole;
9✔
189

190
  return mgmtFunc;
9✔
191
}
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