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

taosdata / TDengine / #5001

24 Mar 2026 01:11AM UTC coverage: 72.254% (-0.05%) from 72.307%
#5001

push

travis-ci

web-flow
fix: possible memory leak in tdb; (#34872)

1 of 20 new or added lines in 2 files covered. (5.0%)

770 existing lines in 143 files now uncovered.

253287 of 350550 relevant lines covered (72.25%)

130300301.72 hits per line

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

83.65
/source/dnode/vnode/src/vnd/vnodeStream.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 <stdbool.h>
17
#include <stdint.h>
18
#include <taos.h>
19
#include <tdef.h>
20
#include "executor.h"
21
#include "nodes.h"
22
#include "osMemPool.h"
23
#include "osMemory.h"
24
#include "scalar.h"
25
#include "stream.h"
26
#include "streamReader.h"
27
#include "taosdef.h"
28
#include "taoserror.h"
29
#include "tarray.h"
30
#include "tcommon.h"
31
#include "tdatablock.h"
32
#include "tdb.h"
33
#include "tdef.h"
34
#include "tencode.h"
35
#include "tglobal.h"
36
#include "thash.h"
37
#include "tlist.h"
38
#include "tlockfree.h"
39
#include "tmsg.h"
40
#include "tsimplehash.h"
41
#include "ttypes.h"
42
#include "vnd.h"
43
#include "vnode.h"
44
#include "vnodeInt.h"
45
#include "executor.h"
46

47
int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid, col_id_t colId, SRWLatch* lock);
48

49
#define BUILD_OPTION(options, _suid, _ver, _order, startTime, endTime, _schemas, _isSchema, _pSlotList)      \
50
  SStreamOptions                       options = {.suid = _suid,                                                   \
51
                                                  .ver = _ver,                                                     \
52
                                                  .order = _order,                                                 \
53
                                                  .twindows = {.skey = startTime, .ekey = endTime},                \
54
                                                  .schemas = _schemas,                                             \
55
                                                  .isSchema = _isSchema,                                           \
56
                                                  .pSlotList = _pSlotList};
57

58
typedef struct WalMetaResult {
59
  uint64_t    id;
60
  int64_t     skey;
61
  int64_t     ekey;
62
} WalMetaResult;
63

64
static int64_t getSuid(SStreamTriggerReaderInfo* sStreamReaderInfo, STableKeyInfo* pList) {
6,605,491✔
65
  int64_t suid = 0;
6,605,491✔
66
  if (!sStreamReaderInfo->isVtableStream) {
6,605,491✔
67
    suid = sStreamReaderInfo->suid;
6,535,513✔
68
    goto end;
6,535,513✔
69
  }
70

71
  if (pList == NULL) {
69,978✔
72
    goto end;
×
73
  }
74

75
  taosRLockLatch(&sStreamReaderInfo->lock);
69,978✔
76
  SStreamTableMapElement* element = taosHashGet(sStreamReaderInfo->vSetTableList.uIdMap, &pList->uid, LONG_BYTES);  
69,978✔
77
  if (element != 0) {
69,978✔
78
    suid = element->table->groupId;
65,857✔
79
    taosRUnLockLatch(&sStreamReaderInfo->lock);
65,857✔
80
    goto end;
65,857✔
81
  }
82
  taosRUnLockLatch(&sStreamReaderInfo->lock);
4,121✔
83

84
end:
6,605,491✔
85
  return suid;
6,605,491✔
86
}
87

88
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
6,491,798✔
89

90
int32_t sortCid(const void *lp, const void *rp) {
111,507✔
91
  int16_t* c1 = (int16_t*)lp;
111,507✔
92
  int16_t* c2 = (int16_t*)rp;
111,507✔
93

94
  if (*c1 < *c2) {
111,507✔
95
    return -1;
110,882✔
96
  } else if (*c1 > *c2) {
844✔
97
    return 1;
844✔
98
  }
99

100
  return 0;
×
101
}
102

103
int32_t sortSSchema(const void *lp, const void *rp) {
111,726✔
104
  SSchema* c1 = (SSchema*)lp;
111,726✔
105
  SSchema* c2 = (SSchema*)rp;
111,726✔
106

107
  if (c1->colId < c2->colId) {
111,726✔
108
    return -1;
110,882✔
109
  } else if (c1->colId > c2->colId) {
844✔
110
    return 1;
844✔
111
  }
112

113
  return 0;
×
114
}
115

116
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
9,523,283✔
117
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
9,523,283✔
118
  if (pSrc == NULL) {
9,526,655✔
119
    return terrno;
×
120
  }
121

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
9,526,655✔
123
  return 0;
9,521,106✔
124
}
125

126
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
7,786,907✔
127
  int32_t code = pTask->storageApi->tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
7,786,907✔
128
  if (code != TSDB_CODE_SUCCESS) {
7,785,386✔
129
    pTask->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
130
  }
131

132
  return code;
7,784,559✔
133
}
134

135
static int32_t getTableData(SStreamReaderTaskInner* pTask, SSDataBlock** ppRes) {
926,629✔
136
  return pTask->storageApi->tsdReader.tsdReaderRetrieveDataBlock(pTask->pReader, ppRes);
926,629✔
137
}
138

139
static int32_t buildOTableInfoRsp(const SSTriggerOrigTableInfoRsp* rsp, void** data, size_t* size) {
27,160✔
140
  int32_t code = 0;
27,160✔
141
  int32_t lino = 0;
27,160✔
142
  void*   buf = NULL;
27,160✔
143
  int32_t len = tSerializeSTriggerOrigTableInfoRsp(NULL, 0, rsp);
27,160✔
144
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
27,160✔
145
  buf = rpcMallocCont(len);
27,160✔
146
  STREAM_CHECK_NULL_GOTO(buf, terrno);
27,160✔
147
  int32_t actLen = tSerializeSTriggerOrigTableInfoRsp(buf, len, rsp);
27,160✔
148
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
27,160✔
149
  *data = buf;
27,160✔
150
  *size = len;
27,160✔
151
  buf = NULL;
27,160✔
152
end:
27,160✔
153
  rpcFreeCont(buf);
27,160✔
154
  return code;
27,160✔
155
}
156

157
static bool ignoreMetaChange(int64_t tableListVer, int64_t ver) {
151,115✔
158
  stDebug("%s tableListVer:%" PRId64 " ver:%" PRId64, __func__, tableListVer, ver);
151,115✔
159
  return tableListVer >= ver;
151,115✔
160
}
161

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
1,305,404✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
1,305,404✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
592,446✔
165
      suid == sStreamReaderInfo->suid) {
344,212✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
11,588✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
11,588✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
11,588✔
169
    if (gid == (uint64_t)-1) return true;
11,588✔
170
  }
171
  return false;
1,293,886✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
10,351,026✔
175
  int32_t  ret = false;
10,351,026✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
10,351,026✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
6,225,719✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
2,239,432✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
6,360,949✔
181
  if (*id == -1) goto end;
6,359,511✔
182
  ret = true;
4,061,669✔
183

184
end:
10,352,207✔
185
  stTrace("%s ret:%d %p %p check suid:%" PRId64 " uid:%" PRId64 " gid:%"PRIu64, __func__, ret, sStreamReaderInfo, sStreamReaderInfo->tableList.gIdMap, suid, uid, *id);
10,352,207✔
186
  return ret;
10,348,817✔
187
}
188

189
static bool uidInTableListOrigin(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id) {
22,209✔
190
  return uidInTableList(sStreamReaderInfo, suid, uid, id);
22,209✔
191
}
192

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
12,799,658✔
194
  bool ret = false;
12,799,658✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
12,799,658✔
196
  if (sStreamReaderInfo->isVtableStream) {
12,806,417✔
197
    int64_t tmp[2] = {suid, uid};
2,475,908✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
2,475,908✔
199
      *id = uid;
1,195,711✔
200
      ret = true;
1,195,711✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
10,329,042✔
204
  }
205

206
end:
12,798,716✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
12,798,716✔
208
  return ret;
12,803,597✔
209
}
210

211
static int32_t  qTransformStreamTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, void* pTableListInfo, StreamTableListInfo* tableInfo){
190,980✔
212
  SArray* pList = qStreamGetTableListArray(pTableListInfo);
190,980✔
213
  int32_t totalSize = taosArrayGetSize(pList);
190,980✔
214
  int32_t code = 0;
190,980✔
215
  void* pTask = sStreamReaderInfo->pTask;
190,980✔
216
  for (int32_t i = 0; i < totalSize; ++i) {
552,858✔
217
    STableKeyInfo* info = taosArrayGet(pList, i);
361,878✔
218
    if (info == NULL) {
361,878✔
219
      continue;
×
220
    }
221
    code = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
361,878✔
222
    if (code != 0){
361,659✔
223
      ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, code);
×
224
      continue;
×
225
    }
226
    code = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
361,659✔
227
    if (code != 0){
361,394✔
228
      ST_TASK_WLOG("%s cacheTag calc failed for uid:%" PRId64",code:%d", __func__, info->uid, code);
×
229
      continue;
×
230
    }
231
    code = qStreamSetTableList(tableInfo, info->uid, info->groupId);
361,394✔
232
    if (code != 0){
361,878✔
233
      return code;
×
234
    }
235
  }
236
  return 0;
190,980✔
237
}
238

239
static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo) {
190,378✔
240
  int32_t                   code = 0;
190,378✔
241
  int32_t                   lino = 0;
190,378✔
242
  SNodeList* groupNew = NULL;   
190,378✔
243
  void* pTableListInfo = NULL;
190,980✔
244

245
  
246
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
190,980✔
247

248
  STREAM_CHECK_RET_GOTO(qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
190,980✔
249
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi, 
250
                                         &pTableListInfo, sStreamReaderInfo->groupIdMap));
251
  
252
  STREAM_CHECK_RET_GOTO(qTransformStreamTableList(sStreamReaderInfo, pTableListInfo, &sStreamReaderInfo->tableList));
190,980✔
253
  
254
  void* pTask = sStreamReaderInfo->pTask;
190,980✔
255
  ST_TASK_DLOG("vgId:%d %s tablelist size:%" PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList));
190,980✔
256
end:
190,482✔
257
  nodesDestroyList(groupNew);
190,980✔
258
  qStreamDestroyTableList(pTableListInfo);
190,980✔
259
  STREAM_PRINT_LOG_END(code, lino);
190,980✔
260
  return code;
191,245✔
261
}
262

263
static int32_t buildVTableInfoRsp(const SStreamMsgVTableInfo* rsp, void** data, size_t* size) {
24,843✔
264
  int32_t code = 0;
24,843✔
265
  int32_t lino = 0;
24,843✔
266
  void*   buf = NULL;
24,843✔
267
  int32_t len = tSerializeSStreamMsgVTableInfo(NULL, 0, rsp);
24,843✔
268
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
24,843✔
269
  buf = rpcMallocCont(len);
24,843✔
270
  STREAM_CHECK_NULL_GOTO(buf, terrno);
24,843✔
271
  int32_t actLen = tSerializeSStreamMsgVTableInfo(buf, len, rsp);
24,843✔
272
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
24,843✔
273
  *data = buf;
24,843✔
274
  *size = len;
24,843✔
275
  buf = NULL;
24,624✔
276
end:
24,624✔
277
  rpcFreeCont(buf);
24,624✔
278
  return code;
24,843✔
279
}
280

281
static int32_t buildTsRsp(const SStreamTsResponse* tsRsp, void** data, size_t* size) {
326,862✔
282
  int32_t code = 0;
326,862✔
283
  int32_t lino = 0;
326,862✔
284
  void*   buf = NULL;
326,862✔
285
  int32_t len = tSerializeSStreamTsResponse(NULL, 0, tsRsp);
326,862✔
286
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
325,427✔
287
  buf = rpcMallocCont(len);
325,427✔
288
  STREAM_CHECK_NULL_GOTO(buf, terrno);
325,654✔
289
  int32_t actLen = tSerializeSStreamTsResponse(buf, len, tsRsp);
325,654✔
290
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
326,137✔
291
  *data = buf;
326,137✔
292
  *size = len;
326,137✔
293
  buf = NULL;
326,621✔
294
end:
326,621✔
295
  rpcFreeCont(buf);
326,621✔
296
  return code;
326,380✔
297
}
298

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
6,674,439✔
301
  int32_t code = 0;
6,674,439✔
302
  int32_t lino = 0;
6,674,439✔
303
  void*   buf = NULL;
6,674,439✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
6,674,439✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
704,259✔
306
  buf = rpcMallocCont(dataEncodeSize);
704,008✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
703,395✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
703,395✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
703,766✔
310
  *data = buf;
703,766✔
311
  *size = dataEncodeSize;
703,766✔
312
  buf = NULL;
703,394✔
313
end:
6,677,939✔
314
  rpcFreeCont(buf);
6,677,939✔
315
  return code;
6,674,950✔
316
}
317

318
static int32_t buildArrayRsp(SArray* pBlockList, void** data, size_t* size) {
58,036✔
319
  int32_t code = 0;
58,036✔
320
  int32_t lino = 0;
58,036✔
321

322
  void*   buf = NULL;
58,036✔
323

324
  int32_t blockNum = 0;
58,036✔
325
  size_t  dataEncodeBufSize = 0;
58,036✔
326
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
121,804✔
327
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
63,286✔
328
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
63,286✔
329
    int32_t blockSize = blockGetEncodeSize(pBlock);
63,527✔
330
    dataEncodeBufSize += blockSize;
63,768✔
331
    blockNum++;
63,768✔
332
  }
333
  buf = rpcMallocCont(INT_BYTES + dataEncodeBufSize);
58,277✔
334
  STREAM_CHECK_NULL_GOTO(buf, terrno);
58,036✔
335

336
  char* dataBuf = (char*)buf;
58,036✔
337
  *((int32_t*)(dataBuf)) = blockNum;
58,036✔
338
  dataBuf += INT_BYTES;
58,036✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
121,804✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
63,768✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
63,768✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
63,768✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
63,768✔
344
    dataBuf += actualLen;
63,768✔
345
  }
346
  *data = buf;
58,035✔
347
  *size = INT_BYTES + dataEncodeBufSize;
58,035✔
348
  buf = NULL;
58,035✔
349
end:
58,035✔
350
  rpcFreeCont(buf);
58,035✔
351
  return code;
58,035✔
352
}
353

354
static int32_t buildWalMetaBlock(SSDataBlock* pBlock, int8_t type, int64_t id, bool isVTable, int64_t uid,
×
355
                                 int64_t skey, int64_t ekey, int64_t ver, int64_t rows) {
356
  int32_t code = 0;
×
357
  int32_t lino = 0;
×
358
  int32_t index = 0;
×
359
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &type));
×
360
  if (!isVTable) {
×
361
    STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
×
362
  }
363
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &uid));
×
364
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
×
365
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
×
366
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
×
367
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &rows));
×
368

369
end:
×
370
  // STREAM_PRINT_LOG_END(code, lino)
371
  return code;
×
372
}
373

374
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
2,125,517✔
375
  int32_t code = 0;
2,125,517✔
376
  int32_t lino = 0;
2,125,517✔
377
  int32_t index = 0;
2,125,517✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
2,125,517✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
2,124,023✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
2,123,323✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
2,123,807✔
382

383
end:
2,124,525✔
384
  return code;
2,124,525✔
385
}
386

387
static int32_t buildTableBlock(SSDataBlock* pBlock, int64_t id, int64_t ver, ETableBlockType type) {
3,546✔
388
  int32_t code = 0;
3,546✔
389
  int32_t lino = 0;
3,546✔
390
  int32_t index = 0;
3,546✔
391
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
3,546✔
392
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
3,546✔
393
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &type));
3,546✔
394

395
end:
3,546✔
396
  return code;
3,546✔
397
}
398

399
static void buildTSchema(STSchema* pTSchema, int32_t ver, col_id_t colId, int8_t type, int32_t bytes) {
×
400
  pTSchema->numOfCols = 1;
×
401
  pTSchema->version = ver;
×
402
  pTSchema->columns[0].colId = colId;
×
403
  pTSchema->columns[0].type = type;
×
404
  pTSchema->columns[0].bytes = bytes;
×
405
}
×
406

407
static int32_t scanDeleteDataNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
25,064✔
408
                              int64_t ver) {
409
  int32_t    code = 0;
25,064✔
410
  int32_t    lino = 0;
25,064✔
411
  SDecoder   decoder = {0};
25,064✔
412
  SDeleteRes req = {0};
25,064✔
413
  void* pTask = sStreamReaderInfo->pTask;
25,064✔
414

415
  req.uidList = taosArrayInit(0, sizeof(tb_uid_t));
25,064✔
416
  tDecoderInit(&decoder, data, len);
25,064✔
417
  STREAM_CHECK_RET_GOTO(tDecodeDeleteRes(&decoder, &req));
25,064✔
418
  STREAM_CHECK_CONDITION_GOTO((sStreamReaderInfo->tableType == TSDB_SUPER_TABLE && !sStreamReaderInfo->isVtableStream && req.suid != sStreamReaderInfo->suid), TDB_CODE_SUCCESS);
25,064✔
419
  
420
  for (int32_t i = 0; i < taosArrayGetSize(req.uidList); i++) {
37,496✔
421
    uint64_t* uid = taosArrayGet(req.uidList, i);
21,545✔
422
    STREAM_CHECK_NULL_GOTO(uid, terrno);
21,545✔
423
    uint64_t   id = 0;
21,545✔
424
    ST_TASK_DLOG("stream reader scan delete start data:uid %" PRIu64 ", skey %" PRIu64 ", ekey %" PRIu64, *uid, req.skey, req.ekey);
21,545✔
425
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, req.suid, *uid, &id, false), TDB_CODE_SUCCESS);
21,545✔
426
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->deleteBlock, ((SSDataBlock*)rsp->deleteBlock)->info.rows + 1));
15,951✔
427
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->deleteBlock, id, req.skey, req.ekey, ver));
15,951✔
428
    ((SSDataBlock*)rsp->deleteBlock)->info.rows++;
15,951✔
429
    rsp->totalRows++;
15,951✔
430
  }
431

432
end:
25,064✔
433
  taosArrayDestroy(req.uidList);
25,064✔
434
  tDecoderClear(&decoder);
25,064✔
435
  return code;
25,064✔
436
}
437

438
static int32_t createBlockForProcessMeta(SSDataBlock** pBlock) {
2,855✔
439
  int32_t code = 0;
2,855✔
440
  int32_t lino = 0;
2,855✔
441
  SArray* schemas = NULL;
2,855✔
442

443
  schemas = taosArrayInit(8, sizeof(SSchema));
2,855✔
444
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
2,855✔
445

446
  int32_t index = 0;
2,855✔
447
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid non vtable/uid vtable
2,855✔
448
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
2,855✔
449
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TINYINT, CHAR_BYTES, index++))  // type
2,855✔
450

451
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
2,855✔
452

453
end:
2,855✔
454
  taosArrayDestroy(schemas);
2,855✔
455
  return code;
2,855✔
456
}
457

458
static int32_t addOneRow(void** tmp, int64_t id, int64_t ver, ETableBlockType type) {
3,546✔
459
  int32_t  code = 0;
3,546✔
460
  int32_t  lino = 0;
3,546✔
461
  if (*tmp == NULL) {
3,546✔
462
    STREAM_CHECK_RET_GOTO(createBlockForProcessMeta((SSDataBlock**)tmp));
2,855✔
463
  }
464
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(*tmp, ((SSDataBlock*)(*tmp))->info.rows + 1));
3,546✔
465
  STREAM_CHECK_RET_GOTO(buildTableBlock(*tmp, id, ver, type));
3,546✔
466
  ((SSDataBlock*)(*tmp))->info.rows++;
3,546✔
467
  
468
end:
3,546✔
469
  return code;
3,546✔
470
}
471

472
static int32_t addUidListToBlock(SArray* uidListAdd, void** block, int64_t ver, int32_t* totalRows, ETableBlockType type) {
63,151✔
473
  for (int32_t i = 0; i < taosArrayGetSize(uidListAdd); ++i) {
66,697✔
474
    uint64_t* uid = taosArrayGet(uidListAdd, i);
3,546✔
475
    if (uid == NULL) {
3,546✔
476
      continue;
×
477
    }
478
    int32_t code = addOneRow(block, *uid, ver, type);
3,546✔
479
    if (code != 0) {
3,546✔
480
      return code;
×
481
    }
482
    (*totalRows)++;
3,546✔
483
  }
484
  return 0;
63,151✔
485
}
486

487
static int32_t qStreamGetAddTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* uidListAdd) {
47,310✔
488
  int32_t      code = 0;
47,310✔
489
  int32_t      lino = 0;
47,310✔
490
  if (uidListAdd == NULL) {
47,310✔
491
    return 0;
40,959✔
492
  }
493
  void* pTask = sStreamReaderInfo->pTask;
6,351✔
494
  
495
  taosRLockLatch(&sStreamReaderInfo->lock);
6,351✔
496
  int32_t totalSize = taosArrayGetSize(tableListAdd);
6,351✔
497
  for (int32_t i = 0; i < totalSize; ++i) {
8,519✔
498
    STableKeyInfo* info = taosArrayGet(tableListAdd, i);
2,168✔
499
    if (info == NULL) {
2,168✔
500
      continue;
×
501
    }
502
    if (taosHashGet(sStreamReaderInfo->tableList.uIdMap, &info->uid, LONG_BYTES) != NULL) {
2,168✔
503
      continue;
×
504
    }
505
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListAdd, &info->uid), terrno);
4,336✔
506
    ST_TASK_WLOG("%s real add table to list for uid:%" PRId64, __func__, info->uid);
2,168✔
507
  }
508

509
end:
6,351✔
510
  taosRUnLockLatch(&sStreamReaderInfo->lock);
6,351✔
511
  return code;
6,351✔
512
}
513

