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

taosdata / TDengine / #3720

26 Mar 2025 06:20AM UTC coverage: 30.242% (-31.7%) from 61.936%
#3720

push

travis-ci

web-flow
feat(taosBenchmark): supports decimal data type (#30456)

* feat: taosBenchmark supports decimal data type

* build: decimal script not use pytest.sh

* fix: fix typo for decimal script

* test: insertBasic.py debug

71234 of 313946 branches covered (22.69%)

Branch coverage included in aggregate %.

38 of 423 new or added lines in 8 files covered. (8.98%)

120240 existing lines in 447 files now uncovered.

118188 of 312400 relevant lines covered (37.83%)

1450220.33 hits per line

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

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

22
int64_t tsQueueMemoryAllowed = 0;
23
int64_t tsQueueMemoryUsed = 0;
24

25
int64_t tsApplyMemoryAllowed = 0;
26
int64_t tsApplyMemoryUsed = 0;
27
struct STaosQueue {
28
  STaosQnode   *head;
29
  STaosQnode   *tail;
30
  STaosQueue   *next;     // for queue set
31
  STaosQset    *qset;     // for queue set
32
  void         *ahandle;  // for queue set
33
  FItem         itemFp;
34
  FItems        itemsFp;
35
  int32_t       numOfItems;
36
  int64_t       memOfItems;
37
  int64_t       threadId;
38
  int64_t       memLimit;
39
  int64_t       itemLimit;
40
  TdThreadMutex mutex;
41
};
42

43
struct STaosQset {
44
  STaosQueue   *head;
45
  STaosQueue   *current;
46
  TdThreadMutex mutex;
47
  tsem_t        sem;
48
  int32_t       numOfQueues;
49
  int32_t       numOfItems;
50
};
51

52
struct STaosQall {
53
  STaosQnode *current;
54
  STaosQnode *start;
55
  int32_t     numOfItems;
56
  int64_t     memOfItems;
57
  int32_t     unAccessedNumOfItems;
58
  int64_t     unAccessMemOfItems;
59
};
60

UNCOV
61
void taosSetQueueMemoryCapacity(STaosQueue *queue, int64_t cap) { queue->memLimit = cap; }
×
UNCOV
62
void taosSetQueueCapacity(STaosQueue *queue, int64_t size) { queue->itemLimit = size; }
×
63

64
int32_t taosOpenQueue(STaosQueue **queue) {
28,114✔
65
  *queue = taosMemoryCalloc(1, sizeof(STaosQueue));
28,114!
66
  if (*queue == NULL) {
28,116!
67
    return terrno;
×
68
  }
69

70
  int32_t code = taosThreadMutexInit(&(*queue)->mutex, NULL);
28,116✔
71
  if (code) {
28,113!
72
    taosMemoryFreeClear(*queue);
×
73
    return (terrno = TAOS_SYSTEM_ERROR(code));
×
74
  }
75

76
  uDebug("queue:%p is opened", queue);
28,113✔
77
  return 0;
28,123✔
78
}
79

80
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp) {
4,722✔
81
  if (queue == NULL) return;
4,722!
82
  queue->itemFp = itemFp;
4,722✔
83
  queue->itemsFp = itemsFp;
4,722✔
84
}
85

86
void taosCloseQueue(STaosQueue *queue) {
28,010✔
87
  if (queue == NULL) return;
28,010!
88
  STaosQnode *pTemp;
89
  STaosQset  *qset;
90

91
  (void)taosThreadMutexLock(&queue->mutex);
28,010✔
92
  STaosQnode *pNode = queue->head;
28,011✔
93
  queue->head = NULL;
28,011✔
94
  qset = queue->qset;
28,011✔
95
  (void)taosThreadMutexUnlock(&queue->mutex);
28,011✔
96

97
  if (queue->qset) {
28,010✔
98
    taosRemoveFromQset(qset, queue);
2,646✔
99
  }
100

101
  while (pNode) {
28,018✔
102
    pTemp = pNode;
8✔
103
    pNode = pNode->next;
8✔
104
    taosMemoryFree(pTemp);
8!
105
  }
106

107
  (void)taosThreadMutexDestroy(&queue->mutex);
28,010✔
108
  taosMemoryFree(queue);
28,010!
109

110
  uDebug("queue:%p is closed", queue);
28,009✔
111
}
112

