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

taosdata / TDengine / #4788

14 Oct 2025 11:21AM UTC coverage: 60.992% (-2.3%) from 63.264%
#4788

push

travis-ci

web-flow
Merge 7ca9b50f9 into 19574fe21

154868 of 324306 branches covered (47.75%)

Branch coverage included in aggregate %.

207304 of 269498 relevant lines covered (76.92%)

125773493.22 hits per line

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

69.37
/source/dnode/mgmt/mgmt_snode/src/smInt.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 "smInt.h"
18
#include "libs/function/function.h"
19
#include "libs/function/tudf.h"
20

21
static int32_t smRequire(const SMgmtInputOpt *pInput, bool *required) {
747,420✔
22
  char path[TSDB_FILENAME_LEN];
745,759✔
23
  snprintf(path, TSDB_FILENAME_LEN, "%s%ssnode%d", pInput->path, TD_DIRSEP, pInput->dnodeId);
747,420!
24
  SJson    *pJson = NULL;
747,420✔
25

26
  int32_t code = dmReadFileJson(path, pInput->name, &pJson, required);
747,420✔
27
  if (code) {
747,420!
28
    return code;
×
29
  }
30

31
  SDCreateSnodeReq req = {0};
747,420✔
32
  code = smBuildCreateReqFromJson(pJson, &req);
747,420✔
33
  if (code) {
747,420!
34
    if (pJson != NULL) cJSON_Delete(pJson);
×
35
    return code;
×
36
  }
37

38
  smUpdateSnodeInfo(&req);
747,420✔
39

40
  if (pJson != NULL) cJSON_Delete(pJson);
747,420✔
41
  return code;
747,420✔
42
}
43

44
static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { pOption->msgCb = pMgmt->msgCb; }
137,392✔
45

46
static void smClose(SSnodeMgmt *pMgmt) {
137,392✔
47
  if (pMgmt->pSnode != NULL) {
137,392!
48
    sndClose(pMgmt->pSnode);
137,392✔
49
    smStopWorker(pMgmt);
137,392✔
50
    pMgmt->pSnode = NULL;
137,392✔
51
  }
52

53
  taosMemoryFree(pMgmt);
137,392!
54
}
137,392✔
55
int32_t sndOpenWrapper(const char *path, SSnodeOpt *pOption, SSnode **pNode) {
137,392✔
56
  *pNode = sndOpen(path, pOption);
137,392✔
57
  if (*pNode == NULL) {
137,392!
58
    return terrno;
×
59
  }
60
  return 0;
137,392✔
61
}
62
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
137,392✔
63
  int32_t     code = 0;
137,392✔
64
  SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
137,392!
65
  if (pMgmt == NULL) {
137,392!
66
    code = terrno;
×
67
    return code;
×
68
  }
69

70
  pMgmt->pData = pInput->pData;
137,392✔
71
  pMgmt->path = pInput->path;
137,392✔
72
  pMgmt->name = pInput->name;
137,392✔
73
  pMgmt->msgCb = pInput->msgCb;
137,392✔
74
  pMgmt->msgCb.mgmt = pMgmt;
137,392✔
75
  pMgmt->msgCb.putToQueueFp = (PutToQueueFp)smPutMsgToQueue;
137,392✔
76

77
  SSnodeOpt option = {0};
137,392✔
78
  smInitOption(pMgmt, &option);
137,392✔
79

80
  code = sndOpenWrapper(pMgmt->path, &option, &pMgmt->pSnode);
137,392✔
81
  if (code != 0) {
137,392!
82
    dError("failed to open snode since %s", tstrerror(code));
×
83
    smClose(pMgmt);
×
84
    return code;
×
85
  }
86

87
  tmsgReportStartup("snode-impl", "initialized");
137,392✔
88

89
  if ((code = smStartWorker(pMgmt)) != 0) {
137,392!
90
    dError("failed to start snode worker since %s", tstrerror(code));
×
91
    smClose(pMgmt);
×
92
    return code;
×
93
  }
94
  tmsgReportStartup("snode-worker", "initialized");
137,392✔
95

96
  if ((code = udfcOpen()) != 0) {
137,392!
97
    dError("failed to open udfc in snode since:%s", tstrerror(code));
×
98
    smClose(pMgmt);
×
99
    return code;
×
100
  }
101

102
  pOutput->pMgmt = pMgmt;
137,392✔
103
  return 0;
137,392✔
104
}
105

106
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) { 
137,392✔
107
  return sndInit(pMgmt->pSnode); 
137,392✔
108
}
109

110
SMgmtFunc smGetMgmtFunc() {
747,420✔
111
  SMgmtFunc mgmtFunc = {0};
747,420✔
112
  mgmtFunc.openFp = smOpen;
747,420✔
113
  mgmtFunc.startFp = (NodeStartFp)smStartSnodes;
747,420✔
114
  mgmtFunc.closeFp = (NodeCloseFp)smClose;
747,420✔
115
  mgmtFunc.createFp = (NodeCreateFp)smProcessCreateReq;
747,420✔
116
  mgmtFunc.dropFp = (NodeDropFp)smProcessDropReq;
747,420✔
117
  mgmtFunc.requiredFp = smRequire;
747,420✔
118
  mgmtFunc.getHandlesFp = smGetMsgHandles;
747,420✔
119

120
  return mgmtFunc;
747,420✔
121
}
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