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

taosdata / TDengine / #3541

26 Nov 2024 03:56AM UTC coverage: 60.776% (-0.07%) from 60.846%
#3541

push

travis-ci

web-flow
Merge pull request #28920 from taosdata/fix/TD-33008-3.0

fix(query)[TD-33008]. fix error handling in tsdbCacheRead

120076 of 252763 branches covered (47.51%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1395 existing lines in 154 files now uncovered.

200995 of 275526 relevant lines covered (72.95%)

19612328.37 hits per line

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

56.77
/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)  {
18,383,545✔
59
  if(tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) {
18,383,545!
60
    return TSDB_CODE_SUCCESS;
×
61
  }
62
  if (pInput == NULL || pInput->pData == NULL || pInput->pData->info.rows <= 0) {
18,383,545!
63
    qError("invalid input data");
×
64
    return TSDB_CODE_QRY_INVALID_INPUT;
×
65
  }
66
  SDataBlockDescNode* pSchema = pHandle->pSchema;
18,384,058✔
67
  if (pSchema == NULL || pSchema->totalRowSize != pInput->pData->info.rowSize) {
18,384,058!
UNCOV
68
    qError("invalid schema");
×
69
    return TSDB_CODE_QRY_INVALID_INPUT;
×
70
  }
71

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

77
  SNode*  pNode;
78
  int32_t colNum = 0;
18,381,132✔
79
  FOREACH(pNode, pHandle->pSchema->pSlots) {
83,292,861!
80
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
64,927,753✔
81
    if (pSlotDesc->output) {
64,927,753✔
82
      SColumnInfoData* pColInfoData = taosArrayGet(pInput->pData->pDataBlock, colNum);
64,317,812✔
83
      if (pColInfoData == NULL) {
64,292,883!
84
        return -1;
×
85
      }
86
      if (pColInfoData->info.bytes < 0) {
64,292,883!
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) &&
64,292,883!
91
          TYPE_BYTES[pColInfoData->info.type] != pColInfoData->info.bytes) {
51,402,116!
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) {
64,292,883!
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) {
64,292,883!
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)) {
64,292,883!
106
        qError("invalid column type, type:%d", pColInfoData->info.type);
×
107
        return TSDB_CODE_TSC_INTERNAL_ERROR;
×
108
      }
109
      ++colNum;
64,301,788✔
110
    }
111
  }
112

113

114
  return TSDB_CODE_SUCCESS;
18,365,108✔
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) {
18,384,395✔
127
  int32_t numOfCols = 0;
18,384,395✔
128
  SNode*  pNode;
129

130
  int32_t code = inputSafetyCheck(pHandle, pInput);
18,384,395✔
131
  if (code) {
18,342,390!
132
    qError("failed to check input data, code:%d", code);
×
133
    return code;
×
134
  }
135

136
  FOREACH(pNode, pHandle->pSchema->pSlots) {
83,692,882!
137
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
65,349,460✔
138
    if (pSlotDesc->output) {
65,349,460✔
139
      ++numOfCols;
64,735,213✔
140
    }
141
  }
142

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

150
  pBuf->useSize = sizeof(SDataCacheEntry);
18,343,422✔
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;
18,343,422✔
155
    if ((pBuf->allocSize > tsCompressMsgSize) && (tsCompressMsgSize > 0) && pHandle->pManager->cfg.compress) {
18,343,422!
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);
18,343,422✔
194
      if(pEntry->dataLen < 0) {
18,349,341!
195
        qError("failed to encode data block, code: %d", pEntry->dataLen);
×
196
        return terrno;
×
197
      }
198
      pEntry->rawLen = pEntry->dataLen;
18,351,469✔
199
    }
200
  }
201

202
  pBuf->useSize += pEntry->dataLen;
18,351,469✔
203

204
  (void)atomic_add_fetch_64(&pHandle->cachedSize, pEntry->dataLen);
18,351,469✔
205
  (void)atomic_add_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
18,389,886✔
206

207
  return TSDB_CODE_SUCCESS;
18,383,059✔
208
}
209

210
static int32_t allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, SDataDispatchBuf* pBuf) {
18,391,195✔
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);
18,391,195✔
221

222
  pBuf->pData = taosMemoryMalloc(pBuf->allocSize);
18,333,190✔
223
  if (pBuf->pData == NULL) {
18,386,986!
224
    qError("SinkNode failed to malloc memory, size:%d, code:%x", pBuf->allocSize, terrno);
×
225
    return terrno;
×
226
  }