113
bool taosQueueEmpty(STaosQueue *queue) {
53,908✔
114
  if (queue == NULL) return true;
53,908!
115

116
  bool empty = false;
53,908✔
117
  (void)taosThreadMutexLock(&queue->mutex);
53,908✔
118
  if (queue->head == NULL && queue->tail == NULL && queue->numOfItems == 0 /*&& queue->memOfItems == 0*/) {
53,910!
119
    empty = true;
32,848✔
120
  }
121
  (void)taosThreadMutexUnlock(&queue->mutex);
53,910✔
122

123
  return empty;
53,910✔
124
}
125

126
void taosUpdateItemSize(STaosQueue *queue, int32_t items) {
9,704,951✔
127
  if (queue == NULL) return;
9,704,951!
128

129
  (void)taosThreadMutexLock(&queue->mutex);
9,704,951✔
130
  queue->numOfItems -= items;
9,715,438✔
131
  (void)taosThreadMutexUnlock(&queue->mutex);
9,715,438✔
132
}
133

134
int32_t taosQueueItemSize(STaosQueue *queue) {
48,789✔
135
  if (queue == NULL) return 0;
48,789!
136

137
  (void)taosThreadMutexLock(&queue->mutex);
48,789✔
138
  int32_t numOfItems = queue->numOfItems;
48,790✔
139
  (void)taosThreadMutexUnlock(&queue->mutex);
48,790✔
140

141
  uTrace("queue:%p, numOfItems:%d memOfItems:%" PRId64, queue, queue->numOfItems, queue->memOfItems);
48,790!
142
  return numOfItems;
48,790✔
143
}
144

UNCOV
145
int64_t taosQueueMemorySize(STaosQueue *queue) {
×
UNCOV
146
  (void)taosThreadMutexLock(&queue->mutex);
×
UNCOV
147
  int64_t memOfItems = queue->memOfItems;
×
UNCOV
148
  (void)taosThreadMutexUnlock(&queue->mutex);
×
UNCOV
149
  return memOfItems;
×
150
}
151

152
int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item) {
10,990,423✔
153
  int64_t alloced = -1;
10,990,423✔
154

155
  if (itype == RPC_QITEM) {
10,990,423✔
156
    alloced = atomic_add_fetch_64(&tsQueueMemoryUsed, size + dataSize);
3,213,091✔
157
    if (alloced > tsQueueMemoryAllowed) {
3,218,868!
158
      uError("failed to alloc qitem, size:%" PRId64 " alloc:%" PRId64 " allowed:%" PRId64, size + dataSize, alloced,
×
159
             tsQueueMemoryAllowed);
160
      (void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize);
×
161
      return (terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE);
×
162
    }
163
  } else if (itype == APPLY_QITEM) {
7,777,332✔
164
    alloced = atomic_add_fetch_64(&tsApplyMemoryUsed, size + dataSize);
12,632✔
165
    if (alloced > tsApplyMemoryAllowed) {
12,632!
166
      uDebug("failed to alloc qitem, size:%" PRId64 " alloc:%" PRId64 " allowed:%" PRId64, size + dataSize, alloced,
×
167
             tsApplyMemoryAllowed);
168
      (void)atomic_sub_fetch_64(&tsApplyMemoryUsed, size + dataSize);
×
169
      return (terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE);
×
170
    }
171
  }
172

173
  *item = NULL;
10,996,200✔
174
  STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size);
