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

taosdata / TDengine / #4908

30 Dec 2025 10:52AM UTC coverage: 65.386% (-0.2%) from 65.541%
#4908

push

travis-ci

web-flow
enh: drop multi-stream (#33962)

60 of 106 new or added lines in 4 files covered. (56.6%)

1330 existing lines in 113 files now uncovered.

193461 of 295877 relevant lines covered (65.39%)

115765274.47 hits per line

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

78.39
/source/util/src/tref.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 "tref.h"
18
#include "taoserror.h"
19
#include "tlog.h"
20
#include "tutil.h"
21

22
#define TSDB_REF_OBJECTS        2000
23
#define TSDB_REF_STATE_EMPTY    0
24
#define TSDB_REF_STATE_ACTIVE   1
25
#define TSDB_REF_STATE_DELETED  2
26
#define TSDB_REF_ITER_THRESHOLD 100
27

28
typedef struct SRefNode {
29
  struct SRefNode *prev;     // previous node
30
  struct SRefNode *next;     // next node
31
  void            *p;        // pointer to resource protected,
32
  int64_t          rid;      // reference ID
33
  int32_t          count;    // number of references
34
  int32_t          removed;  // 1: removed
35
} SRefNode;
36

37
typedef struct {
38
  SRefNode **nodeList;  // array of SRefNode linked list
39
  int32_t    state;     // 0: empty, 1: active;  2: deleted
40
  int32_t    rsetId;    // refSet ID, global unique
41
  int64_t    rid;       // increase by one for each new reference
42
  int32_t    max;       // mod
43
  int32_t    count;     // total number of SRefNodes in this set
44
  int64_t   *lockedBy;
45
  void (*fp)(void *);
46
} SRefSet;
47

48
static SRefSet       tsRefSetList[TSDB_REF_OBJECTS];
49
static TdThreadOnce  tsRefModuleInit = PTHREAD_ONCE_INIT;
50
static TdThreadMutex tsRefMutex;
51
static int32_t       tsRefSetNum = 0;
52
static int32_t       tsNextId = 0;
53

54
static void    taosInitRefModule(void);
55
static void    taosLockList(int64_t *lockedBy);
56
static void    taosUnlockList(int64_t *lockedBy);
57
static void    taosIncRsetCount(SRefSet *pSet);
58
static void    taosDecRsetCount(SRefSet *pSet);
59
static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t *isReleased);
60

61
int32_t taosOpenRef(int32_t max, RefFp fp) {
30,108,042✔
62
  SRefNode **nodeList;
63
  SRefSet   *pSet;
64
  int64_t   *lockedBy;
65
  int32_t    i, rsetId;
66

67
  (void)taosThreadOnce(&tsRefModuleInit, taosInitRefModule);
30,108,042✔
68

69
  nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max);
30,108,042✔
70
  if (nodeList == NULL) {
30,108,042✔
71
    return terrno;
×
72
  }
73

74
  lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max);
30,108,042✔
75
  if (lockedBy == NULL) {
30,108,042✔
76
    taosMemoryFree(nodeList);
×
77
    return terrno;
×
78
  }
79

80
  (void)taosThreadMutexLock(&tsRefMutex);
30,108,042✔
81

82
  for (i = 0; i < TSDB_REF_OBJECTS; ++i) {
30,108,042✔
83
    tsNextId = (tsNextId + 1) % TSDB_REF_OBJECTS;
30,108,042✔
84
    if (tsNextId == 0) tsNextId = 1;  // dont use 0 as rsetId
30,108,042✔
85
    if (tsRefSetList[tsNextId].state == TSDB_REF_STATE_EMPTY) break;
30,108,042✔
86
  }
87