514
static int32_t qStreamGetDelTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListDel, SArray* uidListDel) {
37,920✔
515
  int32_t      code = 0;
37,920✔
516
  int32_t      lino = 0;
37,920✔
517
  if (uidListDel == NULL) {
37,920✔
518
    return 0;
×
519
  }
520
  void* pTask = sStreamReaderInfo->pTask;
37,920✔
521
  
522
  taosRLockLatch(&sStreamReaderInfo->lock);
37,920✔
523
  int32_t totalSize = taosArrayGetSize(tableListDel);
37,920✔
524
  for (int32_t i = 0; i < totalSize; ++i) {
38,822✔
525
    int64_t* uid = taosArrayGet(tableListDel, i);
902✔
526
    if (uid == NULL) {
902✔
527
      continue;
×
528
    }
529
    if (taosHashGet(sStreamReaderInfo->tableList.uIdMap, uid, LONG_BYTES) == NULL) {
902✔
530
      continue;
×
531
    }
532
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListDel, uid), terrno);
902✔
533
    ST_TASK_WLOG("%s real del table from list for uid:%" PRId64, __func__, *uid);
902✔
534
  }
535

536
end:
37,920✔
537
  taosRUnLockLatch(&sStreamReaderInfo->lock);
37,920✔
538
  return code;
37,920✔
539
}
540

541
static int32_t scanDropTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
16,777✔
542
                             int64_t ver) {
543
  int32_t  code = 0;
16,777✔
544
  int32_t  lino = 0;
16,777✔
545
  SDecoder decoder = {0};
16,777✔
546
  void* pTask = sStreamReaderInfo->pTask;
16,777✔
547
  SArray* uidList = NULL;
16,777✔
548
  SArray* uidListDel = NULL;
16,777✔
549
  SArray* uidListDelOutTbl = NULL;
16,777✔
550
  SVDropTbBatchReq req = {0};
16,777✔
551
  tDecoderInit(&decoder, data, len);
16,777✔
552
  STREAM_CHECK_RET_GOTO(tDecodeSVDropTbBatchReq(&decoder, &req));
16,777✔
553

554
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
33,554✔
555
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
16,777✔
556
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
16,777✔
557
    uint64_t id = 0;
16,777✔
558
    if(!uidInTableListOrigin(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id)) {
16,777✔
559
      continue;
15,875✔
560
    }
561

562
    if (sStreamReaderInfo->deleteOutTbl != 0) {
902✔
563
      if (uidListDelOutTbl == NULL) {
×
564
        uidListDelOutTbl = taosArrayInit(8, sizeof(tb_uid_t));
×
565
        STREAM_CHECK_NULL_GOTO(uidListDelOutTbl, terrno);
×
566
      }
567
      STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListDelOutTbl, &pDropTbReq->uid), terrno);
×
568
    }
569
    if (sStreamReaderInfo->isVtableStream) {
902✔
570
      if (uidList == NULL) {
902✔
571
        uidList = taosArrayInit(8, sizeof(tb_uid_t));
902✔
572
        STREAM_CHECK_NULL_GOTO(uidList, terrno);
902✔
573
      }
574
      STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pDropTbReq->uid), terrno);
1,804✔
575
    }
576
    
577
    ST_TASK_DLOG("stream reader scan drop uid %" PRId64 ", id %" PRIu64, pDropTbReq->uid, id);
902✔
578
  }
579
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDelOutTbl, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_DROP));
16,777✔
580

581
  if (sStreamReaderInfo->isVtableStream) {
16,777✔
582
    uidListDel = taosArrayInit(8, sizeof(tb_uid_t));
16,777✔
583
    STREAM_CHECK_NULL_GOTO(uidListDel, terrno);
16,777✔
584
    STREAM_CHECK_RET_GOTO(qStreamGetDelTable(sStreamReaderInfo, uidList, uidListDel));
16,777✔
585
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
16,777✔
586
  }
587
  
588
end:
16,777✔
589
  taosArrayDestroy(uidList);
16,777✔
590
  taosArrayDestroy(uidListDel);
16,777✔
591
  taosArrayDestroy(uidListDelOutTbl);
16,777✔
592
  tDecoderClear(&decoder);
16,777✔
593
  return code;
16,777✔
594
}
595

596
static int32_t qStreamModifyTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* tableListDel) {
48,805✔
597
  int32_t      code = 0;
48,805✔
598
  int32_t      lino = 0;
48,805✔
599
  void* pTask = sStreamReaderInfo->pTask;
48,805✔
600
  
601
  taosWLockLatch(&sStreamReaderInfo->lock);
48,805✔
602
  int32_t totalSize = taosArrayGetSize(tableListDel);
48,805✔
603
  for (int32_t i = 0; i < totalSize; ++i) {
48,805✔
604
    int64_t* uid = taosArrayGet(tableListDel, i);
×
605
    if (uid == NULL) {
×
606
      continue;
×
607
    }
608
    STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, *uid));
×
609
  }
610

611
  totalSize = taosArrayGetSize(tableListAdd);
48,805✔
612
  for (int32_t i = 0; i < totalSize; ++i) {
80,428✔
613
    STableKeyInfo* info = taosArrayGet(tableListAdd, i);
31,623✔
614
    if (info == NULL) {
31,623✔
615
      continue;
×
616
    }
617
    int ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
31,623✔
618
    if (ret != 0){
31,623✔
619
      ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, ret);
6,987✔
620
      continue;
6,987✔
621
    }
622
    ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
24,636✔
623
    if (ret != 0){
24,636✔
624
      ST_TASK_WLOG("%s cacheTag calc failed for uid:%" PRId64",code:%d", __func__, info->uid, ret);
×
625
      continue;
×
626
    }
627
    STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, info->uid));
24,636✔
628
    STREAM_CHECK_RET_GOTO(qStreamSetTableList(&sStreamReaderInfo->tableList, info->uid, info->groupId));
24,636✔
629
  }
630

631
end:
48,805✔
632
  taosWUnLockLatch(&sStreamReaderInfo->lock);
48,805✔
633
  return code;
48,805✔
634
}
635

636
static int32_t processTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* uidList, SArray** tableList) {
48,805✔
637
  int32_t code = 0;
48,805✔
638
  int32_t lino = 0;
48,805✔
639
  SNodeList* groupNew = NULL;   
48,805✔
640

641
  if (taosArrayGetSize(uidList) == 0) {
48,805✔
642
    return 0;
17,182✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
31,623✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
31,623✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

649
end:
31,623✔
650
  nodesDestroyList(groupNew);
31,623✔
651
  return code;
31,623✔
652
}
653

654
static int32_t scanCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
26,167✔
655
                             int64_t ver) {
656
  int32_t  code = 0;
26,167✔
657
  int32_t  lino = 0;
26,167✔
658
  SDecoder decoder = {0};
26,167✔
659
  SArray*  uidList = NULL;
26,167✔
660
  SArray*  tableList = NULL;
26,167✔
661
  SArray*  uidListAdd = NULL;
26,167✔
662
  void* pTask = sStreamReaderInfo->pTask;
26,167✔
663

664
  SVCreateTbBatchReq req = {0};
26,167✔
665
  tDecoderInit(&decoder, data, len);
26,167✔
666
  
667
  STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbBatchReq(&decoder, &req));
26,167✔
668

669
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
26,167✔
670
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
26,167✔
671

672
  if (sStreamReaderInfo->isVtableStream) {
26,167✔
673
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
4,874✔
674
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
4,874✔
675
  }
676
  
677
  SVCreateTbReq* pCreateReq = NULL;
26,167✔
678
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
52,334✔
679
    pCreateReq = req.pReqs + iReq;
26,167✔
680
    if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
26,167✔
681
      ST_TASK_DLOG("stream reader scan create table jump, %s", pCreateReq->name);
17,182✔
682
      continue;
17,182✔
683
    }
684
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
8,985✔
685
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
17,970✔
686
  }
687
  
688
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
26,167✔
689
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
26,167✔
690
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
26,167✔
691

692
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
26,167✔
693
end:
26,167✔
694
  taosArrayDestroy(uidList);
26,167✔
695
  taosArrayDestroy(uidListAdd);
26,167✔
696
  taosArrayDestroy(tableList);
26,167✔
697
  tDeleteSVCreateTbBatchReq(&req);
26,167✔
698
  tDecoderClear(&decoder);
26,167✔
699
  return code;
26,167✔
700
}
701

702
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq, int64_t ver) {
1,278,543✔
703
  int32_t  code = 0;
1,278,543✔
704
  int32_t  lino = 0;
1,278,543✔
705
  void*    pTask = sStreamReaderInfo->pTask;
1,278,543✔
706
  SArray*  uidList = NULL;
1,279,237✔
707
  SArray*  tableList = NULL;
1,279,237✔
708

709
  ST_TASK_DLOG("%s start, name:%s uid:%"PRId64, __func__, pCreateReq->name, pCreateReq->uid);
1,278,986✔
710
  if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false) ||
1,281,658✔
711
      ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
2,049✔
712
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
1,277,258✔
713
    goto end;
1,277,015✔
714
  }
715
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,495✔
716
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,495✔
717
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
2,990✔
718
  ST_TASK_DLOG("stream reader scan auto create table %s", pCreateReq->name);
1,495✔
719

720
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,495✔
721
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,495✔
722
end:
1,275,441✔
723
  taosArrayDestroy(uidList);
1,278,623✔
724
  taosArrayDestroy(tableList);
1,277,172✔
725
  return code;
1,276,864✔
726
}
727

728
static bool isColIdInList(SNodeList* colList, col_id_t cid){
476✔
729
  int32_t  code = 0;
476✔
730
  int32_t  lino = 0;
476✔
731
  SNode*  nodeItem = NULL;
476✔
732
  FOREACH(nodeItem, colList) {
1,190✔
733
    SNode*           pNode = ((STargetNode*)nodeItem)->pExpr;
1,190✔
734
    if (nodeType(pNode) == QUERY_NODE_COLUMN) {
1,190✔
735
      SColumnNode*     valueNode = (SColumnNode*)(pNode);
1,190✔
736
      if (cid == valueNode->colId) {
1,190✔
737
        return true;
476✔
738
      }
739
    }
740
  }
741
end:
×
742
  return false;
×
743
}
744

745
static bool isAlteredTable(int8_t action, ETableType tbType) {
26,575✔
746
  if (action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL && tbType == TSDB_CHILD_TABLE) {
26,575✔
747
    return true;
21,143✔
748
  } else if (action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL && tbType == TSDB_SUPER_TABLE) {
5,432✔
749
    return true;
×
750
  } else if ((action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) && 
5,432✔
751
     (tbType == TSDB_VIRTUAL_CHILD_TABLE || tbType == TSDB_VIRTUAL_NORMAL_TABLE)) {
2,128✔
752
    return true;
5,432✔
753
  }
754
  return false;
×
755
}
756

757
void getAlterColId(void* pVnode, int64_t uid, const char* colName, col_id_t* colId) {
476✔
758
  SSchemaWrapper *pSchema = metaGetTableSchema(((SVnode *)pVnode)->pMeta, uid, -1, 1, NULL, 0);
476✔
759
  if (pSchema == NULL) {
476✔
760
    return;
×
761
  }
762
  for (int32_t i = 0; i < pSchema->nCols; i++) {
1,190✔
763
    if (strncmp(pSchema->pSchema[i].name, colName, TSDB_COL_NAME_LEN) == 0) {
1,190✔
764
      *colId = pSchema->pSchema[i].colId;
476✔
765
      break;
476✔
766
    }
767
  }
768
  tDeleteSchemaWrapper(pSchema);
769
  return;
476✔
770
}
771

772
static bool checkAlterCondition() {
×
773
  return true;
×
774
}
775

776
// Handle TSDB_ALTER_TABLE_ALTER_COLUMN_REF and TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
777
static int32_t scanAlterTableColumnRef(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, 
5,432✔
778
                                       SVAlterTbReq* pReq, uint64_t uid, int64_t ver) {
779
  int32_t code = 0;
5,432✔
780
  int32_t lino = 0;
5,432✔
781
  void* pTask = sStreamReaderInfo->pTask;
5,432✔
782
  SArray* uidListAdd = NULL;
5,432✔
783

784
  uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
5,432✔
785
  STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
5,432✔
786

787
  uint64_t id = 0;
5,432✔
788
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListOrigin(sStreamReaderInfo, sStreamReaderInfo->suid, uid, &id), TDB_CODE_SUCCESS);
5,432✔
789

790
  col_id_t colId = 0;
476✔
791
  getAlterColId(sStreamReaderInfo->pVnode, uid, pReq->colName, &colId);
476✔
792
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 0 && !isColIdInList(sStreamReaderInfo->triggerCols, colId)) {
476✔
793
    ST_TASK_ILOG("stream reader scan alter table %s, colId %d not in trigger cols", pReq->tbName, colId);
×
794
    goto end;
×
795
  }
796

797
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListAdd, &uid), terrno);
476✔
798
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
476✔
799

800
  ST_TASK_DLOG("stream reader scan alter table column ref %s", pReq->tbName);
476✔
801

802
end:
5,432✔
803
  taosArrayDestroy(uidListAdd);
5,432✔
804
  STREAM_PRINT_LOG_END_WITHID(code, lino);
5,432✔
805
  return code;
5,432✔
806
}
807

808
static int32_t checkAlter(SStreamTriggerReaderInfo* sStreamReaderInfo, char* tbName, int8_t action, uint64_t *uid) {
26,575✔
809
  int32_t  code = 0;
26,575✔
810
  int32_t  lino = 0;
26,575✔
811
  ETableType tbType = 0;
26,575✔
812
  uint64_t suid = 0;
26,575✔
813

814
  STREAM_CHECK_RET_GOTO(metaGetTableTypeSuidByName(sStreamReaderInfo->pVnode, tbName, &tbType, &suid));
26,575✔
815
  STREAM_CHECK_CONDITION_GOTO(!isAlteredTable(action, tbType), TDB_CODE_SUCCESS);
26,575✔
816
  STREAM_CHECK_CONDITION_GOTO(suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
26,575✔
817
  if (action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
21,161✔
818
    *uid = suid;
×
819
    goto end;
×
820
  }
821
  STREAM_CHECK_RET_GOTO(metaGetTableUidByName(sStreamReaderInfo->pVnode, tbName, uid));
21,161✔
822

823
end:
26,575✔
824
  return code;
26,575✔
825
}
826

827
static SArray* getTableListForAlterSuperTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SVAlterTbReq* pReq){
21,143✔
828
  int32_t code = 0;
21,143✔
829
  int32_t lino = 0;
21,143✔
830
  void* pTask = sStreamReaderInfo->pTask;
21,143✔
831
  SArray* uidList = taosArrayInit(8, sizeof(tb_uid_t));
21,143✔
832
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
21,143✔
833
  for (int32_t i = 0; i < taosArrayGetSize(pReq->tables); i++) {
42,286✔
834
    SUpdateTableTagVal *pTable = taosArrayGet(pReq->tables, i);
21,143✔
835
    uint64_t uid = 0;
21,143✔
836
    code = checkAlter(sStreamReaderInfo, pTable->tbName, pReq->action, &uid);
21,143✔
837
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
21,143✔
838
      code = 0;
×
839
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", pTable->tbName);
×
840
      continue;
×
841
    }
842
    STREAM_CHECK_RET_GOTO(code);
21,143✔
843
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, (const void *)&uid), terrno);
21,143✔
844
  }
845

846
end:
21,143✔
847
  if (code != 0) {
21,143✔
848
    ST_TASK_ELOG("%s failed,code:%d", __func__, code);
×
849
    taosArrayDestroy(uidList);
×
850
    uidList = NULL;
×
851
  }
852
  return uidList;
21,143✔
853
}
854

855
// Handle TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL and TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
856
static int32_t scanAlterTableTagVal(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, 
21,143✔
857
                                    SArray* uidList, int64_t ver) {
858
  int32_t code = 0;
21,143✔
859
  int32_t lino = 0;
21,143✔
860
  void* pTask = sStreamReaderInfo->pTask;
21,143✔
861
  SArray* uidListAdd = NULL;
21,143✔
862
  SArray* uidListDel = NULL;
21,143✔
863
  SArray* tableList = NULL;
21,143✔
864

865
  if (sStreamReaderInfo->isVtableStream) {
21,143✔
866
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
1,477✔
867
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
1,477✔
868
  }
869

870
  uidListDel = taosArrayInit(8, sizeof(tb_uid_t));
21,143✔
871
  STREAM_CHECK_NULL_GOTO(uidListDel, terrno);
21,143✔
872

873
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
21,143✔
874
  STREAM_CHECK_RET_GOTO(qStreamGetDelTable(sStreamReaderInfo, uidList, uidListDel));
21,143✔
875

876
  if (rsp->checkAlter && taosArrayGetSize(uidListDel) > 0 && rsp->totalDataRows > 0) {
21,143✔
877
    rsp->needReturn = true;
×
878
    rsp->ver--;
×
879
    ST_TASK_DLOG("%s stream reader scan alter table need return data", __func__);
×
880
    goto end;
×
881
  }
882

883
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
21,143✔
884
  if (sStreamReaderInfo->isVtableStream) {
21,143✔
885
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
1,477✔
886
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
1,477✔
887
  }
888
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
21,143✔
889

890
  ST_TASK_DLOG("%s stream reader scan alter table tag val", __func__);
21,143✔
891

892
end:
21,143✔
893
  taosArrayDestroy(uidListAdd);
21,143✔
894
  taosArrayDestroy(uidListDel);
21,143✔
895
  taosArrayDestroy(tableList);
21,143✔
896
  STREAM_PRINT_LOG_END_WITHID(code, lino);
21,143✔
897
  return code;
21,143✔
898
}
899

900
static int32_t scanAlterTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len, int64_t ver) {
36,655✔
901
  int32_t  code = 0;
36,655✔
902
  int32_t  lino = 0;
36,655✔
903
  SDecoder decoder = {0};
36,655✔
904
  void* pTask = sStreamReaderInfo->pTask;
36,655✔
905
  SArray* uidList = NULL;
36,415✔
906

907
  ST_TASK_DLOG("%s start", __func__);
36,415✔
908

909
  SVAlterTbReq req = {0};
36,415✔
910
  tDecoderInit(&decoder, data, len);
36,655✔
911
  
912
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
36,655✔
913

914
  STREAM_CHECK_CONDITION_GOTO(req.action != TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL && req.action != TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL && 
36,655✔
915
    req.action != TSDB_ALTER_TABLE_ALTER_COLUMN_REF && req.action != TSDB_ALTER_TABLE_REMOVE_COLUMN_REF, TDB_CODE_SUCCESS);
916

917
  uint64_t uid = 0;
26,815✔
918
  if (req.action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || req.action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
26,575✔
919
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
5,432✔
920
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
5,432✔
921
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", req.tbName);
×
922
      code = 0;
×
923
      goto end;
×
924
    }
925
    STREAM_CHECK_RET_GOTO(scanAlterTableColumnRef(sStreamReaderInfo, rsp, &req, uid, ver));
5,432✔
926
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
21,143✔
927
    uidList = getTableListForAlterSuperTable(sStreamReaderInfo, &req);
21,143✔
928
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
21,143✔
929
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
21,143✔
930
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
×
931
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
×
932
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
×
933
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", req.tbName);
×
934
      code = 0;
×
935
      goto end;
×
936
    }
937
    uidList = taosArrayInit(8, sizeof(uint64_t));
×
938
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
×
939
    STREAM_CHECK_RET_GOTO(vnodeGetCtbIdList(sStreamReaderInfo->pVnode, uid, uidList));
×
940
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
×
941
  }
942

943
  ST_TASK_DLOG("%s stream reader scan alter table", __func__);
26,575✔
944

945
end:
36,415✔
946
  destroyAlterTbReq(&req);
36,655✔
947

948
  taosArrayDestroy(uidList);
36,415✔
949
  tDecoderClear(&decoder);
36,415✔
950
  STREAM_PRINT_LOG_END_WITHID(code, lino);
36,415✔
951
  return code;
36,415✔
952
}
953

954
// static int32_t scanAlterSTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
955
//   int32_t  code = 0;
956
//   int32_t  lino = 0;
957
//   SDecoder decoder = {0};
958
//   SMAlterStbReq reqAlter = {0};
959
//   SVCreateStbReq req = {0};
960
//   tDecoderInit(&decoder, data, len);
961
//   void* pTask = sStreamReaderInfo->pTask;
962
  
963
//   STREAM_CHECK_RET_GOTO(tDecodeSVCreateStbReq(&decoder, &req));
964
//   STREAM_CHECK_CONDITION_GOTO(req.suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
965
//   if (req.alterOriData != 0) {
966
//     STREAM_CHECK_RET_GOTO(tDeserializeSMAlterStbReq(req.alterOriData, req.alterOriDataLen, &reqAlter));
967
//     STREAM_CHECK_CONDITION_GOTO(reqAlter.alterType != TSDB_ALTER_TABLE_DROP_TAG && reqAlter.alterType != TSDB_ALTER_TABLE_UPDATE_TAG_NAME, TDB_CODE_SUCCESS);
968
//   }
969
  
970
//   STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo));
971

972
//   ST_TASK_DLOG("stream reader scan alter suid %" PRId64, req.suid);
973
// end:
974
//   tFreeSMAltertbReq(&reqAlter);
975
//   tDecoderClear(&decoder);
976
//   return code;
977
// }
978

979
// static int32_t scanDropSTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
980
//   int32_t  code = 0;
981
//   int32_t  lino = 0;
982
//   SDecoder decoder = {0};
983
//   void* pTask = sStreamReaderInfo->pTask;
984

985
//   SVDropStbReq req = {0};
986
//   tDecoderInit(&decoder, data, len);
987
//   STREAM_CHECK_RET_GOTO(tDecodeSVDropStbReq(&decoder, &req));
988
//   STREAM_CHECK_CONDITION_GOTO(req.suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
989

990
//   ST_TASK_DLOG("stream reader scan drop suid %" PRId64, req.suid);
991
// end:
992
//   tDecoderClear(&decoder);
993
//   return code;
994
// }
995