10,996,200!
175
  if (pNode == NULL) {
10,991,968!
176
    if (itype == RPC_QITEM) {
×
177
      (void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize);
×
178
    } else if (itype == APPLY_QITEM) {
×
179
      (void)atomic_sub_fetch_64(&tsApplyMemoryUsed, size + dataSize);
×
180
    }
181
    return terrno;
×
182
  }
183

184
  pNode->dataSize = dataSize;
10,991,968✔
185
  pNode->size = size;
10,991,968✔
186
  pNode->itype = itype;
10,991,968✔
187
  pNode->timestamp = taosGetTimestampUs();
10,989,519✔
188
  uTrace("item:%p, node:%p is allocated, alloc:%" PRId64, pNode->item, pNode, alloced);
10,989,519!
189
  *item = pNode->item;
11,007,550✔
190
  return 0;
11,007,550✔
191
}
192

193
void taosFreeQitem(void *pItem) {
11,017,352✔
194
  if (pItem == NULL) return;
11,017,352!
195

196
  STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
11,017,352✔
197
  int64_t     alloced = -1;
11,017,352✔
198
  if (pNode->itype == RPC_QITEM) {
11,017,352✔
199
    alloced = atomic_sub_fetch_64(&tsQueueMemoryUsed, pNode->size + pNode->dataSize);
3,219,832✔
200
  } else if (pNode->itype == APPLY_QITEM) {
7,797,520✔
201
    alloced = atomic_sub_fetch_64(&tsApplyMemoryUsed, pNode->size + pNode->dataSize);
12,632✔
202
  }
203
  uTrace("item:%p, node:%p is freed, alloc:%" PRId64, pItem, pNode, alloced);
11,017,390!
204

205
  taosMemoryFree(pNode);
11,017,390✔
206
}
207

208
int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
10,984,704✔
209
  int32_t     code = 0;
10,984,704✔
210
  STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode));
10,984,704✔
211
  pNode->timestamp = taosGetTimestampUs();
11,002,538✔
212
  pNode->next = NULL;
11,002,538✔
213

214
  (void)taosThreadMutexLock(&queue->mutex);
11,002,538✔
215
  if (queue->memLimit > 0 && (queue->memOfItems + pNode->size + pNode->dataSize) > queue->memLimit) {
11,024,610!
216
    code = TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY;
×
217
    uError("item:%p, failed to put into queue:%p, queue mem limit:%" PRId64 ", reason:%s" PRId64, pItem, queue,
×
218
           queue->memLimit, tstrerror(code));
219

220
    (void)taosThreadMutexUnlock(&queue->mutex);
×
221
    return code;
×
222
  } else if (queue->itemLimit > 0 && queue->numOfItems + 1 > queue->itemLimit) {
11,024,610!
223
    code = TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY;
×
224
    uError("item:%p, failed to put into queue:%p, queue size limit:%" PRId64 ", reason:%s" PRId64, pItem, queue,
×
225
           queue->itemLimit, tstrerror(code));
226
    (void)taosThreadMutexUnlock(&queue->mutex);
×
227
    return code;
×
228
  }
229

230
  if (queue->tail) {
11,024,610✔
231
    queue->tail->next = pNode;
2,783,378✔
232
    queue->tail = pNode;
2,783,378✔
233
  } else {
234
    queue->head = pNode;
8,241,232✔
235
    queue->tail = pNode;
8,241,232✔
236
  }
237
  queue->numOfItems++;
11,024,610✔
238
  queue->memOfItems += (pNode->size + pNode->dataSize);
11,024,610✔
239
  if (queue->qset) {
11,024,610✔
240
    (void)atomic_add_fetch_32(&queue->qset->numOfItems, 1);
11,003,351✔
241
  }
242

243
  uTrace("item:%p, is put into queue:%p, items:%d mem:%" PRId64, pItem, queue, queue->numOfItems, queue->memOfItems);
