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

taosdata / TDengine / #3543

29 Nov 2024 02:58AM UTC coverage: 60.842% (+0.02%) from 60.819%
#3543

push

travis-ci

web-flow
Merge pull request #28973 from taosdata/merge/mainto3.0

merge: from main to 3.0

120460 of 253224 branches covered (47.57%)

Branch coverage included in aggregate %.

706 of 908 new or added lines in 18 files covered. (77.75%)

2401 existing lines in 137 files now uncovered.

201633 of 276172 relevant lines covered (73.01%)

19045673.23 hits per line

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

56.16
/source/libs/executor/src/dataDispatcher.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 "dataSinkInt.h"
17
#include "dataSinkMgt.h"
18
#include "executorInt.h"
19
#include "planner.h"
20
#include "tcompression.h"
21
#include "tdatablock.h"
22
#include "tglobal.h"
23
#include "tqueue.h"
24

25
extern SDataSinkStat gDataSinkStat;
26

27
typedef struct SDataDispatchBuf {
28
  int32_t useSize;
29
  int32_t allocSize;
30
  char*   pData;
31
} SDataDispatchBuf;
32

33
typedef struct SDataCacheEntry {
34
  int32_t rawLen;
35
  int32_t dataLen;
36
  int32_t numOfRows;
37
  int32_t numOfCols;
38
  int8_t  compressed;
39
  char    data[];
40
} SDataCacheEntry;
41

42
typedef struct SDataDispatchHandle {
43
  SDataSinkHandle     sink;
44
  SDataSinkManager*   pManager;
45
  SDataBlockDescNode* pSchema;
46
  STaosQueue*         pDataBlocks;
47
  SDataDispatchBuf    nextOutput;
48
  int32_t             outPutColCounts;
49
  int32_t             status;
50
  bool                queryEnd;
51
  uint64_t            useconds;
52
  uint64_t            cachedSize;
53
  void*               pCompressBuf;
54
  int32_t             bufSize;
55
  TdThreadMutex       mutex;
56
} SDataDispatchHandle;
57

58
static int32_t inputSafetyCheck(SDataDispatchHandle* pHandle, const SInputData* pInput)  {
22,037,266✔
59
  if(tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) {
22,037,266!
60
    return TSDB_CODE_SUCCESS;
×
61
  }
62
  if (pInput == NULL || pInput->pData == NULL || pInput->pData->info.rows <= 0) {
22,037,266!
63
    qError("invalid input data");
×
64
    return TSDB_CODE_QRY_INVALID_INPUT;
×
65
  }
66
  SDataBlockDescNode* pSchema = pHandle->pSchema;
22,037,766✔
67
  if (pSchema == NULL || pSchema->totalRowSize != pInput->pData->info.rowSize) {
22,037,766!
UNCOV
68
    qError("invalid schema");
×
69
    return TSDB_CODE_QRY_INVALID_INPUT;
×
70
  }
71

72
  if (pHandle->outPutColCounts > taosArrayGetSize(pInput->pData->pDataBlock)) {
22,038,088✔
73
    qError("invalid column number, schema:%d, input:%zu", pHandle->outPutColCounts, taosArrayGetSize(pInput->pData->pDataBlock));
73!
74
    return TSDB_CODE_QRY_INVALID_INPUT;
×
75
  }
76

77
  SNode*  pNode;
78
  int32_t colNum = 0;
22,029,023✔
79
  FOREACH(pNode, pHandle->pSchema->pSlots) {
92,937,763!
80
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
70,920,129✔
81
    if (pSlotDesc->output) {
70,920,129✔
82
      SColumnInfoData* pColInfoData = taosArrayGet(pInput->pData->pDataBlock, colNum);
70,243,237✔
83
      if (pColInfoData == NULL) {
70,224,487!
84
        return -1;
×
85
      }
86
      if (pColInfoData->info.bytes < 0) {
70,224,487!
87
        qError("invalid column bytes, schema:%d, input:%d", pSlotDesc->dataType.bytes, pColInfoData->info.bytes);
×
88
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
89
      }
90
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type) &&
70,224,487!
91
          TYPE_BYTES[pColInfoData->info.type] != pColInfoData->info.bytes) {
54,191,145!
92
        qError("invalid column bytes, schema:%d, input:%d", TYPE_BYTES[pColInfoData->info.type],
×
93
               pColInfoData->info.bytes);
94
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
95
      }
96
      if (pColInfoData->info.type != pSlotDesc->dataType.type) {
70,224,487!
97
        qError("invalid column type, schema:%d, input:%d", pSlotDesc->dataType.type, pColInfoData->info.type);
×
98
        return TSDB_CODE_QRY_INVALID_INPUT;
×
99
      }
100
      if (pColInfoData->info.bytes != pSlotDesc->dataType.bytes) {
70,224,487!
101
        qError("invalid column bytes, schema:%d, input:%d", pSlotDesc->dataType.bytes, pColInfoData->info.bytes);
×
102
        return TSDB_CODE_QRY_INVALID_INPUT;
×
103
      }
104

105
      if (IS_INVALID_TYPE(pColInfoData->info.type)) {
70,224,487!
106
        qError("invalid column type, type:%d", pColInfoData->info.type);
×
107
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
108
      }
109
      ++colNum;
70,231,848✔
110
    }