996
static int32_t scanSubmitTbDataForMeta(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* gidHash, int64_t ver) {
5,266,550✔
997
  int32_t code = 0;
5,266,550✔
998
  int32_t lino = 0;
5,266,550✔
999
  WalMetaResult walMeta = {0};
5,266,550✔
1000
  SSubmitTbData submitTbData = {0};
5,267,063✔
1001
  
1002
  if (tStartDecode(pCoder) < 0) {
5,266,580✔
1003
    code = TSDB_CODE_INVALID_MSG;
×
1004
    TSDB_CHECK_CODE(code, lino, end);
×
1005
  }
1006

1007
  uint8_t       version = 0;
5,267,956✔
1008
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
5,268,242✔
1009
    code = TSDB_CODE_INVALID_MSG;
×
1010
    TSDB_CHECK_CODE(code, lino, end);
×
1011
  }
1012
  version = (submitTbData.flags >> 8) & 0xff;
5,268,242✔
1013
  submitTbData.flags = submitTbData.flags & 0xff;
5,268,242✔
1014

1015
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1016
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
5,268,242✔
1017
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
381,285✔
1018
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
380,823✔
1019
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
380,823✔
1020
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
381,285✔
1021
  }
1022

1023
  // submit data
1024
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
5,267,319✔
1025
    code = TSDB_CODE_INVALID_MSG;
×
1026
    TSDB_CHECK_CODE(code, lino, end);
×
1027
  }
1028
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
5,267,479✔
1029
    code = TSDB_CODE_INVALID_MSG;
×
1030
    TSDB_CHECK_CODE(code, lino, end);
×
1031
  }
1032

1033
  if (!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
5,267,479✔
1034
    goto end;
4,479,638✔
1035
  }
1036
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
789,627✔
1037
    code = TSDB_CODE_INVALID_MSG;
×
1038
    TSDB_CHECK_CODE(code, lino, end);
×
1039
  }
1040

1041
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
789,627✔
1042
    uint64_t nColData = 0;
×
1043
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1044
      code = TSDB_CODE_INVALID_MSG;
×
1045
      TSDB_CHECK_CODE(code, lino, end);
×
1046
    }
1047

1048
    SColData colData = {0};
×
1049
    code = tDecodeColData(version, pCoder, &colData, false);
×
1050
    if (code) {
×
1051
      code = TSDB_CODE_INVALID_MSG;
×
1052
      TSDB_CHECK_CODE(code, lino, end);
×
1053
    }
1054

1055
    if (colData.flag != HAS_VALUE) {
×
1056
      code = TSDB_CODE_INVALID_MSG;
×
1057
      TSDB_CHECK_CODE(code, lino, end);
×
1058
    }
1059
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
1060
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
1061

1062
    for (uint64_t i = 1; i < nColData; i++) {
×
1063
      code = tDecodeColData(version, pCoder, &colData, true);
×
1064
      if (code) {
×
1065
        code = TSDB_CODE_INVALID_MSG;
×
1066
        TSDB_CHECK_CODE(code, lino, end);
×
1067
      }
1068
    }
1069
  } else {
1070
    uint64_t nRow = 0;
789,627✔
1071
    if (tDecodeU64v(pCoder, &nRow) < 0) {
788,925✔
1072
      code = TSDB_CODE_INVALID_MSG;
×
1073
      TSDB_CHECK_CODE(code, lino, end);
×
1074
    }
1075

1076
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
2,773,768✔
1077
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
1,984,381✔
1078
      pCoder->pos += pRow->len;
1,984,846✔
1079
      if (iRow == 0){
1,984,846✔
1080
#ifndef NO_UNALIGNED_ACCESS
1081
        walMeta.skey = pRow->ts;
789,147✔
1082
#else
1083
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1084
#endif
1085
      }
1086
      if (iRow == nRow - 1) {
1,985,326✔
1087
#ifndef NO_UNALIGNED_ACCESS
1088
        walMeta.ekey = pRow->ts;
789,147✔
1089
#else
1090
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1091
#endif
1092
      }
1093
    }
1094
  }
1095

1096
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
789,144✔
1097
  if (data != NULL) {
788,901✔
1098
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
1,004✔
1099
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
1,004✔
1100
  } else {
1101
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
787,897✔
1102
  }
1103

1104
end:
5,260,748✔
1105
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
5,267,816✔
1106
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
5,267,631✔
1107
  tEndDecode(pCoder);
5,267,582✔
1108
  return code;
5,267,020✔
1109
}
1110

1111
static int32_t scanSubmitDataForMeta(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len, int64_t ver) {
5,266,010✔
1112
  int32_t  code = 0;
5,266,010✔
1113
  int32_t  lino = 0;
5,266,010✔
1114
  SDecoder decoder = {0};
5,266,010✔
1115
  SSHashObj* gidHash = NULL;
5,266,247✔
1116
  void* pTask = sStreamReaderInfo->pTask;
5,266,247✔
1117

1118
  tDecoderInit(&decoder, data, len);
5,267,219✔
1119
  if (tStartDecode(&decoder) < 0) {
5,267,705✔
1120
    code = TSDB_CODE_INVALID_MSG;
×
1121
    TSDB_CHECK_CODE(code, lino, end);
×
1122
  }
1123

1124
  uint64_t nSubmitTbData = 0;
5,268,025✔
1125
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
5,268,671✔
1126
    code = TSDB_CODE_INVALID_MSG;
×
1127
    TSDB_CHECK_CODE(code, lino, end);
×
1128
  }
1129

1130
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
5,268,671✔
1131
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
5,264,571✔
1132

1133
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
10,531,351✔
1134
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
5,265,575✔
1135
  }
1136
  tEndDecode(&decoder);
5,265,776✔
1137

1138
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
5,254,804✔
1139
  int32_t iter = 0;
5,265,581✔
1140
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
5,266,040✔
1141
  while (px != NULL) {
6,051,603✔
1142
    WalMetaResult* pMeta = (WalMetaResult*)px;
787,438✔
1143
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
787,438✔
1144
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
787,891✔
1145
    rsp->totalRows++;
787,891✔
1146
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
787,651✔
1147
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1148
    px = tSimpleHashIterate(gidHash, px, &iter);
787,651✔
1149
  }
1150
end:
5,264,165✔
1151
  tDecoderClear(&decoder);
5,264,412✔
1152
  tSimpleHashCleanup( gidHash);
5,265,284✔
1153
  return code;
5,264,316✔
1154
}
1155

1156
static int32_t createBlockForTsdbMeta(SSDataBlock** pBlock, bool isVTable) {
121,880✔
1157
  int32_t code = 0;
121,880✔
1158
  int32_t lino = 0;
121,880✔
1159
  SArray* schemas = taosArrayInit(8, sizeof(SSchema));
121,880✔
1160
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
121,880✔
1161

1162
  int32_t index = 1;
121,880✔
1163
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // skey
121,880✔
1164
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // ekey
121,880✔
1165
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
121,880✔
1166
  if (!isVTable) {
121,880✔
1167
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_UBIGINT, LONG_BYTES, index++))  // gid
51,902✔
1168
  }
1169
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))     // nrows
121,880✔
1170

1171
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
121,880✔
1172

1173
end:
121,880✔
1174
  taosArrayDestroy(schemas);
121,880✔
1175
  return code;
121,880✔
1176
}
1177

1178
static int32_t createBlockForWalMetaNew(SSDataBlock** pBlock) {
199,048✔
1179
  int32_t code = 0;
199,048✔
1180
  int32_t lino = 0;
199,048✔
1181
  SArray* schemas = NULL;
199,048✔
1182

1183
  schemas = taosArrayInit(8, sizeof(SSchema));
199,048✔
1184
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
199,048✔
1185

1186
  int32_t index = 0;
199,048✔
1187
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid non vtable/uid vtable
199,048✔
1188
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // skey
199,048✔
1189
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ekey
199,048✔
1190
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
199,048✔
1191

1192
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
199,048✔
1193

1194
end:
199,048✔
1195
  taosArrayDestroy(schemas);
199,048✔
1196
  return code;
199,048✔
1197
}
1198

1199
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int64_t ver) {
297,675✔
1200
  int32_t code = 0;
297,675✔
1201
  int32_t lino = 0;
297,675✔
1202
  void* pTask = sStreamReaderInfo->pTask;
297,675✔
1203

1204
  ST_TASK_DLOG("%s check meta msg, stream ver:%" PRId64 ", wal ver:%" PRId64, __func__, sStreamReaderInfo->tableList.version, ver);
297,915✔
1205

1206
  SDecoder dcoder = {0};
297,915✔
1207
  tDecoderInit(&dcoder, data, len);
298,157✔
1208
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
298,157✔
1209
    if (rsp->deleteBlock == NULL) {
25,064✔
1210
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
8,068✔
1211
    }
1212
      
1213
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
25,064✔
1214
  } else if (msgType == TDMT_VND_DROP_TABLE && 
273,093✔
1215
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
33,057✔
1216
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
16,777✔
1217
  // } else if (msgType == TDMT_VND_DROP_STB) {
1218
  //   STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
1219
  } else if (msgType == TDMT_VND_CREATE_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
256,316✔
1220
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
26,167✔
1221
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
230,149✔
1222
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1223
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
204,084✔
1224
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
36,655✔
1225
  }
1226

1227
end:
298,157✔
1228
  tDecoderClear(&dcoder);
297,915✔
1229
  return code;
297,917✔
1230
}
1231
static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
2,294,379✔
1232
                       int64_t ctime) {
1233
  int32_t code = 0;
2,294,379✔
1234
  int32_t lino = 0;
2,294,379✔
1235
  void* pTask = sStreamReaderInfo->pTask;
2,294,379✔
1236

1237
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
2,294,379✔
1238
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
2,291,334✔
1239
  code = walReaderSeekVer(pWalReader, rsp->ver);
2,291,334✔
1240
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
2,291,855✔
1241
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,001,530✔
1242
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
1243
      rsp->verTime = 0;
×
1244
    } else {
1245
      rsp->verTime = taosGetTimestampUs();
2,002,591✔
1246
    }
1247
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
2,002,226✔
1248
    code = TSDB_CODE_SUCCESS;
2,003,318✔
1249
    goto end;
2,003,318✔
1250
  }
1251
  STREAM_CHECK_RET_GOTO(code);
290,325✔
1252

1253
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
290,325✔
1254
  while (1) {
5,444,777✔
1255
    code = walNextValidMsg(pWalReader, true);
5,734,117✔
1256
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,733,511✔
1257
      rsp->verTime = taosGetTimestampUs();
290,312✔
1258
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
290,312✔
1259
      code = TSDB_CODE_SUCCESS;
290,310✔
1260
      goto end;
290,310✔
1261
    }
1262
    STREAM_CHECK_RET_GOTO(code);
5,444,276✔
1263
    rsp->ver = pWalReader->curVersion;
5,444,276✔
1264
    SWalCont* wCont = &pWalReader->pHead->head;
5,445,243✔
1265
    rsp->verTime = wCont->ingestTs;
5,444,483✔
1266
    if (wCont->ingestTs / 1000 > ctime) break;
5,443,350✔
1267
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
5,442,436✔
1268
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
5,444,633✔
1269
    int64_t ver = wCont->version;
5,444,568✔
1270

1271
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
5,445,263✔
1272
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1273
    if (wCont->msgType == TDMT_VND_SUBMIT) {
5,446,706✔
1274
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
5,267,705✔
1275
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
5,267,702✔
1276
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
5,267,702✔
1277
    } else {
1278
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
178,480✔
1279
    }
1280

1281
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
5,444,000✔
1282
      break;
×
1283
    }
1284
  }
1285

1286
end:
2,293,628✔
1287
  walCloseReader(pWalReader);
2,293,628✔
1288
  return code;
2,291,701✔
1289
}
1290

1291
int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid, col_id_t colId, SRWLatch* lock) {
41,198,004✔
1292
  int32_t     code = 0;
41,198,004✔
1293
  int32_t     lino = 0;
41,198,004✔
1294
  SMetaReader mr = {0};
41,198,004✔
1295
  SArray* tagCache = NULL;
41,202,828✔
1296
  char* data = NULL;
41,204,325✔
1297

1298
  if (lock != NULL) taosWLockLatch(lock);
41,203,666✔
1299
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
41,207,510✔
1300
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,224,784✔
1301
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,225,068✔
1302
  if (uidData == NULL) {
2,225,024✔
1303
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,205,303✔
1304
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,205,303✔
1305
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,205,303✔
1306
      taosArrayDestroy(tagCache);
×
1307
      code = terrno;
×
1308
      goto end;
×
1309
    }
1310
  } else {
1311
    tagCache = *(SArray**)uidData;
19,721✔
1312
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
19,721✔
1313
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
19,721✔
1314
  }
1315
  
1316
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,225,024✔
1317
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,225,024✔
1318
  api->metaReaderFn.readerReleaseLock(&mr);
2,223,040✔
1319
  STREAM_CHECK_RET_GOTO(code);
2,223,646✔
1320
  
1321
  for (int32_t j = 0; j < numOfExpr; ++j) {
7,874,336✔
1322
    const SExprInfo* pExpr1 = &pExprInfo[j];
5,657,537✔
1323
    int32_t functionId = pExpr1->pExpr->_function.functionId;
5,657,878✔
1324
    col_id_t cid = 0;
5,659,182✔
1325
    // this is to handle the tbname
1326
    if (fmIsScanPseudoColumnFunc(functionId)) {
5,659,182✔
1327
      int32_t fType = pExpr1->pExpr->_function.functionType;
525,700✔
1328
      if (fType == FUNCTION_TYPE_TBNAME) {
525,216✔
1329
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
525,216✔
1330
        STREAM_CHECK_NULL_GOTO(data, terrno);
525,492✔
1331
        STR_TO_VARSTR(data, mr.me.name)
525,492✔
1332
      }
1333
      cid = -1;
525,719✔
1334
    } else {  // these are tags
1335
      const char* p = NULL;
5,131,778✔
1336
      char* pData = NULL;
5,131,778✔
1337
      int8_t type = pExpr1->base.resSchema.type;
5,131,778✔
1338
      int32_t len = pExpr1->base.resSchema.bytes;
5,131,778✔
1339
      STagVal tagVal = {0};
5,132,846✔
1340
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
5,133,626✔
1341
      cid = tagVal.cid;
5,132,846✔
1342
      if (colId != 0 && cid != colId) {
5,132,846✔
1343
        continue;
1,032✔
1344
      }
1345
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
5,131,814✔
1346

1347
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
5,125,900✔
1348
        pData = tTagValToData((const STagVal*)p, false);
5,123,140✔
1349
      } else {
1350
        pData = (char*)p;
2,760✔
1351
      }
1352

1353
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
5,128,632✔
1354
        if (type == TSDB_DATA_TYPE_JSON) {
2,614,016✔
1355
          len = getJsonValueLen(pData);
×
1356
        }
1357
        data = taosMemoryCalloc(1, len);
2,614,016✔
1358
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,612,066✔
1359
        (void)memcpy(data, pData, len);
2,612,066✔
1360
      } else {
1361
        data = pData;
2,514,616✔
1362
      }
1363
    }
1364
    if (uidData == NULL){
5,652,507✔
1365
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
11,233,095✔
1366
    } else {
1367
      void* pre = taosArrayGetP(tagCache, j);
38,199✔
1368
      taosMemoryFree(pre);
38,199✔
1369
      taosArraySet(tagCache, j, &data);
38,199✔
1370
    }
1371
    data = NULL;
5,656,047✔
1372
  }
1373

1374
end:
41,205,500✔
1375
  taosMemoryFree(data);
41,202,386✔
1376
  api->metaReaderFn.clearReader(&mr);
41,201,740✔
1377
  if (lock != NULL) taosWUnLockLatch(lock);
41,196,885✔
1378
  return code;
41,200,429✔
1379
}
1380

1381
int32_t fillTag(SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr,
115,208,376✔
1382
                uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, SRWLatch* lock) {
1383
  int32_t     code = 0;
115,208,376✔
1384
  int32_t     lino = 0;
115,208,376✔
1385
  SArray* tagCache = NULL;
115,208,376✔
1386
  if (numOfExpr == 0) {
115,208,376✔
1387
    return TSDB_CODE_SUCCESS;
38,589,007✔
1388
  }
1389

1390
  taosRLockLatch(lock);
76,619,369✔
1391
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
76,673,919✔
1392
  if (uidData == NULL) {
76,664,646✔
1393
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1394
  } else {
1395
    tagCache = *(SArray**)uidData;
76,664,646✔
1396
    if(taosArrayGetSize(tagCache) != numOfExpr) {
76,664,646✔
1397
      stError("%s numOfExpr:%d,tagCache size:%zu", __func__, numOfExpr, taosArrayGetSize(tagCache));
×
1398
      tagCache = NULL;
×
1399
    }
1400
  }
1401
  
1402
  for (int32_t j = 0; j < numOfExpr; ++j) {
344,768,962✔
1403
    const SExprInfo* pExpr1 = &pExprInfo[j];
268,099,560✔
1404
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
268,126,112✔
1405

1406
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
268,145,272✔
1407
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
267,862,949✔
1408
    int32_t functionId = pExpr1->pExpr->_function.functionId;
267,862,949✔
1409

1410
    // this is to handle the tbname
1411
    if (fmIsScanPseudoColumnFunc(functionId)) {
267,941,312✔
1412
      int32_t fType = pExpr1->pExpr->_function.functionType;
2,861,087✔
1413
      if (fType == FUNCTION_TYPE_TBNAME) {
2,861,045✔
1414
        pColInfoData->info.colId = -1;
2,861,045✔
1415
      }
1416
    } 
1417
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
267,864,722✔
1418

1419
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
267,856,850✔
1420
    if (isNullVal) {
267,893,666✔
1421
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1422
    } else {
1423
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
267,893,666✔
1424
        for (uint32_t i = 0; i < numOfRows; i++){
2,147,483,647✔
1425
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
2,147,483,647✔
1426
        }
1427
      }
1428
      code = colDataSetNItems(pColInfoData, currentRow, (const char*)data, numOfRows, numOfBlocks, false);
267,868,390✔
1429
      STREAM_CHECK_RET_GOTO(code);
268,110,699✔
1430
    }
1431
  }
1432
end:
76,669,402✔
1433
  taosRUnLockLatch(lock);
76,669,402✔
1434
  return code;
76,670,589✔
1435
}
1436

1437
static int32_t processTag(SStreamTriggerReaderInfo* info, bool isCalc, 
2,706,433✔
1438
  uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks) {
1439
  int32_t     code = 0;
2,706,433✔
1440
  int32_t     lino = 0;
2,706,433✔
1441

1442
  void* pTask = info->pTask;
2,706,433✔
1443
  ST_TASK_DLOG("%s start. rows:%" PRIu32 ",uid:%"PRIu64, __func__,  numOfRows, uid);
2,706,433✔
1444
  
1445
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
2,706,433✔
1446
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
2,706,674✔
1447
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
2,706,192✔
1448
  
1449
  code = fillTag(metaCache, pExprInfo, numOfExpr, uid, pBlock, currentRow, numOfRows, numOfBlocks, &info->lock);
2,706,674✔
1450
  STREAM_CHECK_RET_GOTO(code);
2,707,157✔
1451

1452
end:
2,707,157✔
1453
  return code;
2,707,157✔
1454
}
1455

1456
int32_t getRowRange(SColData* pCol, STimeWindow* window, int32_t* rowStart, int32_t* rowEnd, int32_t* nRows) {
×
1457
  int32_t code = 0;
×
1458
  int32_t lino = 0;
×
1459
  *nRows = 0;
×
1460
  *rowStart = 0;
×
1461
  *rowEnd = pCol->nVal;
×
1462
  if (window != NULL) {
×
1463
    SColVal colVal = {0};
×
1464
    *rowStart = -1;
×
1465
    *rowEnd = -1;
×
1466
    for (int32_t k = 0; k < pCol->nVal; k++) {
×
1467
      STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, k, &colVal));
×
1468
      int64_t ts = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
×
1469
      if (ts >= window->skey && *rowStart == -1) {
×
1470
        *rowStart = k;
×
1471
      }
1472
      if (ts > window->ekey && *rowEnd == -1) {
×
1473
        *rowEnd = k;
×
1474
      }
1475
    }
1476
    STREAM_CHECK_CONDITION_GOTO(*rowStart == -1 || *rowStart == *rowEnd, TDB_CODE_SUCCESS);
×
1477

1478
    if (*rowStart != -1 && *rowEnd == -1) {
×
1479
      *rowEnd = pCol->nVal;
×
1480
    }
1481
  }
1482
  *nRows = *rowEnd - *rowStart;
×
1483

1484
end:
×
1485
  return code;
×
1486
}
1487

1488
static int32_t setColData(int64_t rows, int32_t rowStart, int32_t rowEnd, SColData* colData, SColumnInfoData* pColData) {
×
1489
  int32_t code = 0;
×
1490
  int32_t lino = 0;
×
1491
  for (int32_t k = rowStart; k < rowEnd; k++) {
×
1492
    SColVal colVal = {0};
×
1493
    STREAM_CHECK_RET_GOTO(tColDataGetValue(colData, k, &colVal));
×
1494
    STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, rows + k - rowStart, VALUE_GET_DATUM(&colVal.value, colVal.value.type),
×
1495
                                        !COL_VAL_IS_VALUE(&colVal)));
1496
  }
1497
  end:
×
1498
  return code;
×
1499
}
1500

1501
static int32_t getColId(int64_t suid, int64_t uid, int16_t i, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, int16_t* colId) {
1,682,279✔
1502
  int32_t code = 0;
1,682,279✔
1503
  int32_t lino = 0;
1,682,279✔
1504
  int64_t id[2] = {suid, uid};
1,682,279✔
1505
  taosRLockLatch(&sStreamReaderInfo->lock);
1,682,279✔
1506
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
1,682,519✔
1507
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
1,682,039✔
1508
  SSHashObj* uInfo = *(SSHashObj **)px;
1,682,039✔
1509
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
1,682,039✔
1510
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
1,682,039✔
1511
  if (tmp != NULL) {
1,681,799✔
1512
    *colId = *tmp;
1,444,884✔
1513
  } else {
1514
    *colId = -1;
236,915✔
1515
  }
1516

1517
end:
1,682,039✔
1518
  taosRUnLockLatch(&sStreamReaderInfo->lock);
1,681,799✔
1519
  return code;
1,682,039✔
1520
}
1521

1522
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
3,130,948✔
1523
  int32_t code = 0;