88
  if (i < TSDB_REF_OBJECTS) {
30,108,042✔
89
    rsetId = tsNextId;
30,108,042✔
90
    pSet = tsRefSetList + rsetId;
30,108,042✔
91
    pSet->max = max;
30,108,042✔
92
    pSet->nodeList = nodeList;
30,108,042✔
93
    pSet->lockedBy = lockedBy;
30,108,042✔
94
    pSet->fp = fp;
30,108,042✔
95
    pSet->rid = 1;
30,108,042✔
96
    pSet->rsetId = rsetId;
30,108,042✔
97
    pSet->state = TSDB_REF_STATE_ACTIVE;
30,108,042✔
98
    taosIncRsetCount(pSet);
30,108,042✔
99

100
    tsRefSetNum++;
30,108,042✔
101
    uTrace("rsetId:%d, is opened, max:%d, fp:%p refSetNum:%d", rsetId, max, fp, tsRefSetNum);
30,108,042✔
102
  } else {
103
    rsetId = TSDB_CODE_REF_FULL;
×
104
    taosMemoryFree(nodeList);
×
105
    taosMemoryFree(lockedBy);
×
106
    uTrace("run out of Ref ID, maximum:%d refSetNum:%d", TSDB_REF_OBJECTS, tsRefSetNum);
×
107
  }
108

109
  (void)taosThreadMutexUnlock(&tsRefMutex);
30,108,042✔
110

111
  return rsetId;
30,108,042✔
112
}
113

114
void taosCloseRef(int32_t rsetId) {
27,273,792✔
115
  SRefSet *pSet;
116
  int32_t  deleted = 0;
27,273,792✔
117

118
  if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
27,273,792✔
119
    uTrace("rsetId:%d, is invalid, out of range", rsetId);
30✔
120
    return;
30✔
121
  }
122

123
  pSet = tsRefSetList + rsetId;
27,273,762✔
124

125
  (void)taosThreadMutexLock(&tsRefMutex);
27,273,762✔
126

127
  if (pSet->state == TSDB_REF_STATE_ACTIVE) {
27,273,762✔
128
    pSet->state = TSDB_REF_STATE_DELETED;
25,472,090✔
129
    deleted = 1;
25,472,090✔
130
    uTrace("rsetId:%d, is closed, count:%d", rsetId, pSet->count);
25,472,090✔
131
  } else {
132
    uTrace("rsetId:%d, is already closed, count:%d", rsetId, pSet->count);
1,801,672✔
133
  }
134

135
  (void)taosThreadMutexUnlock(&tsRefMutex);
27,273,762✔
136

137
  if (deleted) taosDecRsetCount(pSet);
27,273,762✔
138
}
139

140
int64_t taosAddRef(int32_t rsetId, void *p) {
2,147,483,647✔
141
  int32_t   hash;
142
  SRefNode *pNode;
143
  SRefSet  *pSet;
144
  int64_t   rid = 0;
2,147,483,647✔
145

146
  if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
2,147,483,647✔
147
    uTrace("p:%p, failed to add, rsetId not valid, rsetId:%d", p, rsetId);
×
148
    return terrno = TSDB_CODE_REF_INVALID_ID;
×
149
  }
150

151
  pSet = tsRefSetList + rsetId;
2,147,483,647✔
152
  taosIncRsetCount(pSet);
2,147,483,647✔
153
  if (pSet->state != TSDB_REF_STATE_ACTIVE) {
2,147,483,647✔
154
    taosDecRsetCount(pSet);
×
155
    uTrace("p:%p, failed to add, not active, rsetId:%d", p, rsetId);
×
156
    return terrno = TSDB_CODE_REF_ID_REMOVED;
×
157
  }
158

159
  pNode = taosMemoryCalloc(sizeof(SRefNode), 1);
2,147,483,647✔
160
  if (pNode == NULL) {
2,147,483,647✔
161
    taosDecRsetCount(pSet);
×
162
    uError("p:%p, failed to add, out of memory, rsetId:%d", p, rsetId);
×
163
    return terrno;
×
164
  }
165

166
  rid = atomic_add_fetch_64(&pSet->rid, 1);
2,147,483,647✔
167
  hash = rid % pSet->max;
2,147,483,647✔
168
  taosLockList(pSet->lockedBy + hash);
2,147,483,647✔
169

170
  pNode->p = p;
2,147,483,647✔
171
  pNode->rid = rid;
2,147,483,647✔
172
  pNode->count = 1;
2,147,483,647✔
173

174
  pNode->prev = NULL;
2,147,483,647✔
175
  pNode->next = pSet->nodeList[hash];
2,147,483,647✔
176
  if (pSet->nodeList[hash]) pSet->nodeList[hash]->prev = pNode;
2,147,483,647✔
177
  pSet->nodeList[hash] = pNode;
2,147,483,647✔
178

179
  uTrace("p:%p, rid:0x%" PRIx64 " is added, count:%d, remain count:%d rsetId:%d", p, rid, pSet->count, pNode->count,
2,147,483,647✔
180
         rsetId);
