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

taosdata / TDengine / #5071

17 May 2026 01:15AM UTC coverage: 63.054% (-10.3%) from 73.326%
#5071

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

238317 of 377957 relevant lines covered (63.05%)

130539817.12 hits per line

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

56.59
/source/dnode/mnode/impl/src/mndEncryptAlgr.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 MND_ENCRYPT_ALGR_VER_NUMBER 1
17
#if defined(TD_ENTERPRISE) && defined(LINUX)
18
#define MND_ENCRYPT_ALGR_LAST_ID 6
19
#else
20
#define MND_ENCRYPT_ALGR_LAST_ID 1
21
#endif
22

23
#include "audit.h"
24
#include "mndEncryptAlgr.h"
25
#include "mndMnode.h"
26
#include "mndShow.h"
27
#include "mndSync.h"
28
#include "mndTrans.h"
29
#include "tencrypt.h"
30

31
static void tFreeEncryptAlgrObj(SEncryptAlgrObj *pEncryptAlgr) {}
2,713,962✔
32

33
static int32_t tSerializeSEncryptAlgrObj(void *buf, int32_t bufLen, const SEncryptAlgrObj *pObj) {
9,918,168✔
34
  SEncoder encoder = {0};
9,918,168✔
35
  int32_t  code = 0;
9,918,168✔
36
  int32_t  lino;
37
  int32_t  tlen;
38
  tEncoderInit(&encoder, buf, bufLen);
9,918,168✔
39

40
  TAOS_CHECK_EXIT(tStartEncode(&encoder));
9,918,168✔
41
  TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->id));
19,836,336✔
42
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->algorithm_id));
19,836,336✔
43
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->name));
19,836,336✔
44
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->desc));
19,836,336✔
45
  TAOS_CHECK_EXIT(tEncodeI16(&encoder, pObj->type));
19,836,336✔
46
  TAOS_CHECK_EXIT(tEncodeI8(&encoder, pObj->source));
19,836,336✔
47
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->ossl_algr_name));
19,836,336✔
48

49
  tEndEncode(&encoder);
9,918,168✔
50

51
_exit:
9,918,168✔
52
  if (code) {
9,918,168✔
53
    tlen = code;
×
54
  } else {
55
    tlen = encoder.pos;
9,918,168✔
56
  }
57
  tEncoderClear(&encoder);
9,918,168✔
58
  return tlen;
9,918,168✔
59
}
60

61
static int32_t tDeserializeSEncryptAlgrObj(void *buf, int32_t bufLen, SEncryptAlgrObj *pObj) {
2,713,962✔
62
  int32_t  code = 0;
2,713,962✔
63
  int32_t  lino;
64
  SDecoder decoder = {0};
2,713,962✔
65
  tDecoderInit(&decoder, buf, bufLen);
2,713,962✔
66

67
  TAOS_CHECK_EXIT(tStartDecode(&decoder));
2,713,962✔
68
  TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->id));
5,427,924✔
69
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->algorithm_id));
2,713,962✔
70
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->name));
2,713,962✔
71
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->desc));
2,713,962✔
72
  TAOS_CHECK_EXIT(tDecodeI16(&decoder, &pObj->type));
5,427,924✔
73
  TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pObj->source));
5,427,924✔
74
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->ossl_algr_name));
2,713,962✔
75

76
  tEndDecode(&decoder);
2,713,962✔
77

78
_exit:
2,713,962✔
79
  tDecoderClear(&decoder);
2,713,962✔
80
  return code;
2,713,962✔
81
}
82

83
static SSdbRaw *mndEncryptAlgrActionEncode(SEncryptAlgrObj *pEncryptAlgr) {
4,959,084✔
84
  int32_t code = 0;
4,959,084✔
85
  int32_t lino = 0;
4,959,084✔
86
  terrno = TSDB_CODE_SUCCESS;
4,959,084✔
87

88
  void    *buf = NULL;
4,959,084✔
89
  SSdbRaw *pRaw = NULL;
4,959,084✔
90

91
  int32_t tlen = tSerializeSEncryptAlgrObj(NULL, 0, pEncryptAlgr);
4,959,084✔
92
  if (tlen < 0) {
4,959,084✔
93
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
94
    goto OVER;
×
95
  }
96

97
  int32_t size = sizeof(int32_t) + tlen;
4,959,084✔
98
  pRaw = sdbAllocRaw(SDB_ENCRYPT_ALGORITHMS, MND_ENCRYPT_ALGR_VER_NUMBER, size);
4,959,084✔
99
  if (pRaw == NULL) {
4,959,084✔
100
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
101
    goto OVER;
×
102
  }
103

104
  buf = taosMemoryMalloc(tlen);
4,959,084✔
105
  if (buf == NULL) {
4,959,084✔
106
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
107
    goto OVER;
×
108
  }
109

110
  tlen = tSerializeSEncryptAlgrObj(buf, tlen, pEncryptAlgr);
4,959,084✔
111
  if (tlen < 0) {
4,959,084✔
112
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
113
    goto OVER;
×
114
  }
115

116
  int32_t dataPos = 0;
4,959,084✔
117
  SDB_SET_INT32(pRaw, dataPos, tlen, OVER);
4,959,084✔
118
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER);
4,959,084✔
119
  SDB_SET_DATALEN(pRaw, dataPos, OVER);