227

228
  return TSDB_CODE_SUCCESS;
18,386,986✔
229
}
230

231
static int32_t updateStatus(SDataDispatchHandle* pDispatcher) {
36,293,039✔
232
  (void)taosThreadMutexLock(&pDispatcher->mutex);
36,293,039✔
233
  int32_t blockNums = taosQueueItemSize(pDispatcher->pDataBlocks);
36,310,193✔
234
  int32_t status =
36,316,493✔
235
      (0 == blockNums ? DS_BUF_EMPTY
236
                      : (blockNums < pDispatcher->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL));
36,316,493✔
237
  pDispatcher->status = status;
36,316,493✔
238
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
36,316,493✔
239
  return status;
36,318,291✔
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) {
18,370,123✔
250
  int32_t              code = 0;
18,370,123✔
251
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
18,370,123✔
252
  SDataDispatchBuf*    pBuf = NULL;
18,370,123✔
253

254
  code = taosAllocateQitem(sizeof(SDataDispatchBuf), DEF_QITEM, 0, (void**)&pBuf);
18,370,123✔
255
  if (code) {
18,392,667!
256
    return code;
×
257
  }
258

259
  code = allocBuf(pDispatcher, pInput, pBuf);
18,392,667✔
260
  if (code) {
18,385,384!
261
    taosFreeQitem(pBuf);
×
262
    return code;
×
263
  }
264

265
  QRY_ERR_JRET(toDataCacheEntry(pDispatcher, pInput, pBuf));
18,385,384!
266
  QRY_ERR_JRET(taosWriteQitem(pDispatcher->pDataBlocks, pBuf));
18,381,657!
267

268
  int32_t status = updateStatus(pDispatcher);
18,395,271✔
269
  *pContinue = (status == DS_BUF_LOW || status == DS_BUF_EMPTY);
18,393,357!
270
  return TSDB_CODE_SUCCESS;
18,393,357✔
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,427,924✔
280
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
8,427,924✔
281
  (void)taosThreadMutexLock(&pDispatcher->mutex);
8,427,924✔
282
  pDispatcher->queryEnd = true;
8,429,367✔
283
  pDispatcher->useconds = useconds;
8,429,367✔
284
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
8,429,367✔
285
}
8,429,352✔
286

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