181

182
  taosUnlockList(pSet->lockedBy + hash);
2,147,483,647✔
183

184
  return rid;
2,147,483,647✔
185
}
186

187
int32_t taosRemoveRef(int32_t rsetId, int64_t rid) { return taosDecRefCount(rsetId, rid, 1, NULL); }
2,147,483,647✔
188

189
// if rid is 0, return the first p in hash list, otherwise, return the next after current rid
190
void *taosAcquireRef(int32_t rsetId, int64_t rid) {
2,147,483,647✔
191
  int32_t   hash;
192
  SRefNode *pNode;
193
  SRefSet  *pSet;
194
  int32_t   iter = 0;
2,147,483,647✔
195
  void     *p = NULL;
2,147,483,647✔
196

197
  if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
2,147,483,647✔
198
    // uTrace("rsetId:%d, rid:0x%" PRIx64 " failed to acquire, rsetId not valid", rsetId, rid);
199
    terrno = TSDB_CODE_REF_INVALID_ID;
×
200
    return NULL;
7,589✔
201
  }
202

203
  if (rid <= 0) {
2,147,483,647✔
204
    uTrace("rid:0x%" PRIx64 ", failed to acquire, rid not valid, rsetId:%d", rid, rsetId);
154,927,175✔
205
    terrno = TSDB_CODE_REF_NOT_EXIST;
154,927,175✔
206
    return NULL;
154,927,644✔
207
  }
208

209
  pSet = tsRefSetList + rsetId;
2,147,483,647✔
210
  taosIncRsetCount(pSet);
2,147,483,647✔
211
  if (pSet->state != TSDB_REF_STATE_ACTIVE) {
2,147,483,647✔
212
    uTrace("rid:0x%" PRIx64 ", failed to acquire, not active, rsetId:%d", rid, rsetId);
×
213
    taosDecRsetCount(pSet);
×
214
    terrno = TSDB_CODE_REF_ID_REMOVED;
×
215
    return NULL;
×
216
  }
217

218
  hash = rid % pSet->max;
2,147,483,647✔
219
  taosLockList(pSet->lockedBy + hash);
2,147,483,647✔
220

221
  pNode = pSet->nodeList[hash];
2,147,483,647✔
222

223
  while (pNode) {
2,147,483,647✔
224
    if (pNode->rid == rid) {
2,147,483,647✔
225
      break;
2,147,483,647✔
226
    }
227
    iter++;
40,371✔
228
    pNode = pNode->next;
40,371✔
229
  }
230
 
231
 if (iter >= TSDB_REF_ITER_THRESHOLD) {
2,147,483,647✔
232
    uWarn("rsetId:%d rid:%" PRId64 " iter:%d", rsetId, rid, iter);
×
233
  }
234

235
  if (pNode) {
2,147,483,647✔
236
    if (pNode->removed == 0) {
2,147,483,647✔
237
      pNode->count++;
2,147,483,647✔
238
      p = pNode->p;
2,147,483,647✔
239
      uTrace("p:%p, rid:0x%" PRIx64 " is acquired, remain count:%d, rsetId:%d", pNode->p, rid, pNode->count, rsetId);
2,147,483,647✔
240
    } else {
241
      terrno = TSDB_CODE_REF_NOT_EXIST;
4,086,677✔
242
      uTrace("p:%p, rid:0x%" PRIx64 " is already removed, failed to acquire, rsetId:%d", pNode->p, rid, rsetId);
4,087,668✔
243
    }
244
  } else {
245
    terrno = TSDB_CODE_REF_NOT_EXIST;
1,101,537,854✔
246
    uTrace("rid:0x%" PRIx64 ", is not there, failed to acquire, rsetId:%d", rid, rsetId);
1,101,536,683✔
247
  }
248

249
  taosUnlockList(pSet->lockedBy + hash);
2,147,483,647✔
250

251
  taosDecRsetCount(pSet);
2,147,483,647✔
252

253
  return p;
2,147,483,647✔
254
}
255

256
int32_t taosReleaseRef(int32_t rsetId, int64_t rid) { return taosDecRefCount(rsetId, rid, 0, NULL); }
2,147,483,647✔
257
int32_t taosReleaseRefEx(int32_t rsetId, int64_t rid, int32_t *isReleased) {
681,228,375✔
258
  return taosDecRefCount(rsetId, rid, 0, isReleased);
681,228,375✔
259
}
260

