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

taosdata / TDengine / #3633

11 Mar 2025 12:59PM UTC coverage: 0.0% (-60.7%) from 60.719%
#3633

push

travis-ci

web-flow
Merge pull request #30118 from taosdata/wl30

udpate ci workflow

0 of 280412 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 275582 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/source/dnode/vnode/src/meta/metaOpen.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
#include "meta.h"
17
#include "vnd.h"
18

19
static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
20
static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
21
static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
22
int        tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
23
static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
24
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
25
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
26

27
static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
28
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
29

30
static void metaInitLock(SMeta *pMeta) {
×
31
  TdThreadRwlockAttr attr;
32
  (void)taosThreadRwlockAttrInit(&attr);
×
33
  (void)taosThreadRwlockAttrSetKindNP(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
×
34
  (void)taosThreadRwlockInit(&pMeta->lock, &attr);
×
35
  (void)taosThreadRwlockAttrDestroy(&attr);
×
36
  return;
×
37
}
38
static void metaDestroyLock(SMeta *pMeta) { (void)taosThreadRwlockDestroy(&pMeta->lock); }
×
39

40
static void metaCleanup(SMeta **ppMeta);
41

42
static void doScan(SMeta *pMeta) {
×
43
  TBC    *cursor = NULL;
×
44
  int32_t code;
45

46
  // open file to write
47
  char path[TSDB_FILENAME_LEN] = {0};
×
48
  snprintf(path, TSDB_FILENAME_LEN - 1, "%s%s", pMeta->path, TD_DIRSEP "scan.txt");
×
49
  TdFilePtr fp = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
×
50
  if (fp == NULL) {
×
51
    metaError("failed to open file:%s, reason:%s", path, tstrerror(terrno));
×
52
    return;
×
53
  }
54

55
  code = tdbTbcOpen(pMeta->pTbDb, &cursor, NULL);
×
56
  if (code) {
×
57
    if (taosCloseFile(&fp) != 0) {
×
58
      metaError("failed to close file:%s, reason:%s", path, tstrerror(terrno));
×
59
    }
60
    metaError("failed to open table.db cursor, reason:%s", tstrerror(terrno));
×
61
    return;
×
62
  }
63

64
  code = tdbTbcMoveToFirst(cursor);
×
65
  if (code) {
×
66
    if (taosCloseFile(&fp) != 0) {
×
67
      metaError("failed to close file:%s, reason:%s", path, tstrerror(terrno));
×
68
    }
69
    tdbTbcClose(cursor);
×
70
    metaError("failed to move to first, reason:%s", tstrerror(terrno));
×
71
    return;
×
72
  }
73

74
  for (;;) {
×
75
    const void *pKey;
76
    int         kLen;
77
    const void *pVal;
78
    int         vLen;
79
    if (tdbTbcGet(cursor, &pKey, &kLen, &pVal, &vLen) < 0) {
×
80
      break;
×
81
    }
82

83
    // decode entry
84
    SDecoder   dc = {0};
×
85
    SMetaEntry me = {0};
×
86

87
    tDecoderInit(&dc, (uint8_t *)pVal, vLen);
×
88

89
    if (metaDecodeEntry(&dc, &me) < 0) {
×
90
      tDecoderClear(&dc);
×
91
      break;
×
92
    }
93

94
    // skip deleted entry
95
    if (tdbTbGet(pMeta->pUidIdx, &me.uid, sizeof(me.uid), NULL, NULL) == 0) {
×
96
      // print entry
97
      char buf[1024] = {0};
×
98
      if (me.type == TSDB_SUPER_TABLE) {
×
99
        snprintf(buf, sizeof(buf) - 1, "type: super table, version:%" PRId64 " uid: %" PRId64 " name: %s\n", me.version,
×
100
                 me.uid, me.name);
101

102
      } else if (me.type == TSDB_CHILD_TABLE) {
×
103
        snprintf(buf, sizeof(buf) - 1,
×
104
                 "type: child table, version:%" PRId64 " uid: %" PRId64 " name: %s suid:%" PRId64 "\n", me.version,
105
                 me.uid, me.name, me.ctbEntry.suid);
106
      } else {
107
        snprintf(buf, sizeof(buf) - 1, "type: normal table, version:%" PRId64 " uid: %" PRId64 " name: %s\n",
×
108
                 me.version, me.uid, me.name);
109
      }
110

111
      if (taosWriteFile(fp, buf, strlen(buf)) < 0) {
×
112
        metaError("failed to write file:%s, reason:%s", path, tstrerror(terrno));
×
113
        tDecoderClear(&dc);
×
114
        break;
×
115
      }
116
    }
117

118
    tDecoderClear(&dc);
×
119

120
    if (tdbTbcMoveToNext(cursor) < 0) {
×
121
      break;
×
122
    }
123
  }
124

125
  tdbTbcClose(cursor);
×
126

127
  // close file
128
  if (taosFsyncFile(fp) < 0) {
×
129
    metaError("failed to fsync file:%s, reason:%s", path, tstrerror(terrno));
×
130
  }
131
  if (taosCloseFile(&fp) < 0) {
×
132
    metaError("failed to close file:%s, reason:%s", path, tstrerror(terrno));
×
133
  }
134
}
135

136
int32_t metaOpenImpl(SVnode *pVnode, SMeta **ppMeta, const char *metaDir, int8_t rollback) {
×
137
  SMeta  *pMeta = NULL;
×
138
  int32_t code = 0;
×
139
  int32_t lino;
140
  int32_t offset;
141
  int32_t pathLen = 0;
×
142
  char    path[TSDB_FILENAME_LEN] = {0};
×
143
  char    indexFullPath[128] = {0};
×
144

145
  // create handle
146
  vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN);
×
147
  offset = strlen(path);
×
148
  snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, metaDir);