111
  }
112

113

114
  return TSDB_CODE_SUCCESS;
22,017,634✔
115
}
116

117
// clang-format off
118
// data format:
119
// +----------------+------------------+--------------+--------------+------------------+--------------------------------------------+------------------------------------+-------------+-----------+-------------+-----------+
120
// |SDataCacheEntry |  version         | total length | numOfRows    |     group id     | col1_schema | col2_schema | col3_schema... | column#1 length, column#2 length...| col1 bitmap | col1 data | col2 bitmap | col2 data |
121
// |                |  sizeof(int32_t) |sizeof(int32) | sizeof(int32)| sizeof(uint64_t) | (sizeof(int8_t)+sizeof(int32_t))*numOfCols | sizeof(int32_t) * numOfCols        | actual size |           |                         |
122
// +----------------+------------------+--------------+--------------+------------------+--------------------------------------------+------------------------------------+-------------+-----------+-------------+-----------+
123
// The length of bitmap is decided by number of rows of this data block, and the length of each column data is
124
// recorded in the first segment, next to the struct header
125
// clang-format on
126
static int32_t toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) {
22,038,922✔
127
  int32_t numOfCols = 0;
22,038,922✔
128
  SNode*  pNode;
129

130
  int32_t code = inputSafetyCheck(pHandle, pInput);
22,038,922✔
131
  if (code) {
22,002,439!
132
    qError("failed to check input data, code:%d", code);
×
133
    return code;
×
134
  }
135

136
  FOREACH(pNode, pHandle->pSchema->pSlots) {
93,248,819!
137
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
71,245,353✔
138
    if (pSlotDesc->output) {
71,245,353✔
139
      ++numOfCols;
70,563,837✔
140
    }
141
  }
142

143
  SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData;
22,003,466✔
144
  pEntry->compressed = 0;
22,003,466✔
145
  pEntry->numOfRows = pInput->pData->info.rows;
22,003,466✔
146
  pEntry->numOfCols = numOfCols;
22,003,466✔
147
  pEntry->dataLen = 0;
22,003,466✔
148
  pEntry->rawLen = 0;
22,003,466✔
149

150
  pBuf->useSize = sizeof(SDataCacheEntry);
22,003,466✔
151

152
  {
153
    // allocate additional 8 bytes to avoid invalid write if compress failed to reduce the size
154
    size_t dataEncodeBufSize = pBuf->allocSize + 8;
22,003,466✔
155
    if ((pBuf->allocSize > tsCompressMsgSize) && (tsCompressMsgSize > 0) && pHandle->pManager->cfg.compress) {
22,003,466!
156
      if (pHandle->pCompressBuf == NULL) {
×
157
        pHandle->pCompressBuf = taosMemoryMalloc(dataEncodeBufSize);
×
158
        if (NULL == pHandle->pCompressBuf) {
×
159
          QRY_RET(terrno);
×
160
        }
161
        pHandle->bufSize = dataEncodeBufSize;
×
162
      } else {
163
        if (pHandle->bufSize < dataEncodeBufSize) {
×
164
          pHandle->bufSize = dataEncodeBufSize;
×
165
          void* p = taosMemoryRealloc(pHandle->pCompressBuf, pHandle->bufSize);
×
166
          if (p != NULL) {
×
167
            pHandle->pCompressBuf = p;
×
168
          } else {
169
            qError("failed to prepare compress buf:%d, code: %x", pHandle->bufSize, terrno);
×
170
            return terrno;
×
171
          }
172
        }
173
      }
174

175
      int32_t dataLen = blockEncode(pInput->pData, pHandle->pCompressBuf, dataEncodeBufSize, numOfCols);
×
176
      if(dataLen < 0) {
×
177
        qError("failed to encode data block, code: %d", dataLen);
×
178
        return terrno;
×
179
      }
180
      int32_t len =
181
          tsCompressString(pHandle->pCompressBuf, dataLen, 1, pEntry->data, pBuf->allocSize, ONE_STAGE_COMP, NULL, 0);
×
182
      if (len < dataLen) {
×
183
        pEntry->compressed = 1;
×
184
        pEntry->dataLen = len;
×
185
        pEntry->rawLen = dataLen;
×
186
      } else {  // no need to compress data
187
        pEntry->compressed = 0;
×
188
        pEntry->dataLen = dataLen;
×
189
        pEntry->rawLen = dataLen;
×
190
        TAOS_MEMCPY(pEntry->data, pHandle->pCompressBuf, dataLen);
×
191
      }
192
    } else {
193
      pEntry->dataLen = blockEncode(pInput->pData, pEntry->data,  pBuf->allocSize, numOfCols);
22,003,466✔
194
      if(pEntry->dataLen < 0) {
22,012,351!
195
        qError("failed to encode data block, code: %d", pEntry->dataLen);
×
196
        return terrno;
×
197
      }
198
      pEntry->rawLen = pEntry->dataLen;
22,013,620✔
199
    }
200
  }
201

202
  pBuf->useSize += pEntry->dataLen;
22,013,620✔
203

204
  (void)atomic_add_fetch_64(&pHandle->cachedSize, pEntry->dataLen);
22,013,620✔
205
  (void)atomic_add_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
22,049,659✔
206

207
  return TSDB_CODE_SUCCESS;
22,044,905✔
208
}
209