261
// if rid is 0, return the first p in hash list, otherwise, return the next after current rid
262
void *taosIterateRef(int32_t rsetId, int64_t rid) {
185,757,944✔
263
  SRefNode *pNode = NULL;
185,757,944✔
264
  SRefSet  *pSet;
265

266
  if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
185,757,944✔
267
    uTrace("rid:0x%" PRIx64 ", failed to iterate, rsetId not valid, rsetId:%d", rid, rsetId);
×
268
    terrno = TSDB_CODE_REF_INVALID_ID;
×
269
    return NULL;
×
270
  }
271

272
  if (rid < 0) {
185,757,944✔
273
    uTrace("rid:0x%" PRIx64 ", failed to iterate, rid not valid, rsetId:%d", rid, rsetId);
×
274
    terrno = TSDB_CODE_REF_NOT_EXIST;
×
275
    return NULL;
×
276
  }
277

278
  void *newP = NULL;
185,757,944✔
279
  pSet = tsRefSetList + rsetId;
185,757,944✔
280
  taosIncRsetCount(pSet);
185,757,944✔
281
  if (pSet->state != TSDB_REF_STATE_ACTIVE) {
185,757,944✔
282
    uTrace("rid:0x%" PRIx64 ", failed to iterate, rset not active, rsetId:%d", rid, rsetId);
×
283
    terrno = TSDB_CODE_REF_ID_REMOVED;
×
284
    taosDecRsetCount(pSet);
×
285
    return NULL;
×
286
  }
287

288
  do {
289
    newP = NULL;
185,757,944✔
290
    int32_t hash = 0;
185,757,944✔
291
    int32_t iter = 0;
185,757,944✔
292
    if (rid > 0) {
185,757,944✔
293
      hash = rid % pSet->max;
140,660,081✔
294
      taosLockList(pSet->lockedBy + hash);
140,660,081✔
295

296
      pNode = pSet->nodeList[hash];
140,660,081✔
297
      while (pNode) {
143,814,533✔
298
        if (pNode->rid == rid) break;
143,814,533✔
299
        pNode = pNode->next;
3,154,452✔
300
        iter++;
3,154,452✔
301
      }
302

303
      if (iter >= TSDB_REF_ITER_THRESHOLD) {
140,660,081✔
304
        uWarn("rid:0x%" PRIx64 ", iter:%d, rsetId:%d", rid, iter, rsetId);
×
305
      }
306

307
      if (pNode == NULL) {
140,660,081✔
308
        uError("rid:0x%" PRIx64 ", not there and quit, rsetId:%d", rid, rsetId);
×
309
        terrno = TSDB_CODE_REF_NOT_EXIST;
×
310
        taosUnlockList(pSet->lockedBy + hash);
×
311
        taosDecRsetCount(pSet);
×
312
        return NULL;
×
313
      }
314

315
      // rid is there
316
      pNode = pNode->next;
140,660,081✔
317
      // check first place
318
      while (pNode) {
140,660,081✔
319
        if (!pNode->removed) break;
2,950,868✔
320
        pNode = pNode->next;
×
321
      }
322
      if (pNode == NULL) {
140,660,081✔
323
        taosUnlockList(pSet->lockedBy + hash);
137,709,213✔
324
        hash++;
137,709,213✔
325
      }
326
    }
327

328
    if (pNode == NULL) {
185,757,944✔
329
      for (; hash < pSet->max; ++hash) {
2,147,483,647✔
330
        taosLockList(pSet->lockedBy + hash);
2,147,483,647✔
331
        pNode = pSet->nodeList[hash];
2,147,483,647✔
332
        if (pNode) {
2,147,483,647✔
333
          // check first place
334
          while (pNode) {
137,709,213✔
335
            if (!pNode->removed) break;
137,709,213✔
336
            pNode = pNode->next;
×
337
          }
338
          if (pNode) break;
137,709,213✔
339
        }
340
        taosUnlockList(pSet->lockedBy + hash);
2,147,483,647✔
341
      }
342
    }
343

344
    if (pNode) {
185,757,944✔
345
      pNode->count++;  // acquire it
140,660,081✔
346
      newP = pNode->p;
140,660,081✔
347
      taosUnlockList(pSet->lockedBy + hash);
140,660,081✔
348
      uTrace("p:%p, rid:0x%" PRIx64 " is returned, rsetId:%d", newP, rid, rsetId);
140,660,081✔
349
    } else {
350
      uTrace("rsetId:%d, the list is over", rsetId);
45,097,863✔
351
    }
352

353
    if (rid > 0) taosReleaseRef(rsetId, rid);  // release the current one
185,757,944✔
354
    if (pNode) rid = pNode->rid;
185,757,944✔
355
  } while (newP && pNode->removed);