×
149

150
  if (strncmp(metaDir, VNODE_META_TMP_DIR, strlen(VNODE_META_TMP_DIR)) == 0) {
×
151
    taosRemoveDir(path);
×
152
  }
153

154
  pathLen = strlen(path) + 1;
×
155
  if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + pathLen)) == NULL) {
×
156
    TSDB_CHECK_CODE(code = terrno, lino, _exit);
×
157
  }
158

159
  metaInitLock(pMeta);
×
160

161
  pMeta->path = (char *)&pMeta[1];
×
162
  tstrncpy(pMeta->path, path, pathLen);
×
163
  int32_t ret = taosRealPath(pMeta->path, NULL, strlen(path) + 1);
×
164

165
  pMeta->pVnode = pVnode;
×
166

167
  // create path if not created yet
168
  code = taosMkDir(pMeta->path);
×
169
  TSDB_CHECK_CODE(code, lino, _exit);
×
170

171
  // open env
172
  code = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv, rollback,
×
173
                 pVnode->config.tdbEncryptAlgorithm, pVnode->config.tdbEncryptKey);
×
174
  TSDB_CHECK_CODE(code, lino, _exit);
×
175

176
  // open pTbDb
177
  code = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb, 0);
×
178
  TSDB_CHECK_CODE(code, lino, _exit);
×
179

180
  // open pSkmDb
181
  code = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb, 0);
×
182
  TSDB_CHECK_CODE(code, lino, _exit);
×
183

184
  // open pUidIdx
185
  code = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(SUidIdxVal), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx, 0);
×
186
  TSDB_CHECK_CODE(code, lino, _exit);
×
187

188
  // open pNameIdx
189
  code = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx, 0);
×
190
  TSDB_CHECK_CODE(code, lino, _exit);
×
191

192
  // open pCtbIdx
193
  code = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), -1, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx, 0);
×
194
  TSDB_CHECK_CODE(code, lino, _exit);
×
195

196
  // open pSuidIdx
197
  code = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx, 0);
×
198
  TSDB_CHECK_CODE(code, lino, _exit);
×
199

200
  (void)tsnprintf(indexFullPath, sizeof(indexFullPath), "%s/%s", pMeta->path, "invert");
×
201
  ret = taosMkDir(indexFullPath);
×
202

203
  SIndexOpts opts = {.cacheSize = 8 * 1024 * 1024};
×
204
  code = indexOpen(&opts, indexFullPath, (SIndex **)&pMeta->pTagIvtIdx);
×
205
  TSDB_CHECK_CODE(code, lino, _exit);