11,024,664!
244

245
  (void)taosThreadMutexUnlock(&queue->mutex);
11,024,664✔
246

247
  if (queue->qset) {
11,024,259✔
248
    if (tsem_post(&queue->qset->sem) != 0) {
11,003,175!
249
      uError("failed to post semaphore for queue set:%p", queue->qset);
×
250
    }
251
  }
252
  return code;
11,016,913✔
253
}
254

255
void taosReadQitem(STaosQueue *queue, void **ppItem) {
50,210✔
256
  STaosQnode *pNode = NULL;
50,210✔
257

258
  (void)taosThreadMutexLock(&queue->mutex);
50,210✔
259

260
  if (queue->head) {
50,210✔
261
    pNode = queue->head;
21,193✔
262
    *ppItem = pNode->item;
21,193✔
263
    queue->head = pNode->next;
21,193✔
264
    if (queue->head == NULL) {
21,193✔
265
      queue->tail = NULL;
18,255✔
266
    }
267
    queue->numOfItems--;
21,193✔
268
    queue->memOfItems -= (pNode->size + pNode->dataSize);
21,193✔
269
    if (queue->qset) {
21,193!
270
      (void)atomic_sub_fetch_32(&queue->qset->numOfItems, 1);
×
271
    }
272
    uTrace("item:%p, is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems,
21,193!
273
           queue->memOfItems);
274
  }
275

276
  (void)taosThreadMutexUnlock(&queue->mutex);
50,210✔
277
}
50,210✔
278

279
int32_t taosAllocateQall(STaosQall **qall) {
2,043✔
280
  *qall = taosMemoryCalloc(1, sizeof(STaosQall));
2,043!
281
  if (*qall == NULL) {
2,043!
282
    return terrno;
×
283
  }
284
  return 0;
2,043✔
285
}
286

287
void taosFreeQall(STaosQall *qall) { taosMemoryFree(qall); }
2,043!
288

UNCOV
289
int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
×
UNCOV
290
  int32_t numOfItems = 0;
×
291
  bool    empty;
292

UNCOV
293
  (void)taosThreadMutexLock(&queue->mutex);
×
294

UNCOV
295
  empty = queue->head == NULL;
×
UNCOV
296
  if (!empty) {
×
UNCOV
297
    memset(qall, 0, sizeof(STaosQall));
×
UNCOV
298
    qall->current = queue->head;
×
UNCOV
299
    qall->start = queue->head;
×
UNCOV
300
    qall->numOfItems = queue->numOfItems;
×
UNCOV
301
    qall->memOfItems = queue->memOfItems;
×
302

UNCOV
303
    qall->unAccessedNumOfItems = queue->numOfItems;
×
UNCOV
304
    qall->unAccessMemOfItems = queue->memOfItems;
×
305

UNCOV
306
    numOfItems = qall->numOfItems;
×
307

UNCOV
308
    queue->head = NULL;
×
UNCOV
309
    queue->tail = NULL;
×
UNCOV
310
    queue->numOfItems = 0;
×
UNCOV
311
    queue->memOfItems = 0;
×
UNCOV
312
    uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, numOfItems, queue, queue->numOfItems,
×
313
           queue->memOfItems);
UNCOV
314
    if (queue->qset) {
×
315
      (void)atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems);
×
316
    }
317
  }
318

UNCOV
319
  (void)taosThreadMutexUnlock(&queue->mutex);
×
320

321
  // if source queue is empty, we set destination qall to empty too.
UNCOV
322
  if (empty) {
×
UNCOV
323
    qall->current = NULL;
×
UNCOV
324
    qall->start = NULL;
×
UNCOV
325
    qall->numOfItems = 0;
×
326
  }
UNCOV
327
  return numOfItems;
×
328
}
329

330
int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
3,169,370✔
331
  STaosQnode *pNode;
332
  int32_t     num = 0;
3,169,370✔
333