185,757,944✔
356

357
  taosDecRsetCount(pSet);
185,757,944✔
358

359
  return newP;
185,757,944✔
360
}
361

362
int32_t taosListRef() {
×
363
  SRefSet  *pSet;
364
  SRefNode *pNode;
365
  int32_t   num = 0;
×
366

367
  (void)taosThreadMutexLock(&tsRefMutex);
×
368

369
  for (int32_t i = 0; i < TSDB_REF_OBJECTS; ++i) {
×
370
    pSet = tsRefSetList + i;
×
371

372
    if (pSet->state == TSDB_REF_STATE_EMPTY) continue;
×
373

374
    uInfo("rsetId:%d, state:%d count:%d", i, pSet->state, pSet->count);
×
375

376
    for (int32_t j = 0; j < pSet->max; ++j) {
×
377
      pNode = pSet->nodeList[j];
×
378

379
      while (pNode) {
×
380
        uInfo("p:%p, rid:0x%" PRIx64 " count:%d, rsetId:%d", pNode->p, pNode->rid, pNode->count, i);
×
381
        pNode = pNode->next;
×
382
        num++;
×
383
      }
384
    }
385
  }
386

387
  (void)taosThreadMutexUnlock(&tsRefMutex);
×
388

389
  return num;
×
390
}
391

392
static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t *isReleased) {
2,147,483,647✔
393
  int32_t   hash;
394
  SRefSet  *pSet;
395
  SRefNode *pNode;
396
  int32_t   iter = 0;
2,147,483,647✔
397
  int32_t   released = 0;
2,147,483,647✔
398
  int32_t   code = 0;
2,147,483,647✔
399

400
  if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
2,147,483,647✔
UNCOV
401
    uTrace("rid:0x%" PRIx64 ", failed to remove, rsetId not valid, rsetId:%d", rid, rsetId);
×
UNCOV
402
    return terrno = TSDB_CODE_REF_INVALID_ID;
×
403
  }
404

405
  if (rid <= 0) {
2,147,483,647✔
406
    uTrace("rid:0x%" PRIx64 ", failed to remove, rid not valid, rsetId:%d", rid, rsetId);
497,621,666✔
407
    return terrno = TSDB_CODE_REF_NOT_EXIST;
497,621,666✔
408
  }
409

410
  pSet = tsRefSetList + rsetId;
2,147,483,647✔
411
  if (pSet->state == TSDB_REF_STATE_EMPTY) {
2,147,483,647✔
412
    uTrace("rid:0x%" PRIx64 ", failed to remove, cleaned, rsetId:%d", rid, rsetId);
×
413
    return terrno = TSDB_CODE_REF_ID_REMOVED;
×
414
  }
415

416
  hash = rid % pSet->max;
2,147,483,647✔
417
  taosLockList(pSet->lockedBy + hash);
2,147,483,647✔
418

419
  pNode = pSet->nodeList[hash];
2,147,483,647✔
420
  while (pNode) {
2,147,483,647✔
421
    if (pNode->rid == rid) break;
2,147,483,647✔
422

423
    pNode = pNode->next;
3,245,290✔
424
    iter++;
3,245,290✔
425
  }
426

427
  if (iter >= TSDB_REF_ITER_THRESHOLD) {
2,147,483,647✔
428
    uWarn("rid:0x%" PRIx64 ", iter:%d, rsetId:%d", rid, iter, rsetId);
×
429
  }
430

