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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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

UNCOV
35
int32_t mndInitAcct(SMnode *pMnode) {
×
UNCOV
36
  SSdbTable table = {
×
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

UNCOV
47
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq);
×
UNCOV
48
  mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq);
×
UNCOV
49
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq);
×
50

UNCOV
51
  return sdbSetTable(pMnode->pSdb, table);
×
52
}
53

UNCOV
54
void mndCleanupAcct(SMnode *pMnode) {}
×
55

UNCOV
56
static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
×
UNCOV
57
  int32_t  code = 0;
×
UNCOV
58
  SAcctObj acctObj = {0};
×
UNCOV
59
  tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
×
UNCOV
60
  acctObj.createdTime = taosGetTimestampMs();
×
UNCOV
61
  acctObj.updateTime = acctObj.createdTime;
×
UNCOV
62
  acctObj.acctId = 1;
×
UNCOV
63
  acctObj.status = 0;
×
UNCOV
64
  acctObj.cfg = (SAcctCfg){
×
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

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

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

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

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

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

UNCOV
111
  mndTransDrop(pTrans);
×
UNCOV
112
  return 0;
×
113
}
114

UNCOV
115
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
×
UNCOV
116
  int32_t code = 0;
×
UNCOV
117
  int32_t lino = 0;
×
UNCOV
118
  terrno = TSDB_CODE_OUT_OF_MEMORY;
×
119

UNCOV
120
  SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE);
×
UNCOV
121
  if (pRaw == NULL) goto _OVER;
×
122

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

UNCOV
144
  terrno = 0;
×
145

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

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

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

UNCOV
164
  int8_t sver = 0;
×
UNCOV
165
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
×
166

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

UNCOV
172
  pRow = sdbAllocRow(sizeof(SAcctObj));
×
UNCOV
173
  if (pRow == NULL) goto _OVER;
×
174

UNCOV
175
  pAcct = sdbGetRowObj(pRow);
×
UNCOV
176
  if (pAcct == NULL) goto _OVER;
×
177

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

UNCOV
198
  terrno = 0;
×
199

UNCOV
200
_OVER:
×
UNCOV
201
  if (terrno != 0) {
×
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

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

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

UNCOV
216
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
×
UNCOV
217
  mTrace("acct:%s, perform delete action, row:%p", pAcct->acct, pAcct);
×
UNCOV
218
  return 0;
×
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

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

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

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

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

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

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