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

taosdata / TDengine / #3562

20 Dec 2024 09:57AM UTC coverage: 26.655% (-32.2%) from 58.812%
#3562

push

travis-ci

web-flow
Merge pull request #29229 from taosdata/enh/TS-5749-3.0

enh: seperate tsdb async tasks to different thread pools

21498 of 109421 branches covered (19.65%)

Branch coverage included in aggregate %.

66 of 96 new or added lines in 7 files covered. (68.75%)

39441 existing lines in 157 files now uncovered.

35007 of 102566 relevant lines covered (34.13%)

53922.97 hits per line

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

16.38
/source/dnode/mgmt/node_util/src/dmFile.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 "crypt.h"
18
#include "dmUtil.h"
19
#include "tchecksum.h"
20
#include "tgrant.h"
21
#include "tjson.h"
22

23
#define MAXLEN               1024
24
#define DM_KEY_INDICATOR     "this indicator!"
25
#define DM_ENCRYPT_CODE_FILE "encryptCode.cfg"
26
#define DM_CHECK_CODE_FILE   "checkCode.bin"
27

UNCOV
28
static int32_t dmDecodeFile(SJson *pJson, bool *deployed) {
×
UNCOV
29
  int32_t code = 0;
×
UNCOV
30
  int32_t value = 0;
×
31

UNCOV
32
  tjsonGetInt32ValueFromDouble(pJson, "deployed", value, code);
×
UNCOV
33
  if (code < 0) return code;
×
34

UNCOV
35
  *deployed = (value != 0);
×
UNCOV
36
  return code;
×
37
}
38

39
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
86✔
40
  int32_t   code = -1;
86✔
41
  TdFilePtr pFile = NULL;
86✔
42
  char     *content = NULL;
86✔
43
  SJson    *pJson = NULL;
86✔
44
  char      file[PATH_MAX] = {0};
86✔
45
  int32_t   nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
86✔
46
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
86!
47
    code = TSDB_CODE_OUT_OF_BUFFER;
×
48
    goto _OVER;
×
49
  }
50

51
  if (taosStatFile(file, NULL, NULL, NULL) < 0) {
86!
52
    dInfo("file:%s not exist", file);
86!
53
    code = 0;
86✔
54
    goto _OVER;
86✔
55
  }
56

UNCOV
57
  pFile = taosOpenFile(file, TD_FILE_READ);
×
UNCOV
58
  if (pFile == NULL) {
×
59
    code = terrno;
×
60
    dError("failed to open file:%s since %s", file, tstrerror(code));
×
61
    goto _OVER;
×
62
  }
63

UNCOV
64
  int64_t size = 0;
×
UNCOV
65
  code = taosFStatFile(pFile, &size, NULL);
×
UNCOV
66
  if (code != 0) {
×
67
    dError("failed to fstat file:%s since %s", file, tstrerror(code));
×
68
    goto _OVER;
×
69
  }
70

UNCOV
71
  content = taosMemoryMalloc(size + 1);
×
UNCOV
72
  if (content == NULL) {
×
73
    code = terrno;
×
74
    goto _OVER;
×
75
  }
76

UNCOV
77
  if (taosReadFile(pFile, content, size) != size) {
×
78
    code = terrno;
×
79
    dError("failed to read file:%s since %s", file, tstrerror(code));
×
80
    goto _OVER;
×
81
  }
82

UNCOV
83
  content[size] = '\0';
×
84

UNCOV
85
  pJson = tjsonParse(content);
×
UNCOV
86
  if (pJson == NULL) {
×
87
    code = TSDB_CODE_INVALID_JSON_FORMAT;
×
88
    goto _OVER;
×
89
  }
90

UNCOV
91
  if (dmDecodeFile(pJson, pDeployed) < 0) {
×
92
    code = TSDB_CODE_INVALID_JSON_FORMAT;
×
93
    goto _OVER;
×
94
  }
95

UNCOV
96
  code = 0;
×
UNCOV
97
  dInfo("succceed to read mnode file %s", file);
×
98

99
_OVER:
×
100
  if (content != NULL) taosMemoryFree(content);
86!
101
  if (pJson != NULL) cJSON_Delete(pJson);
86!
102
  if (pFile != NULL) taosCloseFile(&pFile);
86!
103

104
  if (code != 0) {
86!
105
    dError("failed to read dnode file:%s since %s", file, tstrerror(code));
×
106
  }
