• 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/sdb/src/sdbHash.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 "sdb.h"
18

19
static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow);
20

UNCOV
21
const char *sdbTableName(ESdbType type) {
×
UNCOV
22
  switch (type) {
×
UNCOV
23
    case SDB_TRANS:
×
UNCOV
24
      return "trans";
×
UNCOV
25
    case SDB_CLUSTER:
×
UNCOV
26
      return "cluster";
×
UNCOV
27
    case SDB_MNODE:
×
UNCOV
28
      return "mnode";
×
UNCOV
29
    case SDB_QNODE:
×
UNCOV
30
      return "qnode";
×
UNCOV
31
    case SDB_SNODE:
×
UNCOV
32
      return "snode";
×
UNCOV
33
    case SDB_DNODE:
×
UNCOV
34
      return "dnode";
×
UNCOV
35
    case SDB_USER:
×
UNCOV
36
      return "user";
×
UNCOV
37
    case SDB_AUTH:
×
UNCOV
38
      return "auth";
×
UNCOV
39
    case SDB_ACCT:
×
UNCOV
40
      return "acct";
×
UNCOV
41
    case SDB_STREAM_CK:
×
UNCOV
42
      return "stream_ck";
×
UNCOV
43
    case SDB_STREAM:
×
UNCOV
44
      return "stream";
×
UNCOV
45
    case SDB_OFFSET:
×
UNCOV
46
      return "offset";
×
UNCOV
47
    case SDB_SUBSCRIBE:
×
UNCOV
48
      return "subscribe";
×
UNCOV
49
    case SDB_CONSUMER:
×
UNCOV
50
      return "consumer";
×
UNCOV
51
    case SDB_TOPIC:
×
UNCOV
52
      return "topic";
×
UNCOV
53
    case SDB_VGROUP:
×
UNCOV
54
      return "vgroup";
×
UNCOV
55
    case SDB_SMA:
×
UNCOV
56
      return "sma";
×
UNCOV
57
    case SDB_STB:
×
UNCOV
58
      return "stb";
×
UNCOV
59
    case SDB_DB:
×
UNCOV
60
      return "db";
×
UNCOV
61
    case SDB_FUNC:
×
UNCOV
62
      return "func";
×
UNCOV
63
    case SDB_IDX:
×
UNCOV
64
      return "idx";
×
UNCOV
65
    case SDB_VIEW:
×
UNCOV
66
      return "view";
×
UNCOV
67
    case SDB_STREAM_SEQ:
×
UNCOV
68
      return "stream_seq";
×
UNCOV
69
    case SDB_COMPACT:
×
UNCOV
70
      return "compact";
×
UNCOV
71
    case SDB_COMPACT_DETAIL:
×
UNCOV
72
      return "compact_detail";
×
UNCOV
73
    case SDB_GRANT:
×
UNCOV
74
      return "grant";
×
UNCOV
75
    case SDB_ARBGROUP:
×
UNCOV
76
      return "arb_group";
×
UNCOV
77
    case SDB_ANODE:
×
UNCOV
78
      return "anode";
×
UNCOV
79
    case SDB_CFG:
×
UNCOV
80
      return "config";
×
UNCOV
81
    default:
×
UNCOV
82
      return "undefine";
×
83
  }
84
}
85

UNCOV
86
const char *sdbStatusName(ESdbStatus status) {
×
UNCOV
87
  switch (status) {
×
UNCOV
88
    case SDB_STATUS_CREATING:
×
UNCOV
89
      return "creating";
×
UNCOV
90
    case SDB_STATUS_DROPPING:
×
UNCOV
91
      return "dropping";
×
UNCOV
92
    case SDB_STATUS_READY:
×
UNCOV
93
      return "ready";
×
UNCOV
94
    case SDB_STATUS_DROPPED:
×
UNCOV
95
      return "dropped";
×
UNCOV
96
    case SDB_STATUS_INIT:
×
UNCOV
97
      return "init";
×
UNCOV
98
    case SDB_STATUS_UPDATE:
×
UNCOV
99
      return "update";
×
UNCOV
100
    default:
×
UNCOV
101
      return "undefine";
×
102
  }
103
}
104