3,130,948✔
1524
  int32_t lino = 0;
3,130,948✔
1525
  int64_t id = suid != 0 ? suid : uid;
3,130,948✔
1526
  if (sStreamReaderInfo->isVtableStream) {
3,130,948✔
1527
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
660,279✔
1528
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
660,279✔
1529
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
18,958✔
1530
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
18,958✔
1531
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
18,958✔
1532
      if (code != 0) {
18,958✔
1533
        taosMemoryFree(*schema);
×
1534
        goto end;
×
1535
      }
1536
    } else {
1537
      *schema = *schemaTmp;
641,321✔
1538
    }
1539
  } else {
1540
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
2,470,667✔
1541
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
80,826✔
1542
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
80,826✔
1543
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
80,826✔
1544
    }
1545
    *schema = sStreamReaderInfo->triggerTableSchema;
2,470,426✔
1546
  }
1547
  
1548
end:
3,131,672✔
1549
  return code;
3,131,672✔
1550
}
1551

1552
static int32_t scanSubmitTbData(SVnode* pVnode, SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,797,270✔
1553
  SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
1554
  int32_t code = 0;
3,797,270✔
1555
  int32_t lino = 0;
3,797,270✔
1556
  uint64_t id = 0;
3,797,270✔
1557
  WalMetaResult walMeta = {0};
3,797,995✔
1558
  void* pTask = sStreamReaderInfo->pTask;
3,798,237✔
1559
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
3,797,767✔
1560

1561
  if (tStartDecode(pCoder) < 0) {
3,797,510✔
1562
    ST_TASK_ELOG("vgId:%d %s invalid submit data", TD_VID(pVnode), __func__);
×
1563
    code = TSDB_CODE_INVALID_MSG;
×
1564
    TSDB_CHECK_CODE(code, lino, end);
×
1565
  }
1566

1567
  SSubmitTbData submitTbData = {0};
3,799,446✔
1568
  uint8_t       version = 0;
3,799,205✔
1569
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
3,798,981✔
1570
    ST_TASK_ELOG("vgId:%d %s invalid submit data flags", TD_VID(pVnode), __func__);
×
1571
    code = TSDB_CODE_INVALID_MSG;
×
1572
    TSDB_CHECK_CODE(code, lino, end);
×
1573
  }
1574
  version = (submitTbData.flags >> 8) & 0xff;
3,798,981✔
1575
  submitTbData.flags = submitTbData.flags & 0xff;
3,798,981✔
1576
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1577
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
3,798,981✔
1578
    if (tStartDecode(pCoder) < 0) {
30,529✔
1579
      ST_TASK_ELOG("vgId:%d %s invalid auto create table data", TD_VID(pVnode), __func__);
×
1580
      code = TSDB_CODE_INVALID_MSG;
×
1581
      TSDB_CHECK_CODE(code, lino, end);
×
1582
    }
1583
    tEndDecode(pCoder);
30,529✔
1584
  }
1585

1586
  // submit data
1587
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
3,798,944✔
1588
    ST_TASK_ELOG("vgId:%d %s invalid submit data suid", TD_VID(pVnode), __func__);
×
1589
    code = TSDB_CODE_INVALID_MSG;
×
1590
    TSDB_CHECK_CODE(code, lino, end);
×
1591
  }
1592
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
3,798,961✔
1593
    ST_TASK_ELOG("vgId:%d %s invalid submit data uid", TD_VID(pVnode), __func__);
×
1594
    code = TSDB_CODE_INVALID_MSG;
×
1595
    TSDB_CHECK_CODE(code, lino, end);
×
1596
  }
1597

1598
  ST_TASK_DLOG("%s uid:%" PRId64 ", suid:%" PRId64 ", ver:%" PRId64, __func__, submitTbData.uid, submitTbData.suid, ver);
3,798,961✔
1599

1600
  if (rsp->uidHash != NULL) {
3,799,220✔
1601
    uint64_t* gid = tSimpleHashGet(rsp->uidHash, &submitTbData.uid, LONG_BYTES);
1,810,022✔
1602
    STREAM_CHECK_CONDITION_GOTO(gid == NULL, TDB_CODE_SUCCESS);
1,810,506✔
1603
    ST_TASK_DLOG("%s get uid gid from uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, submitTbData.uid, submitTbData.suid, *gid);
1,810,506✔
1604
    id = *gid;
1,810,506✔
1605
  } else {
1606
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
1,989,422✔
1607
  }
1608

1609
  walMeta.id = id;
3,131,430✔
1610
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
3,131,430✔
1611

1612
  if (ranges != NULL){
3,131,430✔
1613
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
1,810,264✔
1614
    if (timerange == NULL) goto end;;
1,810,023✔
1615
    int64_t* pRange = (int64_t*)timerange;
1,810,023✔
1616
    window.skey = pRange[0];
1,810,023✔
1617
    window.ekey = pRange[1];
1,810,023✔
1618
    ST_TASK_DLOG("%s get time range from ranges, uid:%" PRId64 ", suid:%" PRId64 ", gid:%" PRIu64 ", skey:%" PRId64 ", ekey:%" PRId64,
1,810,023✔
1619
      __func__, submitTbData.uid, submitTbData.suid, id, window.skey, window.ekey);
1620
  }
1621
  
1622
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,130,463✔
1623
    ST_TASK_ELOG("vgId:%d %s invalid submit data sver", TD_VID(pVnode), __func__);
×
1624
    code = TSDB_CODE_INVALID_MSG;
×
1625
    TSDB_CHECK_CODE(code, lino, end);
×
1626
  }
1627

1628
  STSchema*    schema = NULL;
3,130,463✔
1629
  STREAM_CHECK_RET_GOTO(getSchemas(pVnode, submitTbData.suid, submitTbData.uid, submitTbData.sver, sStreamReaderInfo, &schema));
3,130,463✔
1630

1631
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
3,131,430✔
1632
  int32_t blockStart = 0;
3,131,434✔
1633
  int32_t numOfRows = 0;
3,131,434✔
1634
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
3,130,708✔
1635
    uint64_t nColData = 0;
×
1636
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1637
      ST_TASK_ELOG("vgId:%d %s invalid submit data nColData", TD_VID(pVnode), __func__);
×
1638
      code = TSDB_CODE_INVALID_MSG;
×
1639
      TSDB_CHECK_CODE(code, lino, end);
×
1640
    }
1641

1642
    SColData colData = {0};
×
1643
    code = tDecodeColData(version, pCoder, &colData, false);
×
1644
    if (code) {
×
1645
      ST_TASK_ELOG("vgId:%d %s invalid submit data colData", TD_VID(pVnode), __func__);
×
1646
      code = TSDB_CODE_INVALID_MSG;
×
1647
      TSDB_CHECK_CODE(code, lino, end);
×
1648
    }
1649

1650
    if (colData.flag != HAS_VALUE) {
×
1651
      ST_TASK_ELOG("vgId:%d %s invalid submit data colData flag", TD_VID(pVnode), __func__);
×
1652
      code = TSDB_CODE_INVALID_MSG;
×
1653
      TSDB_CHECK_CODE(code, lino, end);
×
1654
    }
1655
    
1656
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
1657
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
1658

1659
    int32_t rowStart = 0;
×
1660
    int32_t rowEnd = 0;
×
1661
    STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, &numOfRows));
×
1662
    STREAM_CHECK_CONDITION_GOTO(numOfRows <= 0, TDB_CODE_SUCCESS);
×
1663

1664
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
×
1665
    blockStart = pSlice->currentRowIdx;
×
1666
    int32_t pos = pCoder->pos;
×
1667
    for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {
×
1668
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
×
1669
      STREAM_CHECK_NULL_GOTO(pColData, terrno);
×
1670
      if (pColData->info.colId <= -1) {
×
1671
        pColData->hasNull = true;
×
1672
        continue;
×
1673
      }
1674
      if (pColData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
×
1675
        STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colData, pColData));
×
1676
        continue;
×
1677
      }
1678

1679
      pCoder->pos = pos;
×
1680

1681
      int16_t colId = 0;
×
1682
      if (sStreamReaderInfo->isVtableStream){
×
1683
        STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
×
1684
        ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
×
1685
      } else {
1686
        colId = pColData->info.colId;
×
1687
      }
1688
      
1689
      uint64_t j = 1;
×
1690
      for (; j < nColData; j++) {
×
1691
        int16_t cid = 0;
×
1692
        int32_t posTmp = pCoder->pos;
×
1693
        pCoder->pos += INT_BYTES;
×
1694
        if ((code = tDecodeI16v(pCoder, &cid))) return code;
×
1695
        pCoder->pos = posTmp;
×
1696
        if (cid == colId) {
×
1697
          SColData colDataTmp = {0};
×
1698
          code = tDecodeColData(version, pCoder, &colDataTmp, false);
×
1699
          if (code) {
×
1700
            code = TSDB_CODE_INVALID_MSG;
×
1701
            TSDB_CHECK_CODE(code, lino, end);
×
1702
          }
1703
          STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colDataTmp, pColData));
×
1704
          break;
×
1705
        }
1706
        code = tDecodeColData(version, pCoder, &colData, true);
×
1707
        if (code) {
×
1708
          code = TSDB_CODE_INVALID_MSG;
×
1709
          TSDB_CHECK_CODE(code, lino, end);
×
1710
        }
1711
      }
1712
      if (j == nColData) {
×
1713
        colDataSetNNULL(pColData, blockStart, numOfRows);
×
1714
      }
1715
    }
1716
  } else {
1717
    uint64_t nRow = 0;
3,130,708✔
1718
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,130,227✔
1719
      code = TSDB_CODE_INVALID_MSG;
×
1720
      TSDB_CHECK_CODE(code, lino, end);
×
1721
    }
1722
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
7,571,702✔
1723
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
4,440,992✔
1724
      pCoder->pos += pRow->len;
4,441,233✔
1725

1726
      if (iRow == 0){
4,440,259✔
1727
#ifndef NO_UNALIGNED_ACCESS
1728
        walMeta.skey = pRow->ts;
3,129,512✔
1729
#else
1730
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1731
#endif
1732
      }
1733
      if (iRow == nRow - 1) {
4,440,743✔
1734
#ifndef NO_UNALIGNED_ACCESS
1735
        walMeta.ekey = pRow->ts;
3,130,468✔
1736
#else
1737
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1738
#endif
1739
      }
1740

1741
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
4,440,018✔
1742
        continue;
8,094✔
1743
      }
1744
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
4,431,942✔
1745
      blockStart = pSlice->currentRowIdx;
4,431,942✔
1746
     
1747
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
29,416,805✔
1748
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
24,980,953✔
1749
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
24,980,477✔
1750
        if (pColData->info.colId <= -1) {
24,980,477✔
1751
          pColData->hasNull = true;
8,564,246✔
1752
          continue;
8,564,005✔
1753
        }
1754
        int16_t colId = 0;
16,422,788✔
1755
        if (sStreamReaderInfo->isVtableStream){
16,423,030✔
1756
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
1,681,319✔
1757
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
1,681,799✔
1758
        } else {
1759
          colId = pColData->info.colId;
14,742,189✔
1760
        }
1761
        
1762
        SColVal colVal = {0};
16,424,472✔
1763
        int32_t sourceIdx = 0;
16,424,472✔
1764
        while (1) {
1765
          if (sourceIdx >= schema->numOfCols) {
41,104,505✔
1766
            break;
6,785,125✔
1767
          }
1768
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
34,321,033✔
1769
          if (colVal.cid == colId) {
34,323,679✔
1770
            break;
9,643,646✔
1771
          }
1772
          sourceIdx++;
24,680,033✔
1773
        }
1774
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
16,428,771✔
1775
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
9,566,444✔
1776
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
26,977✔
1777
            ST_TASK_TLOG("%s vtable colId:%d, i:%d, colData:%p, data:%s, len:%d, rowIndex:%d, offset:%d, uid:%" PRId64, __func__, colId, i, pColData, 
27,142✔
1778
              (const char*)colVal.value.pData, colVal.value.nData, blockStart+ numOfRows, pColData->varmeta.offset[blockStart+ numOfRows], submitTbData.uid);
1779
          } else {
1780
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
9,539,564✔
1781
          }
1782
        } else {
1783
          colDataSetNULL(pColData, blockStart + numOfRows);
6,862,327✔
1784
        }
1785
      }
1786
      
1787
      numOfRows++;
4,433,381✔
1788
    }
1789
  }
1790

1791
  if (numOfRows > 0) {
3,130,468✔
1792
    if (!sStreamReaderInfo->isVtableStream) {
3,130,468✔
1793
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, rsp->isCalc, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
2,470,428✔
1794
    }
1795
    
1796
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
3,131,193✔
1797
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
3,130,690✔
1798
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
3,130,690✔
1799

1800
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
3,130,950✔
1801
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
3,130,950✔
1802
      ", uid:%" PRId64 ", ver:%"PRId64 ", row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1803
      id, submitTbData.uid, ver, pSlice->currentRowIdx, numOfRows);
1804
    pSlice->currentRowIdx += numOfRows;
3,130,950✔
1805
    pBlock->info.rows += numOfRows;
3,130,950✔
1806
  } else {
1807
    ST_TASK_DLOG("%s no valid data in time range:skey %" PRId64 ", ekey %" PRId64 ", uid:%" PRId64 ", suid:%" PRId64,
×
1808
      __func__, window.skey, window.ekey, submitTbData.uid, submitTbData.suid);
1809
  }
1810
  
1811
  if (gidHash == NULL) goto end;
3,131,192✔
1812

1813
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,320,926✔
1814
  if (data != NULL) {
1,320,926✔
1815
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
1816
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
1817
  } else {
1818
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
1,320,926✔
1819
  }
1820

1821
end:
3,795,947✔
1822
  if (code != 0) {                                                             \
3,799,203✔
1823
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1824
  }
1825
  tEndDecode(pCoder);
3,799,203✔
1826
  return code;
3,799,685✔
1827
}
1828
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
3,798,236✔
1829
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1830
  int32_t  code = 0;
3,798,236✔
1831
  int32_t  lino = 0;
3,798,236✔
1832
  SDecoder decoder = {0};
3,798,236✔
1833
  SSHashObj* gidHash = NULL;
3,798,237✔
1834
  void* pTask = sStreamReaderInfo->pTask;
3,798,237✔
1835

1836
  tDecoderInit(&decoder, data, len);
3,798,237✔
1837
  if (tStartDecode(&decoder) < 0) {
3,799,202✔
1838
    code = TSDB_CODE_INVALID_MSG;
×
1839
    TSDB_CHECK_CODE(code, lino, end);
×
1840
  }
1841

1842
  uint64_t nSubmitTbData = 0;
3,799,927✔
1843
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
3,798,942✔
1844
    code = TSDB_CODE_INVALID_MSG;
×
1845
    TSDB_CHECK_CODE(code, lino, end);
×
1846
  }
1847

1848
  if (rsp->metaBlock != NULL){
3,798,942✔
1849
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
1,989,421✔
1850
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
1,986,310✔
1851
  }
1852

1853
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
7,595,519✔
1854
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
3,796,315✔
1855
  }
1856

1857
  tEndDecode(&decoder);
3,799,204✔
1858

1859
  if (rsp->metaBlock != NULL){
3,799,446✔
1860
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
1,988,698✔
1861
    int32_t iter = 0;
1,988,457✔
1862
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
1,988,457✔
1863
    while (px != NULL) {
3,309,380✔
1864
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,321,167✔
1865
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,321,167✔
1866
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,320,924✔
1867
      rsp->totalRows++;
1,320,924✔
1868
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,320,924✔
1869
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1870
      px = tSimpleHashIterate(gidHash, px, &iter);
1,320,924✔
1871
    }
1872
  }
1873
  
1874

1875
end:
3,794,253✔
1876
  tSimpleHashCleanup(gidHash);
3,798,477✔
1877
  tDecoderClear(&decoder);
3,799,442✔
1878
  return code;
3,799,940✔
1879
}
1880

1881
static int32_t scanSubmitTbDataPre(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* ranges, 
5,524,571✔
1882
  uint64_t* gid, int64_t* uid, int32_t* numOfRows, SSTriggerWalNewRsp* rsp, int64_t ver) {
1883
  int32_t code = 0;
5,524,571✔
1884
  int32_t lino = 0;
5,524,571✔
1885
  void* pTask = sStreamReaderInfo->pTask;
5,524,571✔
1886

1887
  if (tStartDecode(pCoder) < 0) {
5,524,812✔
1888
    code = TSDB_CODE_INVALID_MSG;
×
1889
    TSDB_CHECK_CODE(code, lino, end);
×
1890
  }
1891

1892
  SSubmitTbData submitTbData = {0};
5,524,811✔
1893
  uint8_t       version = 0;
5,524,309✔
1894
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
5,525,406✔
1895
    code = TSDB_CODE_INVALID_MSG;
×
1896
    TSDB_CHECK_CODE(code, lino, end);
×
1897
  }
1898
  version = (submitTbData.flags >> 8) & 0xff;
5,525,406✔
1899
  submitTbData.flags = submitTbData.flags & 0xff;
5,525,406✔
1900

1901
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1902
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
5,525,406✔
1903
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
897,710✔
1904
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
896,352✔
1905
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
896,352✔
1906
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
896,741✔
1907
  }
1908

1909
  // submit data
1910
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
5,525,889✔
1911
    code = TSDB_CODE_INVALID_MSG;
×
1912
    TSDB_CHECK_CODE(code, lino, end);
×
1913
  }
1914
  if (tDecodeI64(pCoder, uid) < 0) {
5,523,601✔
1915
    code = TSDB_CODE_INVALID_MSG;
×
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  ST_TASK_DLOG("%s uid:%" PRId64 ", suid:%" PRId64, __func__, *uid, submitTbData.suid);
5,523,601✔
1919
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
5,523,730✔
1920
  if (rsp->uidHash != NULL) {
3,131,189✔
1921
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
1,810,265✔
1922
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
1,810,506✔
1923
  }
1924
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
3,131,430✔
1925

1926
  if (ranges != NULL){
3,131,430✔
1927
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
1,810,506✔
1928
    if (timerange == NULL) goto end;;
1,810,265✔
1929
    int64_t* pRange = (int64_t*)timerange;
1,810,265✔
1930
    window.skey = pRange[0];
1,810,265✔
1931
    window.ekey = pRange[1];
1,810,265✔
1932
  }
1933
  
1934
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,129,481✔
1935
    code = TSDB_CODE_INVALID_MSG;
×
1936
    TSDB_CHECK_CODE(code, lino, end);
×
1937
  }
1938

1939
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
3,129,481✔
1940
    uint64_t nColData = 0;
×
1941
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1942
      code = TSDB_CODE_INVALID_MSG;
×
1943
      TSDB_CHECK_CODE(code, lino, end);
×
1944
    }
1945

1946
    SColData colData = {0};
×
1947
    code = tDecodeColData(version, pCoder, &colData, false);
×
1948
    if (code) {
×
1949
      code = TSDB_CODE_INVALID_MSG;
×
1950
      TSDB_CHECK_CODE(code, lino, end);
×
1951
    }
1952

1953
    if (colData.flag != HAS_VALUE) {
×
1954
      code = TSDB_CODE_INVALID_MSG;
×
1955
      TSDB_CHECK_CODE(code, lino, end);
×
1956
    }
1957
    int32_t rowStart = 0;
×
1958
    int32_t rowEnd = 0;
×
1959
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) {
×
1960
      STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, numOfRows));
×
1961
    } else {
1962
      (*numOfRows) = colData.nVal;
×
1963
    } 
1964
  } else {
1965
    uint64_t nRow = 0;
3,129,481✔
1966
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,128,759✔
1967
      code = TSDB_CODE_INVALID_MSG;
×
1968
      TSDB_CHECK_CODE(code, lino, end);
×
1969
    }
1970

1971
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
3,128,759✔
1972
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
4,718,502✔
1973
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
2,908,477✔
1974
        pCoder->pos += pRow->len;
2,908,720✔
1975
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
2,908,719✔
1976
          continue;
8,094✔
1977
        }
1978
        (*numOfRows)++;
2,900,884✔
1979
      }
1980
    } else {
1981
      (*numOfRows) = nRow;
1,319,234✔
1982
    }
1983
  }
1984
  
1985
end:
5,522,879✔
1986
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
5,522,152✔
1987
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
5,521,645✔
1988
  tEndDecode(pCoder);
5,521,887✔
1989
  return code;
5,523,118✔
1990
}
1991

1992
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
5,525,776✔
1993
  int32_t  code = 0;
5,525,776✔
1994
  int32_t  lino = 0;
5,525,776✔
1995
  SDecoder decoder = {0};
5,525,776✔
1996
  void* pTask = sStreamReaderInfo->pTask;
5,525,776✔
1997

1998
  tDecoderInit(&decoder, data, len);
5,525,776✔
1999
  if (tStartDecode(&decoder) < 0) {
5,525,290✔
2000
    code = TSDB_CODE_INVALID_MSG;
×
2001
    TSDB_CHECK_CODE(code, lino, end);
×
2002
  }
2003

2004
  uint64_t nSubmitTbData = 0;
5,524,549✔
2005
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
5,522,617✔
2006
    code = TSDB_CODE_INVALID_MSG;
×
2007
    TSDB_CHECK_CODE(code, lino, end);
×
2008
  }
2009
  ST_TASK_DLOG("%s nSubmitTbData:%" PRIu64 ", ver:%"PRId64 " bodyLen:%d", __func__, nSubmitTbData, ver, len);
5,522,617✔
2010

2011
  for (int32_t i = 0; i < nSubmitTbData; i++) {
11,046,475✔
2012
    uint64_t gid = -1;
5,524,320✔
2013
    int64_t  uid = 0;
5,524,801✔
2014
    int32_t numOfRows = 0;
5,524,801✔
2015
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
5,524,431✔
2016
    if (numOfRows <= 0) {
5,523,418✔
2017
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
2,392,955✔
2018
      continue;
2,393,862✔
2019
    }
2020
    rsp->totalRows += numOfRows;
3,130,463✔
2021
    rsp->totalDataRows += numOfRows;
3,130,947✔
2022

2023
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
3,129,979✔
2024
    if (pSlice != NULL) {
3,129,740✔
2025
      pSlice->numRows += numOfRows;
2,742,601✔
2026
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d, hash:%p %d, ver:%"PRId64, __func__, uid, gid, pSlice->numRows, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash), ver);
2,742,601✔
2027
      pSlice->gId = gid;
2,742,601✔
2028
    } else {
2029
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
387,139✔
2030
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, hash:%p %d, ver:%"PRId64, __func__, uid, gid, tmp.numRows, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash), ver);
387,381✔
2031
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
387,381✔
2032
    } 
2033
  }