107
  return code;
86✔
108
}
109

110
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
4✔
111
  if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return TSDB_CODE_INVALID_JSON_FORMAT;
4!
112
  return 0;
4✔
113
}
114

115
int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
4✔
116
  int32_t   code = -1;
4✔
117
  char     *buffer = NULL;
4✔
118
  SJson    *pJson = NULL;
4✔
119
  TdFilePtr pFile = NULL;
4✔
120
  char      file[PATH_MAX] = {0};
4✔
121
  char      realfile[PATH_MAX] = {0};
4✔
122

123
  int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
4✔
124
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
4!
125
    code = TSDB_CODE_OUT_OF_BUFFER;
×
126
    goto _OVER;
×
127
  }
128

129
  nBytes = snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
4✔
130
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
4!
131
    code = TSDB_CODE_OUT_OF_BUFFER;
×
132
    goto _OVER;
×
133
  }
134

135
  pJson = tjsonCreateObject();
4✔
136
  if (pJson == NULL) {
4!
137
    code = terrno;
×
138
    goto _OVER;
×
139
  }
140

141
  if ((code = dmEncodeFile(pJson, deployed)) != 0) goto _OVER;
4!
142

143
  buffer = tjsonToString(pJson);
4✔
144
  if (buffer == NULL) {
4!
145
    code = TSDB_CODE_INVALID_JSON_FORMAT;
×
146
    goto _OVER;
×
147
  }
148

149
  pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
4✔
150
  if (pFile == NULL) {
4!
151
    code = terrno;
×
152
    goto _OVER;
×
153
  }
154

155
  int32_t len = strlen(buffer);
4✔
156
  if (taosWriteFile(pFile, buffer, len) <= 0) {
4!
157
    code = terrno;
×
158
    goto _OVER;
×
159
  }
160
  if (taosFsyncFile(pFile) < 0) {
4!
161
    code = terrno;
×
162
    goto _OVER;
×
163
  }
164

165
  if (taosCloseFile(&pFile) != 0) {
4!
166
    code = TAOS_SYSTEM_ERROR(errno);
×
167
    goto _OVER;
×
168
  }
169
  TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
4!
170

171
  dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
4!
172

173
_OVER:
×
174
  if (pJson != NULL) tjsonDelete(pJson);
4!
175
  if (buffer != NULL) taosMemoryFree(buffer);
4!
176
  if (pFile != NULL) taosCloseFile(&pFile);
4!
177

178
  if (code != 0) {
4!
179
    dError("failed to write file:%s since %s, deloyed:%d", realfile, tstrerror(code), deployed);
×
180
  }
181
  return code;
4✔
182
}
183

184
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
43✔
185
  int32_t code = 0;
43✔
186
  char    filepath[PATH_MAX] = {0};
43✔
187
  snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
43✔
188

189
  *pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
43✔
190
  if (*pFile == NULL) {
43!
191
    code = terrno;
×
192
    dError("failed to open file:%s since %s", filepath, tstrerror(code));
×
193
    return code;
×
194
  }
195

196
  int32_t retryTimes = 0;
43✔
197
  int32_t ret = 0;
43✔
198
  do {
199
    ret = taosLockFile(*pFile);
43✔
200
    if (ret == 0) break;
43!
201

UNCOV
202
    code = terrno;
×
UNCOV
203
    taosMsleep(1000);
×
UNCOV
204
    retryTimes++;
×
UNCOV
205
    dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
×
UNCOV
206
  } while (retryTimes < 12);
×
207

208
  if (ret < 0) {
43!
UNCOV
209
    code = TAOS_SYSTEM_ERROR(errno);
×
UNCOV
210
    (void)taosCloseFile(pFile);
×
UNCOV
211
    *pFile = NULL;
×
UNCOV
212
    return code;
×
213
  }
214

215
  dDebug("lock file:%s to prevent repeated starts", filepath);
43✔
216
  return code;
43✔
217
}
218

219
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
220