4,959,084✔
120

121
OVER:
4,959,084✔
122
  taosMemoryFreeClear(buf);
4,959,084✔
123
  if (terrno != TSDB_CODE_SUCCESS) {
4,959,084✔
124
    mError("encrypt_algr:%" PRId32 ", failed to encode to raw:%p since %s", pEncryptAlgr->id, pRaw, terrstr());
×
125
    sdbFreeRaw(pRaw);
×
126
    return NULL;
×
127
  }
128

129
  mTrace("encrypt_algr:%" PRId32 ", encode to raw:%p, row:%p", pEncryptAlgr->id, pRaw, pEncryptAlgr);
4,959,084✔
130
  return pRaw;
4,959,084✔
131
}
132

133
SSdbRow *mndEncryptAlgrActionDecode(SSdbRaw *pRaw) {
2,713,962✔
134
  int32_t      code = 0;
2,713,962✔
135
  int32_t      lino = 0;
2,713,962✔
136
  SSdbRow     *pRow = NULL;
2,713,962✔
137
  SEncryptAlgrObj *pEncryptAlgr = NULL;
2,713,962✔
138
  void        *buf = NULL;
2,713,962✔
139
  terrno = TSDB_CODE_SUCCESS;
2,713,962✔
140

141
  int8_t sver = 0;
2,713,962✔
142
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
2,713,962✔
143
    goto OVER;
×
144
  }
145

146
  if (sver != MND_ENCRYPT_ALGR_VER_NUMBER) {
2,713,962✔
147
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
148
    mError("encrypt_algr read invalid ver, data ver: %d, curr ver: %d", sver, MND_ENCRYPT_ALGR_VER_NUMBER);
×
149
    goto OVER;
×
150
  }
151

152
  pRow = sdbAllocRow(sizeof(SEncryptAlgrObj));
2,713,962✔
153
  if (pRow == NULL) {
2,713,962✔
154
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
155
    goto OVER;
×
156
  }
157

158
  pEncryptAlgr = sdbGetRowObj(pRow);
2,713,962✔
159
  if (pEncryptAlgr == NULL) {
2,713,962✔
160
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
161
    goto OVER;
×
162
  }
163

164
  int32_t tlen;
2,709,114✔
165
  int32_t dataPos = 0;
2,713,962✔
166
  SDB_GET_INT32(pRaw, dataPos, &tlen, OVER);
2,713,962✔
167
  buf = taosMemoryMalloc(tlen + 1);
2,713,962✔
168
  if (buf == NULL) {
2,713,962✔
169
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
170
    goto OVER;
×
171
  }
172
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OVER);
2,713,962✔
173

174
  if ((terrno = tDeserializeSEncryptAlgrObj(buf, tlen, pEncryptAlgr)) < 0) {
2,713,962✔
175
    goto OVER;
×
176
  }
177

178
OVER:
2,713,962✔
179
  taosMemoryFreeClear(buf);
2,713,962✔
180
  if (terrno != TSDB_CODE_SUCCESS) {
2,713,962✔
181
    mError("encrypt_algr:%" PRId32 ", failed to decode from raw:%p since %s", pEncryptAlgr->id, pRaw, terrstr());
×
182
    taosMemoryFreeClear(pRow);
×
183
    return NULL;
×
184
  }
185

186
  mTrace("encrypt_algr:%" PRId32 ", decode from raw:%p, row:%p", pEncryptAlgr->id, pRaw, pEncryptAlgr);
2,713,962✔
187
  return pRow;
2,713,962✔
188
}
189

190
int32_t mndEncryptAlgrActionInsert(SSdb *pSdb, SEncryptAlgrObj *pEncryptAlgr) {
2,426,214✔
191
  mTrace("encrypt_algr:%" PRId32 ", perform insert action", pEncryptAlgr->id);
2,426,214✔
192
  return 0;
2,426,214✔
193
}
194

195
int32_t mndEncryptAlgrActionDelete(SSdb *pSdb, SEncryptAlgrObj *pEncryptAlgr) {
2,713,962✔
196
  mTrace("encrypt_algr:%" PRId32 ", perform delete action", pEncryptAlgr->id);
2,713,962✔
197
  tFreeEncryptAlgrObj(pEncryptAlgr);
2,713,962✔
198
  return 0;
2,713,962✔
199
}
200