×
206

207
  code = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx, 0);
×
208
  TSDB_CHECK_CODE(code, lino, _exit);
×
209

210
  // open pTtlMgr ("ttlv1.idx")
211
  char logPrefix[128] = {0};
×
212
  (void)tsnprintf(logPrefix, sizeof(logPrefix), "vgId:%d", TD_VID(pVnode));
×
213
  code = ttlMgrOpen(&pMeta->pTtlMgr, pMeta->pEnv, 0, logPrefix, tsTtlFlushThreshold);
×
214
  TSDB_CHECK_CODE(code, lino, _exit);
×
215

216
  // open pSmaIdx
217
  code = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx, 0);
×
218
  TSDB_CHECK_CODE(code, lino, _exit);
×
219

220
  // idx table create time
221
  code = tdbTbOpen("ctime.idx", sizeof(SBtimeIdxKey), 0, btimeIdxCmpr, pMeta->pEnv, &pMeta->pBtimeIdx, 0);
×
222
  TSDB_CHECK_CODE(code, lino, _exit);
×
223

224
  // idx num of col, normal table only
225
  code = tdbTbOpen("ncol.idx", sizeof(SNcolIdxKey), 0, ncolIdxCmpr, pMeta->pEnv, &pMeta->pNcolIdx, 0);
×
226
  TSDB_CHECK_CODE(code, lino, _exit);
×
227

228
  code = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb, 0);
×
229
  TSDB_CHECK_CODE(code, lino, _exit);
×
230

231
  code = metaCacheOpen(pMeta);
×
232
  TSDB_CHECK_CODE(code, lino, _exit);
×
233

234
  code = metaInitTbFilterCache(pMeta);
×
235
  TSDB_CHECK_CODE(code, lino, _exit);
×
236

237
#if 0
238
  // Do NOT remove this code, it is used to do debug stuff
239
  doScan(pMeta);
240
#endif
241

242
_exit:
×
243
  if (code) {
×
244
    metaError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code));
×
245
    metaCleanup(&pMeta);
×
246
    *ppMeta = NULL;
×
247
  } else {
248
    metaDebug("vgId:%d %s success", TD_VID(pVnode), __func__);
×
249
    *ppMeta = pMeta;
×
250
  }
251
  return code;
×
252
}
253

254
void vnodeGetMetaPath(SVnode *pVnode, const char *metaDir, char *fname) {
×
255
  vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, fname, TSDB_FILENAME_LEN);
×
256
  int32_t offset = strlen(fname);
×
257
  snprintf(fname + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, metaDir);
×
258
}
×
259

260
int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
×
261
  int32_t code = TSDB_CODE_SUCCESS;
×
262
  char    metaDir[TSDB_FILENAME_LEN] = {0};
×
263
  char    metaTempDir[TSDB_FILENAME_LEN] = {0};
×
264

265
  vnodeGetMetaPath(pVnode, VNODE_META_DIR, metaDir);
×
266
  vnodeGetMetaPath(pVnode, VNODE_META_TMP_DIR, metaTempDir);
×
267

268
  // Check file states
269
  if (!taosCheckExistFile(metaDir) && taosCheckExistFile(metaTempDir)) {
×
270
    code = taosRenameFile(metaTempDir, metaDir);
×
271
    if (code) {
×
272
      metaError("vgId:%d, %s failed at %s:%d since %s: rename %s to %s failed", TD_VID(pVnode), __func__, __FILE__,
×
273
                __LINE__, tstrerror(code), metaTempDir, metaDir);
274
      return code;
×
275
    }
276
  }
277

278
  // Do open meta
279
  code = metaOpenImpl(pVnode, ppMeta, VNODE_META_DIR, rollback);
×
280
  if (code) {
×
281
    metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code));
×
282
    return code;
×
283
  }
284

285
  return TSDB_CODE_SUCCESS;
×
286
}
287