210
static int32_t allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, SDataDispatchBuf* pBuf) {
22,042,402✔
211
  /*
212
    uint32_t capacity = pDispatcher->pManager->cfg.maxDataBlockNumPerQuery;
213
    if (taosQueueItemSize(pDispatcher->pDataBlocks) > capacity) {
214
      qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity,
215
             taosQueueItemSize(pDispatcher->pDataBlocks));
216
      return false;
217
    }
218
  */
219

220
  pBuf->allocSize = sizeof(SDataCacheEntry) + blockGetEncodeSize(pInput->pData);
22,042,402✔
221

222
  pBuf->pData = taosMemoryMalloc(pBuf->allocSize);
21,992,514✔
223
  if (pBuf->pData == NULL) {
22,042,266!
224
    qError("SinkNode failed to malloc memory, size:%d, code:%x", pBuf->allocSize, terrno);
×
225
    return terrno;
×
226
  }
227

228
  return TSDB_CODE_SUCCESS;
22,042,266✔
229
}
230

231
static int32_t updateStatus(SDataDispatchHandle* pDispatcher) {
43,548,699✔
232
  (void)taosThreadMutexLock(&pDispatcher->mutex);
43,548,699✔
233
  int32_t blockNums = taosQueueItemSize(pDispatcher->pDataBlocks);
43,572,394✔
234
  int32_t status =
43,600,287✔
235
      (0 == blockNums ? DS_BUF_EMPTY
236
                      : (blockNums < pDispatcher->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL));
43,600,287✔
237
  pDispatcher->status = status;
43,600,287✔
238
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
43,600,287✔
239
  return status;
43,583,159✔
240
}
241