334
  pNode = qall->current;
3,169,370✔
335
  if (pNode) qall->current = pNode->next;
3,169,370✔
336

337
  if (pNode) {
3,169,370✔
338
    *ppItem = pNode->item;
3,169,366✔
339
    num = 1;
3,169,366✔
340

341
    qall->unAccessedNumOfItems -= 1;
3,169,366✔
342
    qall->unAccessMemOfItems -= pNode->dataSize;
3,169,366✔
343

344
    uTrace("item:%p, is fetched", *ppItem);
3,169,366!
345
  } else {
346
    *ppItem = NULL;
4✔
347
  }
348

349
  return num;
3,169,355✔
350
}
351

352
int32_t taosOpenQset(STaosQset **qset) {
2,436✔
353
  *qset = taosMemoryCalloc(sizeof(STaosQset), 1);
2,436!
354
  if (*qset == NULL) {
2,436!
355
    return terrno;
×
356
  }
357

358
  (void)taosThreadMutexInit(&(*qset)->mutex, NULL);
2,436✔
359
  if (tsem_init(&(*qset)->sem, 0, 0) != 0) {
2,436!
360
    taosMemoryFree(*qset);
×
361
    return terrno;
×
362
  }
363

364
  uDebug("qset:%p, is opened", qset);
2,436✔
365
  return 0;
2,436✔
366
}
367

368
void taosCloseQset(STaosQset *qset) {
2,436✔
369
  if (qset == NULL) return;
2,436!
370

371
  // remove all the queues from qset
372
  (void)taosThreadMutexLock(&qset->mutex);
2,436✔
373
  while (qset->head) {
4,512✔
374
    STaosQueue *queue = qset->head;
2,076✔
375
    qset->head = qset->head->next;
2,076✔
376

377
    queue->qset = NULL;
2,076✔
378
    queue->next = NULL;
2,076✔
379
  }
380
  (void)taosThreadMutexUnlock(&qset->mutex);
2,436✔
381

382
  (void)taosThreadMutexDestroy(&qset->mutex);
2,436✔
383
  if (tsem_destroy(&qset->sem) != 0) {
2,436!
384
    uError("failed to destroy semaphore for qset:%p", qset);
×
385
  }
386
  taosMemoryFree(qset);
2,436!
387
  uDebug("qset:%p, is closed", qset);
2,436✔
388
}
389

390
// tsem_post 'qset->sem', so that reader threads waiting for it
391
// resumes execution and return, should only be used to signal the
392
// thread to exit.
393
void taosQsetThreadResume(STaosQset *qset) {
14,222✔
394
  uDebug("qset:%p, it will exit", qset);
14,222✔
395
  if (tsem_post(&qset->sem) != 0) {
14,222!
396
    uError("failed to post semaphore for qset:%p", qset);
×
397
  }
398
}
14,222✔
399

400
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) {
4,722✔
401
  if (queue->qset) return TSDB_CODE_INVALID_PARA;
4,722!
402

403
  (void)taosThreadMutexLock(&qset->mutex);
4,722✔
404

405
  queue->next = qset->head;
4,722✔
406
  queue->ahandle = ahandle;
4,722✔
407
  qset->head = queue;
4,722✔
408
  qset->numOfQueues++;
4,722✔
409

410
  (void)taosThreadMutexLock(&queue->mutex);
4,722✔
411
  (void)atomic_add_fetch_32(&qset->numOfItems, queue->numOfItems);
4,722✔
412
  queue->qset = qset;
4,722✔
413
  (void)taosThreadMutexUnlock(&queue->mutex);
4,722✔
414

415
  (void)taosThreadMutexUnlock(&qset->mutex);
4,722✔
416

417
  uTrace("queue:%p, is added into qset:%p", queue, qset);
4,722!
418
  return 0;
4,722✔
419
}
420

421
void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
2,646✔
422
  STaosQueue *tqueue = NULL;