288
int32_t metaUpgrade(SVnode *pVnode, SMeta **ppMeta) {
×
289
  int32_t code = TSDB_CODE_SUCCESS;
×
290
  int32_t lino;
291
  SMeta  *pMeta = *ppMeta;
×
292

293
  if (ttlMgrNeedUpgrade(pMeta->pEnv)) {
×
294
    code = metaBegin(pMeta, META_BEGIN_HEAP_OS);
×
295
    TSDB_CHECK_CODE(code, lino, _exit);
×
296

297
    code = ttlMgrUpgrade(pMeta->pTtlMgr, pMeta);
×
298
    TSDB_CHECK_CODE(code, lino, _exit);
×
299

300
    code = metaCommit(pMeta, pMeta->txn);
×
301
    TSDB_CHECK_CODE(code, lino, _exit);
×
302
  }
303

304
_exit:
×
305
  if (code) {
×
306
    metaError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, __LINE__, tstrerror(code));
×
307
    metaCleanup(ppMeta);
×
308
  }
309
  return code;
×
310
}
311

312
void metaClose(SMeta **ppMeta) {
×
313
  metaCleanup(ppMeta);
×
314
  return;
×
315
}
316

317
int metaAlterCache(SMeta *pMeta, int32_t nPage) {
×
318
  int32_t code = 0;
×
319
  metaWLock(pMeta);
×
320
  code = tdbAlter(pMeta->pEnv, nPage);
×
321
  metaULock(pMeta);
×
322

323
  if (code) {
×
324
    metaError("vgId:%d %s failed since %s", TD_VID(pMeta->pVnode), __func__, tstrerror(code));
×
325
  }
326
  return code;
×
327
}
328

329
void metaRLock(SMeta *pMeta) {
×
330
  metaTrace("meta rlock %p", &pMeta->lock);
×
331
  if (taosThreadRwlockRdlock(&pMeta->lock) != 0) {
×
332
    metaError("vgId:%d failed to lock %p", TD_VID(pMeta->pVnode), &pMeta->lock);
×
333
  }
334
}
×
335

336
void metaWLock(SMeta *pMeta) {
×
337
  metaTrace("meta wlock %p", &pMeta->lock);
×
338
  if (taosThreadRwlockWrlock(&pMeta->lock) != 0) {
×
339
    metaError("vgId:%d failed to lock %p", TD_VID(pMeta->pVnode), &pMeta->lock);
×
340
  }
341
}
×
342

343
void metaULock(SMeta *pMeta) {
×
344
  metaTrace("meta ulock %p", &pMeta->lock);
×
345
  if (taosThreadRwlockUnlock(&pMeta->lock) != 0) {
×
346
    metaError("vgId:%d failed to unlock %p", TD_VID(pMeta->pVnode), &pMeta->lock);
×
347
  }
348
}
×
349

350
static void metaCleanup(SMeta **ppMeta) {
×
351
  SMeta *pMeta = *ppMeta;
×
352
  if (pMeta) {
×
353
    metaInfo("vgId:%d meta clean up, path:%s", TD_VID(pMeta->pVnode), pMeta->path);
×
354
    if (pMeta->pEnv) metaAbort(pMeta);
×
355
    if (pMeta->pCache) metaCacheClose(pMeta);
×
356
#ifdef BUILD_NO_CALL
357
    if (pMeta->pIdx) metaCloseIdx(pMeta);
358
#endif
359
    if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
×
360
    if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
×
361
    if (pMeta->pBtimeIdx) tdbTbClose(pMeta->pBtimeIdx);
×
362
    if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
×
363
    if (pMeta->pTtlMgr) ttlMgrClose(pMeta->pTtlMgr);
×
364
    if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
×
365
    if (pMeta->pTagIdx) tdbTbClose(pMeta->pTagIdx);
×
366
    if (pMeta->pCtbIdx) tdbTbClose(pMeta->pCtbIdx);
×
367
    if (pMeta->pSuidIdx) tdbTbClose(pMeta->pSuidIdx);
×
368
    if (pMeta->pNameIdx) tdbTbClose(pMeta->pNameIdx);
×
369
    if (pMeta->pUidIdx) tdbTbClose(pMeta->pUidIdx);
×
370
    if (pMeta->pSkmDb) tdbTbClose(pMeta->pSkmDb);
×
371
    if (pMeta->pTbDb) tdbTbClose(pMeta->pTbDb);
×
372
    if (pMeta->pEnv) tdbClose(pMeta->pEnv);
×
373
    metaDestroyLock(pMeta);
×
374

375
    taosMemoryFreeClear(*ppMeta);
×
376
  }
377
}
×
378

