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

taosdata / TDengine / #3844

10 Apr 2025 08:48AM UTC coverage: 43.852% (-19.2%) from 63.077%
#3844

push

travis-ci

web-flow
fix: the REPLICA parameter supports plural forms when used to create and alter a database (#30732)

104394 of 310659 branches covered (33.6%)

Branch coverage included in aggregate %.

167442 of 309240 relevant lines covered (54.15%)

3866624.94 hits per line

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

75.51
/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

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

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

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

76
  uDebug("queue:%p is opened", queue);
209,332✔
77
  return 0;
209,318✔
78
}
79

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

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

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

97
  if (queue->qset) {
178,050✔
98
    taosRemoveFromQset(qset, queue);
432✔
99
  }
100

101
  while (pNode) {
179,064✔
102
    pTemp = pNode;
1,014✔
103
    pNode = pNode->next;
1,014✔
104
    taosMemoryFree(pTemp);
1,014!
105
  }
106

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

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

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

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

123
  return empty;
342,170✔
124
}
125

126
void taosUpdateItemSize(STaosQueue *queue, int32_t items) {
26,263,874✔
127
  if (queue == NULL) return;
26,263,874!
128

129
  (void)taosThreadMutexLock(&queue->mutex);
26,263,874✔
130
  queue->numOfItems -= items;
26,268,518✔
131
  (void)taosThreadMutexUnlock(&queue->mutex);
26,268,518✔
132
}
133

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

137
  (void)taosThreadMutexLock(&queue->mutex);
24,232,080✔
138
  int32_t numOfItems = queue->numOfItems;
24,233,118✔
139
  (void)taosThreadMutexUnlock(&queue->mutex);
24,233,118✔
140

141
  uTrace("queue:%p, numOfItems:%d memOfItems:%" PRId64, queue, queue->numOfItems, queue->memOfItems);
24,233,194✔
142
  return numOfItems;
24,233,206✔
143
}
144

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

152
int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item) {
36,374,514✔
153
  int64_t alloced = -1;
36,374,514✔
154

155
  if (itype == RPC_QITEM) {
36,374,514✔
156
    alloced = atomic_add_fetch_64(&tsQueueMemoryUsed, size + dataSize);
15,200✔
157
    if (alloced > tsQueueMemoryAllowed) {
15,210!
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) {
36,359,314✔
164
    alloced = atomic_add_fetch_64(&tsApplyMemoryUsed, size + dataSize);
108✔
165
    if (alloced > tsApplyMemoryAllowed) {
108!
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;
36,374,524✔
174
  STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size);
36,374,524✔
175
  if (pNode == NULL) {
36,375,442!
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;
36,375,442✔
185
  pNode->size = size;
36,375,442✔
186
  pNode->itype = itype;
36,375,442✔
187
  pNode->timestamp = taosGetTimestampUs();
36,375,924✔
188
  uTrace("item:%p, node:%p is allocated, alloc:%" PRId64, pNode->item, pNode, alloced);
36,375,924✔
189
  *item = pNode->item;
36,374,086✔
190
  return 0;
36,374,086✔
191
}
192

193
void taosFreeQitem(void *pItem) {
36,373,702✔
194
  if (pItem == NULL) return;
36,373,702!
195

196
  STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
36,373,702✔
197
  int64_t     alloced = -1;
36,373,702✔
198
  if (pNode->itype == RPC_QITEM) {
36,373,702✔
199
    alloced = atomic_sub_fetch_64(&tsQueueMemoryUsed, pNode->size + pNode->dataSize);
15,216✔
200
  } else if (pNode->itype == APPLY_QITEM) {
36,358,486✔
201
    alloced = atomic_sub_fetch_64(&tsApplyMemoryUsed, pNode->size + pNode->dataSize);
108✔
202
  }
203
  uTrace("item:%p, node:%p is freed, alloc:%" PRId64, pItem, pNode, alloced);
36,373,702✔
204

205
  taosMemoryFree(pNode);
36,373,702!
206
}
207

208
int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
36,372,004✔
209
  int32_t     code = 0;
36,372,004✔
210
  STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode));
36,372,004✔
211
  pNode->timestamp = taosGetTimestampUs();
36,375,286✔
212
  pNode->next = NULL;
36,375,286✔
213

214
  (void)taosThreadMutexLock(&queue->mutex);
36,375,286✔
215
  if (queue->memLimit > 0 && (queue->memOfItems + pNode->size + pNode->dataSize) > queue->memLimit) {
36,377,652!
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) {
36,377,652!
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) {
36,377,652✔
231
    queue->tail->next = pNode;
5,443,384✔
232
    queue->tail = pNode;
5,443,384✔
233
  } else {
234
    queue->head = pNode;
30,934,268✔
235
    queue->tail = pNode;
30,934,268✔
236
  }
237
  queue->numOfItems++;
36,377,652✔
238
  queue->memOfItems += (pNode->size + pNode->dataSize);
36,377,652✔
239
  if (queue->qset) {
36,377,652✔
240
    (void)atomic_add_fetch_32(&queue->qset->numOfItems, 1);
26,271,770✔
241
  }
242

243
  uTrace("item:%p, is put into queue:%p, items:%d mem:%" PRId64, pItem, queue, queue->numOfItems, queue->memOfItems);
36,377,656✔
244

245
  (void)taosThreadMutexUnlock(&queue->mutex);
36,377,656✔
246

247
  if (queue->qset) {
36,377,954✔
248
    if (tsem_post(&queue->qset->sem) != 0) {
26,271,758!
249
      uError("failed to post semaphore for queue set:%p", queue->qset);
×
250
    }
251
  }
252
  return code;
36,376,368✔
253
}
254