2,646✔
423

424
  (void)taosThreadMutexLock(&qset->mutex);
2,646✔
425

426
  if (qset->head) {
2,646!
427
    if (qset->head == queue) {
2,646✔
428
      qset->head = qset->head->next;
2,515✔
429
      tqueue = queue;
2,515✔
430
    } else {
431
      STaosQueue *prev = qset->head;
131✔
432
      tqueue = qset->head->next;
131✔
433
      while (tqueue) {
310!
434
        if (tqueue == queue) {
310✔
435
          prev->next = tqueue->next;
131✔
436
          break;
131✔
437
        } else {
438
          prev = tqueue;
179✔
439
          tqueue = tqueue->next;
179✔
440
        }
441
      }
442
    }
443

444
    if (tqueue) {
2,646!
445
      if (qset->current == queue) qset->current = tqueue->next;
2,646✔
446
      qset->numOfQueues--;
2,646✔
447

448
      (void)taosThreadMutexLock(&queue->mutex);
2,646✔
449
      (void)atomic_sub_fetch_32(&qset->numOfItems, queue->numOfItems);
2,646✔
450
      queue->qset = NULL;
2,646✔
451
      queue->next = NULL;
2,646✔
452
      (void)taosThreadMutexUnlock(&queue->mutex);
2,646✔
453
    }
454
  }
455

456
  (void)taosThreadMutexUnlock(&qset->mutex);
2,646✔
457

458
  uDebug("queue:%p, is removed from qset:%p", queue, qset);
2,646✔
459
}
2,646✔
460

461
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) {
7,842,675✔
462
  STaosQnode *pNode = NULL;
7,842,675✔
463
  int32_t     code = 0;
7,842,675✔
464

465
  if (tsem_wait(&qset->sem) != 0) {
7,842,675!
466
    uError("failed to wait semaphore for qset:%p", qset);
×
467
  }
468

469
  (void)taosThreadMutexLock(&qset->mutex);
7,838,299✔
470

471
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
7,958,358✔
472
    if (qset->current == NULL) qset->current = qset->head;
7,946,193✔
473
    STaosQueue *queue = qset->current;
7,946,193✔
474
    if (queue) qset->current = queue->next;
7,946,193✔
475
    if (queue == NULL) break;
7,946,193!
476
    if (queue->head == NULL) continue;
7,946,193✔
477

478
    (void)taosThreadMutexLock(&queue->mutex);
7,834,033✔
479

480
    if (queue->head) {
7,834,033!
481
      pNode = queue->head;
7,834,033✔
482
      *ppItem = pNode->item;
7,834,033✔
483
      qinfo->ahandle = queue->ahandle;
7,834,033✔
484
      qinfo->fp = queue->itemFp;
7,834,033✔
485
      qinfo->queue = queue;
7,834,033✔
486
      qinfo->timestamp = pNode->timestamp;
7,834,033✔
487

488
      queue->head = pNode->next;
7,834,033✔
489
      if (queue->head == NULL) queue->tail = NULL;
7,834,033✔
490
      // queue->numOfItems--;
491
      queue->memOfItems -= (pNode->size + pNode->dataSize);
7,834,033✔
492
      (void)atomic_sub_fetch_32(&qset->numOfItems, 1);
7,834,033✔
493
      code = 1;
7,834,032✔
494
      uTrace("item:%p, is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems - 1,
7,834,032!
495
             queue->memOfItems);
496
    }
497

498
    (void)taosThreadMutexUnlock(&queue->mutex);
7,834,032✔
499
    if (pNode) break;
7,834,023!
500
  }
501

502
  (void)taosThreadMutexUnlock(&qset->mutex);
7,846,188✔
503

504
  return code;
7,845,891✔
505
}
506