UNCOV
105
void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
×
106
#if 1
UNCOV
107
  EKeyType keyType = pSdb->keyTypes[pRow->type];
×
108

UNCOV
109
  if (keyType == SDB_KEY_BINARY) {
×
UNCOV
110
    mTrace("%s:%s, ref:%d oper:%s row:%p row->pObj:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj,
×
111
           pRow->refCount, oper, pRow, pRow->pObj, sdbStatusName(pRow->status));
UNCOV
112
  } else if (keyType == SDB_KEY_INT32) {
×
UNCOV
113
    mTrace("%s:%d, ref:%d oper:%s row:%p row->pObj:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj,
×
114
           pRow->refCount, oper, pRow, pRow->pObj, sdbStatusName(pRow->status));
UNCOV
115
  } else if (keyType == SDB_KEY_INT64) {
×
UNCOV
116
    mTrace("%s:%" PRId64 ", ref:%d oper:%s row:%p row->pObj:%p status:%s", sdbTableName(pRow->type),
×
117
           *(int64_t *)pRow->pObj, pRow->refCount, oper, pRow, pRow->pObj, sdbStatusName(pRow->status));
118
  } else {
119
  }
120
#endif
UNCOV
121
}
×
122

UNCOV
123
static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
×
UNCOV
124
  if (type >= SDB_MAX || type < 0) {
×
125
    terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
×
UNCOV
126
    return NULL;
×
127
  }
128

UNCOV
129
  SHashObj *hash = pSdb->hashObjs[type];
×
UNCOV
130
  if (hash == NULL) {
×
UNCOV
131
    terrno = TSDB_CODE_APP_ERROR;
×
UNCOV
132
    return NULL;
×
133
  }
134

UNCOV
135
  return hash;
×
136
}
137

UNCOV
138
static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, const void *pKey) {
×
UNCOV
139
  int32_t  keySize = 0;
×
UNCOV
140
  EKeyType keyType = pSdb->keyTypes[type];
×
141

UNCOV
142
  if (keyType == SDB_KEY_INT32) {
×
UNCOV
143
    keySize = sizeof(int32_t);
×
UNCOV
144
  } else if (keyType == SDB_KEY_BINARY) {
×
UNCOV
145
    keySize = strlen(pKey) + 1;
×
146
  } else {
UNCOV
147
    keySize = sizeof(int64_t);
×
148
  }
149

UNCOV
150
  return keySize;
×
151
}
152

UNCOV
153
static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
×
UNCOV
154
  int32_t type = pRow->type;
×
UNCOV
155
  sdbWriteLock(pSdb, type);
×
156

UNCOV
157
  SSdbRow *pOldRow = taosHashGet(hash, pRow->pObj, keySize);
×
UNCOV
158
  if (pOldRow != NULL) {
×
159
    sdbUnLock(pSdb, type);
×
160
    sdbFreeRow(pSdb, pRow, false);
×
161
    terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
×
162
    return terrno;
×
163
  }
164

UNCOV
165
  pRow->refCount = 0;
×
UNCOV
166
  pRow->status = pRaw->status;
×
UNCOV
167
  sdbPrintOper(pSdb, pRow, "insert");
×
168

UNCOV
169
  int32_t code = 0;
×
UNCOV
170
  if ((code = taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *))) != 0) {
×
171
    sdbUnLock(pSdb, type);
×
172
    sdbFreeRow(pSdb, pRow, false);
×
173
    return code;
×
174
  }
175

UNCOV
176
  SdbInsertFp insertFp = pSdb->insertFps[pRow->type];
×
UNCOV
177
  if (insertFp != NULL) {
×
UNCOV
178
    code = (*insertFp)(pSdb, pRow->pObj);
×
UNCOV
179
    if (code != 0) {
×
180
      if (taosHashRemove(hash, pRow->pObj, keySize) != 0) {
×
181
        mError("failed to remove row from hash");
×
182
      }
183
      sdbFreeRow(pSdb, pRow, false);
×
184
      sdbUnLock(pSdb, type);
×
185
      terrno = code;
×
186
      return terrno;
×
187
    }
188
  }
189

UNCOV
190
  sdbUnLock(pSdb, type);
×
191