431
  if (pNode) {
2,147,483,647✔
432
    pNode->count--;
2,147,483,647✔
433
    if (remove) pNode->removed = 1;
2,147,483,647✔
434

435
    if (pNode->count <= 0) {
2,147,483,647✔
436
      if (pNode->prev) {
2,147,483,647✔
437
        pNode->prev->next = pNode->next;
65,324✔
438
      } else {
439
        pSet->nodeList[hash] = pNode->next;
2,147,483,647✔
440
      }
441

442
      if (pNode->next) {
2,147,483,647✔
443
        pNode->next->prev = pNode->prev;
278,860✔
444
      }
445
      released = 1;
2,147,483,647✔
446
    } else {
447
      uTrace("p:%p, rid:0x%" PRIx64 " is released, remain count:%d, rsetId:%d", pNode->p, rid, pNode->count, rsetId);
2,147,483,647✔
448
    }
449
  } else {
450
    uTrace("rid:0x%" PRIx64 ", is not there, failed to release/remove, rsetId:%d", rid, rsetId);
898,680✔
451
    terrno = TSDB_CODE_REF_NOT_EXIST;
898,680✔
452
    code = terrno;
898,680✔
453
  }
454

455
  taosUnlockList(pSet->lockedBy + hash);
2,147,483,647✔
456

457
  if (released) {
2,147,483,647✔
458
    uTrace("p:%p, rid:0x%" PRIx64 " is removed, count:%d, free mem:%p, rsetId:%d", pNode->p, rid, pSet->count, pNode,
2,147,483,647✔
459
           rsetId);
460
    (*pSet->fp)(pNode->p);
2,147,483,647✔
461
    taosMemoryFree(pNode);
2,147,483,647✔
462

463
    taosDecRsetCount(pSet);
2,147,483,647✔
464
  }
465

466
  if (isReleased) {
2,147,483,647✔
467
    *isReleased = released;
681,243,691✔
468
  }
469

470
  return code;
2,147,483,647✔
471
}
472

473
static void taosLockList(int64_t *lockedBy) {
2,147,483,647✔
474
  int64_t tid = taosGetSelfPthreadId();
2,147,483,647✔
475
  int32_t i = 0;
2,147,483,647✔
476
  while (atomic_val_compare_exchange_64(lockedBy, 0, tid) != 0) {
2,147,483,647✔
477
    if (++i % 100 == 0) {
2,147,483,647✔
478
      (void)sched_yield();
158,170,246✔
479
    }
480

481
  }
482
}
2,147,483,647✔
483

484
static void taosUnlockList(int64_t *lockedBy) {
2,147,483,647✔
485
  int64_t tid = taosGetSelfPthreadId();
2,147,483,647✔
486
  (void)atomic_val_compare_exchange_64(lockedBy, tid, 0);
2,147,483,647✔
487
}
2,147,483,647✔
488

489
static void taosInitRefModule(void) { (void)taosThreadMutexInit(&tsRefMutex, NULL); }
2,301,237✔
490

491
static void taosIncRsetCount(SRefSet *pSet) {
2,147,483,647✔
492
  (void)atomic_add_fetch_32(&pSet->count, 1);
2,147,483,647✔
493
  // uTrace("rsetId:%d, inc count:%d", pSet->rsetId, count);
494
}
2,147,483,647✔
495

496
static void taosDecRsetCount(SRefSet *pSet) {
2,147,483,647✔
497
  int32_t count = atomic_sub_fetch_32(&pSet->count, 1);
2,147,483,647✔
498
  // uTrace("rsetId:%d, dec count:%d", pSet->rsetId, count);
499

500
  if (count > 0) return;
2,147,483,647✔
501

502
  (void)taosThreadMutexLock(&tsRefMutex);
25,271,745✔
503

504
  if (pSet->state != TSDB_REF_STATE_EMPTY) {
25,271,951✔
505
    pSet->state = TSDB_REF_STATE_EMPTY;
25,271,951✔
506
    pSet->max = 0;
25,271,951✔
507
    pSet->fp = NULL;
25,271,951✔
508

509
    taosMemoryFreeClear(pSet->nodeList);
25,271,951✔
510
    taosMemoryFreeClear(pSet->lockedBy);
25,271,951✔
511

512
    tsRefSetNum--;
25,271,951✔
513
    uTrace("rsetId:%d, is cleaned, refSetNum:%d count:%d", pSet->rsetId, tsRefSetNum, pSet->count);
25,271,951✔
514
  }
515

516
  (void)taosThreadMutexUnlock(&tsRefMutex);
25,271,951✔
517
}
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