507
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo *qinfo) {
1,883,448✔
508
  STaosQueue *queue;
509
  int32_t     code = 0;
1,883,448✔
510

511
  if (tsem_wait(&qset->sem) != 0) {
1,883,448!
512
    uError("failed to wait semaphore for qset:%p", qset);
×
513
  }
514
  (void)taosThreadMutexLock(&qset->mutex);
1,883,404✔
515

516
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
1,891,743✔
517
    if (qset->current == NULL) qset->current = qset->head;
1,889,701✔
518
    queue = qset->current;
1,889,701✔
519
    if (queue) qset->current = queue->next;
1,889,701✔
520
    if (queue == NULL) break;
1,889,701!
521
    if (queue->head == NULL) continue;
1,889,701✔
522

523
    (void)taosThreadMutexLock(&queue->mutex);
1,881,401✔
524

525
    if (queue->head) {
1,881,402!
526
      qall->current = queue->head;
1,881,402✔
527
      qall->start = queue->head;
1,881,402✔
528
      qall->numOfItems = queue->numOfItems;
1,881,402✔
529
      qall->memOfItems = queue->memOfItems;
1,881,402✔
530
      qall->unAccessedNumOfItems = queue->numOfItems;
1,881,402✔
531
      qall->unAccessMemOfItems = queue->memOfItems;
1,881,402✔
532

533
      code = qall->numOfItems;
1,881,402✔
534
      qinfo->ahandle = queue->ahandle;
1,881,402✔
535
      qinfo->fp = queue->itemsFp;
1,881,402✔
536
      qinfo->queue = queue;
1,881,402✔
537
      qinfo->timestamp = queue->head->timestamp;
1,881,402✔
538

539
      queue->head = NULL;
1,881,402✔
540
      queue->tail = NULL;
1,881,402✔
541
      // queue->numOfItems = 0;
542
      queue->memOfItems = 0;
1,881,402✔
543
      uTrace("read %d items from queue:%p, items:0 mem:%" PRId64, code, queue, queue->memOfItems);
1,881,402!
544

545
      (void)atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems);
1,881,402✔
546
      for (int32_t j = 1; j < qall->numOfItems; ++j) {
3,169,401✔
547
        if (tsem_wait(&qset->sem) != 0) {
1,287,997!
548
          uError("failed to wait semaphore for qset:%p", qset);
×
549
        }
550
      }
551
    }
552

553
    (void)taosThreadMutexUnlock(&queue->mutex);
1,881,404✔
554

555
    if (code != 0) break;
1,881,400!
556
  }
557

558
  (void)taosThreadMutexUnlock(&qset->mutex);
1,883,442✔
559
  return code;
1,883,447✔
560
}
561

UNCOV
562
int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; }
×
563
int64_t taosQallMemSize(STaosQall *qall) { return qall->memOfItems; }
×
564

UNCOV
565
int64_t taosQallUnAccessedItemSize(STaosQall *qall) { return qall->unAccessedNumOfItems; }
×
UNCOV
566
int64_t taosQallUnAccessedMemSize(STaosQall *qall) { return qall->unAccessMemOfItems; }
×
567

568
void    taosResetQitems(STaosQall *qall) { qall->current = qall->start; }
×
569
int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; }
882✔
570

571
void taosQueueSetThreadId(STaosQueue *pQueue, int64_t threadId) { pQueue->threadId = threadId; }
3,087✔
572

573
int64_t taosQueueGetThreadId(STaosQueue *pQueue) { return pQueue->threadId; }
5,292✔
574

575
#if 0
576

577
void taosResetQsetThread(STaosQset *qset, void *pItem) {
578
  if (pItem == NULL) return;
579
  STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
580

581
  (void)taosThreadMutexLock(&qset->mutex);
582
  for (int32_t i = 0; i < pNode->queue->numOfItems; ++i) {
583
    tsem_post(&qset->sem);
584
  }
585
  (void)taosThreadMutexUnlock(&qset->mutex);
586
}
587

588
#endif
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