255
void taosReadQitem(STaosQueue *queue, void **ppItem) {
28,847,706✔
256
  STaosQnode *pNode = NULL;
28,847,706✔
257

258
  (void)taosThreadMutexLock(&queue->mutex);
28,847,706✔
259

260
  if (queue->head) {
28,847,828✔
261
    pNode = queue->head;
10,102,816✔
262
    *ppItem = pNode->item;
10,102,816✔
263
    queue->head = pNode->next;
10,102,816✔
264
    if (queue->head == NULL) {
10,102,816✔
265
      queue->tail = NULL;
7,194,804✔
266
    }
267
    queue->numOfItems--;
10,102,816✔
268
    queue->memOfItems -= (pNode->size + pNode->dataSize);
10,102,816✔
269
    if (queue->qset) {
10,102,816!
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,
10,102,816✔
273
           queue->memOfItems);
274
  }
275

276
  (void)taosThreadMutexUnlock(&queue->mutex);
28,847,828✔
277
}
28,847,882✔
278

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

287
void taosFreeQall(STaosQall *qall) { taosMemoryFree(qall); }
534!
288

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

293
  (void)taosThreadMutexLock(&queue->mutex);
3,488✔
294

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

303
    qall->unAccessedNumOfItems = queue->numOfItems;
1,310✔
304
    qall->unAccessMemOfItems = queue->memOfItems;
1,310✔
305

306
    numOfItems = qall->numOfItems;
1,310✔
307

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

319
  (void)taosThreadMutexUnlock(&queue->mutex);
3,488✔
320

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

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

334
  pNode = qall->current;
18,496✔
335
  if (pNode) qall->current = pNode->next;
18,496✔
336

337
  if (pNode) {
18,496✔
338
    *ppItem = pNode->item;
12,126✔
339
    num = 1;
12,126✔
340

341
    qall->unAccessedNumOfItems -= 1;
12,126✔
342
    qall->unAccessMemOfItems -= pNode->dataSize;
12,126✔
343

344
    uTrace("item:%p, is fetched", *ppItem);
12,126!
345
  } else {
346
    *ppItem = NULL;
6,370✔
347
  }