242
static int32_t getStatus(SDataDispatchHandle* pDispatcher) {
×
243
  (void)taosThreadMutexLock(&pDispatcher->mutex);
×
244
  int32_t status = pDispatcher->status;
×
245
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
×
246
  return status;
×
247
}
248

249
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
22,031,139✔
250
  int32_t              code = 0;
22,031,139✔
251
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
22,031,139✔
252
  SDataDispatchBuf*    pBuf = NULL;
22,031,139✔
253

254
  code = taosAllocateQitem(sizeof(SDataDispatchBuf), DEF_QITEM, 0, (void**)&pBuf);
22,031,139✔
255
  if (code) {
22,043,795!
256
    return code;
×
257
  }
258

259
  code = allocBuf(pDispatcher, pInput, pBuf);
22,043,795✔
260
  if (code) {
22,040,700!
261
    taosFreeQitem(pBuf);
×
262
    return code;
×
263
  }
264

265
  QRY_ERR_JRET(toDataCacheEntry(pDispatcher, pInput, pBuf));
22,040,700!
266
  QRY_ERR_JRET(taosWriteQitem(pDispatcher->pDataBlocks, pBuf));
22,043,876!
267

268
  int32_t status = updateStatus(pDispatcher);
22,050,320✔
269
  *pContinue = (status == DS_BUF_LOW || status == DS_BUF_EMPTY);
22,049,410!
270
  return TSDB_CODE_SUCCESS;
22,049,410✔
271

272
_return:
×
273

274
  taosMemoryFreeClear(pBuf->pData);
×
275
  taosFreeQitem(pBuf);
×
276
  return code;
×
277
}
278

279
static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) {
8,253,263✔
280
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
8,253,263✔
281
  (void)taosThreadMutexLock(&pDispatcher->mutex);
8,253,263✔
282
  pDispatcher->queryEnd = true;
8,255,006✔
283
  pDispatcher->useconds = useconds;
8,255,006✔
284
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
8,255,006✔
285
}
8,255,097✔
286

287
static void resetDispatcher(struct SDataSinkHandle* pHandle) {
1,027✔
288
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
1,027✔
289
  (void)taosThreadMutexLock(&pDispatcher->mutex);
1,027✔
290
  pDispatcher->queryEnd = false;
1,028✔
291
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
1,028✔
292
}
1,028✔
293

294
static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, int64_t* pRowLen, bool* pQueryEnd) {
23,825,017✔
295
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
23,825,017✔
296
  if (taosQueueEmpty(pDispatcher->pDataBlocks)) {
23,825,017✔
297
    *pQueryEnd = pDispatcher->queryEnd;
2,360,602✔
298
    *pLen = 0;
2,360,602✔
299
    return;
2,360,602✔
300
  }
301

302
  SDataDispatchBuf* pBuf = NULL;
21,534,061✔
303
  taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
21,534,061✔
304
  if (pBuf != NULL) {
21,541,909✔
305
    TAOS_MEMCPY(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
21,539,223✔
306
    taosFreeQitem(pBuf);
21,539,223✔
307
  }
308

309
  SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData;
21,550,503✔
310
  *pLen = pEntry->dataLen;
21,550,503✔
311
  *pRowLen = pEntry->rawLen;
21,550,503✔
312

313
  *pQueryEnd = pDispatcher->queryEnd;
21,550,503✔
314
  qDebug("got data len %" PRId64 ", row num %d in sink", *pLen,
21,550,503✔
315
         ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows);
316
}
317

318
static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
23,611,947✔
319
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
23,611,947✔
320
  if (NULL == pDispatcher->nextOutput.pData) {
23,611,947✔
321
    if (!pDispatcher->queryEnd) {
2,156,568!
322
      qError("empty res while query not end in data dispatcher");
×
323
      return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
324
    }
325

326
    pOutput->useconds = pDispatcher->useconds;
2,156,568✔
327
    pOutput->precision = pDispatcher->pSchema->precision;
2,156,568✔
328
    pOutput->bufStatus = DS_BUF_EMPTY;
2,156,568✔
329
    pOutput->queryEnd = pDispatcher->queryEnd;
2,156,568✔
330
    return TSDB_CODE_SUCCESS;
2,156,568✔
331
  }
332

333
  SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDispatcher->nextOutput.pData);
