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

taosdata / TDengine / #4897

25 Dec 2025 10:17AM UTC coverage: 65.717% (-0.2%) from 65.929%
#4897

push

travis-ci

web-flow
fix: [6622889291] Fix invalid rowSize. (#34043)

186011 of 283047 relevant lines covered (65.72%)

113853896.64 hits per line

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

67.32
/source/dnode/mnode/impl/src/mndAcct.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 "mndAcct.h"
18
#include "mndPrivilege.h"
19
#include "mndShow.h"
20
#include "mndTrans.h"
21

22
#define ACCT_VER_NUMBER   1
23
#define ACCT_RESERVE_SIZE 128
24

25
static int32_t  mndCreateDefaultAcct(SMnode *pMnode);
26
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
27
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw);
28
static int32_t  mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct);
29
static int32_t  mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct);
30
static int32_t  mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew);
31
static int32_t  mndProcessCreateAcctReq(SRpcMsg *pReq);
32
static int32_t  mndProcessAlterAcctReq(SRpcMsg *pReq);
33
static int32_t  mndProcessDropAcctReq(SRpcMsg *pReq);
34

35
int32_t mndInitAcct(SMnode *pMnode) {
514,231✔
36
  SSdbTable table = {
514,231✔
37
      .sdbType = SDB_ACCT,
38
      .keyType = SDB_KEY_BINARY,
39
      .deployFp = mndCreateDefaultAcct,
40
      .encodeFp = (SdbEncodeFp)mndAcctActionEncode,
41
      .decodeFp = (SdbDecodeFp)mndAcctActionDecode,
42
      .insertFp = (SdbInsertFp)mndAcctActionInsert,
43
      .updateFp = (SdbUpdateFp)mndAcctActionUpdate,
44
      .deleteFp = (SdbDeleteFp)mndAcctActionDelete,
45
  };
46

47
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq);
514,231✔
48
  mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq);
514,231✔
49
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq);
514,231✔
50

51
  return sdbSetTable(pMnode->pSdb, table);
514,231✔
52
}
53

54
void mndCleanupAcct(SMnode *pMnode) {}
514,110✔
55

56
static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
335,343✔
57
  int32_t  code = 0;
335,343✔
58
  SAcctObj acctObj = {0};
335,343✔
59
  tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
335,343✔
60
  acctObj.createdTime = taosGetTimestampMs();
335,343✔
61
  acctObj.updateTime = acctObj.createdTime;
335,343✔
62
  acctObj.acctId = 1;
335,343✔
63
  acctObj.status = 0;
335,343✔
64
  acctObj.cfg = (SAcctCfg){
335,343✔
65
      .maxUsers = INT32_MAX,
66
      .maxDbs = INT32_MAX,
67
      .maxStbs = INT32_MAX,
68
      .maxTbs = INT32_MAX,
69
      .maxTimeSeries = INT32_MAX,
70
      .maxStreams = INT32_MAX,
71
      .maxFuncs = INT32_MAX,
72
      .maxConsumers = INT32_MAX,
73
      .maxConns = INT32_MAX,
74
      .maxTopics = INT32_MAX,
75
      .maxStorage = INT64_MAX,
76
      .accessState = TSDB_VN_ALL_ACCCESS,
77
  };
78

79
  SSdbRaw *pRaw = mndAcctActionEncode(&acctObj);
335,343✔
80
  if (pRaw == NULL) {
335,343✔
81
    code = terrno;
×
82
    TAOS_RETURN(code);
×
83
  }
84
  TAOS_CHECK_RETURN(sdbSetRawStatus(pRaw, SDB_STATUS_READY));
335,343✔
85

86
  mInfo("acct:%s, will be created when deploying, raw:%p", acctObj.acct, pRaw);
335,343✔
87