348

349
  return num;
18,498✔
350
}
351

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

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

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

368
void taosCloseQset(STaosQset *qset) {
32,002✔
369
  if (qset == NULL) return;
32,002✔
370

371
  // remove all the queues from qset
372
  (void)taosThreadMutexLock(&qset->mutex);
32,000✔
373
  while (qset->head) {
63,844✔
374
    STaosQueue *queue = qset->head;
31,844✔
375
    qset->head = qset->head->next;
31,844✔
376

377
    queue->qset = NULL;
31,844✔
378
    queue->next = NULL;
31,844✔
379
  }
380
  (void)taosThreadMutexUnlock(&qset->mutex);
32,000✔
381

382
  (void)taosThreadMutexDestroy(&qset->mutex);
32,000✔
383
  if (tsem_destroy(&qset->sem) != 0) {
32,000!
384
    uError("failed to destroy semaphore for qset:%p", qset);
×
385
  }
386
  taosMemoryFree(qset);
32,000!
387
  uDebug("qset:%p, is closed", qset);
32,000✔
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) {
2,505,402✔
394
  uDebug("qset:%p, it will exit", qset);
2,505,402✔
395
  if (tsem_post(&qset->sem) != 0) {
2,505,402!
396
    uError("failed to post semaphore for qset:%p", qset);
×
397
  }
398
}
2,505,402✔
399

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

403
  (void)taosThreadMutexLock(&qset->mutex);
32,276✔
404

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

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

415
  (void)taosThreadMutexUnlock(&qset->mutex);
32,276✔
416

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

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

424
  (void)taosThreadMutexLock(&qset->mutex);
432✔
425

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

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

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

456
  (void)taosThreadMutexUnlock(&qset->mutex);
432✔
457

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

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

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

469
  (void)taosThreadMutexLock(&qset->mutex);
28,688,448✔
470

471
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
31,271,978✔
472
    if (qset->current == NULL) qset->current = qset->head;
28,767,360✔
473
    STaosQueue *queue = qset->current;
28,767,360✔
474
    if (queue) qset->current = queue->next;
28,767,360!
475
    if (queue == NULL) break;
28,767,360!
476
    if (queue->head == NULL) continue;
28,767,360✔
477

478
    (void)taosThreadMutexLock(&queue->mutex);
26,262,948✔
479

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

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

498
    (void)taosThreadMutexUnlock(&queue->mutex);
26,262,948✔
499
    if (pNode) break;
26,262,948!
500
  }
501

502
  (void)taosThreadMutexUnlock(&qset->mutex);
28,767,566✔
503

504
  return code;
28,763,876✔
505
}
506

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

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

516
  for (int32_t i = 0; i < qset->numOfQueues; ++i) {
6,272✔
517
    if (qset->current == NULL) qset->current = qset->head;
5,878✔
518
    queue = qset->current;
5,878✔
519
    if (queue) qset->current = queue->next;
5,878!
520
    if (queue == NULL) break;
5,878!
521
    if (queue->head == NULL) continue;
5,878✔
522

523
    (void)taosThreadMutexLock(&queue->mutex);
5,570✔
524

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

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

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

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

553
    (void)taosThreadMutexUnlock(&queue->mutex);
5,570✔
554

555
    if (code != 0) break;
5,568!
556
  }
557

558
  (void)taosThreadMutexUnlock(&qset->mutex);
5,962✔
559
  return code;
5,962✔
560
}
561

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

565
int64_t taosQallUnAccessedItemSize(STaosQall *qall) { return qall->unAccessedNumOfItems; }
1,038✔
566
int64_t taosQallUnAccessedMemSize(STaosQall *qall) { return qall->unAccessMemOfItems; }
260✔
567

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

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

573
int64_t taosQueueGetThreadId(STaosQueue *pQueue) { return pQueue->threadId; }
864✔
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