2034

2035
  tEndDecode(&decoder);
5,522,155✔
2036

2037
end:
5,524,808✔
2038
  tDecoderClear(&decoder);
5,525,051✔
2039
  return code;
5,523,842✔
2040
}
2041

2042
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
328,411✔
2043
  void*   pe = NULL;
328,411✔
2044
  int32_t iter = 0;
328,411✔
2045
  int32_t index = 0;
328,411✔
2046
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
716,759✔
2047
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
388,348✔
2048
    pInfo->startRowIdx = index;
388,348✔
2049
    pInfo->currentRowIdx = index;
388,348✔
2050
    index += pInfo->numRows;
388,348✔
2051
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
588,835✔
2052
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2053
  }
2054
}
328,411✔
2055

2056
static void printIndexHash(SSHashObj* indexHash, void* pTask){
328,169✔
2057
  if (qDebugFlag & DEBUG_TRACE) {
328,169✔
2058
    void*   pe = NULL;
2,568✔
2059
    int32_t iter = 0;
2,568✔
2060
    while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
5,583✔
2061
      SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
3,015✔
2062
      ST_TASK_TLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
3,249✔
2063
      pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2064
    }
2065
  }
2066
}
328,169✔
2067

2068
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
5,622✔
2069
  void*   pe = NULL;
5,622✔
2070
  int32_t iter = 0;
5,622✔
2071
  int32_t index = 0;
5,622✔
2072
  int32_t pIndex = 0;
5,622✔
2073
  int8_t* pIndicator = (int8_t*)pRet->pData;
5,622✔
2074
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
12,906✔
2075
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
7,284✔
2076
    pInfo->startRowIdx = index;
7,284✔
2077
    int32_t size = pInfo->numRows;
7,284✔
2078
    for (int32_t i = 0; i < pInfo->numRows; i++) {
73,128✔
2079
      if (pIndicator && !pIndicator[pIndex++]) {
65,844✔
2080
        size--;
22,064✔
2081
      }
2082
    }
2083
    pInfo->numRows = size;
7,284✔
2084
    index += pInfo->numRows;
7,284✔
2085
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
7,284✔
2086
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2087
  }
2088
}
5,622✔
2089

2090
static int32_t prepareIndexMetaData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* resultRsp){
3,189,925✔
2091
  int32_t      code = 0;
3,189,925✔
2092
  int32_t      lino = 0;
3,189,925✔
2093
  void* pTask = sStreamReaderInfo->pTask;
3,189,925✔
2094

2095
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,190,248✔
2096
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,185,923✔
2097
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,694,538✔
2098
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
2099
      resultRsp->verTime = 0;
×
2100
    } else {
2101
      resultRsp->verTime = taosGetTimestampUs();
2,693,922✔
2102
    }
2103
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
2,694,515✔
2104
    code = TSDB_CODE_SUCCESS;
2,694,428✔
2105
    goto end;
2,694,428✔
2106
  }
2107
  STREAM_CHECK_RET_GOTO(code);
491,385✔
2108

2109
  while (1) {
3,832,291✔
2110
    code = walNextValidMsg(pWalReader, true);
4,323,676✔
2111
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
4,325,041✔
2112
      resultRsp->verTime = taosGetTimestampUs();
492,502✔
2113
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
492,502✔
2114
      code = TSDB_CODE_SUCCESS;
492,753✔
2115
      goto end;
492,753✔
2116
    }
2117
    STREAM_CHECK_RET_GOTO(code);
3,830,645✔
2118
    resultRsp->ver = pWalReader->curVersion;
3,830,645✔
2119
    SWalCont* wCont = &pWalReader->pHead->head;
3,833,122✔
2120
    resultRsp->verTime = wCont->ingestTs;
3,832,397✔
2121
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
3,831,828✔
2122
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
3,831,707✔
2123
    int64_t ver = wCont->version;
3,832,078✔
2124
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
3,832,154✔
2125
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2126
    if (wCont->msgType == TDMT_VND_SUBMIT) {
3,833,210✔
2127
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
3,714,303✔
2128
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
3,714,061✔
2129
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
3,714,302✔
2130
    } else {
2131
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
119,195✔
2132
    }
2133

2134
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
3,832,773✔
2135
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
3,832,773✔
2136
      break;
2137
    }
2138
  }
2139
  
2140
end:
725✔
2141
  STREAM_PRINT_LOG_END(code, lino);
3,187,906✔
2142
  return code;
3,186,937✔
2143
}
2144

2145
static int32_t prepareIndexData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, 
990,241✔
2146
  SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp){
2147
  int32_t      code = 0;
990,241✔
2148
  int32_t      lino = 0;
990,241✔
2149
  void* pTask = sStreamReaderInfo->pTask;
990,241✔
2150

2151
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
2,800,987✔
2152
    int64_t *ver = taosArrayGet(versions, i);
1,810,505✔
2153
    if (ver == NULL) continue;
1,810,508✔
2154

2155
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
1,810,508✔
2156
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
1,810,023✔
2157
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
2158
      ST_TASK_TLOG("%s not data, skip, ver:%"PRId64, __func__, *ver);
×
2159
      continue;
×
2160
    }
2161
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
1,809,782✔
2162

2163
    SWalCont* wCont = &pWalReader->pHead->head;
1,810,265✔
2164
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
1,810,024✔
2165
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
1,810,507✔
2166

2167
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
1,809,781✔
2168
  }
2169
  
2170
end:
990,001✔
2171
  return code;
990,001✔
2172
}
2173

2174
static int32_t filterData(SSTriggerWalNewRsp* resultRsp, SStreamTriggerReaderInfo* sStreamReaderInfo) {
328,653✔
2175
  int32_t      code = 0;
328,653✔
2176
  int32_t       lino = 0;
328,653✔
2177
  SColumnInfoData* pRet = NULL;
328,653✔
2178

2179
  int64_t totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
328,653✔
2180
  STREAM_CHECK_RET_GOTO(qStreamFilter(((SSDataBlock*)resultRsp->dataBlock), sStreamReaderInfo->pFilterInfo, &pRet));
328,653✔
2181

2182
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
328,653✔
2183
    filterIndexHash(resultRsp->indexHash, pRet);
5,622✔
2184
  }
2185

2186
end:
328,653✔
2187
  colDataDestroy(pRet);
328,411✔
2188
  taosMemoryFree(pRet);
328,411✔
2189
  return code;
328,653✔
2190
}
2191

2192
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,189,445✔
2193
                                    SSTriggerWalNewRsp* resultRsp) {
2194
  int32_t      code = 0;
3,189,445✔
2195
  int32_t      lino = 0;
3,189,445✔
2196
  void* pTask = sStreamReaderInfo->pTask;
3,189,445✔
2197
                                        
2198
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,188,435✔
2199
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,186,907✔
2200
  blockDataEmpty(resultRsp->dataBlock);
3,186,907✔
2201
  blockDataEmpty(resultRsp->metaBlock);
3,185,877✔
2202
  int64_t lastVer = resultRsp->ver;                                      
3,187,924✔
2203
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,187,924✔
2204
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,185,730✔
2205

2206
  buildIndexHash(resultRsp->indexHash, pTask);
131,061✔
2207
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
131,061✔
2208
  while(lastVer < resultRsp->ver) {
2,157,487✔
2209
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
2,027,150✔
2210
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
2,025,933✔
2211
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
37,476✔
2212
      continue;
37,476✔
2213
    }
2214
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
1,988,939✔
2215
    SWalCont* wCont = &pWalReader->pHead->head;
1,989,180✔
2216
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
1,989,180✔
2217
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
1,988,688✔
2218
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
1,988,929✔
2219
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
1,988,929✔
2220
  }
2221

2222
  int32_t metaRows = resultRsp->totalRows - ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
131,061✔
2223
  STREAM_CHECK_RET_GOTO(filterData(resultRsp, sStreamReaderInfo));
131,061✔
2224
  resultRsp->totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows + metaRows;
131,061✔
2225

2226
end:
3,185,003✔
2227
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
3,185,003✔
2228
          resultRsp->totalRows, resultRsp->ver, walGetAppliedVer(pWalReader->pWal));
2229
  walCloseReader(pWalReader);
3,185,003✔
2230
  return code;
3,185,729✔
2231
}
2232

2233
static int32_t processWalVerDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
990,238✔
2234
                                    SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
2235
  int32_t      code = 0;
990,238✔
2236
  int32_t      lino = 0;
990,238✔
2237

2238
  void* pTask = sStreamReaderInfo->pTask;
990,238✔
2239
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
990,238✔
2240
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
990,251✔
2241
  
2242
  if (taosArrayGetSize(versions) > 0) {
990,251✔
2243
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
197,592✔
2244
  }
2245
  
2246
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
990,241✔
2247
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
989,758✔
2248

2249
  ST_TASK_TLOG("%s index hash:%p %d", __func__, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash));
197,592✔
2250
  buildIndexHash(rsp->indexHash, pTask);
197,592✔
2251

2252
  blockDataEmpty(rsp->dataBlock);
197,592✔
2253
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
197,592✔
2254

2255
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
2,007,857✔
2256
    int64_t *ver = taosArrayGet(versions, i);
1,810,266✔
2257
    if (ver == NULL) continue;
1,810,024✔
2258
    ST_TASK_TLOG("vgId:%d %s scan wal process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, *ver, walGetAppliedVer(pWalReader->pWal));
1,810,024✔
2259

2260
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
1,810,024✔
2261
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
1,810,026✔
2262
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
2263
      continue;
×
2264
    }
2265
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
1,809,784✔
2266
    SWalCont* wCont = &pWalReader->pHead->head;
1,809,786✔
2267
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
1,809,544✔
2268
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
1,809,786✔
2269

2270
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
1,809,544✔
2271
  }
2272
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2273
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
197,350✔
2274
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
197,592✔
2275

2276
end:
990,009✔
2277
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
990,009✔
2278
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
2279
  walCloseReader(pWalReader);
990,259✔
2280
  return code;
990,489✔
2281
}
2282

2283
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas, SStorageAPI* api) {
48,652✔
2284
  int32_t code = 0;
48,652✔
2285
  int32_t lino = 0;
48,652✔
2286
  SMetaReader metaReader = {0};
48,652✔
2287
  *schemas = taosArrayInit(8, sizeof(SSchema));
48,652✔
2288
  STREAM_CHECK_NULL_GOTO(*schemas, terrno);
48,652✔
2289
  
2290
  api->metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api->metaFn);
48,871✔
2291
  STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, uid));
48,871✔
2292

2293
  SSchemaWrapper* sSchemaWrapper = NULL;
48,871✔
2294
  if (metaReader.me.type == TD_CHILD_TABLE) {
48,871✔
2295
    int64_t suid = metaReader.me.ctbEntry.suid;
48,871✔
2296
    tDecoderClear(&metaReader.coder);
48,871✔
2297
    STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, suid));
48,871✔
2298
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
48,871✔
2299
  } else if (metaReader.me.type == TD_NORMAL_TABLE) {
×
2300
    sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
×
2301
  } else {
2302
    qError("invalid table type:%d", metaReader.me.type);
×
2303
  }
2304

2305
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
249,330✔
2306
    SSchema* s = sSchemaWrapper->pSchema + j;
200,459✔
2307
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
400,918✔
2308
  }
2309

2310
end:
48,871✔
2311
  api->metaReaderFn.clearReader(&metaReader);
48,871✔
2312
  STREAM_PRINT_LOG_END(code, lino);
48,871✔
2313
  if (code != 0)  {
48,871✔
UNCOV
2314
    taosArrayDestroy(*schemas);
×
UNCOV
2315
    *schemas = NULL;
×
2316
  }
2317
  return code;
48,871✔
2318
}
2319

2320
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
48,871✔
2321
  int32_t code = 0;
48,871✔
2322
  int32_t lino = 0;
48,871✔
2323
  size_t  schemaLen = taosArrayGetSize(schemas);
48,871✔
2324
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
48,871✔
2325
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
152,761✔
2326
    col_id_t* id = taosArrayGet(cols, i);
103,890✔
2327
    STREAM_CHECK_NULL_GOTO(id, terrno);
103,890✔
2328
    for (size_t i = 0; i < schemaLen; i++) {
227,714✔
2329
      SSchema* s = taosArrayGet(schemas, i);
227,714✔
2330
      STREAM_CHECK_NULL_GOTO(s, terrno);
227,714✔
2331
      if (*id == s->colId) {
227,714✔
2332
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
103,890✔
2333
        break;
103,890✔
2334
      }
2335
    }
2336
  }
2337
  taosArrayPopFrontBatch(schemas, schemaLen);
48,871✔
2338

2339
end:
48,871✔
2340
  return code;
48,871✔
2341
}
2342

2343
static int32_t createTSAndCondition(int64_t start, int64_t end, SLogicConditionNode** pCond,
×
2344
                                    STargetNode* pTargetNodeTs) {
2345
  int32_t code = 0;
×
2346
  int32_t lino = 0;
×
2347

2348
  SColumnNode*         pCol = NULL;
×
2349
  SColumnNode*         pCol1 = NULL;
×
2350
  SValueNode*          pVal = NULL;
×
2351
  SValueNode*          pVal1 = NULL;
×
2352
  SOperatorNode*       op = NULL;
×
2353
  SOperatorNode*       op1 = NULL;
×
2354
  SLogicConditionNode* cond = NULL;
×
2355

2356
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol));
×
2357
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
×
2358
  pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
×
2359
  pCol->node.resType.bytes = LONG_BYTES;
×
2360
  pCol->slotId = pTargetNodeTs->slotId;
×
2361
  pCol->dataBlockId = pTargetNodeTs->dataBlockId;
×
2362

2363
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pCol, (SNode**)&pCol1));
×
2364

2365
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal));
×
2366
  pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
×
2367
  pVal->node.resType.bytes = LONG_BYTES;
×
2368
  pVal->datum.i = start;
×
2369
  pVal->typeData = start;
×
2370

2371
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
×
2372
  pVal1->datum.i = end;
×
2373
  pVal1->typeData = end;
×
2374

2375
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op));
×
2376
  op->opType = OP_TYPE_GREATER_EQUAL;
×
2377
  op->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2378
  op->node.resType.bytes = CHAR_BYTES;
×
2379
  op->pLeft = (SNode*)pCol;
×
2380
  op->pRight = (SNode*)pVal;
×
2381
  pCol = NULL;
×
2382
  pVal = NULL;
×
2383

2384
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op1));
×
2385
  op1->opType = OP_TYPE_LOWER_EQUAL;
×
2386
  op1->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2387
  op1->node.resType.bytes = CHAR_BYTES;
×
2388
  op1->pLeft = (SNode*)pCol1;
×
2389
  op1->pRight = (SNode*)pVal1;
×
2390
  pCol1 = NULL;
×
2391
  pVal1 = NULL;
×
2392

2393
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
×
2394
  cond->condType = LOGIC_COND_TYPE_AND;
×
2395
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2396
  cond->node.resType.bytes = CHAR_BYTES;
×
2397
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
×
2398
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op));
×
2399
  op = NULL;
×
2400
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op1));
×
2401
  op1 = NULL;
×
2402

2403
  *pCond = cond;
×
2404

2405
end:
×
2406
  if (code != 0) {
×
2407
    nodesDestroyNode((SNode*)pCol);
×
2408
    nodesDestroyNode((SNode*)pCol1);
×
2409
    nodesDestroyNode((SNode*)pVal);
×
2410
    nodesDestroyNode((SNode*)pVal1);
×
2411
    nodesDestroyNode((SNode*)op);
×
2412
    nodesDestroyNode((SNode*)op1);
×
2413
    nodesDestroyNode((SNode*)cond);
×
2414
  }
2415
  STREAM_PRINT_LOG_END(code, lino);
×
2416

2417
  return code;
×
2418
}
2419

2420
/*
2421
static int32_t createExternalConditions(SStreamRuntimeFuncInfo* data, SLogicConditionNode** pCond, STargetNode* pTargetNodeTs, STimeRangeNode* node) {
2422
  int32_t              code = 0;
2423
  int32_t              lino = 0;
2424
  SLogicConditionNode* pAndCondition = NULL;
2425
  SLogicConditionNode* cond = NULL;
2426

2427
  if (pTargetNodeTs == NULL) {
2428
    vError("stream reader %s no ts column", __func__);
2429
    return TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN;
2430
  }
2431
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
2432
  cond->condType = LOGIC_COND_TYPE_OR;
2433
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
2434
  cond->node.resType.bytes = CHAR_BYTES;
2435
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
2436

2437
  for (int i = 0; i < taosArrayGetSize(data->pStreamPesudoFuncVals); ++i) {
2438
    data->curIdx = i;
2439

2440
    SReadHandle handle = {0};
2441
    calcTimeRange(node, data, &handle.winRange, &handle.winRangeValid);
2442
    if (!handle.winRangeValid) {
2443
      stError("stream reader %s invalid time range, skey:%" PRId64 ", ekey:%" PRId64, __func__, handle.winRange.skey,
2444
              handle.winRange.ekey);
2445
      continue;
2446
    }
2447
    STREAM_CHECK_RET_GOTO(createTSAndCondition(handle.winRange.skey, handle.winRange.ekey, &pAndCondition, pTargetNodeTs));
2448
    stDebug("%s create condition skey:%" PRId64 ", eksy:%" PRId64, __func__, handle.winRange.skey, handle.winRange.ekey);
2449
    STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)pAndCondition));
2450
    pAndCondition = NULL;
2451
  }
2452

2453
  *pCond = cond;
2454

2455
end:
2456
  if (code != 0) {
2457
    nodesDestroyNode((SNode*)pAndCondition);
2458
    nodesDestroyNode((SNode*)cond);
2459
  }
2460
  STREAM_PRINT_LOG_END(code, lino);
2461

2462
  return code;
2463
}
2464
*/
2465

2466
static int32_t processCalaTimeRange(SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo, SResFetchReq* req,
375,734✔
2467
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
2468
  int32_t code = 0;
375,734✔
2469
  int32_t lino = 0;
375,734✔
2470
  void* pTask = sStreamReaderCalcInfo->pTask;
375,734✔
2471
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
375,734✔
2472
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
375,734✔
2473
  
2474
  if (req->pStRtFuncInfo->withExternalWindow) {
375,734✔
2475
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
221,971✔
2476
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
221,971✔
2477
    sStreamReaderCalcInfo->tmpRtFuncInfo.isWindowTrigger = req->pStRtFuncInfo->isWindowTrigger;
221,971✔
2478
    sStreamReaderCalcInfo->tmpRtFuncInfo.precision = req->pStRtFuncInfo->precision;
221,971✔
2479

2480
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
221,971✔
2481
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
221,971✔
2482
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
221,971✔
2483
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
221,971✔
2484

2485
    if (!node->needCalc) {
221,971✔
2486
      pWin->skey = pFirst->wstart;
206,284✔
2487
      pWin->ekey = pLast->wend;
206,284✔
2488
      *pValid = true;
206,284✔
2489
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
206,284✔
2490
        pWin->ekey--;
130,888✔
2491
      }
2492
    } else {
2493
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
15,687✔
2494
      memcpy(pTmp, pFirst, sizeof(*pTmp));
15,687✔
2495

2496
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
15,687✔
2497
      if (*pValid) {
15,687✔
2498
        int64_t skey = pWin->skey;
15,687✔
2499

2500
        memcpy(pTmp, pLast, sizeof(*pTmp));
15,687✔
2501
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
15,687✔
2502

2503
        if (*pValid) {
15,687✔
2504
          pWin->skey = skey;
15,687✔
2505
        }
2506
      }
2507
      pWin->ekey--;
15,687✔
2508
    }
2509
  } else {
2510
    if (!node->needCalc) {
153,763✔
2511
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
110,032✔
2512
      pWin->skey = pCurr->wstart;
110,032✔
2513
      pWin->ekey = pCurr->wend;
110,032✔
2514
      *pValid = true;
110,032✔
2515
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
110,032✔
2516
        pWin->ekey--;
61,730✔
2517
      }
2518
    } else {
2519
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
43,731✔
2520
      pWin->ekey--;
43,731✔
2521
    }
2522
  }
2523

2524
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
375,734✔
2525
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
2526

2527
end:
6,284✔
2528

2529
  if (code) {
375,734✔
2530
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
2531
  }
2532
  
2533
  return code;
375,734✔
2534
}
2535

2536
static int32_t createDataBlockTsUid(SSDataBlock** pBlockRet, uint32_t numOfRows) {
280,812✔
2537
  int32_t      code = 0;
280,812✔
2538
  int32_t      lino = 0;
280,812✔
2539
  SSDataBlock* pBlock = NULL;
280,812✔
2540
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
281,289✔
2541
  SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID);
281,077✔
2542
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
281,077✔
2543
  idata = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID + 1);
280,806✔
2544
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
280,806✔
2545
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, numOfRows));
281,289✔
2546

2547
end:
281,289✔
2548
  STREAM_PRINT_LOG_END(code, lino)
281,289✔
2549
  if (code != TSDB_CODE_SUCCESS) {
281,289✔
2550
    blockDataDestroy(pBlock);
×
2551
    pBlock = NULL;
×
2552
  }
2553
  *pBlockRet = pBlock;
281,289✔
2554
  return code;
281,047✔
2555
}
2556

2557
static int32_t processTsOutPutAllTables(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
92,883✔
2558
  int32_t code = 0;
92,883✔
2559
  int32_t lino = 0;
92,883✔
2560
  void* pTask = sStreamReaderInfo->pTask;
92,883✔
2561

2562
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
92,883✔
2563
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
92,883✔
2564
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
92,883✔
2565
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
92,883✔
2566
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
338,239✔
2567
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
490,493✔
2568
      continue;
×
2569
    }