UNCOV
221
static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool toLogFile) {
×
UNCOV
222
  TdFilePtr pFile = NULL;
×
UNCOV
223
  char     *result = NULL;
×
UNCOV
224
  int32_t   code = -1;
×
225

UNCOV
226
  int32_t len = ENCRYPTED_LEN(sizeof(DM_KEY_INDICATOR));
×
UNCOV
227
  result = taosMemoryMalloc(len);
×
UNCOV
228
  if (result == NULL) {
×
229
    return terrno;
×
230
  }
231

232
  SCryptOpts opts;
UNCOV
233
  tstrncpy(opts.key, key, ENCRYPT_KEY_LEN + 1);
×
UNCOV
234
  opts.len = len;
×
UNCOV
235
  opts.source = DM_KEY_INDICATOR;
×
UNCOV
236
  opts.result = result;
×
UNCOV
237
  opts.unitLen = 16;
×
UNCOV
238
  (void)CBC_Encrypt(&opts);
×
239

UNCOV
240
  pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
×
UNCOV
241
  if (pFile == NULL) {
×
242
    code = terrno;
×
243
    goto _OVER;
×
244
  }
245

UNCOV
246
  if (taosWriteFile(pFile, opts.result, len) <= 0) {
×
247
    code = terrno;
×
248
    goto _OVER;
×
249
  }
250

UNCOV
251
  if (taosFsyncFile(pFile) < 0) {
×
252
    code = TAOS_SYSTEM_ERROR(errno);
×
253
    goto _OVER;
×
254
  }
255

UNCOV
256
  if (taosCloseFile(&pFile) != 0) {
×
257
    code = TAOS_SYSTEM_ERROR(errno);
×
258
    goto _OVER;
×
259
  }
260

UNCOV
261
  TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
×
262

UNCOV
263
  encryptDebug("succeed to write checkCode file:%s", realfile);
×
264

UNCOV
265
  code = 0;
×
UNCOV
266
_OVER:
×
UNCOV
267
  if (pFile != NULL) taosCloseFile(&pFile);
×
UNCOV
268
  if (result != NULL) taosMemoryFree(result);
×
269

UNCOV
270
  return code;
×
271
}
272

UNCOV
273
static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptCode, bool toLogFile) {
×
UNCOV
274
  TdFilePtr pFile = NULL;
×
UNCOV
275
  int32_t   code = -1;
×
276

UNCOV
277
  pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
×
UNCOV
278
  if (pFile == NULL) {
×
279
    code = terrno;
×
280
    goto _OVER;
×
281
  }
282

UNCOV
283
  int32_t len = strlen(encryptCode);
×
UNCOV
284
  if (taosWriteFile(pFile, encryptCode, len) <= 0) {
×
285
    code = terrno;
×
286
    goto _OVER;
×
287
  }
UNCOV
288
  if (taosFsyncFile(pFile) < 0) {
×
289
    code = terrno;
×
290
    goto _OVER;
×
291
  }
292

UNCOV
293
  if (taosCloseFile(&pFile) != 0) {
×
294
    code = TAOS_SYSTEM_ERROR(errno);
×
295
    goto _OVER;
×
296
  }
297

UNCOV
298
  TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
×
299

UNCOV
300
  encryptDebug("succeed to write encryptCode file:%s", realfile);
×
301

UNCOV
302
  code = 0;
×
UNCOV
303
_OVER:
×
UNCOV
304
  if (pFile != NULL) taosCloseFile(&pFile);
×
305

UNCOV
306
  return code;
×
307
}
308

309
static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) {
×
310
  char     *content = NULL;
×
311
  int64_t   size = 0;
×
312
  TdFilePtr pFile = NULL;
×
313
  char     *result = NULL;
×
314
  int32_t   code = -1;
×
315

316
  pFile = taosOpenFile(file, TD_FILE_READ);
×
317
  if (pFile == NULL) {
×
318
    code = terrno;
×
319
    encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
×
320
    goto _OVER;
×
321
  }
322

323
  code = taosFStatFile(pFile, &size, NULL);
×
324
  if (code != 0) {
×
325
    encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
×
326
    goto _OVER;
×
327
  }
328

329
  content = taosMemoryMalloc(size);
×
330
  if (content == NULL) {
×
331
    code = terrno;
×
332
    goto _OVER;
×
333
  }
334

335
  if (taosReadFile(pFile, content, size) != size) {
×
336
    code = terrno;
×
337
    encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
×
338
    goto _OVER;
×
339
  }
340

341
  encryptDebug("succeed to read checkCode file:%s", file);
×
342

343
  int len = ENCRYPTED_LEN(size);
×
344
  result = taosMemoryMalloc(len);
×
345
  if (result == NULL) {
×
346
    code = terrno;
×
347
    encryptError("failed to alloc memory file:%s since %s", file, tstrerror(code));
×
348
    goto _OVER;
×
349
  }
350

351
  SCryptOpts opts = {0};
×
352
  tstrncpy(opts.key, key, ENCRYPT_KEY_LEN + 1);
×
353
  opts.len = len;
×
354
  opts.source = content;
×
355
  opts.result = result;
×
356
  opts.unitLen = 16;
×
357
  (void)CBC_Decrypt(&opts);
×
358

359
  if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
×
360
    code = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
×
361
    encryptError("failed to compare decrypted result");
×
362
    goto _OVER;
×
363
  }
