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

taosdata / TDengine / #3780

31 Mar 2025 08:30AM UTC coverage: 11.99% (-22.0%) from 34.001%
#3780

push

travis-ci

happyguoxy
test:add case 2

40223 of 491333 branches covered (8.19%)

Branch coverage included in aggregate %.

70904 of 435487 relevant lines covered (16.28%)

1596.49 hits per line

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

67.02
/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) {
8✔
21
  if (pInput->pData->dnodeId > 0) return false;
8!
22
  if (pInput->pData->clusterId > 0) return false;
8!
23
  if (strcmp(tsLocalEp, tsFirst) != 0) return false;
8✔
24
  return true;
7✔
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);
8✔
36
    if (*required) {
8✔
37
      dInfo("deploy mnode required. dnodeId:%d<=0, clusterId:0x%" PRIx64 "<=0, localEp:%s==firstEp",
7!
38
            pInput->pData->dnodeId, pInput->pData->clusterId, tsLocalEp);
39
    }
40
  } else {
41
    *required = true;
1✔
42
    dInfo("deploy mnode required. option deploy:%d", option.deploy);
1!
43
  }
44

45
  return code;
9✔
46
}
47

48
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
3✔
49
  pOption->deploy = true;
3✔
50
  pOption->msgCb = pMgmt->msgCb;
3✔
51
  pOption->dnodeId = pMgmt->pData->dnodeId;
3✔
52
  pOption->selfIndex = 0;
3✔
53
  pOption->numOfReplicas = 1;
3✔
54
  pOption->numOfTotalReplicas = 1;
3✔
55
  pOption->replicas[0].id = 1;
3✔
56
  pOption->replicas[0].port = tsServerPort;
3✔
57
  tstrncpy(pOption->replicas[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
3✔
58
  pOption->lastIndex = SYNC_INDEX_INVALID;
3✔
59
}
3✔
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) {
3✔
68
  if (pMgmt->pMnode != NULL) {
3!
69
    mmStopWorker(pMgmt);
3✔
70
    mndClose(pMgmt->pMnode);
3✔
71
    (void)taosThreadRwlockDestroy(&pMgmt->lock);
3✔
72
    pMgmt->pMnode = NULL;
3✔
73
  }
74

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

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

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

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

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

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

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

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

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

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

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

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

170
  mndStop(pMgmt->pMnode);
3✔
171
}
3✔
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