201
int32_t mndEncryptAlgrActionUpdate(SSdb *pSdb, SEncryptAlgrObj *pOldEncryptAlgr, SEncryptAlgrObj *pNewEncryptAlgr) {
287,748✔
202
  mTrace("encrypt_algr:%" PRId32 ", perform update action, old row:%p new row:%p", pOldEncryptAlgr->id, pOldEncryptAlgr,
287,748✔
203
         pNewEncryptAlgr);
204

205
  return 0;
287,748✔
206
}
207

208
typedef void (*mndSetEncryptAlgrFp)(SEncryptAlgrObj *Obj);
209

210
static void mndSetSM4EncryptAlgr(SEncryptAlgrObj *Obj){
349,364✔
211
  Obj->id = 1;
349,364✔
212
  tstrncpy(Obj->algorithm_id, "SM4-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
213
  tstrncpy(Obj->name, "SM4", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
214
  tstrncpy(Obj->desc, "SM4 symmetric encryption", TSDB_ENCRYPT_ALGR_DESC_LEN);
349,364✔
215
  Obj->type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
349,364✔
216
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
349,364✔
217
  tstrncpy(Obj->ossl_algr_name, "SM4-CBC:SM4", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
218
}
349,364✔
219

220
static void mndSetAESEncryptAlgr(SEncryptAlgrObj *Obj){
349,364✔
221
  Obj->id = 2;
349,364✔
222
  tstrncpy(Obj->algorithm_id, "AES-128-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
223
  tstrncpy(Obj->name, "AES", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
224
  tstrncpy(Obj->desc, "AES symmetric encryption", TSDB_ENCRYPT_ALGR_DESC_LEN);
349,364✔
225
  Obj->type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
349,364✔
226
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
349,364✔
227
  tstrncpy(Obj->ossl_algr_name, "AES-128-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
228
}
349,364✔
229

230
static void mndSetSM3EncryptAlgr(SEncryptAlgrObj *Obj) {
349,364✔
231
  Obj->id = 3;
349,364✔
232
  tstrncpy(Obj->algorithm_id, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
233
  tstrncpy(Obj->name, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
234
  tstrncpy(Obj->desc, "SM3 digests", TSDB_ENCRYPT_ALGR_DESC_LEN);
349,364✔
235
  Obj->type = ENCRYPT_ALGR_TYPE__DIGEST;
349,364✔
236
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
349,364✔
237
  tstrncpy(Obj->ossl_algr_name, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
238
}
349,364✔
239

240
static void mndSetSHAEncryptAlgr(SEncryptAlgrObj *Obj) {
349,364✔
241
  Obj->id = 4;
349,364✔
242
  tstrncpy(Obj->algorithm_id, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
243
  tstrncpy(Obj->name, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
244
  tstrncpy(Obj->desc, "SHA2 digests", TSDB_ENCRYPT_ALGR_DESC_LEN);
349,364✔
245
  Obj->type = ENCRYPT_ALGR_TYPE__DIGEST;
349,364✔
246
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
349,364✔
247
  tstrncpy(Obj->ossl_algr_name, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
248
}
349,364✔
249

250
static void mndSetSM2EncryptAlgr(SEncryptAlgrObj *Obj) {
349,364✔
251
  Obj->id = 5;
349,364✔
252
  tstrncpy(Obj->algorithm_id, "SM2", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
253
  tstrncpy(Obj->name, "SM2", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
254
  tstrncpy(Obj->desc, "SM2 Asymmetric Cipher", TSDB_ENCRYPT_ALGR_DESC_LEN);
349,364✔
255
  Obj->type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
349,364✔
256
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
349,364✔
257
}
349,364✔
258

259
static void mndSetRSAEncryptAlgr(SEncryptAlgrObj *Obj) {
349,364✔
260
  Obj->id = 6;
349,364✔
261
  tstrncpy(Obj->algorithm_id, "RSA", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
262
  tstrncpy(Obj->name, "RSA", TSDB_ENCRYPT_ALGR_NAME_LEN);
349,364✔
263
  tstrncpy(Obj->desc, "RSA Asymmetric Cipher", TSDB_ENCRYPT_ALGR_DESC_LEN);
349,364✔
264
  Obj->type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
349,364✔
265
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
349,364✔
266
}
349,364✔
267

268
static SSdbRaw * mndCreateEncryptAlgrRaw(STrans *pTrans, SEncryptAlgrObj *Obj) {
2,096,184✔
269
  int32_t code = 0;
2,096,184✔
270

271
  SSdbRaw *pRaw = mndEncryptAlgrActionEncode(Obj);
2,096,184✔
272
  if (pRaw == NULL) {
2,096,184✔
273
    return NULL;
×
274
  }
275
  code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
2,096,184✔
276
  if (code != 0) {
2,096,184✔
277
    terrno = code;
×
278
    return NULL;
×
279
  }
280

281
  if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
2,096,184✔
282
    terrno = code;
×
283
    return NULL;
×
284
  }
285
  return pRaw;
2,096,184✔
286
}
287

288
int32_t mndSendCreateBuiltinReq(SMnode *pMnode) {
349,366✔
289
  int32_t code = 0;
349,366✔
290

291
  SRpcMsg rpcMsg = {.pCont = NULL,
349,366✔
292
                    .contLen = 0,
293
                    .msgType = TDMT_MND_BUILTIN_ENCRYPT_ALGR,
294
                    .info.ahandle = 0,
295
                    .info.notFreeAhandle = 1,
296
                    .info.refId = 0,
297
                    .info.noResp = 0,
298
                    .info.handle = 0};
299
  SEpSet  epSet = {0};
349,366✔
300

301
  mndGetMnodeEpSet(pMnode, &epSet);
349,366✔
302

303
  code = tmsgSendReq(&epSet, &rpcMsg);
349,366✔
304
  if (code != 0) {
349,366✔
305
    mError("failed to send builtin encrypt algr req, since %s", tstrerror(code));
×
306
  }
307
  return code;
349,366✔
308
}
309

310
static int32_t mndCreateBuiltinEncryptAlgr(SMnode *pMnode) {
349,364✔
311
  int32_t code = 0;
349,364✔
312
  STrans *pTrans = NULL;
349,364✔
313

314
  mndSetEncryptAlgrFp setFpArr[] = {mndSetSM4EncryptAlgr
349,364✔
315
#if defined(TD_ENTERPRISE) && defined(LINUX)
316
                                    ,
317
                                    mndSetAESEncryptAlgr,
318
                                    mndSetSM3EncryptAlgr,
319
                                    mndSetSHAEncryptAlgr,
320
                                    mndSetSM2EncryptAlgr,
321
                                    mndSetRSAEncryptAlgr
322
#endif
323
  };
324

325
  int32_t algrNum = sizeof(setFpArr) / sizeof(mndSetEncryptAlgrFp);
349,364✔
326

327
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-enc-algr");
349,364✔
328
  if (pTrans == NULL) {
349,364✔
329
    mError("failed to create since %s",terrstr());
×
330
    code = terrno;
×
331
    goto _OVER;
×
332
  }
333
  mInfo("trans:%d, used to create default encrypt_algr", pTrans->id);
349,364✔
334

335
  for (int32_t i = 0; i < algrNum; i++) {
2,445,548✔
336
    SEncryptAlgrObj *Obj = taosMemoryMalloc(sizeof(SEncryptAlgrObj));
2,096,184✔
337
    if (Obj == NULL) {
2,096,184✔
338
      goto _OVER;
×
339
    }
340
    memset(Obj, 0, sizeof(SEncryptAlgrObj));
2,096,184✔
341
    setFpArr[i](Obj);
2,096,184✔
342
    SSdbRaw *pRaw = mndCreateEncryptAlgrRaw(pTrans, Obj);
2,096,184✔
343
    taosMemoryFree(Obj);
2,096,184✔
344
    if (pRaw == NULL) {
2,096,184✔
345
      mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
346
      goto _OVER;
×
347
    }
348
  }
349

350
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
349,364✔
351
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
352
    goto _OVER;
×
353
  }
354

355
  code = 0;
349,364✔
356

357
_OVER:
349,364✔
358
  mndTransDrop(pTrans);
349,364✔
359
  return code;
349,364✔
360
}
361

362
static int32_t mndProcessBuiltinReq(SRpcMsg *pReq) {
349,364✔
363
  SMnode *pMnode = pReq->info.node;
349,364✔
364
  if (!mndIsLeader(pMnode)) {
349,364✔
365
    return TSDB_CODE_SUCCESS;
×
366
  }
367

368
  return mndCreateBuiltinEncryptAlgr(pMnode);
349,364✔
369
}
370

371
static int32_t mndProcessBuiltinRsp(SRpcMsg *pRsp) {
349,366✔
372
  mInfo("builtin rsp");
349,366✔
373
  return 0;
349,366✔
374
}
375

376
static int32_t mndUpgradeBuiltinEncryptAlgr(SMnode *pMnode, int32_t version) {
349,366✔
377
  if (version >= TSDB_MNODE_BUILTIN_DATA_VERSION) return 0;
349,366✔
378

379
  mInfo("upgrade builtin encrypt algr, current version:%d, target version:%d", version,
349,366✔
380
        TSDB_MNODE_BUILTIN_DATA_VERSION);
381
  return mndSendCreateBuiltinReq(pMnode);
349,366✔
382
}
383

384
static bool mndIsUpgradedBuiltinEncryptAlgr(SMnode *pMnode) {
1,052,231✔
385
  SEncryptAlgrObj *obj = mndAcquireEncryptAlgrById(pMnode, MND_ENCRYPT_ALGR_LAST_ID);
1,052,231✔
386
  if (obj != NULL) {
1,052,231✔
387
    mndReleaseEncryptAlgr(pMnode, obj);
353,600✔
388
    return true;
353,600✔
389
  }
390
  return false;
698,631✔
391
}
392

393
#define SYMCBC "Symmetric Ciphers CBC mode"
394
#define ASYM       "Asymmetric Ciphers"
395
#define DIGEST     "Digests"
396
#define BUILTIN "build-in"
397
#define CUSTOMIZED "customized"
398
static int32_t mndRetrieveEncryptAlgr(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows){
829✔
399
  SMnode      *pMnode = pMsg->info.node;
829✔
400
  SSdb        *pSdb = pMnode->pSdb;
829✔
401
  int32_t      code = 0;
829✔
402
  int32_t      lino = 0;
829✔
403
  int32_t      numOfRows = 0;
829✔
404
  int32_t      cols = 0;
829✔
405
  SEncryptAlgrObj *pObj = NULL;
829✔
406

407
  char tmpBuf[1000] = {0};
829✔
408

409
  while (numOfRows < rows) {
5,803✔
410
    pShow->pIter = sdbFetch(pSdb, SDB_ENCRYPT_ALGORITHMS, pShow->pIter, (void **)&pObj);
5,803✔
411
    if (pShow->pIter == NULL) break;
5,803✔
412

413
    cols = 0;
4,974✔
414
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
415
    COL_DATA_SET_VAL_GOTO((const char *)&pObj->id, false, pObj, pShow->pIter, _OVER);
4,974✔
416

417
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
418
    tstrncpy(varDataVal(tmpBuf), pObj->algorithm_id, TSDB_ENCRYPT_ALGR_NAME_LEN);
4,974✔
419
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
4,974✔
420
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
4,974✔
421

422
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
423
    tstrncpy(varDataVal(tmpBuf), pObj->name, TSDB_ENCRYPT_ALGR_NAME_LEN);
4,974✔
424
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
4,974✔
425
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
4,974✔
426

427
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
428
    tstrncpy(varDataVal(tmpBuf), pObj->desc, TSDB_ENCRYPT_ALGR_DESC_LEN);
4,974✔
429
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
4,974✔
430
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
4,974✔
431

432
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
433
    if(pObj->type == ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS){
4,974✔
434
      tstrncpy(varDataVal(tmpBuf), SYMCBC, strlen(SYMCBC) + 1);
1,658✔
435
    } else if (pObj->type == ENCRYPT_ALGR_TYPE__DIGEST) {
3,316✔
436
      tstrncpy(varDataVal(tmpBuf), DIGEST, strlen(DIGEST) + 1);
1,658✔
437
    } else if (pObj->type == ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS) {
1,658✔
438
      tstrncpy(varDataVal(tmpBuf), ASYM, strlen(ASYM) + 1);
1,658✔
439
    }
440
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
4,974✔
441
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
4,974✔
442

443
    memset(tmpBuf, 0, 1000);
4,974✔
444
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
445
    if(pObj->source == ENCRYPT_ALGR_SOURCE_BUILTIN){
4,974✔
446
      tstrncpy(varDataVal(tmpBuf), BUILTIN, strlen(BUILTIN) + 1);
4,974✔
447
    } else if (pObj->source == ENCRYPT_ALGR_SOURCE_CUSTOMIZED) {
×
448
      tstrncpy(varDataVal(tmpBuf), CUSTOMIZED, strlen(CUSTOMIZED) + 1);
×
449
    }
450
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
4,974✔
451
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
4,974✔
452

453
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,974✔
454
    tstrncpy(varDataVal(tmpBuf), pObj->ossl_algr_name, TSDB_ENCRYPT_ALGR_NAME_LEN);
4,974✔
455
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
4,974✔
456
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
4,974✔
457

458
    sdbRelease(pSdb, pObj);
4,974✔
459
    numOfRows++;
4,974✔
460
  }
461

462
  pShow->numOfRows += numOfRows;
829✔
463

464
_OVER:
829✔
465
  if (code != 0) {
829✔
466
    mError("failed to retrieve encrypt_algr info at line %d since %s", lino, tstrerror(code));
×
467
    TAOS_RETURN(code);
×
468
  }
469
  return numOfRows;
829✔
470
}
471

472
static void mndCancelRetrieveEncryptAlgr(SMnode *pMnode, void *pIter) {
×
473
  SSdb *pSdb = pMnode->pSdb;
×
474
  sdbCancelFetchByType(pSdb, pIter, SDB_ENCRYPT_ALGORITHMS);
×
475
}
×
476

477
static int32_t mndProcessCreateEncryptAlgrReq(SRpcMsg *pReq) {
×
478
  SMnode               *pMnode = pReq->info.node;
×
479
  int32_t               code = 0;
×
480
  int32_t               lino = 0;
×
481
  SCreateEncryptAlgrReq createReq = {0};
×
482
  STrans               *pTrans = NULL;
×
483

484
  int64_t tss = taosGetTimestampMs();
×
485

486
  if (tDeserializeSCreateEncryptAlgrReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
×
487
    TAOS_CHECK_GOTO(TSDB_CODE_INVALID_MSG, &lino, _OVER);
×
488
  }
489

490
  mInfo("algr:%s, start to create, ossl_name:%s", createReq.algorithmId, createReq.osslAlgrName);
×
491

492
  // TAOS_CHECK_GOTO(grantCheck(TSDB_GRANT_USER), &lino, _OVER);
493

494
  SEncryptAlgrObj *exist = mndAcquireEncryptAlgrByAId(pMnode, createReq.algorithmId);
×
495
  if (exist != NULL) {
×
496
    mndReleaseEncryptAlgr(pMnode, exist);
×
497
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ALGR_EXIST, &lino, _OVER);
×
498
  }
499

500
  SEncryptAlgrObj Obj = {0};
×
501
  int32_t         id = sdbGetMaxId(pMnode->pSdb, SDB_ENCRYPT_ALGORITHMS);
×
502
  if (id < 100) id = 101;
×
503
  Obj.id = id;
×
504
  tstrncpy(Obj.algorithm_id, createReq.algorithmId, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
505
  tstrncpy(Obj.name, createReq.name, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
506
  tstrncpy(Obj.desc, createReq.desc, TSDB_ENCRYPT_ALGR_DESC_LEN);
×
507
  if (strncmp(createReq.type, "Symmetric_Ciphers_CBC_mode", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
508
    Obj.type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
×
509
  } else if (strncmp(createReq.type, "Digests", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
510
    Obj.type = ENCRYPT_ALGR_TYPE__DIGEST;
×
511
  } else if (strncmp(createReq.type, "Asymmetric_Ciphers", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
512
    Obj.type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
×
513
  } else {
514
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_INVALID_ENCRYPT_ALGR_TYPE, &lino, _OVER);
×
515
  }
516
  Obj.source = ENCRYPT_ALGR_SOURCE_CUSTOMIZED;
×
517
  tstrncpy(Obj.ossl_algr_name, createReq.osslAlgrName, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
518

519
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-enc-algr");
×
520
  if (pTrans == NULL) {
×
521
    mError("failed to create since %s", terrstr());
×
522
    code = terrno;
×
523
    goto _OVER;
×
524
  }
525
  mInfo("trans:%d, used to create encrypt_algr", pTrans->id);
×
526

527
  SSdbRaw *pRaw = mndCreateEncryptAlgrRaw(pTrans, &Obj);
×
528
  if (pRaw == NULL) {
×
529
    mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
530
    goto _OVER;
×
531
  }
532

533
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
×
534
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
535
    goto _OVER;
×
536
  }
537

538
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
×
539
    int64_t tse = taosGetTimestampMs();
×
540
    double  duration = (double)(tse - tss);
×
541
    duration = duration / 1000;
×
542
    auditRecord(pReq, pMnode->clusterId, "createEncryptAlgr", "", createReq.algorithmId, createReq.sql,
×
543
                strlen(createReq.sql), duration, 0);
×
544
  }
545

546
  return code;
×
547
_OVER:
×
548
  if (code < 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
549
    mError("algr:%s, failed to create at line %d since %s", createReq.algorithmId, lino, tstrerror(code));
×
550
  }
551

552
  tFreeSCreateEncryptAlgrReq(&createReq);
×
553
  mndTransDrop(pTrans);
×
554
  TAOS_RETURN(code);
×
555
}
556

557
static int32_t mndDropEncryptAlgr(SMnode *pMnode, SRpcMsg *pReq, SEncryptAlgrObj *pAlgr) {
×
558
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "drop-encrypt-algr");
×
559
  if (pTrans == NULL) {
×
560
    mError("algr:%s, failed to drop since %s", pAlgr->algorithm_id, terrstr());
×
561
    TAOS_RETURN(terrno);
×
562
  }
563
  mInfo("trans:%d, used to drop algr:%s", pTrans->id, pAlgr->algorithm_id);
×
564

565
  SSdbRaw *pCommitRaw = mndEncryptAlgrActionEncode(pAlgr);
×
566
  if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
×
567
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
×
568
    mndTransDrop(pTrans);
×
569
    TAOS_RETURN(terrno);
×
570
  }
571
  if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) < 0) {
×
572
    mndTransDrop(pTrans);
×
573
    TAOS_RETURN(terrno);
×
574
  }
575

576
  if (mndTransPrepare(pMnode, pTrans) != 0) {
×
577
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
578
    mndTransDrop(pTrans);
×
579
    TAOS_RETURN(terrno);
×
580
  }
581

582
  mndTransDrop(pTrans);
×
583
  TAOS_RETURN(0);
×
584
}
585

586
static int32_t mndProcessDropEncryptAlgrReq(SRpcMsg *pReq) {
×
587
  SMnode             *pMnode = pReq->info.node;
×
588
  int32_t             code = 0;
×
589
  int32_t             lino = 0;
×
590
  SEncryptAlgrObj    *pObj = NULL;
×
591
  SDropEncryptAlgrReq dropReq = {0};
×
592

593
  int64_t tss = taosGetTimestampMs();
×
594

595
  TAOS_CHECK_GOTO(tDeserializeSDropEncryptAlgrReq(pReq->pCont, pReq->contLen, &dropReq), &lino, _OVER);
×
596

597
  mInfo("algr:%s, start to drop", dropReq.algorithmId);
×
598
  // TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_DROP_USER), &lino, _OVER);
599

600
  if (dropReq.algorithmId[0] == 0) {
×
601
    TAOS_CHECK_GOTO(TSDB_CODE_MND_INVALID_ENCRYPT_ALGR_FORMAT, &lino, _OVER);
×
602
  }
603

604
  pObj = mndAcquireEncryptAlgrByAId(pMnode, dropReq.algorithmId);
×
605
  if (pObj == NULL) {
×
606
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ENCRYPT_ALGR_NOT_EXIST, &lino, _OVER);
×
607
  }
608

609
  bool    exist = false;
×
610
  void   *pIter = NULL;
×
611
  SDbObj *pDb = NULL;
×
612
  while (1) {
613
    pIter = sdbFetch(pMnode->pSdb, SDB_DB, pIter, (void **)&pDb);
×
614
    if (pIter == NULL) break;
×
615

616
    if (pDb->cfg.encryptAlgorithm == pObj->id) {
×
617
      exist = true;
×
618
      sdbRelease(pMnode->pSdb, pDb);
×
619
      sdbCancelFetch(pMnode->pSdb, pIter);
×
620
      break;
×
621
    }
622

623
    sdbRelease(pMnode->pSdb, pDb);
×
624
  }
625

626
  if (exist) {
×
627
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ENCRYPT_ALGR_IN_USE, &lino, _OVER);
×
628
  }
629

630
  TAOS_CHECK_GOTO(mndDropEncryptAlgr(pMnode, pReq, pObj), &lino, _OVER);
×
631
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
×
632

633
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
×
634
    int64_t tse = taosGetTimestampMs();
×
635
    double  duration = (double)(tse - tss);
×
636
    duration = duration / 1000;
×
637
    auditRecord(pReq, pMnode->clusterId, "dropEncryptAlgr", "", dropReq.algorithmId, dropReq.sql, dropReq.sqlLen,
×
638
                duration, 0);
639
  }
640

641
_OVER:
×
642
  if (code < 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
643
    mError("algr:%s, failed to drop at line %d since %s", dropReq.algorithmId, lino, tstrerror(code));
×
644
  }
645

646
  mndReleaseEncryptAlgr(pMnode, pObj);
×
647
  tFreeSDropEncryptAlgrReq(&dropReq);
×
648
  TAOS_RETURN(code);
×
649
}
650

651
static int32_t mndRetrieveEncryptStatus(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
×
652
  int32_t code = 0;
×
653
  int32_t lino = 0;
×
654
  int32_t numOfRows = 0;
×
655
  int32_t cols = 0;
×
656
  char    tmpBuf[1000] = {0};
×
657

658
  // Only return data if not already retrieved
659
  if (pShow->numOfRows > 0) {
×
660
    return 0;
×
661
  }
662

663
  // Row 1: config encryption status
664
  if (numOfRows < rows) {
×
665
    cols = 0;
×
666
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
667
    tstrncpy(varDataVal(tmpBuf), "config", 32);
×
668
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
669
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
670

671
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
672
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsCfgAlgorithm), 32);
×
673
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
674
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
675

676
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
677
    tstrncpy(varDataVal(tmpBuf), (tsCfgKey[0] != '\0') ? "enabled" : "disabled", 16);
×
678
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
679
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
680

681
    numOfRows++;
×
682
  }
683

684
  // Row 2: metadata encryption status
685
  if (numOfRows < rows) {
×
686
    cols = 0;
×
687
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
688
    tstrncpy(varDataVal(tmpBuf), "metadata", 32);
×
689
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
690
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
691

692
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
693
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsMetaAlgorithm), 32);
×
694
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
695
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
696

697
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
698
    tstrncpy(varDataVal(tmpBuf), (tsMetaKey[0] != '\0') ? "enabled" : "disabled", 16);
×
699
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
700
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
701

702
    numOfRows++;
×
703
  }
704

705
  // Row 3: data encryption status
706
  if (numOfRows < rows) {
×
707
    cols = 0;
×
708
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
709
    tstrncpy(varDataVal(tmpBuf), "data", 32);
×
710
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
711
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
712

713
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
714
    // Data key uses the master algorithm (usually SM4)
715
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsEncryptAlgorithmType), 32);
×
716
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
717
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
718

719
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
720
    tstrncpy(varDataVal(tmpBuf), (tsDataKey[0] != '\0') ? "enabled" : "disabled", 16);
×
721
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
722
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
723

724
    numOfRows++;
×
725
  }
726

727
  pShow->numOfRows += numOfRows;
×
728
  return numOfRows;
×
729

730
_OVER:
×
731
  if (code != 0) {
×
732
    mError("failed to retrieve encrypt status at line %d since %s", lino, tstrerror(code));
×
733
  }
734
  return numOfRows;
×
735
}
736

737
int32_t mndInitEncryptAlgr(SMnode *pMnode) {
404,369✔
738
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ENCRYPT_ALGR, mndProcessCreateEncryptAlgrReq);
404,369✔
739
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS, mndRetrieveEncryptAlgr);
404,369✔
740
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_STATUS, mndRetrieveEncryptStatus);
404,369✔
741
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS, mndCancelRetrieveEncryptAlgr);
404,369✔
742
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_ENCRYPT_ALGR, mndProcessDropEncryptAlgrReq);
404,369✔
743
  mndSetMsgHandle(pMnode, TDMT_MND_BUILTIN_ENCRYPT_ALGR, mndProcessBuiltinReq);