UNCOV
192
  if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) {
×
UNCOV
193
    pSdb->maxId[pRow->type] = TMAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj));
×
194
  }
UNCOV
195
  if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT64) {
×
UNCOV
196
    pSdb->maxId[pRow->type] = TMAX(pSdb->maxId[pRow->type], *((int64_t *)pRow->pObj));
×
197
  }
UNCOV
198
  pSdb->tableVer[pRow->type]++;
×
199

UNCOV
200
  return 0;
×
201
}
202

UNCOV
203
static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) {
×
UNCOV
204
  int32_t type = pNewRow->type;
×
UNCOV
205
  sdbWriteLock(pSdb, type);
×
206

UNCOV
207
  SSdbRow **ppOldRow = taosHashGet(hash, pNewRow->pObj, keySize);
×
UNCOV
208
  if (ppOldRow == NULL || *ppOldRow == NULL) {
×
UNCOV
209
    sdbUnLock(pSdb, type);
×
UNCOV
210
    return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize);
×
211
  }
212

UNCOV
213
  SSdbRow *pOldRow = *ppOldRow;
×
UNCOV
214
  pOldRow->status = pRaw->status;
×
UNCOV
215
  sdbPrintOper(pSdb, pOldRow, "update");
×
216

UNCOV
217
  int32_t     code = 0;
×
UNCOV
218
  SdbUpdateFp updateFp = pSdb->updateFps[type];
×
UNCOV
219
  if (updateFp != NULL) {
×
UNCOV
220
    code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj);
×
221
  }
UNCOV
222
  sdbUnLock(pSdb, type);
×
223

224
  // sdbUnLock(pSdb, type);
UNCOV
225
  sdbFreeRow(pSdb, pNewRow, false);
×
226

UNCOV
227
  pSdb->tableVer[pOldRow->type]++;
×
UNCOV
228
  return code;
×
229
}
230

UNCOV
231
static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
×
UNCOV
232
  int32_t type = pRow->type;
×
UNCOV
233
  sdbWriteLock(pSdb, type);
×
234

UNCOV
235
  SSdbRow **ppOldRow = taosHashGet(hash, pRow->pObj, keySize);
×
UNCOV
236
  if (ppOldRow == NULL || *ppOldRow == NULL) {
×
UNCOV
237
    sdbUnLock(pSdb, type);
×
UNCOV
238
    sdbFreeRow(pSdb, pRow, false);
×
UNCOV
239
    terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
×
UNCOV
240
    return terrno;
×
241
  }
UNCOV
242
  SSdbRow *pOldRow = *ppOldRow;
×
UNCOV
243
  pOldRow->status = pRaw->status;
×
244

UNCOV
245
  (void)atomic_add_fetch_32(&pOldRow->refCount, 1);
×
UNCOV
246
  sdbPrintOper(pSdb, pOldRow, "delete");
×
247

UNCOV
248
  if (taosHashRemove(hash, pOldRow->pObj, keySize) != 0) {
×
249
    sdbUnLock(pSdb, type);
×
250
    sdbFreeRow(pSdb, pRow, false);
×
251
    terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
×
252
    return terrno;
×
253
  }
UNCOV
254
  pSdb->tableVer[pOldRow->type]++;
×
UNCOV
255
  sdbUnLock(pSdb, type);
×
256

UNCOV
257
  sdbFreeRow(pSdb, pRow, false);
×
258

UNCOV
259
  sdbCheckRow(pSdb, pOldRow);
×
UNCOV
260
  return 0;
×
261
}
262

UNCOV
263
int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) {
×
UNCOV
264
  if (pRaw->type == SDB_CFG) {
×
UNCOV
265
    mTrace("sdb write cfg");
×
266
  }
UNCOV
267
  SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
×
UNCOV
268
  if (hash == NULL) return terrno;
×
269

UNCOV
270
  SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type];
×
UNCOV
271
  SSdbRow    *pRow = (*decodeFp)(pRaw);
×
UNCOV
272
  if (pRow == NULL) return terrno;
×
273

UNCOV
274
  pRow->type = pRaw->type;
×
275

UNCOV
276
  int32_t keySize = sdbGetkeySize(pSdb, pRow->type, pRow->pObj);
×
UNCOV
277
  int32_t code = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