2570
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
245,137✔
2571
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
245,137✔
2572
    if (order == TSDB_ORDER_ASC) {
245,137✔
2573
      tsInfo->ts = INT64_MAX;
129,848✔
2574
    } else {
2575
      tsInfo->ts = INT64_MIN;
115,289✔
2576
    }
2577
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
245,137✔
2578
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
244,925✔
2579
      tsInfo->ts = ts;
129,848✔
2580
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
115,077✔
2581
      tsInfo->ts = ts;
115,289✔
2582
    }
2583
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
244,925✔
2584
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
245,137✔
2585
  }
2586

2587
end:
92,883✔
2588
  return code;
92,883✔
2589
}
2590

2591
static int32_t processTsOutPutOneGroup(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
85,991✔
2592
  int32_t code = 0;
85,991✔
2593
  int32_t lino = 0;
85,991✔
2594
  void* pTask = sStreamReaderInfo->pTask;
85,991✔
2595

2596
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
85,542✔
2597
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
85,750✔
2598
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
85,547✔
2599
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
85,547✔
2600
  if (order == TSDB_ORDER_ASC) {
85,547✔
2601
    tsInfo->ts = INT64_MAX;
69,266✔
2602
  } else {
2603
    tsInfo->ts = INT64_MIN;
16,281✔
2604
  }
2605

2606
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
85,046✔
2607
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
85,508✔
2608
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
188,761✔
2609
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
208,422✔
2610
      continue;
×
2611
    }
2612
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
103,979✔
2613
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
103,437✔
2614
      tsInfo->ts = ts;
68,299✔
2615
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
35,137✔
2616
      tsInfo->ts = ts;
16,281✔
2617
    }
2618
  }
2619
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
85,508✔
2620
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
85,024✔
2621
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
85,991✔
2622

2623
end:
31,651✔
2624
  return code;
85,750✔
2625
}
2626

2627
static int32_t processTsOutPutAllGroups(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
7,845✔
2628
  int32_t code = 0;
7,845✔
2629
  int32_t lino = 0;
7,845✔
2630
  STableKeyInfo* pList = NULL;
7,845✔
2631
  StreamTableListInfo     tableInfo = {0};
7,845✔
2632

2633
  void* pTask = sStreamReaderInfo->pTask;
7,845✔
2634
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
7,845✔
2635

2636
  SSHashObj*   uidTsHash = tSimpleHashInit(pResBlock->info.rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,845✔
2637
  STREAM_CHECK_NULL_GOTO(uidTsHash, terrno);
7,845✔
2638
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
7,845✔
2639
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
7,845✔
2640
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
24,306✔
2641
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
32,922✔
2642
      continue;
×
2643
    }
2644
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
16,461✔
2645
    int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
16,461✔
2646
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(uidTsHash, &uid, LONG_BYTES, &ts, LONG_BYTES));
16,461✔
2647
  }
2648
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(sStreamReaderInfo), sizeof(STsInfo));
7,845✔
2649
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
7,845✔
2650
  while (true) {
15,231✔
2651
    int32_t        pNum = 0;
23,076✔
2652
    int64_t        suid = 0;
23,076✔
2653
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
23,076✔
2654
    if(pNum == 0) break;
23,076✔
2655
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
15,837✔
2656
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
15,837✔
2657
    if (order == TSDB_ORDER_ASC) {
15,837✔
2658
      tsInfo->ts = INT64_MAX;
7,417✔
2659
    } else {
2660
      tsInfo->ts = INT64_MIN;
8,420✔
2661
    }
2662
    for (int32_t i = 0; i < pNum; i++) {
31,876✔
2663
      int64_t uid = pList[i].uid;
16,645✔
2664
      int64_t *ts = tSimpleHashGet(uidTsHash, &uid, LONG_BYTES);
16,645✔
2665
      STREAM_CHECK_NULL_GOTO(ts, terrno);
16,645✔
2666
      if (order == TSDB_ORDER_ASC && *ts < tsInfo->ts) {
16,039✔
2667
        tsInfo->ts = *ts;
7,417✔
2668
      } else if (order == TSDB_ORDER_DESC && *ts > tsInfo->ts) {
8,622✔
2669
        tsInfo->ts = *ts;
7,814✔
2670
      }
2671
    }
2672
    int64_t uid = pList[0].uid;
15,231✔
2673
    tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
15,231✔
2674
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
15,231✔
2675
    taosMemoryFreeClear(pList);
15,231✔
2676
  }
2677

2678
end:
7,845✔
2679
  qStreamDestroyTableInfo(&tableInfo);
7,845✔
2680
  taosMemoryFreeClear(pList);
7,845✔
2681
  tSimpleHashCleanup(uidTsHash);
7,845✔
2682
  return code;
7,845✔
2683
}
2684

2685
// static bool stReaderTaskWaitQuit(SStreamTask* pTask) { return taosHasRWWFlag(&pTask->entryLock); }
2686

2687
static int32_t getAllTs(SVnode* pVnode, SSDataBlock*  pResBlock, SStreamReaderTaskInner* pTaskInner, STableKeyInfo* pList, int32_t pNum) {
270,871✔
2688
  int32_t code = 0;
270,871✔
2689
  int32_t lino = 0;
270,871✔
2690

2691
  STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdCreateFirstLastTsIter(pVnode, &pTaskInner->options->twindows, &(SVersionRange){.minVer = -1, .maxVer = pTaskInner->options->ver},
270,871✔
2692
                                                pTaskInner->options->suid, pList, pNum, pTaskInner->options->order, &pTaskInner->pReader, pTaskInner->idStr));
2693
  bool hasNext = true;
270,614✔
2694
  while(1){
2695
    STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdNextFirstLastTsBlock(pTaskInner->pReader, pResBlock, &hasNext));
270,614✔
2696
    STREAM_CHECK_CONDITION_GOTO(!hasNext, TDB_CODE_SUCCESS);
270,146✔
2697
  }
2698

2699
end:
270,146✔
2700
  pTaskInner->storageApi->tsdReader.tsdDestroyFirstLastTsIter(pTaskInner->pReader);
270,387✔
2701
  pTaskInner->pReader = NULL;
269,937✔
2702
  return code;
269,937✔
2703
}
2704

2705
static int32_t processTsVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
38,543✔
2706
                                  SStreamReaderTaskInner* pTaskInner) {
2707
  int32_t code = 0;
38,543✔
2708
  int32_t lino = 0;
38,543✔
2709
  STableKeyInfo* pList = NULL;
38,543✔
2710
  StreamTableListInfo     tableInfo = {0};
38,543✔
2711

2712
  void* pTask = sStreamReaderInfo->pTask;
38,543✔
2713
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
38,543✔
2714

2715
  SSDataBlock*  pResBlock = NULL;
38,543✔
2716
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, qStreamGetTableListNum(sStreamReaderInfo)));
38,543✔
2717

2718
  while (true) {
28,125✔
2719
    int32_t        pNum = 0;
66,668✔
2720
    int64_t        suid = 0;
66,668✔
2721
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
66,668✔
2722
    if(pNum == 0) break;
66,668✔
2723
    pTaskInner->options->suid = suid;
28,125✔
2724
    STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
28,125✔
2725
    taosMemoryFreeClear(pList);
27,885✔
2726
  }
2727

2728
  STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, pTaskInner->options->order));
38,543✔
2729

2730
end:
38,543✔
2731
  qStreamDestroyTableInfo(&tableInfo);
38,543✔
2732
  taosMemoryFreeClear(pList);
38,543✔
2733
  blockDataDestroy(pResBlock);
38,543✔
2734
  STREAM_PRINT_LOG_END_WITHID(code, lino);
38,543✔
2735
  return code;
38,543✔
2736
}
2737

2738
static int32_t processTsNonVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
234,903✔
2739
                                  SStreamReaderTaskInner* pTaskInner) {
2740
  int32_t code = 0;
234,903✔
2741
  int32_t lino = 0;
234,903✔
2742
  STableKeyInfo* pList = NULL;
234,903✔
2743
  void* pTask = sStreamReaderInfo->pTask;
234,903✔
2744
  
2745
  SSDataBlock*  pResBlock = NULL;
234,903✔
2746

2747
  int32_t        pNum = 0;
234,903✔
2748
  int64_t        suid = 0;
234,903✔
2749
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, 0, &pList, &pNum));
234,903✔
2750
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
234,691✔
2751
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
201,602✔
2752

2753
  pTaskInner->options->suid = sStreamReaderInfo->suid;
201,814✔
2754
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
201,814✔
2755
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
201,814✔
2756
  int32_t order = pTaskInner->options->order;
107,244✔
2757

2758
  if (sStreamReaderInfo->groupByTbname) {
107,042✔
2759
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
54,340✔
2760
  } else if (sStreamReaderInfo->partitionCols == NULL) {
52,494✔
2761
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
45,059✔
2762
  } else {
2763
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
7,845✔
2764
  }                             
2765
end:
234,406✔
2766
  blockDataDestroy(pResBlock);
234,903✔
2767
  taosMemoryFreeClear(pList);
234,903✔
2768
  STREAM_PRINT_LOG_END_WITHID(code, lino);
234,903✔
2769
  return code;
234,903✔
2770
}
2771

2772
static int32_t processTsOnce(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
53,416✔
2773
                                  SStreamReaderTaskInner* pTaskInner, uint64_t gid) {
2774
  int32_t code = 0;
53,416✔
2775
  int32_t lino = 0;
53,416✔
2776
  STableKeyInfo* pList = NULL;
53,416✔
2777
  void* pTask = sStreamReaderInfo->pTask;
53,416✔
2778
  
2779
  SSDataBlock*  pResBlock = NULL;
53,416✔
2780

2781
  int32_t        pNum = 0;
53,416✔
2782
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
53,416✔
2783
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
53,416✔
2784
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
40,932✔
2785

2786
  pTaskInner->options->suid = sStreamReaderInfo->suid;
40,932✔
2787
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
40,690✔
2788
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
40,932✔
2789
  int32_t order = pTaskInner->options->order;
39,706✔
2790

2791
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
40,448✔
2792
end:
53,174✔
2793
  blockDataDestroy(pResBlock);
53,174✔
2794
  taosMemoryFreeClear(pList);
53,174✔
2795
  STREAM_PRINT_LOG_END_WITHID(code, lino);
52,932✔
2796
  return code;
52,932✔
2797
}
2798

2799
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
273,181✔
2800
                                  SStreamReaderTaskInner* pTaskInner) {
2801
  if (sStreamReaderInfo->isVtableStream) {
273,181✔
2802
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
38,543✔
2803
  }
2804

2805
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
234,903✔
2806
}
2807

2808
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
27,160✔
2809
  int32_t code = 0;
27,160✔
2810
  int32_t lino = 0;
27,160✔
2811
  void*   buf = NULL;
27,160✔
2812
  size_t  size = 0;
27,160✔
2813
  void* pTask = sStreamReaderInfo->pTask;
27,160✔
2814

2815
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d", TD_VID(pVnode), __func__,
27,160✔
2816
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc));
2817

2818
  taosWLockLatch(&sStreamReaderInfo->lock);
27,160✔
2819
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
27,160✔
2820
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
27,160✔
2821
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
27,160✔
2822
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
27,160✔
2823

2824
  STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->vSetTableList));
27,160✔
2825
  STREAM_CHECK_RET_GOTO(qBuildVTableList(sStreamReaderInfo));
27,160✔
2826
end:
27,160✔
2827
  taosWUnLockLatch(&sStreamReaderInfo->lock);
27,160✔
2828
  STREAM_PRINT_LOG_END_WITHID(code, lino);
27,160✔
2829
  SRpcMsg rsp = {
27,160✔
2830
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2831
  tmsgSendRsp(&rsp);
27,160✔
2832
  return code;
27,160✔
2833
}
2834

2835
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
181,776✔
2836
  int32_t                 code = 0;
181,776✔
2837
  int32_t                 lino = 0;
181,776✔
2838
  SStreamReaderTaskInner* pTaskInner = NULL;
181,776✔
2839
  SStreamTsResponse       tsRsp = {0};
182,253✔
2840
  void*                   buf = NULL;
182,253✔
2841
  size_t                  size = 0;
182,253✔
2842

2843
  void* pTask = sStreamReaderInfo->pTask;
182,253✔
2844

2845
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
182,253✔
2846

2847
  BUILD_OPTION(options, 0, sStreamReaderInfo->tableList.version, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, NULL, false, NULL);
182,253✔
2848
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
182,253✔
2849

2850
  tsRsp.ver = sStreamReaderInfo->tableList.version + 1;
182,253✔
2851

2852
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
182,253✔
2853
  
2854
end:
182,253✔
2855
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
182,253✔
2856
  code = buildTsRsp(&tsRsp, &buf, &size);
182,253✔
2857
  STREAM_PRINT_LOG_END_WITHID(code, lino);
182,253✔
2858
  SRpcMsg rsp = {
182,253✔
2859
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2860
  tmsgSendRsp(&rsp);
182,253✔
2861
  taosArrayDestroy(tsRsp.tsInfo);
182,253✔
2862
  taosMemoryFree(pTaskInner);
182,253✔
2863
  return code;
182,253✔
2864
}
2865

2866
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
144,609✔
2867
  int32_t                 code = 0;
144,609✔
2868
  int32_t                 lino = 0;
144,609✔
2869
  SStreamReaderTaskInner* pTaskInner = NULL;
144,609✔
2870
  SStreamTsResponse       tsRsp = {0};
144,609✔
2871
  void*                   buf = NULL;
144,609✔
2872
  size_t                  size = 0;
144,609✔
2873

2874
  void* pTask = sStreamReaderInfo->pTask;
144,609✔
2875
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64, TD_VID(pVnode), __func__, req->firstTsReq.startTime, req->firstTsReq.ver, req->firstTsReq.gid);
144,609✔
2876
  int32_t        pNum = 0;
144,609✔
2877

2878
  tsRsp.ver = pVnode->state.applied;
144,609✔
2879

2880
  BUILD_OPTION(options, 0, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, NULL, false, NULL);
144,609✔
2881
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
144,609✔
2882

2883
  if (req->firstTsReq.gid != 0) {
144,368✔
2884
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
53,175✔
2885
  } else {
2886
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
91,193✔
2887
  }
2888

2889
end:
144,367✔
2890
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
144,609✔
2891
  code = buildTsRsp(&tsRsp, &buf, &size);
144,609✔
2892
  STREAM_PRINT_LOG_END_WITHID(code, lino);
144,127✔
2893
  SRpcMsg rsp = {
144,127✔
2894
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2895
  tmsgSendRsp(&rsp);
143,159✔
2896
  taosArrayDestroy(tsRsp.tsInfo);
144,368✔
2897
  taosMemoryFree(pTaskInner);
144,609✔
2898
  return code;
144,368✔
2899
}
2900

2901
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
121,880✔
2902
  int32_t code = 0;
121,880✔
2903
  int32_t lino = 0;
121,880✔
2904
  void*   buf = NULL;
121,880✔
2905
  size_t  size = 0;
121,880✔
2906
  STableKeyInfo* pList = NULL;
121,880✔
2907

2908
  void* pTask = sStreamReaderInfo->pTask;
121,880✔
2909
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64 ",skey:%" PRId64 ",ekey:%" PRId64 ",gid:%" PRId64, TD_VID(pVnode),
121,880✔
2910
               __func__, req->tsdbMetaReq.ver, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime,
2911
               req->tsdbMetaReq.gid);
2912

2913
  SStreamReaderTaskInner* pTaskInner = NULL;
121,880✔
2914
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
121,880✔
2915

2916
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
121,880✔
2917
    int32_t        pNum = 0;
121,880✔
2918
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbMetaReq.gid, &pList, &pNum));
121,880✔
2919
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, 
121,880✔
2920
                          sStreamReaderInfo->tsSchemas, true, NULL);
2921
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, pList, pNum, &sStreamReaderInfo->storageApi));
121,880✔
2922
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
121,880✔
2923
    
2924
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
121,880✔
2925
  } else {
2926
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2927
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2928
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2929
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2930
  }
2931

2932
  blockDataCleanup(pTaskInner->pResBlockDst);
121,880✔
2933
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
121,880✔
2934
  bool hasNext = true;
121,880✔
2935
  while (true) {
212,907✔
2936
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
334,787✔
2937
    if (!hasNext) {
334,787✔
2938
      break;
121,880✔
2939
    }
2940
    pTaskInner->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
212,907✔
2941
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
212,907✔
2942

2943
    int32_t index = 0;
212,907✔
2944
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
212,907✔
2945
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
212,907✔
2946
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
212,907✔
2947
    if (!sStreamReaderInfo->isVtableStream) {
212,907✔
2948
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
178,441✔
2949
    }
2950
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
212,907✔
2951

2952
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
212,907✔
2953
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2954
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2955
            pTaskInner->pResBlockDst->info.rows++;
212,907✔
2956
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
212,907✔
2957
      break;
×
2958
    }
2959
  }
2960

2961
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
121,880✔
2962
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
121,880✔
2963
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
121,751✔
2964
  if (!hasNext) {
121,751✔
2965
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
121,751✔
2966
  }
2967

2968
end:
121,880✔
2969
  STREAM_PRINT_LOG_END_WITHID(code, lino);
121,543✔
2970
  SRpcMsg rsp = {
121,672✔
2971
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2972
  tmsgSendRsp(&rsp);
121,880✔
2973
  taosMemoryFree(pList);
121,880✔
2974
  return code;
121,880✔
2975
}
2976

2977
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
171,753✔
2978
  int32_t                 code = 0;
171,753✔
2979
  int32_t                 lino = 0;
171,753✔
2980
  SStreamReaderTaskInner* pTaskInner = NULL;
171,753✔
2981
  void*                   buf = NULL;
171,753✔
2982
  size_t                  size = 0;
171,753✔
2983
  SSDataBlock*            pBlockRes = NULL;
171,753✔
2984

2985
  void* pTask = sStreamReaderInfo->pTask;
171,753✔
2986
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
171,753✔
2987
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2988
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2989

2990
  int32_t        pNum = 1;
171,753✔
2991
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
171,753✔
2992
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
171,753✔
2993
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
171,753✔
2994
               sStreamReaderInfo->triggerCols, false, NULL);
2995
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
171,753✔
2996
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
171,753✔
2997
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
171,753✔
2998

2999
  while (1) {
171,753✔
3000
    bool hasNext = false;
343,506✔
3001
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
343,506✔
3002
    if (!hasNext) {
343,506✔
3003
      break;
171,753✔
3004
    }
3005
    // if (!sStreamReaderInfo->isVtableStream){
3006
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
171,753✔
3007
    // }
3008

3009
    SSDataBlock* pBlock = NULL;
171,753✔
3010
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
171,753✔
3011
    if (pBlock != NULL && pBlock->info.rows > 0) {
171,753✔
3012
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
171,753✔
3013
          0, pBlock->info.rows, 1));
3014
    }
3015
    
3016
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
171,753✔
3017
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
171,753✔
3018
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
171,753✔
3019
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3020
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3021
  }
3022

3023
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
171,753✔
3024

3025
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
171,753✔
3026
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
171,753✔
3027

3028
end:
171,753✔
3029
  STREAM_PRINT_LOG_END_WITHID(code, lino);
171,753✔
3030
  SRpcMsg rsp = {
171,753✔
3031
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3032
  tmsgSendRsp(&rsp);
171,753✔
3033
  blockDataDestroy(pBlockRes);
171,753✔
3034

3035
  releaseStreamTask(&pTaskInner);
171,753✔
3036
  return code;
171,753✔
3037
}
3038

UNCOV
3039
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
×
UNCOV
3040
  int32_t                 code = 0;
×
UNCOV
3041
  int32_t                 lino = 0;
×
UNCOV
3042
  SStreamReaderTaskInner* pTaskInner = NULL;
×
UNCOV
3043
  void*                   buf = NULL;
×
UNCOV
3044
  size_t                  size = 0;
×
UNCOV
3045
  SSDataBlock*            pBlockRes = NULL;
×
3046

UNCOV
3047
  void* pTask = sStreamReaderInfo->pTask;
×
UNCOV
3048
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
×
3049
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3050
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3051

UNCOV
3052
  int32_t        pNum = 1;
×
UNCOV
3053
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
×
UNCOV
3054
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
×
UNCOV
3055
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
×
3056
               sStreamReaderInfo->tsSchemas, true, NULL);
UNCOV
3057
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
×
UNCOV
3058
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
×
3059

UNCOV
3060
  while (1) {
×
UNCOV
3061
    bool hasNext = false;
×
UNCOV
3062
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
×
UNCOV
3063
    if (!hasNext) {
×
UNCOV
3064
      break;
×
3065
    }
3066

UNCOV
3067
    SSDataBlock* pBlock = NULL;
×
UNCOV
3068
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
×
UNCOV
3069
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
×
UNCOV
3070
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
×
3071
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
3072
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
3073
  }
3074

UNCOV
3075
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
×
UNCOV
3076
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
×
3077

UNCOV
3078
end:
×
UNCOV
3079
  STREAM_PRINT_LOG_END_WITHID(code, lino);
×
UNCOV
3080
  SRpcMsg rsp = {
×
3081
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
UNCOV
3082
  tmsgSendRsp(&rsp);
×
UNCOV
3083
  blockDataDestroy(pBlockRes);
×
3084

UNCOV
3085
  releaseStreamTask(&pTaskInner);
×
UNCOV
3086
  return code;
×
3087
}
3088

3089
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
116,554✔
3090
  int32_t code = 0;
116,554✔
3091
  int32_t lino = 0;
116,554✔
3092
  void*   buf = NULL;
116,554✔
3093
  size_t  size = 0;
116,554✔
3094
  STableKeyInfo* pList = NULL;
116,554✔
3095
  SArray*        pResList = NULL;
116,554✔
3096
  SSDataBlock*   pBlockTmp = NULL;
116,554✔
3097

3098
  SStreamReaderTaskInner* pTaskInner = NULL;