294
static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, int64_t* pRowLen, bool* pQueryEnd) {
20,237,662✔
295
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
20,237,662✔
296
  if (taosQueueEmpty(pDispatcher->pDataBlocks)) {
20,237,662✔
297
    *pQueryEnd = pDispatcher->queryEnd;
2,337,692✔
298
    *pLen = 0;
2,337,692✔
299
    return;
2,337,692✔
300
  }
301

302
  SDataDispatchBuf* pBuf = NULL;
17,925,966✔
303
  taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
17,925,966✔
304
  if (pBuf != NULL) {
17,925,385✔
305
    TAOS_MEMCPY(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
17,924,338✔
306
    taosFreeQitem(pBuf);
17,924,338✔
307
  }
308

309
  SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData;
17,933,479✔
310
  *pLen = pEntry->dataLen;
17,933,479✔
311
  *pRowLen = pEntry->rawLen;
17,933,479✔
312

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

318
static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
20,078,993✔
319
  SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
20,078,993✔
320
  if (NULL == pDispatcher->nextOutput.pData) {
20,078,993✔
321
    if (!pDispatcher->queryEnd) {
2,176,100!
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,176,100✔
327
    pOutput->precision = pDispatcher->pSchema->precision;
2,176,100✔
328
    pOutput->bufStatus = DS_BUF_EMPTY;
2,176,100✔
329
    pOutput->queryEnd = pDispatcher->queryEnd;
2,176,100✔
330
    return TSDB_CODE_SUCCESS;
2,176,100✔
331
  }
332

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

339
  (void)atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
17,902,893✔
340
  (void)atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
17,921,379✔
341

342
  taosMemoryFreeClear(pDispatcher->nextOutput.pData);  // todo persistent
17,917,564!
343
  pOutput->bufStatus = updateStatus(pDispatcher);
17,915,470✔
344
  
345
  (void)taosThreadMutexLock(&pDispatcher->mutex);
17,924,715✔
346
  pOutput->queryEnd = pDispatcher->queryEnd;
17,926,835✔
347
  pOutput->useconds = pDispatcher->useconds;
17,926,835✔
348
  pOutput->precision = pDispatcher->pSchema->precision;
17,926,835✔
349
  (void)taosThreadMutexUnlock(&pDispatcher->mutex);
17,926,835✔
350

351
  return TSDB_CODE_SUCCESS;
17,930,351✔
352
}
353

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

359
  while (!taosQueueEmpty(pDispatcher->pDataBlocks)) {
8,936,299✔
360
    SDataDispatchBuf* pBuf = NULL;
457,768✔
361
    taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
457,768✔
362
    if (pBuf != NULL) {
457,763✔
363
      taosMemoryFreeClear(pBuf->pData);
457,762!
364
      taosFreeQitem(pBuf);
457,741✔
365
    }
366
  }
367

368
  taosCloseQueue(pDispatcher->pDataBlocks);
8,478,414✔
369
  taosMemoryFreeClear(pDispatcher->pCompressBuf);
8,478,718!
370
  pDispatcher->bufSize = 0;
8,478,718✔
371

372
  (void)taosThreadMutexDestroy(&pDispatcher->mutex);
8,478,718✔
373
  taosMemoryFree(pDispatcher->pManager);
8,478,071✔
374
  return TSDB_CODE_SUCCESS;
8,478,720✔
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,463,453✔
385
  if(tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) {
8,463,453!
386
    return TSDB_CODE_SUCCESS;
×
387
  }
388

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

394
  SNode*  pNode;
395
  int32_t realOutputRowSize = 0;
8,463,453✔
396
  FOREACH(pNode, pInputDataBlockDesc->pSlots) {
46,553,463!
397
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
38,455,790✔
398
    if (pSlotDesc->output) {
38,455,790✔
399
      realOutputRowSize += pSlotDesc->dataType.bytes;
38,090,010✔
400
    } else {
401
      // Slots must be sorted, and slots with 'output' set to true must come first
402
      break;
365,780✔
403
    }
404
  }
405
  if (realOutputRowSize !=  pInputDataBlockDesc->outputRowSize) {
8,463,453!
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,463,453✔
410
}
411

412
int32_t getOutputColCounts(SDataBlockDescNode* pInputDataBlockDesc) {
8,468,226✔
413
  if (pInputDataBlockDesc == NULL) {
8,468,226!
414
    qError("invalid schema");
×
415
    return 0;
×
416
  }
417
  SNode*  pNode;
418
  int32_t numOfCols = 0;
8,468,226✔
419
  FOREACH(pNode, pInputDataBlockDesc->pSlots) {
46,566,683!
420
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
38,464,225✔
421
    if (pSlotDesc->output) {
38,464,225✔
422
      ++numOfCols;
38,098,457✔
423
    } else {
424
      // Slots must be sorted, and slots with 'output' set to true must come first
425
      break;
365,768✔
426
    }
427
  }
428
  return numOfCols;
8,468,226✔
429
}
430

431
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) {
8,463,932✔
432
  int32_t code;
433
  code = blockDescNodeCheck(pDataSink->pInputDataBlockDesc);
8,463,932✔
434
  if (code) {
8,473,128!
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,473,128✔
440
  if (NULL == dispatcher) {
8,467,517!
441
    goto _return;
×
442
  }
443

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

452
  dispatcher->pManager = pManager;
8,467,517✔
453
  pManager = NULL;
8,467,517✔
454
  dispatcher->pSchema = pDataSink->pInputDataBlockDesc;
8,467,517✔
455
  dispatcher->outPutColCounts = getOutputColCounts(dispatcher->pSchema);
8,467,517✔
456
  dispatcher->status = DS_BUF_EMPTY;
8,471,443✔
457
  dispatcher->queryEnd = false;
8,471,443✔
458
  code = taosOpenQueue(&dispatcher->pDataBlocks);
8,471,443✔
459
  if (code) {
8,472,524!
460
    terrno = code;
×
461
    goto _return;
×
462
  }
463
  code = taosThreadMutexInit(&dispatcher->mutex, NULL);
8,472,524✔
464
  if (code) {
8,469,023✔
465
    terrno = code;
1,066✔
466
    goto _return;
×
467
  }
468

469
  *pHandle = dispatcher;
8,467,957✔
470
  return TSDB_CODE_SUCCESS;
8,467,957✔
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