×
278

UNCOV
279
  switch (pRaw->status) {
×
UNCOV
280
    case SDB_STATUS_CREATING:
×
UNCOV
281
      code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
×
UNCOV
282
      break;
×
UNCOV
283
    case SDB_STATUS_READY:
×
284
    case SDB_STATUS_UPDATE:
285
    case SDB_STATUS_DROPPING:
UNCOV
286
      code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
×
UNCOV
287
      break;
×
UNCOV
288
    case SDB_STATUS_DROPPED:
×
UNCOV
289
      code = sdbDeleteRow(pSdb, hash, pRaw, pRow, keySize);
×
UNCOV
290
      break;
×
291
  }
292

UNCOV
293
  return code;
×
294
}
295

UNCOV
296
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
×
UNCOV
297
  int32_t code = sdbWriteWithoutFree(pSdb, pRaw);
×
UNCOV
298
  sdbFreeRaw(pRaw);
×
UNCOV
299
  return code;
×
300
}
301

UNCOV
302
void *sdbAcquireAll(SSdb *pSdb, ESdbType type, const void *pKey, bool onlyReady) {
×
UNCOV
303
  terrno = 0;
×
304

UNCOV
305
  SHashObj *hash = sdbGetHash(pSdb, type);
×
UNCOV
306
  if (hash == NULL) return NULL;
×
307

UNCOV
308
  void   *pRet = NULL;
×
UNCOV
309
  int32_t keySize = sdbGetkeySize(pSdb, type, pKey);
×
310

UNCOV
311
  sdbReadLock(pSdb, type);
×
312

UNCOV
313
  SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
×
UNCOV
314
  if (ppRow == NULL || *ppRow == NULL) {
×
UNCOV
315
    sdbUnLock(pSdb, type);
×
UNCOV
316
    terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
×
UNCOV
317
    return NULL;
×
318
  }
319

UNCOV
320
  SSdbRow *pRow = *ppRow;
×
UNCOV
321
  switch (pRow->status) {
×
UNCOV
322
    case SDB_STATUS_READY:
×
UNCOV
323
      (void)atomic_add_fetch_32(&pRow->refCount, 1);
×
UNCOV
324
      pRet = pRow->pObj;
×
UNCOV
325
      sdbPrintOper(pSdb, pRow, "acquire");
×
UNCOV
326
      break;
×
UNCOV
327
    case SDB_STATUS_CREATING:
×
UNCOV
328
      terrno = TSDB_CODE_SDB_OBJ_CREATING;
×
UNCOV
329
      break;
×
UNCOV
330
    case SDB_STATUS_DROPPING:
×
UNCOV
331
      terrno = TSDB_CODE_SDB_OBJ_DROPPING;
×
UNCOV
332
      break;
×
333
    default:
×
334
      terrno = TSDB_CODE_APP_ERROR;
×
UNCOV
335
      break;
×
336
  }
337

UNCOV
338
  if (pRet == NULL) {
×
UNCOV
339
    if (!onlyReady) {
×
340
      terrno = 0;
×
341
      (void)atomic_add_fetch_32(&pRow->refCount, 1);
×
342
      pRet = pRow->pObj;
×
343
      sdbPrintOper(pSdb, pRow, "acquire");
×
344
    }
345
  }
346

UNCOV
347
  sdbUnLock(pSdb, type);
×
UNCOV
348
  return pRet;
×
349
}
350

UNCOV
351
void *sdbAcquire(SSdb *pSdb, ESdbType type, const void *pKey) { return sdbAcquireAll(pSdb, type, pKey, true); }
×
UNCOV
352
void *sdbAcquireNotReadyObj(SSdb *pSdb, ESdbType type, const void *pKey) {
×
UNCOV
353
  return sdbAcquireAll(pSdb, type, pKey, false);
×
354
}
355

UNCOV
356
static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow) {
×
UNCOV
357
  int32_t type = pRow->type;
×
UNCOV
358
  sdbWriteLock(pSdb, type);
×
359

UNCOV
360
  int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
×
UNCOV
361
  sdbPrintOper(pSdb, pRow, "check");
×
UNCOV
362
  if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
×
UNCOV
363
    sdbFreeRow(pSdb, pRow, true);
×
364
  }