404,369✔
744
  mndSetMsgHandle(pMnode, TDMT_MND_BUILTIN_ENCRYPT_ALGR_RSP, mndProcessBuiltinRsp);
404,369✔
745

746
  SSdbTable table = {
404,369✔
747
      .sdbType = SDB_ENCRYPT_ALGORITHMS,
748
      .keyType = SDB_KEY_INT32,
749
      .upgradeFp = (SdbUpgradeFp)mndUpgradeBuiltinEncryptAlgr,
750
      .encodeFp = (SdbEncodeFp)mndEncryptAlgrActionEncode,
751
      .decodeFp = (SdbDecodeFp)mndEncryptAlgrActionDecode,
752
      .insertFp = (SdbInsertFp)mndEncryptAlgrActionInsert,
753
      .updateFp = (SdbUpdateFp)mndEncryptAlgrActionUpdate,
754
      .deleteFp = (SdbDeleteFp)mndEncryptAlgrActionDelete,
755
      .isUpgradedFp = (SdbIsUpgradedFp)mndIsUpgradedBuiltinEncryptAlgr,
756
  };
757

758
  return sdbSetTable(pMnode->pSdb, table);
404,369✔
759
}
760

761
void mndCleanupEncryptAlgr(SMnode *pMnode) { mDebug("mnd encrypt algorithms cleanup"); }
404,369✔
762