116,554✔
3099
  void* pTask = sStreamReaderInfo->pTask;
116,554✔
3100
  ST_TASK_DLOG("vgId:%d %s start. ver:%"PRId64",order:%d,startTs:%"PRId64",gid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, req->tsdbTriggerDataReq.gid);
116,554✔
3101
  
3102
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
116,554✔
3103

3104
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
116,312✔
3105
    int32_t        pNum = 0;
58,035✔
3106
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbTriggerDataReq.gid, &pList, &pNum));
58,035✔
3107
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
58,277✔
3108
                 sStreamReaderInfo->triggerCols, false, NULL);
3109
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
58,277✔
3110
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
58,277✔
3111
  } else {
3112
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
58,277✔
3113
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
58,277✔
3114
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3115
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3116
  }
3117

3118
  blockDataCleanup(pTaskInner->pResBlockDst);
58,277✔
3119
  bool hasNext = true;
58,026✔
3120
  int32_t totalRows = 0;
58,026✔
3121
    
3122
  pResList = taosArrayInit(4, POINTER_BYTES);
58,026✔
3123
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
58,026✔
3124
  while (1) {
63,768✔
3125
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
121,794✔
3126
    if (!hasNext) {
121,322✔
3127
      break;
58,036✔
3128
    }
3129
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
63,286✔
3130
    // pTaskInner->pResBlockDst->info.id.groupId = pTaskInner->pResBlock->info.id.groupId;
3131

3132
    SSDataBlock* pBlock = NULL;
63,768✔
3133
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
63,768✔
3134
    if (pBlock != NULL && pBlock->info.rows > 0) {
63,768✔
3135
      STREAM_CHECK_RET_GOTO(
63,768✔
3136
        processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
3137
    }
3138
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
63,768✔
3139
    // STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3140
    ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
63,768✔
3141
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
63,768✔
3142
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
63,527✔
3143
    totalRows += blockDataGetNumOfRows(pBlockTmp);
63,527✔
3144
    pBlockTmp = NULL;
63,527✔
3145

3146
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
63,527✔
3147
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3148
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3149
    if (totalRows >= STREAM_RETURN_ROWS_NUM) {  //todo optimize send multi blocks in one group
63,527✔
3150
      break;
×
3151
    }
3152
  }
3153

3154
  STREAM_CHECK_RET_GOTO(buildArrayRsp(pResList, &buf, &size));
58,036✔
3155
  if (!hasNext) {
58,035✔
3156
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
58,035✔
3157
  }
3158

3159
end:
116,313✔
3160
  STREAM_PRINT_LOG_END_WITHID(code, lino);
116,071✔
3161
  SRpcMsg rsp = {
116,071✔
3162
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3163
  tmsgSendRsp(&rsp);
116,071✔
3164
  taosMemoryFree(pList);
116,554✔
3165
  blockDataDestroy(pBlockTmp);
116,554✔
3166
  taosArrayDestroyP(pResList, (FDelete)blockDataDestroy);
116,554✔
3167
  return code;
116,554✔
3168
}
3169

3170
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
6,253,147✔
3171
  int32_t code = 0;
6,253,147✔
3172
  int32_t lino = 0;
6,253,147✔
3173
  void*   buf = NULL;
6,253,147✔
3174
  size_t  size = 0;
6,253,581✔
3175
  SSDataBlock*   pBlockRes = NULL;
6,253,581✔
3176
  STableKeyInfo* pList = NULL;
6,253,581✔
3177

3178

3179
  void* pTask = sStreamReaderInfo->pTask;
6,253,364✔
3180
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
6,253,581✔
3181
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid, req->tsdbCalcDataReq.ver);
3182

3183
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
6,253,581✔
3184

3185
  SStreamReaderTaskInner* pTaskInner = NULL;
6,253,581✔
3186
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
6,253,581✔
3187

3188
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
6,253,339✔
3189
    int32_t        pNum = 0;
6,253,339✔
3190
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbCalcDataReq.gid, &pList, &pNum));
6,253,339✔
3191
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
6,253,581✔
3192
                 sStreamReaderInfo->triggerCols, false, NULL);
3193
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
6,253,581✔
3194

3195
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
6,247,722✔
3196
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
6,252,062✔
3197
  } else {
3198
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3199
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3200
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3201
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3202
  }
3203

3204
  blockDataCleanup(pTaskInner->pResBlockDst);
6,248,156✔
3205
  bool hasNext = true;
6,248,171✔
3206
  while (1) {
641,380✔
3207
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
6,890,217✔
3208
    if (!hasNext) {
6,887,139✔
3209
      break;
6,246,395✔
3210
    }
3211
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
640,744✔
3212

3213
    SSDataBlock* pBlock = NULL;
642,479✔
3214
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
642,479✔
3215
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
641,380✔
3216
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
642,026✔
3217
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
642,237✔
3218
      break;
×
3219
    }
3220
  }
3221

3222
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
6,245,961✔
3223
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
6,253,147✔
3224
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
6,249,207✔
3225
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
6,250,518✔
3226
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
6,248,999✔
3227
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
6,246,627✔
3228
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
6,252,269✔
3229

3230
  if (!hasNext) {
6,253,339✔
3231
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
6,253,339✔
3232
  }
3233

3234
end:
6,256,185✔
3235
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,251,795✔
3236
  SRpcMsg rsp = {
6,253,748✔
3237
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3238
  tmsgSendRsp(&rsp);
6,253,097✔
3239
  blockDataDestroy(pBlockRes);
6,252,496✔
3240
  taosMemoryFree(pList);
6,252,037✔
3241
  return code;
6,252,713✔
3242
}
3243

3244
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
48,871✔
3245
  int32_t code = 0;
48,871✔
3246
  int32_t lino = 0;
48,871✔
3247
  void*   buf = NULL;
48,871✔
3248
  size_t  size = 0;
48,871✔
3249
  int32_t* slotIdList = NULL;
48,871✔
3250
  SArray* sortedCid = NULL;
48,871✔
3251
  SArray* schemas = NULL;
48,871✔
3252
  SSDataBlock*   pBlockRes = NULL;
48,871✔
3253
  
3254
  void* pTask = sStreamReaderInfo->pTask;
48,871✔
3255
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
48,871✔
3256
    req->tsdbDataReq.skey, req->tsdbDataReq.ekey, req->tsdbDataReq.uid, req->tsdbDataReq.ver);
3257
    
3258
  SStreamReaderTaskInner* pTaskInner = NULL;
48,871✔
3259
  int64_t key = req->tsdbDataReq.uid;
48,871✔
3260

3261
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
48,871✔
3262
    // sort cid and build slotIdList
3263
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
48,871✔
3264
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
48,871✔
3265
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
48,871✔
3266
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
48,871✔
3267
    taosArraySort(sortedCid, sortCid);
48,871✔
3268
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
152,542✔
3269
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
103,890✔
3270
      STREAM_CHECK_NULL_GOTO(cid, terrno);
103,671✔
3271
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
166,526✔
3272
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
166,964✔
3273
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
166,745✔
3274
        if (*cid == *cidSorted) {
166,745✔
3275
          slotIdList[j] = i;
103,671✔
3276
          break;
103,890✔
3277
        }
3278
      }
3279
    }
3280

3281
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas, &sStreamReaderInfo->storageApi));
48,871✔
3282
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
48,871✔
3283
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlockRes));
48,871✔
3284

3285
    taosArraySort(schemas, sortSSchema);
48,871✔
3286
    BUILD_OPTION(options, req->tsdbDataReq.suid, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
48,871✔
3287
                    req->tsdbDataReq.ekey, schemas, true, &slotIdList);
3288
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid, .groupId = 0};
48,871✔
3289
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, pBlockRes, &keyInfo, 1, &sStreamReaderInfo->storageApi));
48,871✔
3290
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
48,652✔
3291
    pTaskInner->pResBlockDst = pBlockRes;
48,871✔
3292
    pBlockRes = NULL;
48,652✔
3293
  } else {
3294
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3295
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3296
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3297
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3298
  }
3299

3300
  blockDataCleanup(pTaskInner->pResBlockDst);
48,652✔
3301
  bool hasNext = true;
48,871✔
3302
  while (1) {
48,871✔
3303
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
97,742✔
3304
    if (!hasNext) {
97,742✔
3305
      break;
48,871✔
3306
    }
3307

3308
    SSDataBlock* pBlock = NULL;
48,871✔
3309
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
48,628✔
3310
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
48,628✔
3311
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
48,871✔
3312
      break;
×
3313
    }
3314
  }
3315
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
48,871✔
3316
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
48,871✔
3317
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
48,871✔
3318
  if (!hasNext) {
48,871✔
3319
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
48,871✔
3320
  }
3321

3322
end:
49,090✔
3323
  STREAM_PRINT_LOG_END_WITHID(code, lino);
48,628✔
3324
  SRpcMsg rsp = {
48,628✔
3325
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3326
  tmsgSendRsp(&rsp);
48,628✔
3327
  taosMemFree(slotIdList);
48,871✔
3328
  taosArrayDestroy(sortedCid);
48,871✔
3329
  taosArrayDestroy(schemas);
48,871✔
3330
  blockDataDestroy(pBlockRes);
48,871✔
3331
  return code;
48,871✔
3332
}
3333

3334
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
2,293,933✔
3335
  int32_t      code = 0;
2,293,933✔
3336
  int32_t      lino = 0;
2,293,933✔
3337
  void*        buf = NULL;
2,293,933✔
3338
  size_t       size = 0;
2,293,933✔
3339
  int64_t      lastVer = 0;
2,293,933✔
3340
  SSTriggerWalNewRsp resultRsp = {0};
2,293,933✔
3341

3342
  void* pTask = sStreamReaderInfo->pTask;
2,294,145✔
3343
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
2,292,241✔
3344

3345
  if (sStreamReaderInfo->metaBlock == NULL) {
2,292,453✔
3346
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
92,514✔
3347
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
92,514✔
3348
  }
3349
  blockDataEmpty(sStreamReaderInfo->metaBlock);
2,293,876✔
3350
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
2,292,906✔
3351
  resultRsp.ver = req->walMetaNewReq.lastVer;
2,292,906✔
3352
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
2,292,906✔
3353

3354
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
2,292,184✔
3355
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
2,293,390✔
3356
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
84,294✔
3357
  buf = rpcMallocCont(size);
84,294✔
3358
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
84,294✔
3359
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
84,294✔
3360
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
84,294✔
3361
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
84,294✔
3362

3363
end:
2,293,390✔
3364
  if (code == 0 && resultRsp.totalRows == 0) {
2,293,390✔
3365
    code = TSDB_CODE_STREAM_NO_DATA;
2,208,376✔
3366
    size = sizeof(int64_t) * 2;
2,208,376✔
3367
    buf = rpcMallocCont(size);
2,208,376✔
3368
    *(int64_t*)buf = resultRsp.ver;
2,205,478✔
3369
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
2,205,720✔
3370
  }
3371
  SRpcMsg rsp = {
2,290,735✔
3372
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3373
  tmsgSendRsp(&rsp);
2,291,227✔
3374
  if (code == TSDB_CODE_STREAM_NO_DATA){
2,294,838✔
3375
    code = 0;
2,210,544✔
3376
  }
3377
  STREAM_PRINT_LOG_END_WITHID(code, lino);
2,294,838✔
3378
  blockDataDestroy(resultRsp.deleteBlock);
2,294,838✔
3379
  blockDataDestroy(resultRsp.tableBlock);
2,294,838✔
3380

3381
  return code;
2,294,598✔
3382
}
3383
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,190,560✔
3384
  int32_t      code = 0;
3,190,560✔
3385
  int32_t      lino = 0;
3,190,560✔
3386
  void*        buf = NULL;
3,190,560✔
3387
  size_t       size = 0;
3,190,560✔
3388
  SSTriggerWalNewRsp resultRsp = {0};
3,190,560✔
3389
  
3390
  void* pTask = sStreamReaderInfo->pTask;
3,190,560✔
3391
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,190,075✔
3392

3393
  if (sStreamReaderInfo->metaBlock == NULL) {
3,190,075✔
3394
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
98,466✔
3395
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
98,466✔
3396
  }
3397

3398
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,190,802✔
3399
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
3,190,078✔
3400
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,188,480✔
3401
  resultRsp.checkAlter = true;
3,188,610✔
3402
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,188,610✔
3403
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
3,188,606✔
3404

3405
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,188,606✔
3406

3407
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,185,694✔
3408
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
129,337✔
3409
  buf = rpcMallocCont(size);
131,061✔
3410
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
131,061✔
3411
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
131,061✔
3412
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
131,061✔
3413
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
131,061✔
3414
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
131,061✔
3415
  printIndexHash(resultRsp.indexHash, pTask);
131,061✔
3416

3417
end:
3,187,418✔
3418
  if (resultRsp.totalRows == 0) {
3,186,694✔
3419
    code = TSDB_CODE_STREAM_NO_DATA;
3,055,874✔
3420
    size = sizeof(int64_t) * 2;
3,055,874✔
3421
    buf = rpcMallocCont(size);
3,055,874✔
3422
    *(int64_t*)buf = resultRsp.ver;
3,052,398✔
3423
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
3,052,398✔
3424
  }
3425
  SRpcMsg rsp = {
3,185,006✔
3426
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3427
  tmsgSendRsp(&rsp);
3,185,826✔
3428
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,190,078✔
3429
    code = 0;
3,059,017✔
3430
  }
3431
  blockDataDestroy(resultRsp.dataBlock);
3,190,078✔
3432
  blockDataDestroy(resultRsp.deleteBlock);
3,187,644✔
3433
  blockDataDestroy(resultRsp.tableBlock);
3,187,402✔
3434
  tSimpleHashCleanup(resultRsp.indexHash);
3,187,153✔
3435

3436
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,186,203✔
3437

3438
  return code;
3,187,203✔
3439
}
3440

3441
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
777,095✔
3442
  int32_t      code = 0;
777,095✔
3443
  int32_t      lino = 0;
777,095✔
3444
  void*        buf = NULL;
777,095✔
3445
  size_t       size = 0;
777,095✔
3446
  SSTriggerWalNewRsp resultRsp = {0};
777,095✔
3447

3448
  void* pTask = sStreamReaderInfo->pTask;
777,095✔
3449
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
777,095✔
3450

3451
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
776,868✔
3452
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
776,656✔
3453
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
777,095✔
3454
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
777,095✔
3455
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
776,132✔
3456

3457
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
776,132✔
3458
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
777,095✔
3459

3460
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
777,095✔
3461

3462
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
27,355✔
3463
  buf = rpcMallocCont(size);
27,355✔
3464
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
27,355✔
3465
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
27,355✔
3466
  printIndexHash(resultRsp.indexHash, pTask);
27,355✔
3467

3468
end:
777,095✔
3469
  if (resultRsp.totalRows == 0) {
777,095✔
3470
    buf = rpcMallocCont(sizeof(int64_t));
749,980✔
3471
    *(int64_t *)buf = resultRsp.ver;
749,497✔
3472
    size = sizeof(int64_t);
749,497✔
3473
    code = TSDB_CODE_STREAM_NO_DATA;
749,497✔
3474
  }
3475
  SRpcMsg rsp = {
776,612✔
3476
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3477
  tmsgSendRsp(&rsp);
776,855✔
3478
  if (code == TSDB_CODE_STREAM_NO_DATA){
777,092✔
3479
    code = 0;
749,737✔
3480
  }
3481

3482
  blockDataDestroy(resultRsp.dataBlock);
777,092✔
3483
  blockDataDestroy(resultRsp.deleteBlock);
776,609✔
3484
  blockDataDestroy(resultRsp.tableBlock);
776,369✔
3485
  tSimpleHashCleanup(resultRsp.indexHash);
776,609✔
3486
  tSimpleHashCleanup(resultRsp.uidHash);
775,889✔
3487
  STREAM_PRINT_LOG_END_WITHID(code, lino);
776,609✔
3488

3489
  return code;
776,859✔
3490
}
3491

3492
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
213,636✔
3493
  int32_t      code = 0;
213,636✔
3494
  int32_t      lino = 0;
213,636✔
3495
  void*        buf = NULL;
213,636✔
3496
  size_t       size = 0;
213,636✔
3497
  SSTriggerWalNewRsp resultRsp = {0};
213,636✔
3498
  SSDataBlock* pBlock1 = NULL;
213,636✔
3499
  SSDataBlock* pBlock2 = NULL;
213,636✔
3500
  
3501
  void* pTask = sStreamReaderInfo->pTask;
213,636✔
3502
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
213,636✔
3503

3504
  SSDataBlock* dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
213,636✔
3505
  STREAM_CHECK_RET_GOTO(createOneDataBlock(dataBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
213,636✔
3506
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
213,636✔
3507
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
213,636✔
3508
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
213,636✔
3509
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
213,636✔
3510
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
213,636✔
3511

3512
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
213,636✔
3513
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
213,394✔
3514

3515
  if (!sStreamReaderInfo->isVtableStream){
169,995✔
3516
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
141,428✔
3517
  
3518
    blockDataTransform(pBlock2, resultRsp.dataBlock);
141,428✔
3519
    blockDataDestroy(resultRsp.dataBlock);
141,670✔
3520
    resultRsp.dataBlock = pBlock2;
141,428✔
3521
    pBlock2 = NULL;
141,428✔
3522
  }
3523

3524
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
169,995✔
3525
  buf = rpcMallocCont(size);
170,237✔
3526
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
169,754✔
3527
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
169,995✔
3528
  printIndexHash(resultRsp.indexHash, pTask);
169,995✔
3529

3530
end:
212,911✔
3531
  if (resultRsp.totalRows == 0) {
213,153✔
3532
    buf = rpcMallocCont(sizeof(int64_t));
43,399✔
3533
    *(int64_t *)buf = resultRsp.ver;
43,399✔
3534
    size = sizeof(int64_t);
43,399✔
3535
    code = TSDB_CODE_STREAM_NO_DATA;
43,399✔
3536
  }
3537
  SRpcMsg rsp = {
213,153✔
3538
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3539
  tmsgSendRsp(&rsp);
213,394✔
3540
  if (code == TSDB_CODE_STREAM_NO_DATA){
213,636✔
3541
    code = 0;
43,399✔
3542
  }
3543

3544
  blockDataDestroy(pBlock1);
213,636✔
3545
  blockDataDestroy(pBlock2);
213,636✔
3546
  blockDataDestroy(resultRsp.dataBlock);
213,636✔
3547
  blockDataDestroy(resultRsp.deleteBlock);
213,636✔
3548
  blockDataDestroy(resultRsp.tableBlock);
213,636✔
3549
  tSimpleHashCleanup(resultRsp.indexHash);
213,636✔
3550
  tSimpleHashCleanup(resultRsp.uidHash);
213,636✔
3551
  STREAM_PRINT_LOG_END_WITHID(code, lino);
213,394✔
3552

3553
  return code;
213,394✔
3554
}
3555

3556
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
239,904✔
3557
  int32_t code = 0;
239,904✔
3558
  int32_t lino = 0;
239,904✔
3559
  void*   buf = NULL;
239,904✔
3560
  size_t  size = 0;
239,904✔
3561
  SArray** gInfo = NULL;
239,904✔
3562
  
3563
  void* pTask = sStreamReaderInfo->pTask;
239,904✔
3564
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
239,904✔
3565

3566
  gInfo = taosHashAcquire(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
239,904✔
3567
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
239,904✔
3568
  SStreamGroupInfo pGroupInfo = {0};
239,904✔
3569
  pGroupInfo.gInfo = *gInfo;
239,904✔
3570

3571
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
239,904✔
3572
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3573
  buf = rpcMallocCont(size);
239,904✔
3574
  STREAM_CHECK_NULL_GOTO(buf, terrno);
239,904✔
3575
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
239,904✔
3576
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3577
end:
239,904✔
3578
  taosHashRelease(sStreamReaderInfo->groupIdMap, gInfo);
239,904✔
3579
  if (code != 0) {
239,904✔
3580
    rpcFreeCont(buf);
×
3581
    buf = NULL;
×
3582
    size = 0;
×
3583
  }
3584
  STREAM_PRINT_LOG_END_WITHID(code, lino);
239,904✔
3585
  SRpcMsg rsp = {
239,904✔
3586
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3587
  tmsgSendRsp(&rsp);
239,904✔
3588

3589
  return code;
239,904✔
3590
}
3591

3592
static int32_t setVtableInfo(SVnode* pVnode, SArray* infos, SArray* cids, int64_t uid, uint64_t gid, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo) {
34,085✔
3593
  int32_t              code = 0;
34,085✔
3594
  int32_t              lino = 0;
34,085✔
3595
  void* pTask = sStreamReaderInfo->pTask;
34,085✔
3596

3597
  VTableInfo* vTable = taosArrayReserve(infos, 1);
34,085✔
3598
  STREAM_CHECK_NULL_GOTO(vTable, terrno);
34,085✔
3599
  vTable->uid = uid;
34,085✔
3600
  vTable->gId = gid;
34,085✔
3601

3602
  ST_TASK_DLOG("vgId:%d %s put vtable uid:%"PRId64, TD_VID(pVnode), __func__, uid);
34,085✔
3603

3604
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, sStreamReaderInfo->tableList.version, uid);
34,085✔
3605
  if (code != 0) {
34,085✔
3606
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
3607
    goto end;
×
3608
  }
3609
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
34,085✔
3610
    vTable->cols.nCols = metaReader->me.colRef.nCols;
844✔
3611
    vTable->cols.version = metaReader->me.colRef.version;
844✔
3612
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
844✔
3613
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
844✔
3614
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
5,064✔
3615
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
4,220✔
3616
    }
3617
  } else {
3618
    vTable->cols.nCols = taosArrayGetSize(cids);
33,241✔
3619
    vTable->cols.version = metaReader->me.colRef.version;
33,241✔
3620
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
33,241✔
3621
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
33,241✔
3622
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
107,298✔
3623
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
325,897✔
3624
        if (metaReader->me.colRef.pColRef[j].hasRef &&
291,942✔
3625
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
213,386✔
3626
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
40,102✔
3627
          break;
40,102✔
3628
        }
3629
      }
3630
    }
3631
  }