365

UNCOV
366
  sdbUnLock(pSdb, type);
×
UNCOV
367
}
×
368

UNCOV
369
void sdbReleaseLock(SSdb *pSdb, void *pObj, bool lock) {
×
UNCOV
370
  if (pObj == NULL) return;
×
371

UNCOV
372
  SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
×
UNCOV
373
  if (pRow->type >= SDB_MAX) return;
×
374

UNCOV
375
  int32_t type = pRow->type;
×
UNCOV
376
  if (lock) {
×
UNCOV
377
    sdbWriteLock(pSdb, type);
×
378
  }
379

UNCOV
380
  int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
×
UNCOV
381
  sdbPrintOper(pSdb, pRow, "release");
×
UNCOV
382
  if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
×
UNCOV
383
    sdbFreeRow(pSdb, pRow, true);
×
384
  }
385

UNCOV
386
  if (lock) {
×
UNCOV
387
    sdbUnLock(pSdb, type);
×
388
  }
389
}
390

UNCOV
391
void sdbRelease(SSdb *pSdb, void *pObj) { sdbReleaseLock(pSdb, pObj, true); }
×
392

UNCOV
393
void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
×
UNCOV
394
  *ppObj = NULL;
×
395

UNCOV
396
  SHashObj *hash = sdbGetHash(pSdb, type);
×
UNCOV
397
  if (hash == NULL) return NULL;
×
398

UNCOV
399
  sdbReadLock(pSdb, type);
×
400

UNCOV
401
  SSdbRow **ppRow = taosHashIterate(hash, pIter);
×
UNCOV
402
  while (ppRow != NULL) {
×
UNCOV
403
    SSdbRow *pRow = *ppRow;
×
UNCOV
404
    if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
×
UNCOV
405
      ppRow = taosHashIterate(hash, ppRow);
×
UNCOV
406
      continue;
×
407
    }
408

UNCOV
409
    (void)atomic_add_fetch_32(&pRow->refCount, 1);
×
UNCOV
410
    sdbPrintOper(pSdb, pRow, "fetch");
×
UNCOV
411
    *ppObj = pRow->pObj;
×
UNCOV
412
    break;
×
413
  }
UNCOV
414
  sdbUnLock(pSdb, type);
×
415

UNCOV
416
  return ppRow;
×
417
}
418

UNCOV
419
void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock) {
×
UNCOV
420
  *ppObj = NULL;
×
421

UNCOV
422
  SHashObj *hash = sdbGetHash(pSdb, type);
×
UNCOV
423
  if (hash == NULL) return NULL;
×
424

UNCOV
425
  if (lock) {
×
UNCOV
426
    sdbReadLock(pSdb, type);
×
427
  }
428

UNCOV
429
  SSdbRow **ppRow = taosHashIterate(hash, pIter);
×
UNCOV
430
  while (ppRow != NULL) {
×
UNCOV
431
    SSdbRow *pRow = *ppRow;
×
UNCOV
432
    if (pRow == NULL) {
×
433
      ppRow = taosHashIterate(hash, ppRow);
×
434
      continue;
×
435
    }
436

UNCOV
437
    (void)atomic_add_fetch_32(&pRow->refCount, 1);
×
UNCOV
438
    sdbPrintOper(pSdb, pRow, "fetch");
×
UNCOV
439
    *ppObj = pRow->pObj;
×
UNCOV
440
    *status = pRow->status;
×
UNCOV
441
    break;
×
442
  }
UNCOV
443
  if (lock) {
×
UNCOV
444
    sdbUnLock(pSdb, type);
×
445
  }
446

UNCOV
447
  return ppRow;
×
448
}
449

UNCOV
450
void sdbCancelFetch(SSdb *pSdb, void *pIter) {
×
UNCOV
451
  if (pIter == NULL) return;
×
UNCOV
452
  SSdbRow *pRow = *(SSdbRow **)pIter;
×
UNCOV
453
  mTrace("cancel fetch row:%p", pRow);
×
UNCOV
454
  SHashObj *hash = sdbGetHash(pSdb, pRow->type);
×
UNCOV
455
  if (hash == NULL) return;
×
456

UNCOV
457
  int32_t type = pRow->type;
×
UNCOV
458
  sdbReadLock(pSdb, type);
×
UNCOV
459
  taosHashCancelIterate(hash, pIter);
×
UNCOV
460
  sdbUnLock(pSdb, type);
×
461
}
462