763
SEncryptAlgrObj *mndAcquireEncryptAlgrById(SMnode *pMnode, int64_t id) {
5,437,353✔
764
  SSdb        *pSdb = pMnode->pSdb;
5,437,353✔
765
  SEncryptAlgrObj *pAlgr = sdbAcquire(pSdb, SDB_ENCRYPT_ALGORITHMS, &id);
5,437,353✔
766
  if (pAlgr == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
5,436,724✔
767
    terrno = TSDB_CODE_SUCCESS;
5,077,304✔
768
  }
769
  return pAlgr;
5,435,878✔
770
}
771

772
void mndGetEncryptOsslAlgrNameById(SMnode *pMnode, int64_t id, char* out){
4,385,122✔
773
  SEncryptAlgrObj *obj = mndAcquireEncryptAlgrById(pMnode, id);
4,385,122✔
774
  if(obj != NULL){
4,383,647✔
775
    tstrncpy(out, obj->ossl_algr_name, TSDB_ENCRYPT_ALGR_NAME_LEN);
4,974✔
776
    mndReleaseEncryptAlgr(pMnode, obj);
4,974✔
777
  }
778
}
4,383,647✔
779

780
SEncryptAlgrObj *mndAcquireEncryptAlgrByAId(SMnode *pMnode, char* algorithm_id) {
5,003✔
781
  SSdb        *pSdb = pMnode->pSdb;
5,003✔
782
  SEncryptAlgrObj *pObj = NULL;
5,003✔
783
  void *pIter = NULL;
5,003✔
784
  while (1) {
785
    pIter = sdbFetch(pSdb, SDB_ENCRYPT_ALGORITHMS, pIter, (void **)&pObj);
15,924✔
786
    if (pIter == NULL) break;
15,924✔
787

788
    if (strncasecmp(pObj->algorithm_id, algorithm_id, TSDB_ENCRYPT_ALGR_NAME_LEN) == 0) {
14,242✔
789
      sdbCancelFetch(pSdb, pIter);
3,321✔
790
      break;
3,321✔
791
    }
792

793
    sdbRelease(pSdb, pObj);
10,921✔
794
  }
795
  return pObj;
5,003✔
796
}
797

798
void mndReleaseEncryptAlgr(SMnode *pMnode, SEncryptAlgrObj *pObj) {
358,574✔
799
  SSdb *pSdb = pMnode->pSdb;
358,574✔
800
  sdbRelease(pSdb, pObj);
358,574✔
801
  pObj = NULL;
358,574✔
802
}
358,574✔
803

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