364

365
  encryptDebug("succeed to compare checkCode file:%s", file);
×
366
  code = 0;
×
367
_OVER:
×
368
  if (result != NULL) taosMemoryFree(result);
×
369
  if (content != NULL) taosMemoryFree(content);
×
370
  if (pFile != NULL) taosCloseFile(&pFile);
×
371

372
  return code;
×
373
}
374

UNCOV
375
int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
×
376
#ifdef TD_ENTERPRISE
UNCOV
377
  int32_t code = -1;
×
UNCOV
378
  int32_t lino = 0;
×
UNCOV
379
  char   *machineId = NULL;
×
UNCOV
380
  char   *encryptCode = NULL;
×
381

UNCOV
382
  char folder[PATH_MAX] = {0};
×
383

UNCOV
384
  char encryptFile[PATH_MAX] = {0};
×
UNCOV
385
  char realEncryptFile[PATH_MAX] = {0};
×
386

UNCOV
387
  char checkFile[PATH_MAX] = {0};
×
UNCOV
388
  char realCheckFile[PATH_MAX] = {0};
×
389

UNCOV
390
  int32_t nBytes = snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
×
UNCOV
391
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
×
392
    return TSDB_CODE_OUT_OF_BUFFER;
×
393
  }
394

UNCOV
395
  nBytes = snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
×
UNCOV
396
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
×
397
    return TSDB_CODE_OUT_OF_BUFFER;
×
398
  }
399

UNCOV
400
  nBytes = snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
×
UNCOV
401
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
×
402
    return TSDB_CODE_OUT_OF_BUFFER;
×
403
  }
404

UNCOV
405
  nBytes = snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
×
UNCOV
406
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
×
407
    return TSDB_CODE_OUT_OF_BUFFER;
×
408
  }
409

UNCOV
410
  snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
×
UNCOV
411
  if (nBytes <= 0 || nBytes >= PATH_MAX) {
×
412
    return TSDB_CODE_OUT_OF_BUFFER;
×
413
  }
414

UNCOV
415
  if (taosMkDir(folder) != 0) {
×
416
    code = terrno;
×
417
    encryptError("failed to create dir:%s since %s", folder, tstrerror(code));
×
418
    goto _OVER;
×
419
  }
420

UNCOV
421
  if (taosCheckExistFile(realCheckFile)) {
×
422
    if ((code = dmCompareEncryptKey(realCheckFile, key, toLogFile)) != 0) {
×
423
      goto _OVER;
×
424
    }
425
  }
426

UNCOV
427
  TAOS_CHECK_GOTO(tGetMachineId(&machineId), &lino, _OVER);
×
428

UNCOV
429
  TAOS_CHECK_GOTO(generateEncryptCode(key, machineId, &encryptCode), &lino, _OVER);
×
430

UNCOV
431
  if ((code = dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile)) != 0) {
×
432
    goto _OVER;
×
433
  }
434

UNCOV
435
  if ((code = dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile)) != 0) {
×
436
    goto _OVER;
×
437
  }
438

UNCOV
439
  encryptInfo("Succeed to update encrypt key\n");
×
440

UNCOV
441
  code = 0;
×
UNCOV
442
_OVER:
×
UNCOV
443
  taosMemoryFree(encryptCode);
×
UNCOV
444
  taosMemoryFree(machineId);
×
UNCOV
445
  if (code != 0) {
×
446
    encryptError("failed to update encrypt key at line %d since %s", lino, tstrerror(code));
×
447
  }
UNCOV
448
  TAOS_RETURN(code);
×
449
#else
450
  return 0;
451
#endif
452
}
453

454
extern int32_t checkAndGetCryptKey(const char *encryptCode, const char *machineId, char **key);
455