3632
  tDecoderClear(&metaReader->coder);
34,085✔
3633

3634
end:
34,085✔
3635
  return code;
34,085✔
3636
}
3637

3638
static int32_t getAllVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* cids, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
24,843✔
3639
  int32_t              code = 0;
24,843✔
3640
  int32_t              lino = 0;
24,843✔
3641
  void* pTask = sStreamReaderInfo->pTask;
24,843✔
3642
  SArray*              pTableListArray = NULL;
24,843✔
3643

3644

3645
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
24,843✔
3646
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
24,843✔
3647

3648
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
24,843✔
3649
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
24,843✔
3650

3651
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
58,928✔
3652
    SStreamTableKeyInfo* pKeyInfo = taosArrayGetP(pTableListArray, i);
34,085✔
3653
    if (pKeyInfo == NULL || pKeyInfo->markedDeleted) {
34,085✔
3654
      continue;
×
3655
    }
3656
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, pKeyInfo->uid, pKeyInfo->groupId, metaReader, sStreamReaderInfo);
34,085✔
3657
    if (code != 0) {
34,085✔
3658
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, pKeyInfo->uid, tstrerror(code));
×
3659
      code = 0;
×
3660
      continue;
×
3661
    }
3662
  }
3663

3664
end:
24,843✔
3665
  taosArrayDestroyP(pTableListArray, taosMemFree);
24,843✔
3666
  return code;
24,843✔
3667
}
3668

3669
static int32_t getSpicificVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* uids, SArray* cids, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
×
3670
  int32_t              code = 0;
×
3671
  int32_t              lino = 0;
×
3672
  void* pTask = sStreamReaderInfo->pTask;
×
3673

3674
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(uids), sizeof(VTableInfo));
×
3675
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
×
3676

3677
  for (size_t i = 0; i < taosArrayGetSize(uids); i++) {
×
3678
    int64_t* uid = taosArrayGet(uids, i);
×
3679
    STREAM_CHECK_NULL_GOTO(uid, terrno);
×
3680

3681
    taosRLockLatch(&sStreamReaderInfo->lock);
×
3682
    uint64_t groupId = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, *uid);
×
3683
    taosRUnLockLatch(&sStreamReaderInfo->lock);
×
3684
    if (groupId == -1) {
×
3685
      ST_TASK_WLOG("vgId:%d %s uid:%"PRId64" not found in stream group", TD_VID(pVnode), __func__, *uid);
×
3686
      continue;
×
3687
    }
3688
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, *uid, groupId, metaReader, sStreamReaderInfo);
×
3689
    if (code != 0) {
×
3690
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, *uid, tstrerror(code));
×
3691
      code = 0;
×
3692
      continue;
×
3693
    }
3694
  }
3695
  
3696
end:
×
3697
  return code;
×
3698
}
3699

3700
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
24,624✔
3701
  int32_t              code = 0;
24,624✔
3702
  int32_t              lino = 0;
24,624✔
3703
  void*                buf = NULL;
24,624✔
3704
  size_t               size = 0;
24,843✔
3705
  SStreamMsgVTableInfo vTableInfo = {0};
24,843✔
3706
  SMetaReader          metaReader = {0};
24,843✔
3707

3708
  void* pTask = sStreamReaderInfo->pTask;
24,843✔
3709
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
24,843✔
3710

3711
  SArray* cids = req->virTableInfoReq.cids;
24,843✔
3712
  STREAM_CHECK_NULL_GOTO(cids, terrno);
24,843✔
3713

3714
  if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
24,843✔
3715
    (void)atomic_val_compare_exchange_8(&sStreamReaderInfo->isVtableOnlyTs, 0, 1);
844✔
3716
  }
3717
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
24,843✔
3718

3719
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
24,843✔
3720
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, &metaReader, sStreamReaderInfo));
24,843✔
3721
  } else {
3722
    STREAM_CHECK_RET_GOTO(getSpicificVinfo(pVnode, &vTableInfo, req->virTableInfoReq.uids, cids, &metaReader, sStreamReaderInfo));
×
3723
  }
3724
  ST_TASK_DLOG("vgId:%d %s end, size:%"PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(vTableInfo.infos));
24,843✔
3725
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
24,843✔
3726

3727
end:
24,843✔
3728
  tDestroySStreamMsgVTableInfo(&vTableInfo);
24,843✔
3729
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
24,843✔
3730
  STREAM_PRINT_LOG_END_WITHID(code, lino);
24,843✔
3731
  SRpcMsg rsp = {
24,843✔
3732
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3733
  tmsgSendRsp(&rsp);
24,843✔
3734
  return code;
24,843✔
3735
}
3736

3737
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
27,160✔
3738
  int32_t                   code = 0;
27,160✔
3739
  int32_t                   lino = 0;
27,160✔
3740
  void*                     buf = NULL;
27,160✔
3741
  size_t                    size = 0;
27,160✔
3742
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
27,160✔
3743
  SMetaReader               metaReader = {0};
27,160✔
3744
  void*                     pTask = sStreamReaderInfo->pTask;
27,160✔
3745

3746
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
27,160✔
3747

3748
  SArray* cols = req->origTableInfoReq.cols;
27,160✔
3749
  STREAM_CHECK_NULL_GOTO(cols, terrno);
27,160✔
3750

3751
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
27,160✔
3752

3753
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
27,160✔
3754

3755
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
27,160✔
3756
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
70,638✔
3757
    OTableInfo*    oInfo = taosArrayGet(cols, i);
43,478✔
3758
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
43,478✔
3759
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
43,478✔
3760
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
43,478✔
3761
    code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByName(&metaReader, oInfo->refTableName);
43,478✔
3762
    if (code != 0) {
43,267✔
3763
      code = 0;
211✔
3764
      ST_TASK_ELOG("vgId:%d %s get table entry by name:%s failed, msg:%s", TD_VID(pVnode), __func__, oInfo->refTableName, tstrerror(code));
211✔
3765
      continue;
211✔
3766
    }
3767
    vTableInfo->uid = metaReader.me.uid;
43,056✔
3768
    ST_TASK_DLOG("vgId:%d %s get original uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
43,267✔
3769

3770
    SSchemaWrapper* sSchemaWrapper = NULL;
43,267✔
3771
    if (metaReader.me.type == TD_CHILD_TABLE) {
43,267✔
3772
      int64_t suid = metaReader.me.ctbEntry.suid;
41,357✔
3773
      vTableInfo->suid = suid;
41,357✔
3774
      tDecoderClear(&metaReader.coder);
41,357✔
3775
      STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByUid(&metaReader, suid));
41,357✔
3776
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
41,117✔
3777
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
1,910✔
3778
      vTableInfo->suid = 0;
1,910✔
3779
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
1,910✔
3780
    } else {
3781
      ST_TASK_ELOG("invalid table type:%d", metaReader.me.type);
×
3782
    }
3783

3784
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
195,938✔
3785
      SSchema* s = sSchemaWrapper->pSchema + j;
196,389✔
3786
      if (strcmp(s->name, oInfo->refColName) == 0) {
196,149✔
3787
        vTableInfo->cid = s->colId;
43,267✔
3788
        break;
43,267✔
3789
      }
3790
    }
3791
    if (vTableInfo->cid == 0) {
43,056✔
3792
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
3793
              oInfo->refTableName);
3794
    }
3795
    tDecoderClear(&metaReader.coder);
43,027✔
3796
  }
3797

3798
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
27,160✔
3799

3800
end:
27,160✔
3801
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
27,160✔
3802
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
27,160✔
3803
  STREAM_PRINT_LOG_END_WITHID(code, lino);
27,160✔
3804
  SRpcMsg rsp = {
27,160✔
3805
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3806
  tmsgSendRsp(&rsp);
27,160✔
3807
  return code;
27,160✔
3808
}
3809

3810
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
85,106✔
3811
  int32_t                   code = 0;
85,106✔
3812
  int32_t                   lino = 0;
85,106✔
3813
  void*                     buf = NULL;
85,106✔
3814
  size_t                    size = 0;
85,106✔
3815
  SSDataBlock* pBlock = NULL;
85,106✔
3816

3817
  SMetaReader               metaReader = {0};
85,106✔
3818
  SMetaReader               metaReaderStable = {0};
85,106✔
3819
  int64_t streamId = req->base.streamId;
85,106✔
3820
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
85,106✔
3821

3822
  SArray* cols = req->virTablePseudoColReq.cids;
85,106✔
3823
  STREAM_CHECK_NULL_GOTO(cols, terrno);
85,106✔
3824

3825
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
85,106✔
3826
  STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByUid(&metaReader, req->virTablePseudoColReq.uid));
85,106✔
3827

3828
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
85,106✔
3829

3830
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
85,106✔
3831
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
85,106✔
3832
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
2,156✔
3833
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
2,156✔
3834
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
2,156✔
3835
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
2,156✔
3836
    pBlock->info.rows = 1;
2,156✔
3837
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
2,156✔
3838
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,156✔
3839
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
2,156✔
3840
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
82,950✔
3841
    int64_t suid = metaReader.me.ctbEntry.suid;
82,950✔
3842
    sStreamReaderInfo->storageApi.metaReaderFn.readerReleaseLock(&metaReader);
82,950✔
3843
    sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
82,950✔
3844

3845
    STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
82,950✔
3846
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
82,950✔
3847
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
224,960✔
3848
      col_id_t* id = taosArrayGet(cols, i);
142,010✔
3849
      STREAM_CHECK_NULL_GOTO(id, terrno);
142,010✔
3850
      if (*id == -1) {
142,010✔
3851
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
82,950✔
3852
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
82,950✔
3853
        continue;
82,950✔
3854
      }
3855
      size_t j = 0;
59,060✔
3856
      for (; j < sSchemaWrapper->nCols; j++) {
75,485✔
3857
        SSchema* s = sSchemaWrapper->pSchema + j;
75,485✔
3858
        if (s->colId == *id) {
75,485✔
3859
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
59,060✔
3860
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
59,060✔
3861
          break;
59,060✔
3862
        }
3863
      }
3864
      if (j == sSchemaWrapper->nCols) {
59,060✔
3865
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3866
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3867
      }
3868
    }
3869
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
82,950✔
3870
    pBlock->info.rows = 1;
82,950✔
3871
    
3872
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
224,960✔
3873
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
142,010✔
3874
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
142,010✔
3875

3876
      if (pDst->info.colId == -1) {
142,010✔
3877
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
82,950✔
3878
        continue;
82,950✔
3879
      }
3880
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
59,060✔
3881
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3882
        continue;
×
3883
      }
3884

3885
      STagVal val = {0};
59,060✔
3886
      val.cid = pDst->info.colId;
59,060✔
3887
      const char* p = sStreamReaderInfo->storageApi.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
59,060✔
3888

3889
      char* data = NULL;
59,060✔
3890
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
59,060✔
3891
        data = tTagValToData((const STagVal*)p, false);
59,060✔
3892
      } else {
3893
        data = (char*)p;
×
3894
      }
3895

3896
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
59,060✔
3897
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3898

3899
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
59,060✔
3900
          (data != NULL)) {
3901
        taosMemoryFree(data);
10,950✔
3902
      }
3903
    }
3904
  } else {
UNCOV
3905
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3906
    code = TSDB_CODE_INVALID_PARA;
×
3907
    goto end;
×
3908
  }
3909
  
3910
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
85,106✔
3911
  printDataBlock(pBlock, __func__, "", streamId);
85,106✔
3912
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
85,106✔
3913

3914
end:
85,106✔
3915
  if(size == 0){
85,106✔
3916
    code = TSDB_CODE_STREAM_NO_DATA;
×
3917
  }
3918
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReaderStable);
85,106✔
3919
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
85,106✔
3920
  STREAM_PRINT_LOG_END(code, lino);
85,106✔
3921
  SRpcMsg rsp = {
85,106✔
3922
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3923
  tmsgSendRsp(&rsp);
85,106✔
3924
  blockDataDestroy(pBlock);
85,106✔
3925
  return code;
85,106✔
3926
}
3927

3928
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
7,073,561✔
3929
  int32_t            code = 0;
7,073,561✔
3930
  int32_t            lino = 0;
7,073,561✔
3931
  void*              buf = NULL;
7,073,561✔
3932
  size_t             size = 0;
7,073,561✔
3933
  void*              taskAddr = NULL;
7,073,561✔
3934
  SArray*            pResList = NULL;
7,073,561✔
3935
  bool               hasNext = false;
7,073,561✔
3936

3937
  SResFetchReq req = {0};
7,073,561✔
3938
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
7,073,561✔
3939
                              TSDB_CODE_QRY_INVALID_INPUT);
3940
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
7,073,283✔
3941
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
7,073,321✔
3942

3943
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
7,073,321✔
3944
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
7,073,321✔
3945
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
7,073,561✔
3946
  sStreamReaderCalcInfo->rtInfo.execId = req.execId;
7,073,561✔
3947

3948
  void* pTask = sStreamReaderCalcInfo->pTask;
7,073,561✔
3949
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
7,073,321✔
3950
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
3951

3952
  if (req.reset) {
7,073,561✔
3953
    int64_t uid = 0;
3,637,665✔
3954
    if (req.dynTbname) {
3,637,665✔
3955
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
127,525✔
3956
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
127,525✔
3957
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
127,525✔
3958
        if (pValue != NULL && pValue->isTbname) {
127,525✔
3959
          uid = pValue->uid;
127,525✔
3960
          break;
127,525✔
3961
        }
3962
      }
3963
    }
3964
    
3965
    SReadHandle handle = {0};
3,637,665✔
3966
    handle.vnode = pVnode;
3,637,665✔
3967
    handle.pMsgCb = &pVnode->msgCb;
3,637,665✔
3968
    handle.pWorkerCb = pInfo->workerCb;
3,637,425✔
3969
    handle.uid = uid;
3,637,665✔
3970
    handle.cacheSttStatis = true;
3,637,665✔
3971

3972
    initStorageAPI(&handle.api);
3,637,665✔
3973
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
3,637,665✔
3974
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
2,886,669✔
3975
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,448,918✔
3976
      if (node != NULL) {
3,449,158✔
3977
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
297,964✔
3978
      } else {
3979
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
3,151,194✔
3980
      }
3981

3982
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
3,449,158✔
3983
      if (node != NULL) {
3,449,158✔
3984
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
77,770✔
3985
      } else {
3986
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
3,371,388✔
3987
      }      
3988
    }
3989

3990
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
3,637,665✔
3991
    sStreamReaderCalcInfo->rtInfo.funcInfo.hasPlaceHolder = sStreamReaderCalcInfo->hasPlaceHolder;
3,637,665✔
3992
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
3,637,665✔
3993

3994
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
3,637,665✔
3995
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
447,246✔
3996
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
447,006✔
3997
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
3998
                                                    req.taskId));
3999
    } else {
4000
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
3,190,419✔
4001
    }
4002

4003
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
3,637,400✔
4004
  }
4005

4006
  if (req.pOpParam != NULL) {
7,072,764✔
4007
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
161,418✔
4008
  }
4009

4010
  pResList = taosArrayInit(4, POINTER_BYTES);
7,072,764✔
4011
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
7,073,296✔
4012
  uint64_t ts = 0;
7,073,296✔
4013
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
7,073,031✔
4014

4015
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
18,408,741✔
4016
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
11,336,380✔
4017
    if (pBlock == NULL) continue;
11,336,380✔
4018
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
11,336,380✔
4019
/*    
4020
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
4021
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
4022
      printDataBlock(pBlock, __func__, "fetch filter");
4023
    }
4024
*/    
4025
  }
4026

4027
end:
7,074,093✔
4028
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
7,073,561✔
4029
  taosArrayDestroy(pResList);
7,073,561✔
4030
  streamReleaseTask(taskAddr);
7,073,561✔
4031

4032
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
7,073,304✔
4033
    code = TDB_CODE_SUCCESS;
×
4034
  }
4035
  STREAM_PRINT_LOG_END(code, lino);
7,073,304✔
4036
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
7,073,818✔
4037
  tmsgSendRsp(&rsp);
7,073,304✔
4038
  tDestroySResFetchReq(&req);
7,073,026✔
4039
  if (TDB_CODE_SUCCESS != code) {
7,073,561✔
4040
    ST_TASK_ELOG("vgId:%d %s failed, code:%d - %s", TD_VID(pVnode), __func__,
×
4041
                 code, tstrerror(code));
4042
  }
4043
  return code;
7,073,561✔
4044
}
4045

4046
static int32_t initTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SVnode* pVnode) {
13,918,837✔
4047
  int32_t code = 0;
13,918,837✔
4048
  if (sStreamReaderInfo->tableList.pTableList != NULL) {  
13,918,837✔
4049
    return code;
13,729,041✔
4050
  }
4051
  taosWLockLatch(&sStreamReaderInfo->lock);
190,980✔
4052
  sStreamReaderInfo->pVnode = pVnode;
190,980✔
4053
  initStorageAPI(&sStreamReaderInfo->storageApi);
190,980✔
4054
  if (sStreamReaderInfo->tableList.pTableList == NULL) {
190,493✔
4055
    code = initStreamTableListInfo(&sStreamReaderInfo->tableList);
190,493✔
4056
    if (code == 0) {
190,980✔
4057
      code = generateTablistForStreamReader(pVnode, sStreamReaderInfo);
190,980✔
4058
      if (code != 0) {
190,980✔
4059
        qStreamDestroyTableInfo(&sStreamReaderInfo->tableList);
×
4060
      } else {
4061
        sStreamReaderInfo->tableList.version = pVnode->state.applied;
190,980✔
4062
        stDebug("vgId:%d %s init table list for stream reader, table num:%zu, version:%" PRId64,
190,980✔
4063
                TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList), sStreamReaderInfo->tableList.version);
4064
      }
4065
    }
4066
  }
4067
  taosWUnLockLatch(&sStreamReaderInfo->lock);
190,980✔
4068
  return code;
190,980✔
4069
}
4070

4071
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
21,100,670✔
4072
  int32_t                   code = 0;
21,100,670✔
4073
  int32_t                   lino = 0;
21,100,670✔
4074
  SSTriggerPullRequestUnion req = {0};
21,100,670✔
4075
  void*                     taskAddr = NULL;
21,101,108✔
4076
  bool                      sendRsp = false;
21,096,376✔
4077

4078
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
21,096,376✔
4079
  if (!syncIsReadyForRead(pVnode->sync)) {
21,098,809✔
4080
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
88,323✔
4081
    return 0;
88,136✔
4082
  }
4083

4084
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
21,013,966✔
4085
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
7,073,561✔
4086
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
13,939,921✔
4087
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
13,939,921✔
4088
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
13,939,197✔
4089
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
13,939,924✔
4090
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
13,937,010✔
4091
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId, pVnode->state.applied);
4092
    SStreamTriggerReaderInfo* sStreamReaderInfo = qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
13,937,440✔
4093
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
13,939,098✔
4094
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
13,918,812✔
4095
    sendRsp = true;
13,919,538✔
4096
    switch (req.base.type) {
13,919,538✔
4097
      case STRIGGER_PULL_SET_TABLE:
27,160✔
4098
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
27,160✔
4099
        break;
27,160✔
4100
      case STRIGGER_PULL_LAST_TS:
182,253✔
4101
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
182,253✔
4102
        break;
182,253✔
4103
      case STRIGGER_PULL_FIRST_TS:
144,609✔
4104
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
144,609✔
4105
        break;
144,368✔
4106
      case STRIGGER_PULL_TSDB_META:
121,880✔
4107
      case STRIGGER_PULL_TSDB_META_NEXT:
4108
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
121,880✔
4109
        break;
121,751✔
4110
      case STRIGGER_PULL_TSDB_TS_DATA:
171,753✔
4111
        if (sStreamReaderInfo->isVtableStream) {
171,753✔
UNCOV
4112
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
4113
        } else {
4114
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
171,753✔
4115
        }
4116
        break;
171,753✔
4117
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
116,554✔
4118
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4119
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
116,554✔
4120
        break;
58,277✔
4121
      case STRIGGER_PULL_TSDB_CALC_DATA:
6,253,364✔
4122
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4123
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
6,253,364✔
4124
        break;
6,251,845✔
4125
      case STRIGGER_PULL_TSDB_DATA:
48,871✔
4126
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4127
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
48,871✔
4128
        break;
48,871✔
4129
      case STRIGGER_PULL_GROUP_COL_VALUE:
239,904✔
4130
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
239,904✔
4131
        break;
239,904✔
4132
      case STRIGGER_PULL_VTABLE_INFO:
24,843✔
4133
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
24,843✔
4134
        break;
24,843✔
4135
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
85,106✔
4136
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
85,106✔
4137
        break;
85,106✔
4138
      case STRIGGER_PULL_OTABLE_INFO:
27,160✔
4139
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
27,160✔
4140
        break;
27,160✔
4141
      case STRIGGER_PULL_WAL_META_NEW:
2,294,113✔
4142
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
2,294,113✔
4143
        break;
2,294,598✔
4144
      case STRIGGER_PULL_WAL_DATA_NEW:
777,095✔
4145
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
777,095✔
4146
        break;
776,612✔
4147
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,190,318✔
4148
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,190,318✔
4149
        break;
3,188,386✔
4150
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
213,636✔
4151
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
213,636✔
4152
        break;
213,394✔
4153
      default:
941✔
4154
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
941✔
4155
        sendRsp = false;
×
4156
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4157
    }
4158
  } else {
4159
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
4160
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4161
  }
4162
end:
13,925,844✔
4163

4164
  streamReleaseTask(taskAddr);
13,936,481✔
4165

4166
  tDestroySTriggerPullRequest(&req);
13,939,196✔
4167
  STREAM_PRINT_LOG_END(code, lino);
13,929,442✔
4168
  if (!sendRsp) {
13,935,982✔
4169
    SRpcMsg rsp = {
40,572✔
4170
      .code = code,
4171
      .pCont = pMsg->info.rsp,
20,286✔
4172
      .contLen = pMsg->info.rspLen,
20,286✔
4173
      .info = pMsg->info,
4174
    };
4175
    tmsgSendRsp(&rsp);
20,286✔
4176
  }
4177
  return code;
13,936,489✔
4178
}
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