88
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-acct");
335,343✔
89
  if (pTrans == NULL) {
335,343✔
90
    sdbFreeRaw(pRaw);
×
91
    code = terrno;
×
92
    mError("acct:%s, failed to create since %s", acctObj.acct, tstrerror(code));
×
93
    TAOS_RETURN(code);
×
94
  }
95
  mInfo("trans:%d, used to create acct:%s", pTrans->id, acctObj.acct);
335,343✔
96

97
  code = mndTransAppendCommitlog(pTrans, pRaw);
335,343✔
98
  if (code != 0) {
335,343✔
99
    mError("trans:%d, failed to commit redo log since %s", pTrans->id, tstrerror(code));
×
100
    mndTransDrop(pTrans);
×
101
    TAOS_RETURN(code);
×
102
  }
103

104
  code = mndTransPrepare(pMnode, pTrans);
335,343✔
105
  if (code != 0) {
335,343✔
106
    mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
×
107
    mndTransDrop(pTrans);
×
108
    TAOS_RETURN(code);
×
109
  }
110

111
  mndTransDrop(pTrans);
335,343✔
112
  return 0;
335,343✔
113
}
114

115
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
1,280,739✔
116
  int32_t code = 0;
1,280,739✔
117
  int32_t lino = 0;
1,280,739✔
118
  terrno = TSDB_CODE_OUT_OF_MEMORY;
1,280,739✔
119

120
  SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE);
1,280,739✔
121
  if (pRaw == NULL) goto _OVER;
1,280,739✔
122

123
  int32_t dataPos = 0;
1,280,739✔
124
  SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, _OVER)
1,280,739✔
125
  SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, _OVER)
1,280,739✔
126
  SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, _OVER)
1,280,739✔
127
  SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, _OVER)
1,280,739✔
128
  SDB_SET_INT32(pRaw, dataPos, pAcct->status, _OVER)
1,280,739✔
129
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, _OVER)
1,280,739✔
130
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, _OVER)
1,280,739✔
131
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, _OVER)
1,280,739✔
132
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, _OVER)
1,280,739✔
133
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, _OVER)
1,280,739✔
134
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, _OVER)
1,280,739✔
135
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, _OVER)
1,280,739✔
136
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, _OVER)
1,280,739✔
137
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, _OVER)
1,280,739✔
138
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, _OVER)
1,280,739✔
139
  SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, _OVER)
1,280,739✔
140
  SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, _OVER)
1,280,739✔
141
  SDB_SET_RESERVE(pRaw, dataPos, ACCT_RESERVE_SIZE, _OVER)
1,280,739✔
142
  SDB_SET_DATALEN(pRaw, dataPos, _OVER)
1,280,739✔
143

144
  terrno = 0;
1,280,739✔
145

146
_OVER:
1,280,739✔
147
  if (terrno != 0) {
1,280,739✔
148
    mError("acct:%s, failed to encode to raw:%p since %s", pAcct->acct, pRaw, terrstr());
×
149
    sdbFreeRaw(pRaw);
×
150
    return NULL;
×
151
  }
152

153
  mTrace("acct:%s, encode to raw:%p, row:%p", pAcct->acct, pRaw, pAcct);
1,280,739✔
154
  return pRaw;
1,280,739✔
155
}
156

157
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
514,195✔
158
  int32_t code = 0;
514,195✔
159
  int32_t lino = 0;
514,195✔
160
  terrno = TSDB_CODE_OUT_OF_MEMORY;
514,195✔
161
  SAcctObj *pAcct = NULL;
514,195✔
162
  SSdbRow  *pRow = NULL;
514,195✔
163

164
  int8_t sver = 0;
514,195✔
165
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
514,195✔
166

167
  if (sver != ACCT_VER_NUMBER) {
514,195✔
168
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
169
    goto _OVER;
×
170
  }
171

172
  pRow = sdbAllocRow(sizeof(SAcctObj));
514,195✔
173
  if (pRow == NULL) goto _OVER;
514,195✔
174