463
void sdbCancelFetchByType(SSdb *pSdb, void *pIter, ESdbType type) {
×
464
  if (pIter == NULL) return;
×
465
  if (type >= SDB_MAX || type < 0) return;
×
466
  SHashObj *hash = sdbGetHash(pSdb, type);
×
467
  if (hash == NULL) return;
×
468

469
  sdbReadLock(pSdb, type);
×
470
  taosHashCancelIterate(hash, pIter);
×
471
  sdbUnLock(pSdb, type);
×
472
}
473

UNCOV
474
void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2, void *p3) {
×
UNCOV
475
  SHashObj *hash = sdbGetHash(pSdb, type);
×
UNCOV
476
  if (hash == NULL) return;
×
477

UNCOV
478
  sdbReadLock(pSdb, type);
×
479

UNCOV
480
  SSdbRow **ppRow = taosHashIterate(hash, NULL);
×
UNCOV
481
  while (ppRow != NULL) {
×
UNCOV
482
    SSdbRow *pRow = *ppRow;
×
UNCOV
483
    if (pRow->status == SDB_STATUS_READY) {
×
UNCOV
484
      bool isContinue = (*fp)(pSdb->pMnode, pRow->pObj, p1, p2, p3);
×
UNCOV
485
      if (!isContinue) {
×
UNCOV
486
        taosHashCancelIterate(hash, ppRow);
×
UNCOV
487
        break;
×
488
      }
489
    }
490

UNCOV
491
    ppRow = taosHashIterate(hash, ppRow);
×
492
  }
493

UNCOV
494
  sdbUnLock(pSdb, type);
×
495
}
496

UNCOV
497
int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
×
UNCOV
498
  SHashObj *hash = sdbGetHash(pSdb, type);
×
UNCOV
499
  if (hash == NULL) return 0;
×
500

UNCOV
501
  sdbReadLock(pSdb, type);
×
UNCOV
502
  int32_t size = taosHashGetSize(hash);
×
UNCOV
503
  sdbUnLock(pSdb, type);
×
504

UNCOV
505
  return size;
×
506
}
507

UNCOV
508
int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type) {
×
UNCOV
509
  SHashObj *hash = sdbGetHash(pSdb, type);
×
UNCOV
510
  if (hash == NULL) return -1;
×
511

UNCOV
512
  if (pSdb->keyTypes[type] != SDB_KEY_INT32) return -1;
×
513

UNCOV
514
  int32_t maxId = 0;
×
UNCOV
515
  sdbReadLock(pSdb, type);
×
516

UNCOV
517
  SSdbRow **ppRow = taosHashIterate(hash, NULL);
×
UNCOV
518
  while (ppRow != NULL) {
×
UNCOV
519
    SSdbRow *pRow = *ppRow;
×
UNCOV
520
    int32_t  id = *(int32_t *)pRow->pObj;
×
UNCOV
521
    maxId = TMAX(id, maxId);
×
UNCOV
522
    ppRow = taosHashIterate(hash, ppRow);
×
523
  }
524

UNCOV
525
  sdbUnLock(pSdb, type);
×
UNCOV
526
  maxId = TMAX(maxId, pSdb->maxId[type]);
×
UNCOV
527
  return maxId + 1;
×
528
}
529

UNCOV
530
int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type) {
×
UNCOV
531
  if (type >= SDB_MAX || type < 0) {
×
UNCOV
532
    terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
×
UNCOV
533
    return -1;
×
534
  }
535

UNCOV
536
  return pSdb->tableVer[type];
×
537
}
538

539
bool countValid(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
×
540
  int32_t *pInt = p1;
×
541
  (*pInt) += 1;
×
542
  return true;
×
543
}
544

545
int32_t sdbGetValidSize(SSdb *pSdb, ESdbType type) {
×
546
  int32_t num = 0;
×
547
  sdbTraverse(pSdb, type, countValid, &num, 0, 0);
×
548
  return num;
×
549
}
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