456
static int32_t dmReadEncryptCodeFile(char *file, char **output) {
×
457
  TdFilePtr pFile = NULL;
×
458
  int32_t   code = -1;
×
459
  char     *content = NULL;
×
460

461
  pFile = taosOpenFile(file, TD_FILE_READ);
×
462
  if (pFile == NULL) {
×
463
    code = terrno;
×
464
    dError("failed to open dnode file:%s since %s", file, tstrerror(code));
×
465
    goto _OVER;
×
466
  }
467

468
  int64_t size = 0;
×
469
  code = taosFStatFile(pFile, &size, NULL);
×
470
  if (code != 0) {
×
471
    dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
×
472
    goto _OVER;
×
473
  }
474

475
  content = taosMemoryMalloc(size + 1);
×
476
  if (content == NULL) {
×
477
    code = terrno;
×
478
    goto _OVER;
×
479
  }
480

481
  if (taosReadFile(pFile, content, size) != size) {
×
482
    code = terrno;
×
483
    dError("failed to read dnode file:%s since %s", file, tstrerror(code));
×
484
    goto _OVER;
×
485
  }
486

487
  content[size] = '\0';
×
488

489
  *output = content;
×
490
  content = NULL;
×
491

492
  dInfo("succeed to read encryptCode file:%s", file);
×
493
  code = 0;
×
494
_OVER:
×
495
  if (pFile != NULL) taosCloseFile(&pFile);
×
496
  taosMemoryFree(content);
×
497

498
  return code;
×
499
}
500

501
int32_t dmGetEncryptKey() {
42✔
502
#ifdef TD_ENTERPRISE
503
  int32_t code = -1;
42✔
504
  char    encryptFile[PATH_MAX] = {0};
42✔
505
  char    checkFile[PATH_MAX] = {0};
42✔
506
  char   *machineId = NULL;
42✔
507
  char   *encryptKey = NULL;
42✔
508
  char   *content = NULL;
42✔
509

510
  int32_t nBytes = snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP,
42✔
511
                            DM_ENCRYPT_CODE_FILE);
512
  if (nBytes <= 0 || nBytes >= sizeof(encryptFile)) {
42!
513
    code = TSDB_CODE_OUT_OF_BUFFER;
×
514
    return code;
×
515
  }
516

517
  nBytes = snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
42✔
518
  if (nBytes <= 0 || nBytes >= sizeof(checkFile)) {
42!
519
    code = TSDB_CODE_OUT_OF_BUFFER;
×
520
    return code;
×
521
  }
522

523
  if (!taosCheckExistFile(encryptFile)) {
42!
524
    code = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
42✔
525
    dInfo("no exist, checkCode file:%s", encryptFile);
42!
526
    return 0;
42✔
527
  }
528

529
  if ((code = dmReadEncryptCodeFile(encryptFile, &content)) != 0) {
×
530
    goto _OVER;
×
531
  }
532

533
  if ((code = tGetMachineId(&machineId)) != 0) {
×
534
    goto _OVER;
×
535
  }
536

537
  if ((code = checkAndGetCryptKey(content, machineId, &encryptKey)) != 0) {
×
538
    goto _OVER;
×
539
  }
540

541
  taosMemoryFreeClear(machineId);
×
542
  taosMemoryFreeClear(content);
×
543

544
  if (encryptKey[0] == '\0') {
×
545
    code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
×
546
    dError("failed to read key since %s", tstrerror(code));
×
547
    goto _OVER;
×
548
  }
549

550
  if ((code = dmCompareEncryptKey(checkFile, encryptKey, true)) != 0) {
×
551
    goto _OVER;
×
552
  }
553

554
  tstrncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN + 1);
×
555
  taosMemoryFreeClear(encryptKey);
×
556
  tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, strlen(tsEncryptKey));
×
557
  tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
×
558

559
  code = 0;
×
560
_OVER:
×
561
  if (content != NULL) taosMemoryFree(content);
×
562
  if (encryptKey != NULL) taosMemoryFree(encryptKey);
×
563
  if (machineId != NULL) taosMemoryFree(machineId);
×
564
  if (code != 0) {
×
565
    dError("failed to get encrypt key since %s", tstrerror(code));
×
566
  }
567
  TAOS_RETURN(code);
×
568
#else
569
  return 0;
570
#endif
571
}
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