175
  pAcct = sdbGetRowObj(pRow);
514,195✔
176
  if (pAcct == NULL) goto _OVER;
514,195✔
177

178
  int32_t dataPos = 0;
514,195✔
179
  SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, _OVER)
514,195✔
180
  SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, _OVER)
514,195✔
181
  SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, _OVER)
514,195✔
182
  SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, _OVER)
514,195✔
183
  SDB_GET_INT32(pRaw, dataPos, &pAcct->status, _OVER)
514,195✔
184
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, _OVER)
514,195✔
185
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, _OVER)
514,195✔
186
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, _OVER)
514,195✔
187
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, _OVER)
514,195✔
188
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, _OVER)
514,195✔
189
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, _OVER)
514,195✔
190
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, _OVER)
514,195✔
191
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, _OVER)
514,195✔
192
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, _OVER)
514,195✔
193
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, _OVER)
514,195✔
194
  SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, _OVER)
514,195✔
195
  SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, _OVER)
514,195✔
196
  SDB_GET_RESERVE(pRaw, dataPos, ACCT_RESERVE_SIZE, _OVER)
514,195✔
197

198
  terrno = 0;
514,195✔
199

200
_OVER:
514,195✔
201
  if (terrno != 0) {
514,195✔
202
    mError("acct:%s, failed to decode from raw:%p since %s", pAcct == NULL ? "null" : pAcct->acct, pRaw, terrstr());
×
203
    taosMemoryFreeClear(pRow);
×
204
    return NULL;
×
205
  }
206

207
  mTrace("acct:%s, decode from raw:%p, row:%p", pAcct->acct, pRaw, pAcct);
514,195✔
208
  return pRow;
514,195✔
209
}
210

211
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) {
514,195✔
212
  mTrace("acct:%s, perform insert action, row:%p", pAcct->acct, pAcct);
514,195✔
213
  return 0;
514,195✔
214
}
215

216
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
514,110✔
217
  mTrace("acct:%s, perform delete action, row:%p", pAcct->acct, pAcct);
514,110✔
218
  return 0;
514,110✔
219
}
220

221
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
×
222
  mTrace("acct:%s, perform update action, old row:%p new row:%p", pOld->acct, pOld, pNew);
×
223
  pOld->updateTime = pNew->updateTime;
×
224
  pOld->status = pNew->status;
×
225
  memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg));
×
226
  return 0;
×
227
}
228

229
static int32_t mndProcessCreateAcctReq(SRpcMsg *pReq) {
×
230
  int32_t code = 0;
×
231
  code = mndCheckOperPrivilege(pReq->info.node, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_CREATE_ACCT);
×
232
  if (code != 0) {
×
233
    TAOS_RETURN(code);
×
234
  }
235

236
  code = TSDB_CODE_OPS_NOT_SUPPORT;
×
237
  mError("failed to process create acct request since %s", tstrerror(code));
×
238
  TAOS_RETURN(code);
×
239
}
240

241
static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq) {
×
242
  int32_t code = 0;
×
243
  code = mndCheckOperPrivilege(pReq->info.node, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_ALTER_ACCT);
×
244
  if (code != 0) {
×
245
    TAOS_RETURN(code);
×
246
  }
247

248
  code = TSDB_CODE_OPS_NOT_SUPPORT;
×
249
  mError("failed to process create acct request since %s", tstrerror(code));
×
250
  TAOS_RETURN(code);
×
251
}
252

253
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq) {
×
254
  int32_t code = 0;
×
255
  code = mndCheckOperPrivilege(pReq->info.node, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_DROP_ACCT);
×
256
  if (code != 0) {
×
257
    TAOS_RETURN(code);
×
258
  }
259

260
  code = TSDB_CODE_OPS_NOT_SUPPORT;
×
261
  mError("failed to process create acct request since %s", tstrerror(code));
×
262
  TAOS_RETURN(code);
×
263
}
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