379
static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
380
  STbDbKey *pTbDbKey1 = (STbDbKey *)pKey1;
×
381
  STbDbKey *pTbDbKey2 = (STbDbKey *)pKey2;
×
382

383
  if (pTbDbKey1->version > pTbDbKey2->version) {
×
384
    return 1;
×
385
  } else if (pTbDbKey1->version < pTbDbKey2->version) {
×
386
    return -1;
×
387
  }
388

389
  if (pTbDbKey1->uid > pTbDbKey2->uid) {
×
390
    return 1;
×
391
  } else if (pTbDbKey1->uid < pTbDbKey2->uid) {
×
392
    return -1;
×
393
  }
394

395
  return 0;
×
396
}
397

398
static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
399
  SSkmDbKey *pSkmDbKey1 = (SSkmDbKey *)pKey1;
×
400
  SSkmDbKey *pSkmDbKey2 = (SSkmDbKey *)pKey2;
×
401

402
  if (pSkmDbKey1->uid > pSkmDbKey2->uid) {
×
403
    return 1;
×
404
  } else if (pSkmDbKey1->uid < pSkmDbKey2->uid) {
×
405
    return -1;
×
406
  }
407

408
  if (pSkmDbKey1->sver > pSkmDbKey2->sver) {
×
409
    return 1;
×
410
  } else if (pSkmDbKey1->sver < pSkmDbKey2->sver) {
×
411
    return -1;
×
412
  }
413

414
  return 0;
×
415
}
416

417
static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
418
  tb_uid_t uid1 = *(tb_uid_t *)pKey1;
×
419
  tb_uid_t uid2 = *(tb_uid_t *)pKey2;
×
420

421
  if (uid1 > uid2) {
×
422
    return 1;
×
423
  } else if (uid1 < uid2) {
×
424
    return -1;
×
425
  }
426

427
  return 0;
×
428
}
429

430
static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
431
  SCtbIdxKey *pCtbIdxKey1 = (SCtbIdxKey *)pKey1;
×
432
  SCtbIdxKey *pCtbIdxKey2 = (SCtbIdxKey *)pKey2;
×
433

434
  if (pCtbIdxKey1->suid > pCtbIdxKey2->suid) {
×
435
    return 1;
×
436
  } else if (pCtbIdxKey1->suid < pCtbIdxKey2->suid) {
×
437
    return -1;
×
438
  }
439

440
  if (pCtbIdxKey1->uid > pCtbIdxKey2->uid) {
×
441
    return 1;
×
442
  } else if (pCtbIdxKey1->uid < pCtbIdxKey2->uid) {
×
443
    return -1;
×
444
  }
445

446
  return 0;
×
447
}
448

449
int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
450
  STagIdxKey *pTagIdxKey1 = (STagIdxKey *)pKey1;
×
451
  STagIdxKey *pTagIdxKey2 = (STagIdxKey *)pKey2;
×
452
  tb_uid_t    uid1 = 0, uid2 = 0;
×
453
  int         c;
454

455
  // compare suid
456
  if (pTagIdxKey1->suid > pTagIdxKey2->suid) {
×
457
    return 1;
×
458
  } else if (pTagIdxKey1->suid < pTagIdxKey2->suid) {
×
459
    return -1;
×
460
  }
461

462
  // compare column id
463
  if (pTagIdxKey1->cid > pTagIdxKey2->cid) {
×
464
    return 1;
×
465
  } else if (pTagIdxKey1->cid < pTagIdxKey2->cid) {
×
466
    return -1;
×
467
  }
468

469
  if (pTagIdxKey1->type != pTagIdxKey2->type) {
×
470
    metaError("meta/open: incorrect tag idx type.");
×
471
    return TSDB_CODE_FAILED;
×
472
  }
473

474
  // check NULL, NULL is always the smallest