21,455,379✔
334
  TAOS_MEMCPY(pOutput->pData, pEntry->data, pEntry->dataLen);
21,455,379✔
335
  pOutput->numOfRows = pEntry->numOfRows;
21,455,379✔
336
  pOutput->numOfCols = pEntry->numOfCols;
21,455,379✔
337
  pOutput->compressed = pEntry->compressed;
21,455,379✔
338

339
  (void)atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
21,455,379✔
340
  (void)atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
21,520,866✔
341

342
  taosMemoryFreeClear(pDispatcher->nextOutput.pData);  // todo persistent
21,541,477!
343
  pOutput->bufStatus = updateStatus(pDispatcher);
21,534,079✔
344
  
345
  (void)taosThreadMutexLock(&pDispatcher->mutex);
21,532,677✔
346
  pOutput->queryEnd = pDispatcher->queryEnd;
21,541,953✔
347
  pOutput->useconds = pDispatcher->useconds;
21,541,953✔
348
  pOutput->precision = pDispatcher->pSchema->precision;
21,541,953✔
349
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
21,541,953✔
350

351
  return TSDB_CODE_SUCCESS;
21,550,257✔
352
}
353

354
static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
8,308,411✔
355
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
8,308,411✔
356
  (void)atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pDispatcher->cachedSize);
8,308,411✔
357
  taosMemoryFreeClear(pDispatcher->nextOutput.pData);
8,310,028!
358

359
  while (!taosQueueEmpty(pDispatcher->pDataBlocks)) {
8,759,694✔
360
    SDataDispatchBuf* pBuf = NULL;
449,582✔
361
    taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
449,582✔
362
    if (pBuf != NULL) {
449,654!
363
      taosMemoryFreeClear(pBuf->pData);
449,662!
364
      taosFreeQitem(pBuf);
449,741✔
365
    }
366
  }
367

368
  taosCloseQueue(pDispatcher->pDataBlocks);
8,309,390✔
369
  taosMemoryFreeClear(pDispatcher->pCompressBuf);
8,310,063!
370
  pDispatcher->bufSize = 0;
8,310,063✔
371

372
  (void)taosThreadMutexDestroy(&pDispatcher->mutex);
8,310,063✔
373
  taosMemoryFree(pDispatcher->pManager);
8,308,521✔
374
  return TSDB_CODE_SUCCESS;
8,310,273✔
375
}
376

377
static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) {
×
378
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
×
379

380
  *size = atomic_load_64(&pDispatcher->cachedSize);
×
381
  return TSDB_CODE_SUCCESS;
×
382
}
383

384
static int32_t blockDescNodeCheck(SDataBlockDescNode* pInputDataBlockDesc)  {
8,290,347✔
385
  if(tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) {
8,290,347!
386
    return TSDB_CODE_SUCCESS;
×
387
  }
388

389
  if (pInputDataBlockDesc == NULL) {
8,290,347!
390
    qError("invalid schema");
×
391
    return TSDB_CODE_QRY_INVALID_INPUT;
×
392
  }
393

394
  SNode*  pNode;
395
  int32_t realOutputRowSize = 0;
8,290,347✔
396
  FOREACH(pNode, pInputDataBlockDesc->pSlots) {
45,723,515!
397
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
37,803,057✔
398
    if (pSlotDesc->output) {
37,803,057✔
399
      realOutputRowSize += pSlotDesc->dataType.bytes;
37,433,168✔
400
    } else {
401
      // Slots must be sorted, and slots with 'output' set to true must come first
402
      break;
369,889✔
403
    }
404
  }
405
  if (realOutputRowSize !=  pInputDataBlockDesc->outputRowSize) {
8,290,347!
406
    qError("invalid schema, realOutputRowSize:%d, outputRowSize:%d", realOutputRowSize, pInputDataBlockDesc->outputRowSize);
×
407
    return TSDB_CODE_QRY_INVALID_INPUT;
×
408
  }
409
  return TSDB_CODE_SUCCESS;
8,290,347✔
410
}
411