475
  if (pTagIdxKey1->isNull && !pTagIdxKey2->isNull) {
×
476
    return -1;
×
477
  } else if (!pTagIdxKey1->isNull && pTagIdxKey2->isNull) {
×
478
    return 1;
×
479
  } else if (!pTagIdxKey1->isNull && !pTagIdxKey2->isNull) {
×
480
    // all not NULL, compr tag vals
481
    __compar_fn_t func = getComparFunc(pTagIdxKey1->type, 0);
×
482
    if (func == NULL) {
×
483
      metaError("meta/open: %s", terrstr());
×
484
      return TSDB_CODE_FAILED;
×
485
    }
486
    c = func(pTagIdxKey1->data, pTagIdxKey2->data);
×
487
    if (c) return c;
×
488
  }
489

490
  // both null or tag values are equal, then continue to compare uids
491
  if (IS_VAR_DATA_TYPE(pTagIdxKey1->type)) {
×
492
    uid1 = *(tb_uid_t *)(pTagIdxKey1->data + varDataTLen(pTagIdxKey1->data));
×
493
    uid2 = *(tb_uid_t *)(pTagIdxKey2->data + varDataTLen(pTagIdxKey2->data));
×
494
  } else {
495
    uid1 = *(tb_uid_t *)(pTagIdxKey1->data + tDataTypes[pTagIdxKey1->type].bytes);
×
496
    uid2 = *(tb_uid_t *)(pTagIdxKey2->data + tDataTypes[pTagIdxKey2->type].bytes);
×
497
  }
498

499
  // compare uid
500
  if (uid1 < uid2) {
×
501
    return -1;
×
502
  } else if (uid1 > uid2) {
×
503
    return 1;
×
504
  } else {
505
    return 0;
×
506
  }
507

508
  return 0;
509
}
510

511
static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
512
  SBtimeIdxKey *pBtimeIdxKey1 = (SBtimeIdxKey *)pKey1;
×
513
  SBtimeIdxKey *pBtimeIdxKey2 = (SBtimeIdxKey *)pKey2;
×
514
  if (pBtimeIdxKey1->btime > pBtimeIdxKey2->btime) {
×
515
    return 1;
×
516
  } else if (pBtimeIdxKey1->btime < pBtimeIdxKey2->btime) {
×
517
    return -1;
×
518
  }
519

520
  if (pBtimeIdxKey1->uid > pBtimeIdxKey2->uid) {
×
521
    return 1;
×
522
  } else if (pBtimeIdxKey1->uid < pBtimeIdxKey2->uid) {
×
523
    return -1;
×
524
  }
525

526
  return 0;
×
527
}
528

529
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
530
  SNcolIdxKey *pNcolIdxKey1 = (SNcolIdxKey *)pKey1;
×
531
  SNcolIdxKey *pNcolIdxKey2 = (SNcolIdxKey *)pKey2;
×
532

533
  if (pNcolIdxKey1->ncol > pNcolIdxKey2->ncol) {
×
534
    return 1;
×
535
  } else if (pNcolIdxKey1->ncol < pNcolIdxKey2->ncol) {
×
536
    return -1;
×
537
  }
538

539
  if (pNcolIdxKey1->uid > pNcolIdxKey2->uid) {
×
540
    return 1;
×
541
  } else if (pNcolIdxKey1->uid < pNcolIdxKey2->uid) {
×
542
    return -1;
×
543
  }
544

545
  return 0;
×
546
}
547

548
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
549
  SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1;
×
550
  SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2;
×
551

552
  if (pSmaIdxKey1->uid > pSmaIdxKey2->uid) {
×
553
    return 1;
×
554
  } else if (pSmaIdxKey1->uid < pSmaIdxKey2->uid) {
×
555
    return -1;
×
556
  }
557

558
  if (pSmaIdxKey1->smaUid > pSmaIdxKey2->smaUid) {
×
559
    return 1;
×
560
  } else if (pSmaIdxKey1->smaUid < pSmaIdxKey2->smaUid) {
×
561
    return -1;
×
562
  }
563

564
  return 0;
×
565
}
566

567
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
×
568
  int32_t uid1 = *(int32_t *)pKey1;
×
569
  int32_t uid2 = *(int32_t *)pKey2;
×
570

571
  if (uid1 > uid2) {
×
572
    return 1;
×
573
  } else if (uid1 < uid2) {
×
574
    return -1;
×
575
  }
576

577
  return 0;
×
578
}
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