412
int32_t getOutputColCounts(SDataBlockDescNode* pInputDataBlockDesc) {
8,298,759✔
413
  if (pInputDataBlockDesc == NULL) {
8,298,759!
414
    qError("invalid schema");
×
415
    return 0;
×
416
  }
417
  SNode*  pNode;
418
  int32_t numOfCols = 0;
8,298,759✔
419
  FOREACH(pNode, pInputDataBlockDesc->pSlots) {
45,738,326!
420
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
37,809,444✔
421
    if (pSlotDesc->output) {
37,809,444✔
422
      ++numOfCols;
37,439,567✔
423
    } else {
424
      // Slots must be sorted, and slots with 'output' set to true must come first
425
      break;
369,877✔
426
    }
427
  }
428
  return numOfCols;
8,298,759✔
429
}
430

431
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) {
8,290,190✔
432
  int32_t code;
433
  code = blockDescNodeCheck(pDataSink->pInputDataBlockDesc);
8,290,190✔
434
  if (code) {
8,306,964!
435
    qError("failed to check input data block desc, code:%d", code);
×
436
    return code;
×
437
  }
438

439
  SDataDispatchHandle* dispatcher = taosMemoryCalloc(1, sizeof(SDataDispatchHandle));
8,306,964✔
440
  if (NULL == dispatcher) {
8,297,411!
441
    goto _return;
×
442
  }
443

444
  dispatcher->sink.fPut = putDataBlock;
8,297,411✔
445
  dispatcher->sink.fEndPut = endPut;
8,297,411✔
446
  dispatcher->sink.fReset = resetDispatcher;
8,297,411✔
447
  dispatcher->sink.fGetLen = getDataLength;
8,297,411✔
448
  dispatcher->sink.fGetData = getDataBlock;
8,297,411✔
449
  dispatcher->sink.fDestroy = destroyDataSinker;
8,297,411✔
450
  dispatcher->sink.fGetCacheSize = getCacheSize;
8,297,411✔
451

452
  dispatcher->pManager = pManager;
8,297,411✔
453
  pManager = NULL;
8,297,411✔
454
  dispatcher->pSchema = pDataSink->pInputDataBlockDesc;
8,297,411✔
455
  dispatcher->outPutColCounts = getOutputColCounts(dispatcher->pSchema);
8,297,411✔
456
  dispatcher->status = DS_BUF_EMPTY;
8,305,578✔
457
  dispatcher->queryEnd = false;
8,305,578✔
458
  code = taosOpenQueue(&dispatcher->pDataBlocks);
8,305,578✔
459
  if (code) {
8,301,013!
460
    terrno = code;
×
461
    goto _return;
×
462
  }
463
  code = taosThreadMutexInit(&dispatcher->mutex, NULL);
8,301,013✔
464
  if (code) {
8,297,651!
UNCOV
465
    terrno = code;
×
466
    goto _return;
×
467
  }
468

469
  *pHandle = dispatcher;
8,297,897✔
470
  return TSDB_CODE_SUCCESS;
8,297,897✔
471

472
_return:
×
473

474
  taosMemoryFree(pManager);
×
475
  
476
  if (dispatcher) {
×
477
    dsDestroyDataSinker(dispatcher);
×
478
  }
479
  return terrno;
×
480
}
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