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

taosdata / TDengine / #5005

26 Mar 2026 12:51PM UTC coverage: 72.152% (-0.2%) from 72.338%
#5005

push

travis-ci

web-flow
merge: from main to 3.0 branch #34951

512 of 851 new or added lines in 47 files covered. (60.16%)

6189 existing lines in 147 files now uncovered.

253282 of 351039 relevant lines covered (72.15%)

132156710.33 hits per line

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

84.84
/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) {
7,022,478✔
65
  int64_t suid = 0;
7,022,478✔
66
  if (!sStreamReaderInfo->isVtableStream) {
7,022,478✔
67
    suid = sStreamReaderInfo->suid;
6,606,402✔
68
    goto end;
6,606,609✔
69
  }
70

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

75
  taosRLockLatch(&sStreamReaderInfo->lock);
416,076✔
76
  SStreamTableMapElement* element = taosHashGet(sStreamReaderInfo->vSetTableList.uIdMap, &pList->uid, LONG_BYTES);  
416,076✔
77
  if (element != 0) {
416,076✔
78
    suid = element->table->groupId;
240,404✔
79
    taosRUnLockLatch(&sStreamReaderInfo->lock);
240,404✔
80
    goto end;
240,404✔
81
  }
82
  taosRUnLockLatch(&sStreamReaderInfo->lock);
175,672✔
83

84
end:
7,022,478✔
85
  return suid;
7,022,478✔
86
}
87

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

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

94
  if (*c1 < *c2) {
2,264,198✔
95
    return -1;
2,254,190✔
96
  } else if (*c1 > *c2) {
10,008✔
97
    return 1;
10,008✔
98
  }
99

100
  return 0;
×
101
}
102

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

107
  if (c1->colId < c2->colId) {
2,252,708✔
108
    return -1;
2,242,700✔
109
  } else if (c1->colId > c2->colId) {
10,008✔
110
    return 1;
10,008✔
111
  }
112

113
  return 0;
×
114
}
115

116
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
41,387,280✔
117
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
41,387,280✔
118
  if (pSrc == NULL) {
41,396,996✔
119
    return terrno;
×
120
  }
121

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
41,396,996✔
123
  return 0;
41,391,173✔
124
}
125

126
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
9,604,533✔
127
  int32_t code = pTask->storageApi->tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
9,604,533✔
128
  if (code != TSDB_CODE_SUCCESS) {
9,605,644✔
129
    pTask->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
130
  }
131

132
  return code;
9,603,555✔
133
}
134

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

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

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

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
5,202,567✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
5,202,567✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
2,341,968✔
165
      suid == sStreamReaderInfo->suid) {
855,625✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
10,474✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
10,474✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
10,474✔
169
    if (gid == (uint64_t)-1) return true;
10,474✔
170
  }
171
  return false;
5,192,637✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
12,752,149✔
175
  int32_t  ret = false;
12,752,149✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
12,752,149✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
7,499,895✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
3,480,787✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
8,730,144✔
181
  if (*id == -1) goto end;
8,730,630✔
182
  ret = true;
5,418,547✔
183

184
end:
12,754,730✔
185
  stTrace("%s ret:%d %p %p check suid:%" PRId64 " uid:%" PRId64 " gid:%"PRIu64, __func__, ret, sStreamReaderInfo, sStreamReaderInfo->tableList.gIdMap, suid, uid, *id);
12,754,730✔
186
  return ret;
12,753,300✔
187
}
188

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

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
55,365,776✔
194
  bool ret = false;
55,365,776✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
55,365,776✔
196
  if (sStreamReaderInfo->isVtableStream) {
55,373,503✔
197
    int64_t tmp[2] = {suid, uid};
42,651,297✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
42,651,501✔
199
      *id = uid;
14,689,613✔
200
      ret = true;
14,689,613✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
12,721,210✔
204
  }
205

206
end:
55,367,044✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
55,367,044✔
208
  return ret;
55,373,149✔
209
}
210

211
static int32_t  qTransformStreamTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, void* pTableListInfo, StreamTableListInfo* tableInfo){
297,486✔
212
  SArray* pList = qStreamGetTableListArray(pTableListInfo);
297,486✔
213
  int32_t totalSize = taosArrayGetSize(pList);
297,486✔
214
  int32_t code = 0;
297,486✔
215
  void* pTask = sStreamReaderInfo->pTask;
297,486✔
216
  for (int32_t i = 0; i < totalSize; ++i) {
813,744✔
217
    STableKeyInfo* info = taosArrayGet(pList, i);
516,258✔
218
    if (info == NULL) {
516,258✔
219
      continue;
×
220
    }
221
    code = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
516,258✔
222
    if (code != 0){
515,674✔
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);
515,674✔
227
    if (code != 0){
516,031✔
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);
516,031✔
232
    if (code != 0){
516,258✔
233
      return code;
×
234
    }
235
  }
236
  return 0;
297,486✔
237
}
238

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

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

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

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

281
static int32_t buildTsRsp(const SStreamTsResponse* tsRsp, void** data, size_t* size) {
535,829✔
282
  int32_t code = 0;
535,829✔
283
  int32_t lino = 0;
535,829✔
284
  void*   buf = NULL;
535,829✔
285
  int32_t len = tSerializeSStreamTsResponse(NULL, 0, tsRsp);
535,829✔
286
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
535,182✔
287
  buf = rpcMallocCont(len);
535,182✔
288
  STREAM_CHECK_NULL_GOTO(buf, terrno);
535,367✔
289
  int32_t actLen = tSerializeSStreamTsResponse(buf, len, tsRsp);
535,367✔
290
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
535,367✔
291
  *data = buf;
535,367✔
292
  *size = len;
535,598✔
293
  buf = NULL;
535,136✔
294
end:
535,136✔
295
  rpcFreeCont(buf);
535,136✔
296
  return code;
535,411✔
297
}
298

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
8,448,668✔
301
  int32_t code = 0;
8,448,668✔
302
  int32_t lino = 0;
8,448,668✔
303
  void*   buf = NULL;
8,448,668✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
8,448,668✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
2,273,390✔
306
  buf = rpcMallocCont(dataEncodeSize);
2,273,390✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
2,272,783✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
2,272,783✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
2,272,780✔
310
  *data = buf;
2,272,780✔
311
  *size = dataEncodeSize;
2,272,780✔
312
  buf = NULL;
2,272,780✔
313
end:
8,457,109✔
314
  rpcFreeCont(buf);
8,457,109✔
315
  return code;
8,447,821✔
316
}
317

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

322
  void*   buf = NULL;
56,195✔
323

324
  int32_t blockNum = 0;
56,195✔
325
  size_t  dataEncodeBufSize = 0;
56,195✔
326
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
117,593✔
327
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
61,398✔
328
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
61,398✔
329
    int32_t blockSize = blockGetEncodeSize(pBlock);
61,398✔
330
    dataEncodeBufSize += blockSize;
61,398✔
331
    blockNum++;
61,398✔
332
  }
333
  buf = rpcMallocCont(INT_BYTES + dataEncodeBufSize);
56,195✔
334
  STREAM_CHECK_NULL_GOTO(buf, terrno);
56,195✔
335

336
  char* dataBuf = (char*)buf;
56,195✔
337
  *((int32_t*)(dataBuf)) = blockNum;
56,195✔
338
  dataBuf += INT_BYTES;
56,195✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
117,593✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
61,398✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
61,398✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
61,398✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
61,398✔
344
    dataBuf += actualLen;
61,398✔
345
  }
346
  *data = buf;
56,195✔
347
  *size = INT_BYTES + dataEncodeBufSize;
56,195✔
348
  buf = NULL;
56,195✔
349
end:
56,195✔
350
  rpcFreeCont(buf);
56,195✔
351
  return code;
56,195✔
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) {
9,894,180✔
375
  int32_t code = 0;
9,894,180✔
376
  int32_t lino = 0;
9,894,180✔
377
  int32_t index = 0;
9,894,180✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
9,894,180✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
9,895,656✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
9,894,677✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
9,895,887✔
382

383
end:
9,894,960✔
384
  return code;
9,894,960✔
385
}
386

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

395
end:
3,426✔
396
  return code;
3,426✔
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,
30,112✔
408
                              int64_t ver) {
409
  int32_t    code = 0;
30,112✔
410
  int32_t    lino = 0;
30,112✔
411
  SDecoder   decoder = {0};
30,112✔
412
  SDeleteRes req = {0};
30,112✔
413
  void* pTask = sStreamReaderInfo->pTask;
30,112✔
414

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

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

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

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

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

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

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

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

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

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

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

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

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

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

554
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
65,206✔
555
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
32,603✔
556
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
32,603✔
557
    uint64_t id = 0;
32,603✔
558
    if(!uidInTableListOrigin(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id)) {
32,603✔
559
      continue;
31,733✔
560
    }
561

562
    if (sStreamReaderInfo->deleteOutTbl != 0) {
870✔
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) {
870✔
570
      if (uidList == NULL) {
870✔
571
        uidList = taosArrayInit(8, sizeof(tb_uid_t));
870✔
572
        STREAM_CHECK_NULL_GOTO(uidList, terrno);
870✔
573
      }
574
      STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pDropTbReq->uid), terrno);
1,740✔
575
    }
576
    
577
    ST_TASK_DLOG("stream reader scan drop uid %" PRId64 ", id %" PRIu64, pDropTbReq->uid, id);
870✔
578
  }
579
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDelOutTbl, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_DROP));
32,603✔
580

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

596
static int32_t qStreamModifyTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* tableListDel) {
45,996✔
597
  int32_t      code = 0;
45,996✔
598
  int32_t      lino = 0;
45,996✔
599
  void* pTask = sStreamReaderInfo->pTask;
45,996✔
600
  
601
  taosWLockLatch(&sStreamReaderInfo->lock);
45,996✔
602
  int32_t totalSize = taosArrayGetSize(tableListDel);
45,996✔
603
  for (int32_t i = 0; i < totalSize; ++i) {
45,996✔
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);
45,996✔
612
  for (int32_t i = 0; i < totalSize; ++i) {
75,334✔
613
    STableKeyInfo* info = taosArrayGet(tableListAdd, i);
29,338✔
614
    if (info == NULL) {
29,338✔
615
      continue;
×
616
    }
617
    int ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
29,338✔
618
    if (ret != 0){
29,338✔
619
      ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, ret);
6,637✔
620
      continue;
6,637✔
621
    }
622
    ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
22,701✔
623
    if (ret != 0){
22,701✔
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));
22,701✔
628
    STREAM_CHECK_RET_GOTO(qStreamSetTableList(&sStreamReaderInfo->tableList, info->uid, info->groupId));
22,701✔
629
  }
630

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

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

641
  if (taosArrayGetSize(uidList) == 0) {
45,996✔
642
    return 0;
16,658✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
29,338✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
29,338✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

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

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

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

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

672
  if (sStreamReaderInfo->isVtableStream) {
24,614✔
673
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
5,112✔
674
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
5,112✔
675
  }
676
  
677
  SVCreateTbReq* pCreateReq = NULL;
24,614✔
678
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
49,228✔
679
    pCreateReq = req.pReqs + iReq;
24,614✔
680
    if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
24,614✔
681
      ST_TASK_DLOG("stream reader scan create table jump, %s", pCreateReq->name);
16,658✔
682
      continue;
16,658✔
683
    }
684
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
7,956✔
685
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
15,912✔
686
  }
687
  
688
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
24,614✔
689
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
24,614✔
690
  if (sStreamReaderInfo->isVtableStream) {
24,614✔
691
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
5,112✔
692
  }
693

694
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
24,614✔
695
end:
24,614✔
696
  taosArrayDestroy(uidList);
24,614✔
697
  taosArrayDestroy(uidListAdd);
24,614✔
698
  taosArrayDestroy(tableList);
24,614✔
699
  tDeleteSVCreateTbBatchReq(&req);
24,614✔
700
  tDecoderClear(&decoder);
24,614✔
701
  return code;
24,614✔
702
}
703

704
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq, int64_t ver) {
5,176,590✔
705
  int32_t  code = 0;
5,176,590✔
706
  int32_t  lino = 0;
5,176,590✔
707
  void*    pTask = sStreamReaderInfo->pTask;
5,176,590✔
708
  SArray*  uidList = NULL;
5,177,070✔
709
  SArray*  tableList = NULL;
5,177,070✔
710

711
  ST_TASK_DLOG("%s start, name:%s uid:%"PRId64, __func__, pCreateReq->name, pCreateReq->uid);
5,176,526✔
712
  if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false) ||
5,179,266✔
713
      ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
1,974✔
714
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
5,176,289✔
715
    goto end;
5,176,289✔
716
  }
717
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,430✔
718
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,430✔
719
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
2,860✔
720
  ST_TASK_DLOG("stream reader scan auto create table %s", pCreateReq->name);
1,430✔
721

722
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,430✔
723
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,430✔
724
end:
5,174,993✔
725
  taosArrayDestroy(uidList);
5,177,953✔
726
  taosArrayDestroy(tableList);
5,177,953✔
727
  return code;
5,177,956✔
728
}
729

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

747
static bool isAlteredTable(int8_t action, ETableType tbType) {
20,414✔
748
  if (action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL && tbType == TSDB_CHILD_TABLE) {
20,414✔
749
    return true;
19,952✔
750
  } else if (action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL && tbType == TSDB_SUPER_TABLE) {
462✔
UNCOV
751
    return true;
×
752
  } else if ((action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) && 
462✔
753
     (tbType == TSDB_VIRTUAL_CHILD_TABLE || tbType == TSDB_VIRTUAL_NORMAL_TABLE)) {
462✔
754
    return true;
462✔
755
  }
UNCOV
756
  return false;
×
757
}
758

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

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

782
  uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
462✔
783
  STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
462✔
784

785
  uint64_t id = 0;
462✔
786
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListOrigin(sStreamReaderInfo, sStreamReaderInfo->suid, uid, &id), TDB_CODE_SUCCESS);
462✔
787

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

795
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListAdd, &uid), terrno);
462✔
796
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
462✔
797

798
  ST_TASK_DLOG("stream reader scan alter table column ref %s", pReq->tbName);
462✔
799

800
end:
462✔
801
  taosArrayDestroy(uidListAdd);
462✔
802
  STREAM_PRINT_LOG_END_WITHID(code, lino);
462✔
803
  return code;
462✔
804
}
805

806
static int32_t checkAlter(SStreamTriggerReaderInfo* sStreamReaderInfo, char* tbName, int8_t action, uint64_t *uid) {
20,414✔
807
  int32_t  code = 0;
20,414✔
808
  int32_t  lino = 0;
20,414✔
809
  ETableType tbType = 0;
20,414✔
810
  uint64_t suid = 0;
20,414✔
811

812
  STREAM_CHECK_RET_GOTO(metaGetTableTypeSuidByName(sStreamReaderInfo->pVnode, tbName, &tbType, &suid));
20,414✔
813
  STREAM_CHECK_CONDITION_GOTO(!isAlteredTable(action, tbType), TDB_CODE_SUCCESS);
20,414✔
814
  STREAM_CHECK_CONDITION_GOTO(suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
20,414✔
815
  if (action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
18,374✔
UNCOV
816
    *uid = suid;
×
UNCOV
817
    goto end;
×
818
  }
819
  STREAM_CHECK_RET_GOTO(metaGetTableUidByName(sStreamReaderInfo->pVnode, tbName, uid));
18,374✔
820

821
end:
20,414✔
822
  return code;
20,414✔
823
}
824

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

844
end:
19,952✔
845
  if (code != 0) {
19,952✔
846
    ST_TASK_ELOG("%s failed,code:%d", __func__, code);
×
UNCOV
847
    taosArrayDestroy(uidList);
×
UNCOV
848
    uidList = NULL;
×
849
  }
850
  return uidList;
19,952✔
851
}
852

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

863
  if (sStreamReaderInfo->isVtableStream) {
19,952✔
864
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
1,428✔
865
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
1,428✔
866
  }
867

868
  uidListDel = taosArrayInit(8, sizeof(tb_uid_t));
19,952✔
869
  STREAM_CHECK_NULL_GOTO(uidListDel, terrno);
19,952✔
870

871
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
19,952✔
872
  STREAM_CHECK_RET_GOTO(qStreamGetDelTable(sStreamReaderInfo, uidList, uidListDel));
19,952✔
873

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

881
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
19,952✔
882
  if (sStreamReaderInfo->isVtableStream) {
19,952✔
883
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
1,428✔
884
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
1,428✔
885
  }
886
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
19,952✔
887

888
  ST_TASK_DLOG("%s stream reader scan alter table tag val", __func__);
19,952✔
889

890
end:
19,952✔
891
  taosArrayDestroy(uidListAdd);
19,952✔
892
  taosArrayDestroy(uidListDel);
19,952✔
893
  taosArrayDestroy(tableList);
19,952✔
894
  STREAM_PRINT_LOG_END_WITHID(code, lino);
19,952✔
895
  return code;
19,952✔
896
}
897

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

905
  ST_TASK_DLOG("%s start", __func__);
34,820✔
906

907
  SVAlterTbReq req = {0};
34,820✔
908
  tDecoderInit(&decoder, data, len);
34,820✔
909
  
910
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
34,820✔
911

912
  STREAM_CHECK_CONDITION_GOTO(req.action != TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL && req.action != TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL && 
34,820✔
913
    req.action != TSDB_ALTER_TABLE_ALTER_COLUMN_REF && req.action != TSDB_ALTER_TABLE_REMOVE_COLUMN_REF, TDB_CODE_SUCCESS);
914

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

942
  ST_TASK_DLOG("%s stream reader scan alter table", __func__);
20,414✔
943

944
end:
34,820✔
945
  destroyAlterTbReq(&req);
34,820✔
946

947
  taosArrayDestroy(uidList);
34,820✔
948
  tDecoderClear(&decoder);
34,820✔
949
  STREAM_PRINT_LOG_END_WITHID(code, lino);
34,820✔
950
  return code;
34,820✔
951
}
952

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

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

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

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

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

995
static int32_t scanSubmitTbDataForMeta(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* gidHash, int64_t ver) {
39,288,906✔
996
  int32_t code = 0;
39,288,906✔
997
  int32_t lino = 0;
39,288,906✔
998
  WalMetaResult walMeta = {0};
39,288,906✔
999
  SSubmitTbData submitTbData = {0};
39,292,206✔
1000
  
1001
  if (tStartDecode(pCoder) < 0) {
39,291,716✔
1002
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1003
    TSDB_CHECK_CODE(code, lino, end);
×
1004
  }
1005

1006
  uint8_t       version = 0;
39,291,632✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
39,291,897✔
1008
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
39,291,897✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
39,291,897✔
1013

1014
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1015
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
39,291,897✔
1016
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
4,294,716✔
1017
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
4,294,716✔
1018
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
4,294,716✔
1019
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
4,293,950✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
39,288,473✔
1024
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
39,290,666✔
1028
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1029
    TSDB_CHECK_CODE(code, lino, end);
×
1030
  }
1031

1032
  if (!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
39,290,666✔
1033
    goto end;
31,216,099✔
1034
  }
1035
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
8,075,819✔
1036
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1037
    TSDB_CHECK_CODE(code, lino, end);
×
1038
  }
1039

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

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

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

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

1075
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
17,295,498✔
1076
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,219,679✔
1077
      pCoder->pos += pRow->len;
9,219,445✔
1078
      if (iRow == 0){
9,219,445✔
1079
#ifndef NO_UNALIGNED_ACCESS
1080
        walMeta.skey = pRow->ts;
8,075,585✔
1081
#else
1082
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1083
#endif
1084
      }
1085
      if (iRow == nRow - 1) {
9,219,679✔
1086
#ifndef NO_UNALIGNED_ACCESS
1087
        walMeta.ekey = pRow->ts;
8,075,819✔
1088
#else
1089
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1090
#endif
1091
      }
1092
    }
1093
  }
1094

1095
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
8,075,819✔
1096
  if (data != NULL) {
8,075,819✔
1097
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
960✔
1098
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
960✔
1099
  } else {
1100
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
8,074,859✔
1101
  }
1102

1103
end:
39,284,724✔
1104
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
39,289,684✔
1105
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
39,286,086✔
1106
  tEndDecode(pCoder);
39,286,086✔
1107
  return code;
39,289,660✔
1108
}
1109

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

1117
  tDecoderInit(&decoder, data, len);
39,290,469✔
1118
  if (tStartDecode(&decoder) < 0) {
39,290,578✔
1119
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1120
    TSDB_CHECK_CODE(code, lino, end);
×
1121
  }
1122

1123
  uint64_t nSubmitTbData = 0;
39,280,768✔
1124
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
39,291,724✔
1125
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1126
    TSDB_CHECK_CODE(code, lino, end);
×
1127
  }
1128

1129
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
39,291,724✔
1130
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
39,286,297✔
1131

1132
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
78,576,513✔
1133
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
39,287,001✔
1134
  }
1135
  tEndDecode(&decoder);
39,289,512✔
1136

1137
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
39,273,404✔
1138
  int32_t iter = 0;
39,286,276✔
1139
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
39,286,829✔
1140
  while (px != NULL) {
47,363,558✔
1141
    WalMetaResult* pMeta = (WalMetaResult*)px;
8,074,859✔
1142
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
8,074,859✔
1143
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
8,074,625✔
1144
    rsp->totalRows++;
8,074,625✔
1145
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
8,074,625✔
1146
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1147
    px = tSimpleHashIterate(gidHash, px, &iter);
8,074,625✔
1148
  }
1149
end:
39,288,699✔
1150
  tDecoderClear(&decoder);
39,289,995✔
1151
  tSimpleHashCleanup( gidHash);
39,288,795✔
1152
  return code;
39,286,181✔
1153
}
1154

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

1161
  int32_t index = 1;
460,123✔
1162
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // skey
460,123✔
1163
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // ekey
460,123✔
1164
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
460,123✔
1165
  if (!isVTable) {
460,123✔
1166
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_UBIGINT, LONG_BYTES, index++))  // gid
50,175✔
1167
  }
1168
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))     // nrows
460,123✔
1169

1170
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
460,123✔
1171

1172
end:
460,123✔
1173
  taosArrayDestroy(schemas);
460,123✔
1174
  return code;
460,123✔
1175
}
1176

1177
static int32_t createBlockForWalMetaNew(SSDataBlock** pBlock) {
308,248✔
1178
  int32_t code = 0;
308,248✔
1179
  int32_t lino = 0;
308,248✔
1180
  SArray* schemas = NULL;
308,248✔
1181

1182
  schemas = taosArrayInit(8, sizeof(SSchema));
308,248✔
1183
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
308,248✔
1184

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

1191
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
308,248✔
1192

1193
end:
308,248✔
1194
  taosArrayDestroy(schemas);
308,248✔
1195
  return code;
308,248✔
1196
}
1197

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

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

1205
  SDecoder dcoder = {0};
529,002✔
1206
  tDecoderInit(&dcoder, data, len);
529,002✔
1207
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
529,002✔
1208
    if (rsp->deleteBlock == NULL) {
30,112✔
1209
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
10,762✔
1210
    }
1211
      
1212
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
30,112✔
1213
  } else if (msgType == TDMT_VND_DROP_TABLE && 
498,890✔
1214
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
49,800✔
1215
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
32,603✔
1216
  // } else if (msgType == TDMT_VND_DROP_STB) {
1217
  //   STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
1218
  } else if (msgType == TDMT_VND_CREATE_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
466,287✔
1219
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
24,614✔
1220
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
441,673✔
1221
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1222
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
415,831✔
1223
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
34,820✔
1224
  }
1225

1226
end:
529,002✔
1227
  tDecoderClear(&dcoder);
529,002✔
1228
  return code;
529,002✔
1229
}
1230
static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
11,344,371✔
1231
                       int64_t ctime) {
1232
  int32_t code = 0;
11,344,371✔
1233
  int32_t lino = 0;
11,344,371✔
1234
  void* pTask = sStreamReaderInfo->pTask;
11,344,371✔
1235

1236
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
11,344,371✔
1237
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
11,340,034✔
1238
  code = walReaderSeekVer(pWalReader, rsp->ver);
11,340,034✔
1239
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
11,342,415✔
1240
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
6,397,217✔
1241
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
UNCOV
1242
      rsp->verTime = 0;
×
1243
    } else {
1244
      rsp->verTime = taosGetTimestampUs();
6,397,685✔
1245
    }
1246
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
6,396,830✔
1247
    code = TSDB_CODE_SUCCESS;
6,398,449✔
1248
    goto end;
6,398,449✔
1249
  }
1250
  STREAM_CHECK_RET_GOTO(code);
4,945,198✔
1251

1252
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
4,945,198✔
1253
  while (1) {
39,705,828✔
1254
    code = walNextValidMsg(pWalReader, true);
44,650,001✔
1255
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
44,650,363✔
1256
      rsp->verTime = taosGetTimestampUs();
4,942,696✔
1257
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
4,942,696✔
1258
      code = TSDB_CODE_SUCCESS;
4,942,696✔
1259
      goto end;
4,942,696✔
1260
    }
1261
    STREAM_CHECK_RET_GOTO(code);
39,709,197✔
1262
    rsp->ver = pWalReader->curVersion;
39,709,197✔
1263
    SWalCont* wCont = &pWalReader->pHead->head;
39,710,384✔
1264
    rsp->verTime = wCont->ingestTs;
39,710,687✔
1265
    if (wCont->ingestTs / 1000 > ctime) break;
39,710,527✔
1266
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
39,708,952✔
1267
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
39,711,646✔
1268
    int64_t ver = wCont->version;
39,708,832✔
1269

1270
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
39,708,197✔
1271
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1272
    if (wCont->msgType == TDMT_VND_SUBMIT) {
39,712,103✔
1273
      // return when getting data if there are meta data in vtable scan
1274
      if (sStreamReaderInfo->isVtableStream && rsp->tableBlock != NULL && ((SSDataBlock*)rsp->tableBlock)->info.rows > 0) {
39,293,758✔
1275
        rsp->ver--;
2,502✔
1276
        break;
2,502✔
1277
      }
1278
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
39,290,839✔
1279
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
39,291,490✔
1280
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
39,290,766✔
1281
    } else {
1282
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
418,617✔
1283
    }
1284

1285
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
39,706,564✔
UNCOV
1286
      break;
×
1287
    }
1288
  }
1289

1290
end:
11,343,647✔
1291
  walCloseReader(pWalReader);
11,343,647✔
1292
  return code;
11,343,903✔
1293
}
1294

1295
int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid, col_id_t colId, SRWLatch* lock) {
41,152,624✔
1296
  int32_t     code = 0;
41,152,624✔
1297
  int32_t     lino = 0;
41,152,624✔
1298
  SMetaReader mr = {0};
41,152,624✔
1299
  SArray* tagCache = NULL;
41,154,517✔
1300
  char* data = NULL;
41,157,696✔
1301

1302
  if (lock != NULL) taosWLockLatch(lock);
41,158,735✔
1303
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
41,160,097✔
1304
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,293,911✔
1305
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,294,293✔
1306
  if (uidData == NULL) {
2,294,658✔
1307
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,276,064✔
1308
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,276,064✔
1309
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,276,064✔
UNCOV
1310
      taosArrayDestroy(tagCache);
×
UNCOV
1311
      code = terrno;
×
UNCOV
1312
      goto end;
×
1313
    }
1314
  } else {
1315
    tagCache = *(SArray**)uidData;
18,594✔
1316
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
18,594✔
1317
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
18,594✔
1318
  }
1319
  
1320
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,294,658✔
1321
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,294,658✔
1322
  api->metaReaderFn.readerReleaseLock(&mr);
2,292,605✔
1323
  STREAM_CHECK_RET_GOTO(code);
2,293,130✔
1324
  
1325
  for (int32_t j = 0; j < numOfExpr; ++j) {
7,913,909✔
1326
    const SExprInfo* pExpr1 = &pExprInfo[j];
5,626,140✔
1327
    int32_t functionId = pExpr1->pExpr->_function.functionId;
5,626,866✔
1328
    col_id_t cid = 0;
5,629,394✔
1329
    // this is to handle the tbname
1330
    if (fmIsScanPseudoColumnFunc(functionId)) {
5,629,394✔
1331
      int32_t fType = pExpr1->pExpr->_function.functionType;
638,799✔
1332
      if (fType == FUNCTION_TYPE_TBNAME) {
638,799✔
1333
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
638,799✔
1334
        STREAM_CHECK_NULL_GOTO(data, terrno);
638,559✔
1335
        STR_TO_VARSTR(data, mr.me.name)
638,559✔
1336
      }
1337
      cid = -1;
638,595✔
1338
    } else {  // these are tags
1339
      const char* p = NULL;
4,988,583✔
1340
      char* pData = NULL;
4,988,583✔
1341
      int8_t type = pExpr1->base.resSchema.type;
4,988,583✔
1342
      int32_t len = pExpr1->base.resSchema.bytes;
4,987,405✔
1343
      STagVal tagVal = {0};
4,989,524✔
1344
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
4,988,902✔
1345
      cid = tagVal.cid;
4,990,405✔
1346
      if (colId != 0 && cid != colId) {
4,990,405✔
1347
        continue;
1,023✔
1348
      }
1349
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
4,989,382✔
1350

1351
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
4,986,439✔
1352
        pData = tTagValToData((const STagVal*)p, false);
4,983,844✔
1353
      } else {
1354
        pData = (char*)p;
2,595✔
1355
      }
1356

1357
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
4,986,792✔
1358
        if (type == TSDB_DATA_TYPE_JSON) {
2,498,129✔
UNCOV
1359
          len = getJsonValueLen(pData);
×
1360
        }
1361
        data = taosMemoryCalloc(1, len);
2,498,129✔
1362
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,497,881✔
1363
        (void)memcpy(data, pData, len);
2,497,881✔
1364
      } else {
1365
        data = pData;
2,488,663✔
1366
      }
1367
    }
1368
    if (uidData == NULL){
5,624,360✔
1369
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
11,178,831✔
1370
    } else {
1371
      void* pre = taosArrayGetP(tagCache, j);
35,961✔
1372
      taosMemoryFree(pre);
35,961✔
1373
      taosArraySet(tagCache, j, &data);
35,961✔
1374
    }
1375
    data = NULL;
5,626,011✔
1376
  }
1377

1378
end:
41,159,845✔
1379
  taosMemoryFree(data);
41,156,335✔
1380
  api->metaReaderFn.clearReader(&mr);
41,155,986✔
1381
  if (lock != NULL) taosWUnLockLatch(lock);
41,155,086✔
1382
  return code;
41,160,983✔
1383
}
1384

1385
int32_t fillTag(SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr,
108,619,218✔
1386
                uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, SRWLatch* lock) {
1387
  int32_t     code = 0;
108,619,218✔
1388
  int32_t     lino = 0;
108,619,218✔
1389
  SArray* tagCache = NULL;
108,619,218✔
1390
  if (numOfExpr == 0) {
108,619,218✔
1391
    return TSDB_CODE_SUCCESS;
38,335,696✔
1392
  }
1393

1394
  taosRLockLatch(lock);
70,283,522✔
1395
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
70,353,765✔
1396
  if (uidData == NULL) {
70,346,599✔
UNCOV
1397
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1398
  } else {
1399
    tagCache = *(SArray**)uidData;
70,346,599✔
1400
    if(taosArrayGetSize(tagCache) != numOfExpr) {
70,346,217✔
1401
      stError("%s numOfExpr:%d,tagCache size:%zu", __func__, numOfExpr, taosArrayGetSize(tagCache));
×
UNCOV
1402
      tagCache = NULL;
×
1403
    }
1404
  }
1405
  
1406
  for (int32_t j = 0; j < numOfExpr; ++j) {
305,734,812✔
1407
    const SExprInfo* pExpr1 = &pExprInfo[j];
235,392,274✔
1408
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
235,386,976✔
1409

1410
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
235,404,052✔
1411
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
235,283,556✔
1412
    int32_t functionId = pExpr1->pExpr->_function.functionId;
235,283,556✔
1413

1414
    // this is to handle the tbname
1415
    if (fmIsScanPseudoColumnFunc(functionId)) {
235,308,413✔
1416
      int32_t fType = pExpr1->pExpr->_function.functionType;
3,669,426✔
1417
      if (fType == FUNCTION_TYPE_TBNAME) {
3,669,426✔
1418
        pColInfoData->info.colId = -1;
3,669,426✔
1419
      }
1420
    } 
1421
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
235,227,799✔
1422

1423
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
235,101,027✔
1424
    if (isNullVal) {
235,105,493✔
UNCOV
1425
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1426
    } else {
1427
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
235,105,493✔
1428
        for (uint32_t i = 0; i < numOfRows; i++){
2,147,483,647✔
1429
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
2,147,483,647✔
1430
        }
1431
      }
1432
      code = colDataSetNItems(pColInfoData, currentRow, (const char*)data, numOfRows, numOfBlocks, false);
234,936,715✔
1433
      STREAM_CHECK_RET_GOTO(code);
235,398,645✔
1434
    }
1435
  }
1436
end:
70,342,538✔
1437
  taosRUnLockLatch(lock);
70,342,538✔
1438
  return code;
70,353,294✔
1439
}
1440

1441
static int32_t processTag(SStreamTriggerReaderInfo* info, bool isCalc, 
3,560,397✔
1442
  uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks) {
1443
  int32_t     code = 0;
3,560,397✔
1444
  int32_t     lino = 0;
3,560,397✔
1445

1446
  void* pTask = info->pTask;
3,560,397✔
1447
  ST_TASK_DLOG("%s start. rows:%" PRIu32 ",uid:%"PRIu64, __func__,  numOfRows, uid);
3,560,628✔
1448
  
1449
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
3,560,397✔
1450
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
3,560,629✔
1451
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
3,560,628✔
1452
  
1453
  code = fillTag(metaCache, pExprInfo, numOfExpr, uid, pBlock, currentRow, numOfRows, numOfBlocks, &info->lock);
3,560,628✔
1454
  STREAM_CHECK_RET_GOTO(code);
3,561,082✔
1455

1456
end:
3,561,082✔
1457
  return code;
3,561,082✔
1458
}
1459

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

UNCOV
1482
    if (*rowStart != -1 && *rowEnd == -1) {
×
UNCOV
1483
      *rowEnd = pCol->nVal;
×
1484
    }
1485
  }
1486
  *nRows = *rowEnd - *rowStart;
×
1487

UNCOV
1488
end:
×
UNCOV
1489
  return code;
×
1490
}
1491

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

1505
static int32_t getColId(int64_t suid, int64_t uid, int16_t i, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, int16_t* colId) {
21,231,425✔
1506
  int32_t code = 0;
21,231,425✔
1507
  int32_t lino = 0;
21,231,425✔
1508
  int64_t id[2] = {suid, uid};
21,231,425✔
1509
  taosRLockLatch(&sStreamReaderInfo->lock);
21,232,118✔
1510
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
21,232,586✔
1511
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
21,232,139✔
1512
  SSHashObj* uInfo = *(SSHashObj **)px;
21,232,139✔
1513
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
21,232,139✔
1514
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
21,232,139✔
1515
  if (tmp != NULL) {
21,230,990✔
1516
    *colId = *tmp;
19,576,111✔
1517
  } else {
1518
    *colId = -1;
1,654,879✔
1519
  }
1520

1521
end:
21,231,458✔
1522
  taosRUnLockLatch(&sStreamReaderInfo->lock);
21,231,458✔
1523
  return code;
21,232,352✔
1524
}
1525

1526
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
10,212,310✔
1527
  int32_t code = 0;
10,212,310✔
1528
  int32_t lino = 0;
10,212,310✔
1529
  int64_t id = suid != 0 ? suid : uid;
10,212,310✔
1530
  if (sStreamReaderInfo->isVtableStream) {
10,213,076✔
1531
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
6,877,247✔
1532
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
6,877,247✔
1533
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
64,266✔
1534
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
64,266✔
1535
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
64,266✔
1536
      if (code != 0) {
64,266✔
UNCOV
1537
        taosMemoryFree(*schema);
×
UNCOV
1538
        goto end;
×
1539
      }
1540
    } else {
1541
      *schema = *schemaTmp;
6,812,981✔
1542
    }
1543
  } else {
1544
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
3,335,367✔
1545
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
82,544✔
1546
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
82,544✔
1547
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
82,544✔
1548
    }
1549
    *schema = sStreamReaderInfo->triggerTableSchema;
3,335,358✔
1550
  }
1551
  
1552
end:
10,213,076✔
1553
  return code;
10,213,076✔
1554
}
1555

1556
static int32_t scanSubmitTbData(SVnode* pVnode, SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, 
11,148,287✔
1557
  SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
1558
  int32_t code = 0;
11,148,287✔
1559
  int32_t lino = 0;
11,148,287✔
1560
  uint64_t id = 0;
11,148,287✔
1561
  WalMetaResult walMeta = {0};
11,147,824✔
1562
  void* pTask = sStreamReaderInfo->pTask;
11,147,824✔
1563
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
11,146,826✔
1564

1565
  if (tStartDecode(pCoder) < 0) {
11,147,521✔
UNCOV
1566
    ST_TASK_ELOG("vgId:%d %s invalid submit data", TD_VID(pVnode), __func__);
×
UNCOV
1567
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1568
    TSDB_CHECK_CODE(code, lino, end);
×
1569
  }
1570

1571
  SSubmitTbData submitTbData = {0};
11,147,159✔
1572
  uint8_t       version = 0;
11,146,739✔
1573
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
11,148,519✔
UNCOV
1574
    ST_TASK_ELOG("vgId:%d %s invalid submit data flags", TD_VID(pVnode), __func__);
×
UNCOV
1575
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1576
    TSDB_CHECK_CODE(code, lino, end);
×
1577
  }
1578
  version = (submitTbData.flags >> 8) & 0xff;
11,148,519✔
1579
  submitTbData.flags = submitTbData.flags & 0xff;
11,148,519✔
1580
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1581
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
11,148,519✔
1582
    if (tStartDecode(pCoder) < 0) {
32,509✔
UNCOV
1583
      ST_TASK_ELOG("vgId:%d %s invalid auto create table data", TD_VID(pVnode), __func__);
×
UNCOV
1584
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1585
      TSDB_CHECK_CODE(code, lino, end);
×
1586
    }
1587
    tEndDecode(pCoder);
32,509✔
1588
  }
1589

1590
  // submit data
1591
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
11,148,315✔
UNCOV
1592
    ST_TASK_ELOG("vgId:%d %s invalid submit data suid", TD_VID(pVnode), __func__);
×
UNCOV
1593
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1594
    TSDB_CHECK_CODE(code, lino, end);
×
1595
  }
1596
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
11,147,619✔
1597
    ST_TASK_ELOG("vgId:%d %s invalid submit data uid", TD_VID(pVnode), __func__);
×
1598
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1599
    TSDB_CHECK_CODE(code, lino, end);
×
1600
  }
1601

1602
  ST_TASK_DLOG("%s uid:%" PRId64 ", suid:%" PRId64 ", ver:%" PRId64, __func__, submitTbData.uid, submitTbData.suid, ver);
11,147,619✔
1603

1604
  if (rsp->uidHash != NULL) {
11,147,823✔
1605
    uint64_t* gid = tSimpleHashGet(rsp->uidHash, &submitTbData.uid, LONG_BYTES);
8,411,458✔
1606
    STREAM_CHECK_CONDITION_GOTO(gid == NULL, TDB_CODE_SUCCESS);
8,411,923✔
1607
    ST_TASK_DLOG("%s get uid gid from uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, submitTbData.uid, submitTbData.suid, *gid);
8,411,923✔
1608
    id = *gid;
8,411,923✔
1609
  } else {
1610
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
2,735,903✔
1611
  }
1612

1613
  walMeta.id = id;
10,213,075✔
1614
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,213,075✔
1615

1616
  if (ranges != NULL){
10,213,076✔
1617
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
8,411,923✔
1618
    if (timerange == NULL) goto end;;
8,411,923✔
1619
    int64_t* pRange = (int64_t*)timerange;
8,411,923✔
1620
    window.skey = pRange[0];
8,411,923✔
1621
    window.ekey = pRange[1];
8,411,923✔
1622
    ST_TASK_DLOG("%s get time range from ranges, uid:%" PRId64 ", suid:%" PRId64 ", gid:%" PRIu64 ", skey:%" PRId64 ", ekey:%" PRId64,
8,411,923✔
1623
      __func__, submitTbData.uid, submitTbData.suid, id, window.skey, window.ekey);
1624
  }
1625
  
1626
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,213,076✔
UNCOV
1627
    ST_TASK_ELOG("vgId:%d %s invalid submit data sver", TD_VID(pVnode), __func__);
×
UNCOV
1628
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1629
    TSDB_CHECK_CODE(code, lino, end);
×
1630
  }
1631

1632
  STSchema*    schema = NULL;
10,213,076✔
1633
  STREAM_CHECK_RET_GOTO(getSchemas(pVnode, submitTbData.suid, submitTbData.uid, submitTbData.sver, sStreamReaderInfo, &schema));
10,213,076✔
1634

1635
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
10,212,614✔
1636
  int32_t blockStart = 0;
10,212,842✔
1637
  int32_t numOfRows = 0;
10,212,842✔
1638
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,212,379✔
UNCOV
1639
    uint64_t nColData = 0;
×
UNCOV
1640
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
UNCOV
1641
      ST_TASK_ELOG("vgId:%d %s invalid submit data nColData", TD_VID(pVnode), __func__);
×
UNCOV
1642
      code = TSDB_CODE_INVALID_MSG;
×
1643
      TSDB_CHECK_CODE(code, lino, end);
×
1644
    }
1645

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

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

UNCOV
1663
    int32_t rowStart = 0;
×
1664
    int32_t rowEnd = 0;
×
1665
    STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, &numOfRows));
×
UNCOV
1666
    STREAM_CHECK_CONDITION_GOTO(numOfRows <= 0, TDB_CODE_SUCCESS);
×
1667

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

1683
      pCoder->pos = pos;
×
1684

UNCOV
1685
      int16_t colId = 0;
×
UNCOV
1686
      if (sStreamReaderInfo->isVtableStream){
×
1687
        STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
×
UNCOV
1688
        ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
×
1689
      } else {
1690
        colId = pColData->info.colId;
×
1691
      }
1692
      
UNCOV
1693
      uint64_t j = 1;
×
1694
      for (; j < nColData; j++) {
×
UNCOV
1695
        int16_t cid = 0;
×
UNCOV
1696
        int32_t posTmp = pCoder->pos;
×
1697
        pCoder->pos += INT_BYTES;
×
1698
        if ((code = tDecodeI16v(pCoder, &cid))) return code;
×
1699
        pCoder->pos = posTmp;
×
1700
        if (cid == colId) {
×
1701
          SColData colDataTmp = {0};
×
1702
          code = tDecodeColData(version, pCoder, &colDataTmp, false);
×
1703
          if (code) {
×
1704
            code = TSDB_CODE_INVALID_MSG;
×
1705
            TSDB_CHECK_CODE(code, lino, end);
×
1706
          }
1707
          STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colDataTmp, pColData));
×
1708
          break;
×
1709
        }
UNCOV
1710
        code = tDecodeColData(version, pCoder, &colData, true);
×
1711
        if (code) {
×
1712
          code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1713
          TSDB_CHECK_CODE(code, lino, end);
×
1714
        }
1715
      }
1716
      if (j == nColData) {
×
1717
        colDataSetNNULL(pColData, blockStart, numOfRows);
×
1718
      }
1719
    }
1720
  } else {
1721
    uint64_t nRow = 0;
10,212,379✔
1722
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,211,847✔
UNCOV
1723
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1724
      TSDB_CHECK_CODE(code, lino, end);
×
1725
    }
1726
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
21,686,479✔
1727
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
11,475,331✔
1728
      pCoder->pos += pRow->len;
11,475,331✔
1729

1730
      if (iRow == 0){
11,474,638✔
1731
#ifndef NO_UNALIGNED_ACCESS
1732
        walMeta.skey = pRow->ts;
10,211,919✔
1733
#else
1734
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1735
#endif
1736
      }
1737
      if (iRow == nRow - 1) {
11,474,870✔
1738
#ifndef NO_UNALIGNED_ACCESS
1739
        walMeta.ekey = pRow->ts;
10,212,150✔
1740
#else
1741
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1742
#endif
1743
      }
1744

1745
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
11,475,101✔
1746
        continue;
8,911✔
1747
      }
1748
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
11,465,958✔
1749
      blockStart = pSlice->currentRowIdx;
11,465,958✔
1750
     
1751
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
71,026,895✔
1752
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
59,560,836✔
1753
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
59,561,064✔
1754
        if (pColData->info.colId <= -1) {
59,561,064✔
1755
          pColData->hasNull = true;
20,371,544✔
1756
          continue;
20,371,543✔
1757
        }
1758
        int16_t colId = 0;
39,196,856✔
1759
        if (sStreamReaderInfo->isVtableStream){
39,197,322✔
1760
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
21,231,224✔
1761
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
21,225,522✔
1762
        } else {
1763
          colId = pColData->info.colId;
17,967,087✔
1764
        }
1765
        
1766
        SColVal colVal = {0};
39,192,607✔
1767
        int32_t sourceIdx = 0;
39,196,837✔
1768
        while (1) {
1769
          if (sourceIdx >= schema->numOfCols) {
106,581,759✔
1770
            break;
8,763,263✔
1771
          }
1772
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
97,819,667✔
1773
          if (colVal.cid == colId) {
97,822,564✔
1774
            break;
30,437,642✔
1775
          }
1776
          sourceIdx++;
67,384,922✔
1777
        }
1778
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
39,200,905✔
1779
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
28,042,874✔
1780
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
26,445✔
1781
            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, 
26,210✔
1782
              (const char*)colVal.value.pData, colVal.value.nData, blockStart+ numOfRows, pColData->varmeta.offset[blockStart+ numOfRows], submitTbData.uid);
1783
          } else {
1784
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
28,016,429✔
1785
          }
1786
        } else {
1787
          colDataSetNULL(pColData, blockStart + numOfRows);
11,158,031✔
1788
        }
1789
      }
1790
      
1791
      numOfRows++;
11,465,721✔
1792
    }
1793
  }
1794

1795
  if (numOfRows > 0) {
10,211,682✔
1796
    if (!sStreamReaderInfo->isVtableStream) {
10,211,682✔
1797
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, rsp->isCalc, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
3,334,902✔
1798
    }
1799
    
1800
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
10,212,128✔
1801
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
10,212,359✔
1802
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
10,212,359✔
1803

1804
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
10,212,575✔
1805
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
10,212,575✔
1806
      ", uid:%" PRId64 ", ver:%"PRId64 ", row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1807
      id, submitTbData.uid, ver, pSlice->currentRowIdx, numOfRows);
1808
    pSlice->currentRowIdx += numOfRows;
10,212,452✔
1809
    pBlock->info.rows += numOfRows;
10,212,842✔
1810
  } else {
UNCOV
1811
    ST_TASK_DLOG("%s no valid data in time range:skey %" PRId64 ", ekey %" PRId64 ", uid:%" PRId64 ", suid:%" PRId64,
×
1812
      __func__, window.skey, window.ekey, submitTbData.uid, submitTbData.suid);
1813
  }
1814
  
1815
  if (gidHash == NULL) goto end;
10,212,841✔
1816

1817
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,801,152✔
1818
  if (data != NULL) {
1,801,152✔
UNCOV
1819
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
UNCOV
1820
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
1821
  } else {
1822
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
1,801,152✔
1823
  }
1824

1825
end:
11,144,825✔
1826
  if (code != 0) {                                                             \
11,147,808✔
UNCOV
1827
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1828
  }
1829
  tEndDecode(pCoder);
11,147,808✔
1830
  return code;
11,148,287✔
1831
}
1832
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
11,147,131✔
1833
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1834
  int32_t  code = 0;
11,147,131✔
1835
  int32_t  lino = 0;
11,147,131✔
1836
  SDecoder decoder = {0};
11,147,131✔
1837
  SSHashObj* gidHash = NULL;
11,147,593✔
1838
  void* pTask = sStreamReaderInfo->pTask;
11,147,593✔
1839

1840
  tDecoderInit(&decoder, data, len);
11,147,824✔
1841
  if (tStartDecode(&decoder) < 0) {
11,145,968✔
UNCOV
1842
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1843
    TSDB_CHECK_CODE(code, lino, end);
×
1844
  }
1845

1846
  uint64_t nSubmitTbData = 0;
11,147,137✔
1847
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
11,147,585✔
UNCOV
1848
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1849
    TSDB_CHECK_CODE(code, lino, end);
×
1850
  }
1851

1852
  if (rsp->metaBlock != NULL){
11,147,585✔
1853
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
2,735,893✔
1854
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
2,736,125✔
1855
  }
1856

1857
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
22,295,640✔
1858
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
11,147,585✔
1859
  }
1860

1861
  tEndDecode(&decoder);
11,148,055✔
1862

1863
  if (rsp->metaBlock != NULL){
11,148,284✔
1864
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
2,736,595✔
1865
    int32_t iter = 0;
2,735,660✔
1866
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
2,735,660✔
1867
    while (px != NULL) {
4,535,194✔
1868
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,800,450✔
1869
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,800,450✔
1870
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,800,691✔
1871
      rsp->totalRows++;
1,800,691✔
1872
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,800,691✔
1873
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1874
      px = tSimpleHashIterate(gidHash, px, &iter);
1,800,691✔
1875
    }
1876
  }
1877
  
1878

1879
end:
11,142,167✔
1880
  tSimpleHashCleanup(gidHash);
11,146,433✔
1881
  tDecoderClear(&decoder);
11,147,357✔
1882
  return code;
11,148,056✔
1883
}
1884

1885
static int32_t scanSubmitTbDataPre(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* ranges, 
13,314,385✔
1886
  uint64_t* gid, int64_t* uid, int32_t* numOfRows, SSTriggerWalNewRsp* rsp, int64_t ver) {
1887
  int32_t code = 0;
13,314,385✔
1888
  int32_t lino = 0;
13,314,385✔
1889
  void* pTask = sStreamReaderInfo->pTask;
13,314,385✔
1890

1891
  if (tStartDecode(pCoder) < 0) {
13,314,151✔
UNCOV
1892
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1893
    TSDB_CHECK_CODE(code, lino, end);
×
1894
  }
1895

1896
  SSubmitTbData submitTbData = {0};
13,318,100✔
1897
  uint8_t       version = 0;
13,318,562✔
1898
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
13,317,581✔
UNCOV
1899
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1900
    TSDB_CHECK_CODE(code, lino, end);
×
1901
  }
1902
  version = (submitTbData.flags >> 8) & 0xff;
13,317,581✔
1903
  submitTbData.flags = submitTbData.flags & 0xff;
13,317,581✔
1904

1905
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1906
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
13,317,581✔
1907
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
882,766✔
1908
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
882,766✔
1909
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
882,766✔
1910
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
883,229✔
1911
  }
1912

1913
  // submit data
1914
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
13,318,283✔
UNCOV
1915
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  if (tDecodeI64(pCoder, uid) < 0) {
13,316,466✔
1919
    code = TSDB_CODE_INVALID_MSG;
×
1920
    TSDB_CHECK_CODE(code, lino, end);
×
1921
  }
1922
  ST_TASK_DLOG("%s uid:%" PRId64 ", suid:%" PRId64, __func__, *uid, submitTbData.suid);
13,316,466✔
1923
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
13,316,217✔
1924
  if (rsp->uidHash != NULL) {
10,212,842✔
1925
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
8,411,923✔
1926
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
8,411,157✔
1927
  }
1928
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,213,306✔
1929

1930
  if (ranges != NULL){
10,213,074✔
1931
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
8,411,923✔
1932
    if (timerange == NULL) goto end;;
8,411,923✔
1933
    int64_t* pRange = (int64_t*)timerange;
8,411,923✔
1934
    window.skey = pRange[0];
8,411,923✔
1935
    window.ekey = pRange[1];
8,411,923✔
1936
  }
1937
  
1938
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,212,842✔
UNCOV
1939
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1940
    TSDB_CHECK_CODE(code, lino, end);
×
1941
  }
1942

1943
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,212,842✔
1944
    uint64_t nColData = 0;
×
UNCOV
1945
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
UNCOV
1946
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1947
      TSDB_CHECK_CODE(code, lino, end);
×
1948
    }
1949

1950
    SColData colData = {0};
×
1951
    code = tDecodeColData(version, pCoder, &colData, false);
×
UNCOV
1952
    if (code) {
×
UNCOV
1953
      code = TSDB_CODE_INVALID_MSG;
×
1954
      TSDB_CHECK_CODE(code, lino, end);
×
1955
    }
1956

1957
    if (colData.flag != HAS_VALUE) {
×
1958
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1959
      TSDB_CHECK_CODE(code, lino, end);
×
1960
    }
1961
    int32_t rowStart = 0;
×
1962
    int32_t rowEnd = 0;
×
1963
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) {
×
UNCOV
1964
      STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, numOfRows));
×
1965
    } else {
1966
      (*numOfRows) = colData.nVal;
×
1967
    } 
1968
  } else {
1969
    uint64_t nRow = 0;
10,212,842✔
1970
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,211,912✔
UNCOV
1971
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
1972
      TSDB_CHECK_CODE(code, lino, end);
×
1973
    }
1974

1975
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
10,211,912✔
1976
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
17,877,543✔
1977
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,465,783✔
1978
        pCoder->pos += pRow->len;
9,466,549✔
1979
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
9,466,549✔
1980
          continue;
8,911✔
1981
        }
1982
        (*numOfRows)++;
9,457,872✔
1983
      }
1984
    } else {
1985
      (*numOfRows) = nRow;
1,800,921✔
1986
    }
1987
  }
1988
  
1989
end:
13,318,719✔
1990
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
13,318,561✔
1991
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
13,316,940✔
1992
  tEndDecode(pCoder);
13,316,709✔
1993
  return code;
13,317,839✔
1994
}
1995

1996
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
13,313,229✔
1997
  int32_t  code = 0;
13,313,229✔
1998
  int32_t  lino = 0;
13,313,229✔
1999
  SDecoder decoder = {0};
13,313,229✔
2000
  void* pTask = sStreamReaderInfo->pTask;
13,313,461✔
2001

2002
  tDecoderInit(&decoder, data, len);
13,315,082✔
2003
  if (tStartDecode(&decoder) < 0) {
13,316,008✔
UNCOV
2004
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
2005
    TSDB_CHECK_CODE(code, lino, end);
×
2006
  }
2007

2008
  uint64_t nSubmitTbData = 0;
13,314,698✔
2009
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
13,318,270✔
UNCOV
2010
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
2011
    TSDB_CHECK_CODE(code, lino, end);
×
2012
  }
2013
  ST_TASK_DLOG("%s nSubmitTbData:%" PRIu64 ", ver:%"PRId64 " bodyLen:%d", __func__, nSubmitTbData, ver, len);
13,318,270✔
2014

2015
  for (int32_t i = 0; i < nSubmitTbData; i++) {
26,634,864✔
2016
    uint64_t gid = -1;
13,318,535✔
2017
    int64_t  uid = 0;
13,317,848✔
2018
    int32_t numOfRows = 0;
13,318,311✔
2019
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
13,318,773✔
2020
    if (numOfRows <= 0) {
13,319,947✔
2021
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
3,107,337✔
2022
      continue;
3,106,734✔
2023
    }
2024
    rsp->totalRows += numOfRows;
10,212,610✔
2025
    rsp->totalDataRows += numOfRows;
10,212,842✔
2026

2027
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
10,213,073✔
2028
    if (pSlice != NULL) {
10,211,915✔
2029
      pSlice->numRows += numOfRows;
9,532,525✔
2030
      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);
9,532,759✔
2031
      pSlice->gId = gid;
9,532,759✔
2032
    } else {
2033
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
679,390✔
2034
      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);
679,852✔
2035
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
679,852✔
2036
    } 
2037
  }
2038

2039
  tEndDecode(&decoder);
13,316,329✔
2040

2041
end:
13,316,711✔
2042
  tDecoderClear(&decoder);
13,317,173✔
2043
  return code;
13,317,856✔
2044
}
2045

2046
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
562,161✔
2047
  void*   pe = NULL;
562,161✔
2048
  int32_t iter = 0;
562,161✔
2049
  int32_t index = 0;
562,161✔
2050
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
1,242,013✔
2051
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
679,852✔
2052
    pInfo->startRowIdx = index;
679,852✔
2053
    pInfo->currentRowIdx = index;
679,852✔
2054
    index += pInfo->numRows;
679,852✔
2055
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
1,189,395✔
2056
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2057
  }
2058
}
562,161✔
2059

2060
static void printIndexHash(SSHashObj* indexHash, void* pTask){
562,161✔
2061
  if (qDebugFlag & DEBUG_TRACE) {
562,161✔
2062
    void*   pe = NULL;
8,717✔
2063
    int32_t iter = 0;
8,717✔
2064
    while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
20,871✔
2065
      SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
12,154✔
2066
      ST_TASK_TLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
12,377✔
2067
      pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2068
    }
2069
  }
2070
}
562,161✔
2071

2072
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
11,515✔
2073
  void*   pe = NULL;
11,515✔
2074
  int32_t iter = 0;
11,515✔
2075
  int32_t index = 0;
11,515✔
2076
  int32_t pIndex = 0;
11,515✔
2077
  int8_t* pIndicator = (int8_t*)pRet->pData;
11,515✔
2078
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
24,622✔
2079
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
13,107✔
2080
    pInfo->startRowIdx = index;
13,107✔
2081
    int32_t size = pInfo->numRows;
13,107✔
2082
    for (int32_t i = 0; i < pInfo->numRows; i++) {
179,581✔
2083
      if (pIndicator && !pIndicator[pIndex++]) {
166,474✔
2084
        size--;
64,039✔
2085
      }
2086
    }
2087
    pInfo->numRows = size;
13,107✔
2088
    index += pInfo->numRows;
13,107✔
2089
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
13,107✔
2090
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2091
  }
2092
}
11,515✔
2093

2094
static int32_t prepareIndexMetaData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* resultRsp){
3,340,384✔
2095
  int32_t      code = 0;
3,340,384✔
2096
  int32_t      lino = 0;
3,340,384✔
2097
  void* pTask = sStreamReaderInfo->pTask;
3,340,384✔
2098

2099
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,340,270✔
2100
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,338,034✔
2101
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,831,247✔
UNCOV
2102
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
UNCOV
2103
      resultRsp->verTime = 0;
×
2104
    } else {
2105
      resultRsp->verTime = taosGetTimestampUs();
2,831,316✔
2106
    }
2107
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
2,832,293✔
2108
    code = TSDB_CODE_SUCCESS;
2,831,819✔
2109
    goto end;
2,831,819✔
2110
  }
2111
  STREAM_CHECK_RET_GOTO(code);
506,787✔
2112

2113
  while (1) {
5,016,099✔
2114
    code = walNextValidMsg(pWalReader, true);
5,522,886✔
2115
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,522,454✔
2116
      resultRsp->verTime = taosGetTimestampUs();
508,210✔
2117
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
508,210✔
2118
      code = TSDB_CODE_SUCCESS;
508,210✔
2119
      goto end;
508,210✔
2120
    }
2121
    STREAM_CHECK_RET_GOTO(code);
5,014,716✔
2122
    resultRsp->ver = pWalReader->curVersion;
5,014,716✔
2123
    SWalCont* wCont = &pWalReader->pHead->head;
5,015,873✔
2124
    resultRsp->verTime = wCont->ingestTs;
5,015,505✔
2125
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
5,016,557✔
2126
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
5,017,715✔
2127
    int64_t ver = wCont->version;
5,017,135✔
2128
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
5,018,402✔
2129
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2130
    if (wCont->msgType == TDMT_VND_SUBMIT) {
5,019,233✔
2131
      // return when getting data if there are meta data in vtable scan
2132
      if (sStreamReaderInfo->isVtableStream && resultRsp->tableBlock != NULL && ((SSDataBlock*)resultRsp->tableBlock)->info.rows > 0) {
4,907,329✔
NEW
2133
        resultRsp->ver--;
×
NEW
2134
        break;
×
2135
      }
2136
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,908,257✔
2137
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,908,490✔
2138
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
4,908,258✔
2139
    } else {
2140
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
110,385✔
2141
    }
2142

2143
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
5,014,469✔
2144
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
5,014,469✔
2145
      break;
2146
    }
2147
  }
2148
  
UNCOV
2149
end:
×
2150
  STREAM_PRINT_LOG_END(code, lino);
3,339,583✔
2151
  return code;
3,339,798✔
2152
}
2153

2154
static int32_t prepareIndexData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, 
8,029,972✔
2155
  SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp){
2156
  int32_t      code = 0;
8,029,972✔
2157
  int32_t      lino = 0;
8,029,972✔
2158
  void* pTask = sStreamReaderInfo->pTask;
8,029,972✔
2159

2160
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
16,444,367✔
2161
    int64_t *ver = taosArrayGet(versions, i);
8,410,923✔
2162
    if (ver == NULL) continue;
8,411,923✔
2163

2164
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,411,923✔
2165
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,410,212✔
UNCOV
2166
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
UNCOV
2167
      ST_TASK_TLOG("%s not data, skip, ver:%"PRId64, __func__, *ver);
×
UNCOV
2168
      continue;
×
2169
    }
2170
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,411,209✔
2171

2172
    SWalCont* wCont = &pWalReader->pHead->head;
8,411,923✔
2173
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,411,923✔
2174
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,411,692✔
2175

2176
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
8,411,674✔
2177
  }
2178
  
2179
end:
8,030,146✔
2180
  return code;
8,030,146✔
2181
}
2182

2183
static int32_t filterData(SSTriggerWalNewRsp* resultRsp, SStreamTriggerReaderInfo* sStreamReaderInfo) {
562,161✔
2184
  int32_t      code = 0;
562,161✔
2185
  int32_t       lino = 0;
562,161✔
2186
  SColumnInfoData* pRet = NULL;
562,161✔
2187

2188
  int64_t totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
562,161✔
2189
  STREAM_CHECK_RET_GOTO(qStreamFilter(((SSDataBlock*)resultRsp->dataBlock), sStreamReaderInfo->pFilterInfo, &pRet));
562,161✔
2190

2191
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
562,161✔
2192
    filterIndexHash(resultRsp->indexHash, pRet);
11,515✔
2193
  }
2194

2195
end:
562,161✔
2196
  colDataDestroy(pRet);
562,161✔
2197
  taosMemoryFree(pRet);
562,161✔
2198
  return code;
562,161✔
2199
}
2200

2201
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,338,679✔
2202
                                    SSTriggerWalNewRsp* resultRsp) {
2203
  int32_t      code = 0;
3,338,679✔
2204
  int32_t      lino = 0;
3,338,679✔
2205
  void* pTask = sStreamReaderInfo->pTask;
3,338,679✔
2206
                                        
2207
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,338,919✔
2208
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,337,660✔
2209
  blockDataEmpty(resultRsp->dataBlock);
3,337,660✔
2210
  blockDataEmpty(resultRsp->metaBlock);
3,333,595✔
2211
  int64_t lastVer = resultRsp->ver;                                      
3,335,463✔
2212
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,335,463✔
2213
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,338,872✔
2214

2215
  buildIndexHash(resultRsp->indexHash, pTask);
131,254✔
2216
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
131,254✔
2217
  while(lastVer < resultRsp->ver) {
2,911,052✔
2218
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
2,779,798✔
2219
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
2,777,716✔
2220
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
43,202✔
2221
      continue;
43,202✔
2222
    }
2223
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
2,734,505✔
2224
    SWalCont* wCont = &pWalReader->pHead->head;
2,735,004✔
2225
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
2,735,929✔
2226
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
2,735,929✔
2227
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
2,735,929✔
2228
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
2,736,133✔
2229
  }
2230

2231
  int32_t metaRows = resultRsp->totalRows - ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
131,254✔
2232
  STREAM_CHECK_RET_GOTO(filterData(resultRsp, sStreamReaderInfo));
131,254✔
2233
  resultRsp->totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows + metaRows;
131,254✔
2234

2235
end:
3,339,335✔
2236
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
3,339,335✔
2237
          resultRsp->totalRows, resultRsp->ver, walGetAppliedVer(pWalReader->pWal));
2238
  walCloseReader(pWalReader);
3,339,335✔
2239
  return code;
3,339,352✔
2240
}
2241

2242
static int32_t processWalVerDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
8,031,912✔
2243
                                    SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
2244
  int32_t      code = 0;
8,031,912✔
2245
  int32_t      lino = 0;
8,031,912✔
2246

2247
  void* pTask = sStreamReaderInfo->pTask;
8,031,912✔
2248
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
8,032,116✔
2249
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
8,030,176✔
2250
  
2251
  if (taosArrayGetSize(versions) > 0) {
8,030,176✔
2252
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
430,907✔
2253
  }
2254
  
2255
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
8,030,176✔
2256
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
8,030,146✔
2257

2258
  ST_TASK_TLOG("%s index hash:%p %d", __func__, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash));
430,907✔
2259
  buildIndexHash(rsp->indexHash, pTask);
430,907✔
2260

2261
  blockDataEmpty(rsp->dataBlock);
430,907✔
2262
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
430,907✔
2263

2264
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
8,842,596✔
2265
    int64_t *ver = taosArrayGet(versions, i);
8,411,689✔
2266
    if (ver == NULL) continue;
8,411,923✔
2267
    ST_TASK_TLOG("vgId:%d %s scan wal process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, *ver, walGetAppliedVer(pWalReader->pWal));
8,411,923✔
2268

2269
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,411,923✔
2270
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,410,221✔
UNCOV
2271
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
UNCOV
2272
      continue;
×
2273
    }
2274
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,411,221✔
2275
    SWalCont* wCont = &pWalReader->pHead->head;
8,411,923✔
2276
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,411,923✔
2277
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,411,923✔
2278

2279
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
8,411,923✔
2280
  }
2281
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2282
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
430,907✔
2283
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
430,907✔
2284

2285
end:
8,030,146✔
2286
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
8,030,146✔
2287
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
2288
  walCloseReader(pWalReader);
8,032,648✔
2289
  return code;
8,032,882✔
2290
}
2291

2292
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas, SStorageAPI* api) {
585,613✔
2293
  int32_t code = 0;
585,613✔
2294
  int32_t lino = 0;
585,613✔
2295
  SMetaReader metaReader = {0};
585,613✔
2296
  *schemas = taosArrayInit(8, sizeof(SSchema));
585,613✔
2297
  STREAM_CHECK_NULL_GOTO(*schemas, terrno);
585,613✔
2298
  
2299
  api->metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api->metaFn);
585,613✔
2300
  STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, uid));
585,613✔
2301

2302
  SSchemaWrapper* sSchemaWrapper = NULL;
582,549✔
2303
  if (metaReader.me.type == TD_CHILD_TABLE) {
582,549✔
2304
    int64_t suid = metaReader.me.ctbEntry.suid;
582,549✔
2305
    tDecoderClear(&metaReader.coder);
582,549✔
2306
    STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, suid));
582,549✔
2307
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
582,549✔
UNCOV
2308
  } else if (metaReader.me.type == TD_NORMAL_TABLE) {
×
UNCOV
2309
    sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
×
2310
  } else {
UNCOV
2311
    qError("invalid table type:%d", metaReader.me.type);
×
2312
  }
2313

2314
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
3,461,187✔
2315
    SSchema* s = sSchemaWrapper->pSchema + j;
2,878,638✔
2316
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
5,757,276✔
2317
  }
2318

2319
end:
585,613✔
2320
  api->metaReaderFn.clearReader(&metaReader);
585,613✔
2321
  STREAM_PRINT_LOG_END(code, lino);
585,613✔
2322
  if (code != 0)  {
585,613✔
2323
    taosArrayDestroy(*schemas);
3,064✔
2324
    *schemas = NULL;
3,064✔
2325
  }
2326
  return code;
585,613✔
2327
}
2328

2329
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
582,549✔
2330
  int32_t code = 0;
582,549✔
2331
  int32_t lino = 0;
582,549✔
2332
  size_t  schemaLen = taosArrayGetSize(schemas);
582,549✔
2333
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
582,549✔
2334
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
2,288,338✔
2335
    col_id_t* id = taosArrayGet(cols, i);
1,705,789✔
2336
    STREAM_CHECK_NULL_GOTO(id, terrno);
1,705,789✔
2337
    for (size_t i = 0; i < schemaLen; i++) {
4,500,824✔
2338
      SSchema* s = taosArrayGet(schemas, i);
4,500,824✔
2339
      STREAM_CHECK_NULL_GOTO(s, terrno);
4,500,824✔
2340
      if (*id == s->colId) {
4,500,824✔
2341
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
1,705,789✔
2342
        break;
1,705,789✔
2343
      }
2344
    }
2345
  }
2346
  taosArrayPopFrontBatch(schemas, schemaLen);
582,549✔
2347

2348
end:
582,549✔
2349
  return code;
582,549✔
2350
}
2351

UNCOV
2352
static int32_t createTSAndCondition(int64_t start, int64_t end, SLogicConditionNode** pCond,
×
2353
                                    STargetNode* pTargetNodeTs) {
UNCOV
2354
  int32_t code = 0;
×
UNCOV
2355
  int32_t lino = 0;
×
2356

UNCOV
2357
  SColumnNode*         pCol = NULL;
×
UNCOV
2358
  SColumnNode*         pCol1 = NULL;
×
UNCOV
2359
  SValueNode*          pVal = NULL;
×
UNCOV
2360
  SValueNode*          pVal1 = NULL;
×
2361
  SOperatorNode*       op = NULL;
×
UNCOV
2362
  SOperatorNode*       op1 = NULL;
×
2363
  SLogicConditionNode* cond = NULL;
×
2364

UNCOV
2365
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol));
×
2366
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
×
2367
  pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
×
2368
  pCol->node.resType.bytes = LONG_BYTES;
×
2369
  pCol->slotId = pTargetNodeTs->slotId;
×
2370
  pCol->dataBlockId = pTargetNodeTs->dataBlockId;
×
2371

2372
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pCol, (SNode**)&pCol1));
×
2373

2374
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal));
×
2375
  pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
×
2376
  pVal->node.resType.bytes = LONG_BYTES;
×
2377
  pVal->datum.i = start;
×
2378
  pVal->typeData = start;
×
2379

UNCOV
2380
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
×
2381
  pVal1->datum.i = end;
×
UNCOV
2382
  pVal1->typeData = end;
×
2383

2384
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op));
×
2385
  op->opType = OP_TYPE_GREATER_EQUAL;
×
2386
  op->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2387
  op->node.resType.bytes = CHAR_BYTES;
×
UNCOV
2388
  op->pLeft = (SNode*)pCol;
×
2389
  op->pRight = (SNode*)pVal;
×
2390
  pCol = NULL;
×
2391
  pVal = NULL;
×
2392

2393
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op1));
×
2394
  op1->opType = OP_TYPE_LOWER_EQUAL;
×
2395
  op1->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2396
  op1->node.resType.bytes = CHAR_BYTES;
×
2397
  op1->pLeft = (SNode*)pCol1;
×
2398
  op1->pRight = (SNode*)pVal1;
×
2399
  pCol1 = NULL;
×
2400
  pVal1 = NULL;
×
2401

2402
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
×
2403
  cond->condType = LOGIC_COND_TYPE_AND;
×
2404
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2405
  cond->node.resType.bytes = CHAR_BYTES;
×
2406
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
×
2407
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op));
×
2408
  op = NULL;
×
2409
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op1));
×
UNCOV
2410
  op1 = NULL;
×
2411

2412
  *pCond = cond;
×
2413

2414
end:
×
2415
  if (code != 0) {
×
2416
    nodesDestroyNode((SNode*)pCol);
×
2417
    nodesDestroyNode((SNode*)pCol1);
×
2418
    nodesDestroyNode((SNode*)pVal);
×
2419
    nodesDestroyNode((SNode*)pVal1);
×
UNCOV
2420
    nodesDestroyNode((SNode*)op);
×
2421
    nodesDestroyNode((SNode*)op1);
×
UNCOV
2422
    nodesDestroyNode((SNode*)cond);
×
2423
  }
2424
  STREAM_PRINT_LOG_END(code, lino);
×
2425

2426
  return code;
×
2427
}
2428

2429
/*
2430
static int32_t createExternalConditions(SStreamRuntimeFuncInfo* data, SLogicConditionNode** pCond, STargetNode* pTargetNodeTs, STimeRangeNode* node) {
2431
  int32_t              code = 0;
2432
  int32_t              lino = 0;
2433
  SLogicConditionNode* pAndCondition = NULL;
2434
  SLogicConditionNode* cond = NULL;
2435

2436
  if (pTargetNodeTs == NULL) {
2437
    vError("stream reader %s no ts column", __func__);
2438
    return TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN;
2439
  }
2440
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
2441
  cond->condType = LOGIC_COND_TYPE_OR;
2442
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
2443
  cond->node.resType.bytes = CHAR_BYTES;
2444
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
2445

2446
  for (int i = 0; i < taosArrayGetSize(data->pStreamPesudoFuncVals); ++i) {
2447
    data->curIdx = i;
2448

2449
    SReadHandle handle = {0};
2450
    calcTimeRange(node, data, &handle.winRange, &handle.winRangeValid);
2451
    if (!handle.winRangeValid) {
2452
      stError("stream reader %s invalid time range, skey:%" PRId64 ", ekey:%" PRId64, __func__, handle.winRange.skey,
2453
              handle.winRange.ekey);
2454
      continue;
2455
    }
2456
    STREAM_CHECK_RET_GOTO(createTSAndCondition(handle.winRange.skey, handle.winRange.ekey, &pAndCondition, pTargetNodeTs));
2457
    stDebug("%s create condition skey:%" PRId64 ", eksy:%" PRId64, __func__, handle.winRange.skey, handle.winRange.ekey);
2458
    STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)pAndCondition));
2459
    pAndCondition = NULL;
2460
  }
2461

2462
  *pCond = cond;
2463

2464
end:
2465
  if (code != 0) {
2466
    nodesDestroyNode((SNode*)pAndCondition);
2467
    nodesDestroyNode((SNode*)cond);
2468
  }
2469
  STREAM_PRINT_LOG_END(code, lino);
2470

2471
  return code;
2472
}
2473
*/
2474

2475
static int32_t processCalaTimeRange(SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo, SResFetchReq* req,
540,254✔
2476
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
2477
  int32_t code = 0;
540,254✔
2478
  int32_t lino = 0;
540,254✔
2479
  void* pTask = sStreamReaderCalcInfo->pTask;
540,254✔
2480
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
540,254✔
2481
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
540,022✔
2482
  
2483
  if (req->pStRtFuncInfo->withExternalWindow) {
540,254✔
2484
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
389,539✔
2485
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
389,307✔
2486
    sStreamReaderCalcInfo->tmpRtFuncInfo.isWindowTrigger = req->pStRtFuncInfo->isWindowTrigger;
389,539✔
2487
    sStreamReaderCalcInfo->tmpRtFuncInfo.precision = req->pStRtFuncInfo->precision;
389,539✔
2488

2489
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
389,307✔
2490
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
389,539✔
2491
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
389,539✔
2492
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
389,539✔
2493

2494
    if (!node->needCalc) {
389,539✔
2495
      pWin->skey = pFirst->wstart;
287,301✔
2496
      pWin->ekey = pLast->wend;
287,301✔
2497
      *pValid = true;
287,301✔
2498
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
287,301✔
2499
        pWin->ekey--;
163,975✔
2500
      }
2501
    } else {
2502
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
102,006✔
2503
      memcpy(pTmp, pFirst, sizeof(*pTmp));
102,238✔
2504

2505
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
102,238✔
2506
      if (*pValid) {
102,238✔
2507
        int64_t skey = pWin->skey;
102,238✔
2508

2509
        memcpy(pTmp, pLast, sizeof(*pTmp));
102,238✔
2510
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
102,238✔
2511

2512
        if (*pValid) {
102,238✔
2513
          pWin->skey = skey;
102,238✔
2514
        }
2515
      }
2516
      pWin->ekey--;
102,238✔
2517
    }
2518
  } else {
2519
    if (!node->needCalc) {
150,715✔
2520
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
107,435✔
2521
      pWin->skey = pCurr->wstart;
107,435✔
2522
      pWin->ekey = pCurr->wend;
107,435✔
2523
      *pValid = true;
107,435✔
2524
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
107,435✔
2525
        pWin->ekey--;
59,604✔
2526
      }
2527
    } else {
2528
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
43,280✔
2529
      pWin->ekey--;
43,280✔
2530
    }
2531
  }
2532

2533
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
540,254✔
2534
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
2535

2536
end:
4,648✔
2537

2538
  if (code) {
540,254✔
UNCOV
2539
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
2540
  }
2541
  
2542
  return code;
540,254✔
2543
}
2544

2545
static int32_t createDataBlockTsUid(SSDataBlock** pBlockRet, uint32_t numOfRows) {
490,297✔
2546
  int32_t      code = 0;
490,297✔
2547
  int32_t      lino = 0;
490,297✔
2548
  SSDataBlock* pBlock = NULL;
490,297✔
2549
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
490,529✔
2550
  SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID);
490,529✔
2551
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
490,529✔
2552
  idata = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID + 1);
490,529✔
2553
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
490,529✔
2554
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, numOfRows));
490,529✔
2555

2556
end:
490,529✔
2557
  STREAM_PRINT_LOG_END(code, lino)
490,529✔
2558
  if (code != TSDB_CODE_SUCCESS) {
490,529✔
UNCOV
2559
    blockDataDestroy(pBlock);
×
UNCOV
2560
    pBlock = NULL;
×
2561
  }
2562
  *pBlockRet = pBlock;
490,529✔
2563
  return code;
490,529✔
2564
}
2565

2566
static int32_t processTsOutPutAllTables(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
304,808✔
2567
  int32_t code = 0;
304,808✔
2568
  int32_t lino = 0;
304,808✔
2569
  void* pTask = sStreamReaderInfo->pTask;
304,808✔
2570

2571
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
304,808✔
2572
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
304,808✔
2573
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
304,604✔
2574
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
304,808✔
2575
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
909,904✔
2576
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
1,210,600✔
UNCOV
2577
      continue;
×
2578
    }
2579
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
605,300✔
2580
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
605,096✔
2581
    if (order == TSDB_ORDER_ASC) {
605,096✔
2582
      tsInfo->ts = INT64_MAX;
328,404✔
2583
    } else {
2584
      tsInfo->ts = INT64_MIN;
276,692✔
2585
    }
2586
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
605,300✔
2587
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
605,096✔
2588
      tsInfo->ts = ts;
328,404✔
2589
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
276,692✔
2590
      tsInfo->ts = ts;
276,896✔
2591
    }
2592
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
605,096✔
2593
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
605,096✔
2594
  }
2595

2596
end:
304,808✔
2597
  return code;
304,808✔
2598
}
2599

2600
static int32_t processTsOutPutOneGroup(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
85,872✔
2601
  int32_t code = 0;
85,872✔
2602
  int32_t lino = 0;
85,872✔
2603
  void* pTask = sStreamReaderInfo->pTask;
85,872✔
2604

2605
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
85,872✔
2606
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
85,640✔
2607
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
85,640✔
2608
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
85,872✔
2609
  if (order == TSDB_ORDER_ASC) {
85,872✔
2610
    tsInfo->ts = INT64_MAX;
67,560✔
2611
  } else {
2612
    tsInfo->ts = INT64_MIN;
18,312✔
2613
  }
2614

2615
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
85,872✔
2616
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
85,409✔
2617
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
186,808✔
2618
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
203,031✔
UNCOV
2619
      continue;
×
2620
    }
2621
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
101,631✔
2622
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
101,169✔
2623
      tsInfo->ts = ts;
67,097✔
2624
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
34,304✔
2625
      tsInfo->ts = ts;
18,312✔
2626
    }
2627
  }
2628
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
85,177✔
2629
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
84,947✔
2630
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
86,103✔
2631

2632
end:
30,298✔
2633
  return code;
86,103✔
2634
}
2635

2636
static int32_t processTsOutPutAllGroups(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
7,259✔
2637
  int32_t code = 0;
7,259✔
2638
  int32_t lino = 0;
7,259✔
2639
  STableKeyInfo* pList = NULL;
7,259✔
2640
  StreamTableListInfo     tableInfo = {0};
7,259✔
2641

2642
  void* pTask = sStreamReaderInfo->pTask;
7,259✔
2643
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
7,259✔
2644

2645
  SSHashObj*   uidTsHash = tSimpleHashInit(pResBlock->info.rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,259✔
2646
  STREAM_CHECK_NULL_GOTO(uidTsHash, terrno);
7,259✔
2647
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
7,259✔
2648
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
7,259✔
2649
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
22,390✔
2650
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
30,262✔
UNCOV
2651
      continue;
×
2652
    }
2653
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
15,131✔
2654
    int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
15,131✔
2655
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(uidTsHash, &uid, LONG_BYTES, &ts, LONG_BYTES));
15,131✔
2656
  }
2657
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(sStreamReaderInfo), sizeof(STsInfo));
7,259✔
2658
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
7,259✔
2659
  while (true) {
14,723✔
2660
    int32_t        pNum = 0;
21,982✔
2661
    int64_t        suid = 0;
21,982✔
2662
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
21,982✔
2663
    if(pNum == 0) break;
21,982✔
2664
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
15,304✔
2665
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
15,304✔
2666
    if (order == TSDB_ORDER_ASC) {
15,304✔
2667
      tsInfo->ts = INT64_MAX;
7,173✔
2668
    } else {
2669
      tsInfo->ts = INT64_MIN;
8,131✔
2670
    }
2671
    for (int32_t i = 0; i < pNum; i++) {
30,027✔
2672
      int64_t uid = pList[i].uid;
15,304✔
2673
      int64_t *ts = tSimpleHashGet(uidTsHash, &uid, LONG_BYTES);
15,304✔
2674
      STREAM_CHECK_NULL_GOTO(ts, terrno);
15,304✔
2675
      if (order == TSDB_ORDER_ASC && *ts < tsInfo->ts) {
14,723✔
2676
        tsInfo->ts = *ts;
7,173✔
2677
      } else if (order == TSDB_ORDER_DESC && *ts > tsInfo->ts) {
7,550✔
2678
        tsInfo->ts = *ts;
7,550✔
2679
      }
2680
    }
2681
    int64_t uid = pList[0].uid;
14,723✔
2682
    tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
14,723✔
2683
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
14,723✔
2684
    taosMemoryFreeClear(pList);
14,723✔
2685
  }
2686

2687
end:
7,259✔
2688
  qStreamDestroyTableInfo(&tableInfo);
7,259✔
2689
  taosMemoryFreeClear(pList);
7,259✔
2690
  tSimpleHashCleanup(uidTsHash);
7,259✔
2691
  return code;
7,259✔
2692
}
2693

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

2696
static int32_t getAllTs(SVnode* pVnode, SSDataBlock*  pResBlock, SStreamReaderTaskInner* pTaskInner, STableKeyInfo* pList, int32_t pNum) {
373,846✔
2697
  int32_t code = 0;
373,846✔
2698
  int32_t lino = 0;
373,846✔
2699

2700
  STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdCreateFirstLastTsIter(pVnode, &pTaskInner->options->twindows, &(SVersionRange){.minVer = -1, .maxVer = pTaskInner->options->ver},
373,846✔
2701
                                                pTaskInner->options->suid, pList, pNum, pTaskInner->options->order, &pTaskInner->pReader, pTaskInner->idStr));
2702
  bool hasNext = true;
373,846✔
2703
  while(1){
2704
    STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdNextFirstLastTsBlock(pTaskInner->pReader, pResBlock, &hasNext));
373,846✔
2705
    STREAM_CHECK_CONDITION_GOTO(!hasNext, TDB_CODE_SUCCESS);
373,641✔
2706
  }
2707

2708
end:
373,641✔
2709
  pTaskInner->storageApi->tsdReader.tsdDestroyFirstLastTsIter(pTaskInner->pReader);
373,641✔
2710
  pTaskInner->pReader = NULL;
373,166✔
2711
  return code;
373,166✔
2712
}
2713

2714
static int32_t processTsVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
250,145✔
2715
                                  SStreamReaderTaskInner* pTaskInner) {
2716
  int32_t code = 0;
250,145✔
2717
  int32_t lino = 0;
250,145✔
2718
  STableKeyInfo* pList = NULL;
250,145✔
2719
  StreamTableListInfo     tableInfo = {0};
250,145✔
2720

2721
  void* pTask = sStreamReaderInfo->pTask;
250,145✔
2722
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
250,145✔
2723

2724
  SSDataBlock*  pResBlock = NULL;
250,145✔
2725
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, qStreamGetTableListNum(sStreamReaderInfo)));
250,145✔
2726

2727
  while (true) {
133,462✔
2728
    int32_t        pNum = 0;
383,607✔
2729
    int64_t        suid = 0;
383,607✔
2730
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
383,607✔
2731
    if(pNum == 0) break;
383,607✔
2732
    pTaskInner->options->suid = suid;
133,462✔
2733
    STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
133,462✔
2734
    taosMemoryFreeClear(pList);
133,462✔
2735
  }
2736

2737
  STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, pTaskInner->options->order));
250,145✔
2738

2739
end:
250,145✔
2740
  qStreamDestroyTableInfo(&tableInfo);
250,145✔
2741
  taosMemoryFreeClear(pList);
250,145✔
2742
  blockDataDestroy(pResBlock);
250,145✔
2743
  STREAM_PRINT_LOG_END_WITHID(code, lino);
250,145✔
2744
  return code;
250,145✔
2745
}
2746

2747
static int32_t processTsNonVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
231,075✔
2748
                                  SStreamReaderTaskInner* pTaskInner) {
2749
  int32_t code = 0;
231,075✔
2750
  int32_t lino = 0;
231,075✔
2751
  STableKeyInfo* pList = NULL;
231,075✔
2752
  void* pTask = sStreamReaderInfo->pTask;
231,075✔
2753
  
2754
  SSDataBlock*  pResBlock = NULL;
231,075✔
2755

2756
  int32_t        pNum = 0;
231,075✔
2757
  int64_t        suid = 0;
231,075✔
2758
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, 0, &pList, &pNum));
231,075✔
2759
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
230,843✔
2760
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
198,909✔
2761

2762
  pTaskInner->options->suid = sStreamReaderInfo->suid;
199,141✔
2763
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
199,141✔
2764
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
198,925✔
2765
  int32_t order = pTaskInner->options->order;
106,782✔
2766

2767
  if (sStreamReaderInfo->groupByTbname) {
106,578✔
2768
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
54,459✔
2769
  } else if (sStreamReaderInfo->partitionCols == NULL) {
52,119✔
2770
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
44,860✔
2771
  } else {
2772
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
7,259✔
2773
  }                             
2774
end:
230,388✔
2775
  blockDataDestroy(pResBlock);
230,395✔
2776
  taosMemoryFreeClear(pList);
230,408✔
2777
  STREAM_PRINT_LOG_END_WITHID(code, lino);
230,396✔
2778
  return code;
230,612✔
2779
}
2780

2781
static int32_t processTsOnce(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
54,841✔
2782
                                  SStreamReaderTaskInner* pTaskInner, uint64_t gid) {
2783
  int32_t code = 0;
54,841✔
2784
  int32_t lino = 0;
54,841✔
2785
  STableKeyInfo* pList = NULL;
54,841✔
2786
  void* pTask = sStreamReaderInfo->pTask;
54,841✔
2787
  
2788
  SSDataBlock*  pResBlock = NULL;
54,841✔
2789

2790
  int32_t        pNum = 0;
54,841✔
2791
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
54,841✔
2792
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
54,841✔
2793
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
41,243✔
2794

2795
  pTaskInner->options->suid = sStreamReaderInfo->suid;
41,243✔
2796
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
41,243✔
2797
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
41,011✔
2798
  int32_t order = pTaskInner->options->order;
40,548✔
2799

2800
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
40,780✔
2801
end:
54,841✔
2802
  blockDataDestroy(pResBlock);
54,841✔
2803
  taosMemoryFreeClear(pList);
54,841✔
2804
  STREAM_PRINT_LOG_END_WITHID(code, lino);
54,841✔
2805
  return code;
54,841✔
2806
}
2807

2808
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
481,220✔
2809
                                  SStreamReaderTaskInner* pTaskInner) {
2810
  if (sStreamReaderInfo->isVtableStream) {
481,220✔
2811
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
250,145✔
2812
  }
2813

2814
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
231,075✔
2815
}
2816

2817
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
133,511✔
2818
  int32_t code = 0;
133,511✔
2819
  int32_t lino = 0;
133,511✔
2820
  void*   buf = NULL;
133,511✔
2821
  size_t  size = 0;
133,511✔
2822
  void* pTask = sStreamReaderInfo->pTask;
133,511✔
2823

2824
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d, appver:%"PRId64, TD_VID(pVnode), __func__,
133,511✔
2825
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc), pVnode->state.applied);
2826

2827
  taosWLockLatch(&sStreamReaderInfo->lock);
133,511✔
2828
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
133,511✔
2829
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
133,511✔
2830
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
133,511✔
2831
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
133,511✔
2832

2833
  qStreamClearTableInfo(&sStreamReaderInfo->vSetTableList);
133,511✔
2834
  STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->vSetTableList));
133,511✔
2835
  STREAM_CHECK_RET_GOTO(qBuildVTableList(sStreamReaderInfo));
133,511✔
2836
end:
133,511✔
2837
  taosWUnLockLatch(&sStreamReaderInfo->lock);
133,511✔
2838
  STREAM_PRINT_LOG_END_WITHID(code, lino);
133,511✔
2839
  SRpcMsg rsp = {
133,511✔
2840
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2841
  tmsgSendRsp(&rsp);
133,511✔
2842
  return code;
133,511✔
2843
}
2844

2845
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
288,908✔
2846
  int32_t                 code = 0;
288,908✔
2847
  int32_t                 lino = 0;
288,908✔
2848
  SStreamReaderTaskInner* pTaskInner = NULL;
288,908✔
2849
  SStreamTsResponse       tsRsp = {0};
288,908✔
2850
  void*                   buf = NULL;
288,908✔
2851
  size_t                  size = 0;
288,908✔
2852

2853
  void* pTask = sStreamReaderInfo->pTask;
288,908✔
2854

2855
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
288,908✔
2856

2857
  BUILD_OPTION(options, 0, sStreamReaderInfo->tableList.version, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, NULL, false, NULL);
288,908✔
2858
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
288,908✔
2859

2860
  tsRsp.ver = sStreamReaderInfo->tableList.version + 1;
288,908✔
2861

2862
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
288,908✔
2863
  
2864
end:
288,908✔
2865
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
288,908✔
2866
  code = buildTsRsp(&tsRsp, &buf, &size);
288,908✔
2867
  STREAM_PRINT_LOG_END_WITHID(code, lino);
288,720✔
2868
  SRpcMsg rsp = {
288,720✔
2869
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2870
  tmsgSendRsp(&rsp);
288,676✔
2871
  taosArrayDestroy(tsRsp.tsInfo);
288,908✔
2872
  taosMemoryFree(pTaskInner);
288,908✔
2873
  return code;
288,908✔
2874
}
2875

2876
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
247,153✔
2877
  int32_t                 code = 0;
247,153✔
2878
  int32_t                 lino = 0;
247,153✔
2879
  SStreamReaderTaskInner* pTaskInner = NULL;
247,153✔
2880
  SStreamTsResponse       tsRsp = {0};
247,153✔
2881
  void*                   buf = NULL;
247,153✔
2882
  size_t                  size = 0;
247,153✔
2883

2884
  void* pTask = sStreamReaderInfo->pTask;
247,153✔
2885
  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);
247,153✔
2886
  int32_t        pNum = 0;
247,153✔
2887

2888
  tsRsp.ver = pVnode->state.applied;
247,153✔
2889

2890
  BUILD_OPTION(options, 0, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, NULL, false, NULL);
247,153✔
2891
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
247,153✔
2892

2893
  if (req->firstTsReq.gid != 0) {
247,153✔
2894
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
54,841✔
2895
  } else {
2896
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
192,312✔
2897
  }
2898

2899
end:
247,153✔
2900
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
247,153✔
2901
  code = buildTsRsp(&tsRsp, &buf, &size);
247,153✔
2902
  STREAM_PRINT_LOG_END_WITHID(code, lino);
246,804✔
2903
  SRpcMsg rsp = {
246,921✔
2904
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2905
  tmsgSendRsp(&rsp);
246,229✔
2906
  taosArrayDestroy(tsRsp.tsInfo);
247,153✔
2907
  taosMemoryFree(pTaskInner);
246,921✔
2908
  return code;
246,690✔
2909
}
2910

2911
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
460,123✔
2912
  int32_t code = 0;
460,123✔
2913
  int32_t lino = 0;
460,123✔
2914
  void*   buf = NULL;
460,123✔
2915
  size_t  size = 0;
460,123✔
2916
  STableKeyInfo* pList = NULL;
460,123✔
2917

2918
  void* pTask = sStreamReaderInfo->pTask;
460,123✔
2919
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64 ",skey:%" PRId64 ",ekey:%" PRId64 ",gid:%" PRId64, TD_VID(pVnode),
460,123✔
2920
               __func__, req->tsdbMetaReq.ver, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime,
2921
               req->tsdbMetaReq.gid);
2922

2923
  SStreamReaderTaskInner* pTaskInner = NULL;
460,123✔
2924
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
460,123✔
2925

2926
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
460,123✔
2927
    int32_t        pNum = 0;
460,123✔
2928
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbMetaReq.gid, &pList, &pNum));
460,123✔
2929
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, 
460,123✔
2930
                          sStreamReaderInfo->tsSchemas, true, NULL);
2931
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, pList, pNum, &sStreamReaderInfo->storageApi));
460,123✔
2932
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
460,123✔
2933
    
2934
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
460,123✔
2935
  } else {
UNCOV
2936
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
2937
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
2938
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
2939
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2940
  }
2941

2942
  blockDataCleanup(pTaskInner->pResBlockDst);
460,123✔
2943
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
460,123✔
2944
  bool hasNext = true;
460,123✔
2945
  while (true) {
411,135✔
2946
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
871,258✔
2947
    if (!hasNext) {
871,258✔
2948
      break;
460,123✔
2949
    }
2950
    pTaskInner->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
411,135✔
2951
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
411,135✔
2952

2953
    int32_t index = 0;
411,135✔
2954
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
411,135✔
2955
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
411,135✔
2956
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
411,135✔
2957
    if (!sStreamReaderInfo->isVtableStream) {
411,135✔
2958
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
170,090✔
2959
    }
2960
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
411,135✔
2961

2962
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
411,135✔
2963
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2964
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2965
            pTaskInner->pResBlockDst->info.rows++;
411,135✔
2966
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
411,135✔
UNCOV
2967
      break;
×
2968
    }
2969
  }
2970

2971
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
460,123✔
2972
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
460,123✔
2973
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
460,123✔
2974
  if (!hasNext) {
460,123✔
2975
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
460,123✔
2976
  }
2977

2978
end:
460,123✔
2979
  STREAM_PRINT_LOG_END_WITHID(code, lino);
460,123✔
2980
  SRpcMsg rsp = {
460,123✔
2981
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2982
  tmsgSendRsp(&rsp);
460,123✔
2983
  taosMemoryFree(pList);
460,123✔
2984
  return code;
460,123✔
2985
}
2986

2987
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
163,864✔
2988
  int32_t                 code = 0;
163,864✔
2989
  int32_t                 lino = 0;
163,864✔
2990
  SStreamReaderTaskInner* pTaskInner = NULL;
163,864✔
2991
  void*                   buf = NULL;
163,864✔
2992
  size_t                  size = 0;
163,864✔
2993
  SSDataBlock*            pBlockRes = NULL;
163,864✔
2994

2995
  void* pTask = sStreamReaderInfo->pTask;
163,864✔
2996
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
163,864✔
2997
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2998
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2999

3000
  int32_t        pNum = 1;
163,864✔
3001
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
163,864✔
3002
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
163,864✔
3003
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
163,864✔
3004
               sStreamReaderInfo->triggerCols, false, NULL);
3005
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
163,864✔
3006
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
163,864✔
3007
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
163,864✔
3008

3009
  while (1) {
163,864✔
3010
    bool hasNext = false;
327,728✔
3011
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
327,728✔
3012
    if (!hasNext) {
327,728✔
3013
      break;
163,864✔
3014
    }
3015
    // if (!sStreamReaderInfo->isVtableStream){
3016
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
163,864✔
3017
    // }
3018

3019
    SSDataBlock* pBlock = NULL;
163,864✔
3020
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
163,864✔
3021
    if (pBlock != NULL && pBlock->info.rows > 0) {
163,864✔
3022
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
163,864✔
3023
          0, pBlock->info.rows, 1));
3024
    }
3025
    
3026
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
163,864✔
3027
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
163,864✔
3028
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
163,864✔
3029
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3030
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3031
  }
3032

3033
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
163,864✔
3034

3035
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
163,864✔
3036
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
163,864✔
3037

3038
end:
163,864✔
3039
  STREAM_PRINT_LOG_END_WITHID(code, lino);
163,864✔
3040
  SRpcMsg rsp = {
163,864✔
3041
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3042
  tmsgSendRsp(&rsp);
163,864✔
3043
  blockDataDestroy(pBlockRes);
163,864✔
3044

3045
  releaseStreamTask(&pTaskInner);
163,864✔
3046
  return code;
163,864✔
3047
}
3048

3049
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
6,128✔
3050
  int32_t                 code = 0;
6,128✔
3051
  int32_t                 lino = 0;
6,128✔
3052
  SStreamReaderTaskInner* pTaskInner = NULL;
6,128✔
3053
  void*                   buf = NULL;
6,128✔
3054
  size_t                  size = 0;
6,128✔
3055
  SSDataBlock*            pBlockRes = NULL;
6,128✔
3056

3057
  void* pTask = sStreamReaderInfo->pTask;
6,128✔
3058
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
6,128✔
3059
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3060
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3061

3062
  int32_t        pNum = 1;
6,128✔
3063
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
6,128✔
3064
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
6,128✔
3065
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
6,128✔
3066
               sStreamReaderInfo->tsSchemas, true, NULL);
3067
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
6,128✔
3068
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
6,128✔
3069

3070
  while (1) {
6,128✔
3071
    bool hasNext = false;
12,256✔
3072
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
12,256✔
3073
    if (!hasNext) {
12,256✔
3074
      break;
6,128✔
3075
    }
3076

3077
    SSDataBlock* pBlock = NULL;
6,128✔
3078
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
6,128✔
3079
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
6,128✔
3080
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
6,128✔
3081
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
3082
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
3083
  }
3084

3085
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
6,128✔
3086
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
6,128✔
3087

3088
end:
6,128✔
3089
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,128✔
3090
  SRpcMsg rsp = {
6,128✔
3091
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3092
  tmsgSendRsp(&rsp);
6,128✔
3093
  blockDataDestroy(pBlockRes);
6,128✔
3094

3095
  releaseStreamTask(&pTaskInner);
6,128✔
3096
  return code;
6,128✔
3097
}
3098

3099
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
112,390✔
3100
  int32_t code = 0;
112,390✔
3101
  int32_t lino = 0;
112,390✔
3102
  void*   buf = NULL;
112,390✔
3103
  size_t  size = 0;
112,390✔
3104
  STableKeyInfo* pList = NULL;
112,390✔
3105
  SArray*        pResList = NULL;
112,390✔
3106
  SSDataBlock*   pBlockTmp = NULL;
112,390✔
3107

3108
  SStreamReaderTaskInner* pTaskInner = NULL;
112,390✔
3109
  void* pTask = sStreamReaderInfo->pTask;
112,390✔
3110
  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);
112,390✔
3111
  
3112
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
112,390✔
3113

3114
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
112,390✔
3115
    int32_t        pNum = 0;
56,195✔
3116
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbTriggerDataReq.gid, &pList, &pNum));
56,195✔
3117
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
56,195✔
3118
                 sStreamReaderInfo->triggerCols, false, NULL);
3119
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
56,195✔
3120
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
56,195✔
3121
  } else {
3122
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
56,195✔
3123
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
56,195✔
UNCOV
3124
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
3125
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3126
  }
3127

3128
  blockDataCleanup(pTaskInner->pResBlockDst);
56,195✔
3129
  bool hasNext = true;
55,964✔
3130
  int32_t totalRows = 0;
55,964✔
3131
    
3132
  pResList = taosArrayInit(4, POINTER_BYTES);
55,964✔
3133
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
56,195✔
3134
  while (1) {
61,398✔
3135
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
117,593✔
3136
    if (!hasNext) {
117,362✔
3137
      break;
56,195✔
3138
    }
3139
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
61,167✔
3140
    // pTaskInner->pResBlockDst->info.id.groupId = pTaskInner->pResBlock->info.id.groupId;
3141

3142
    SSDataBlock* pBlock = NULL;
61,398✔
3143
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
61,398✔
3144
    if (pBlock != NULL && pBlock->info.rows > 0) {
61,398✔
3145
      STREAM_CHECK_RET_GOTO(
61,398✔
3146
        processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
3147
    }
3148
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
61,398✔
3149
    // STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3150
    ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
61,398✔
3151
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
61,398✔
3152
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
61,398✔
3153
    totalRows += blockDataGetNumOfRows(pBlockTmp);
61,398✔
3154
    pBlockTmp = NULL;
61,398✔
3155

3156
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
61,398✔
3157
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3158
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3159
    if (totalRows >= STREAM_RETURN_ROWS_NUM) {  //todo optimize send multi blocks in one group
61,398✔
UNCOV
3160
      break;
×
3161
    }
3162
  }
3163

3164
  STREAM_CHECK_RET_GOTO(buildArrayRsp(pResList, &buf, &size));
56,195✔
3165
  if (!hasNext) {
56,195✔
3166
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
56,195✔
3167
  }
3168

3169
end:
111,928✔
3170
  STREAM_PRINT_LOG_END_WITHID(code, lino);
112,159✔
3171
  SRpcMsg rsp = {
112,159✔
3172
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3173
  tmsgSendRsp(&rsp);
112,390✔
3174
  taosMemoryFree(pList);
112,390✔
3175
  blockDataDestroy(pBlockTmp);
112,390✔
3176
  taosArrayDestroyP(pResList, (FDelete)blockDataDestroy);
112,390✔
3177
  return code;
112,390✔
3178
}
3179

3180
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
6,336,168✔
3181
  int32_t code = 0;
6,336,168✔
3182
  int32_t lino = 0;
6,336,168✔
3183
  void*   buf = NULL;
6,336,168✔
3184
  size_t  size = 0;
6,336,168✔
3185
  SSDataBlock*   pBlockRes = NULL;
6,335,961✔
3186
  STableKeyInfo* pList = NULL;
6,335,961✔
3187

3188

3189
  void* pTask = sStreamReaderInfo->pTask;
6,335,961✔
3190
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
6,335,961✔
3191
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid, req->tsdbCalcDataReq.ver);
3192

3193
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
6,335,961✔
3194

3195
  SStreamReaderTaskInner* pTaskInner = NULL;
6,336,375✔
3196
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
6,336,375✔
3197

3198
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
6,336,375✔
3199
    int32_t        pNum = 0;
6,336,375✔
3200
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbCalcDataReq.gid, &pList, &pNum));
6,336,375✔
3201
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
6,336,375✔
3202
                 sStreamReaderInfo->triggerCols, false, NULL);
3203
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
6,336,168✔
3204

3205
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
6,326,646✔
3206
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
6,332,235✔
3207
  } else {
UNCOV
3208
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
3209
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
3210
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
3211
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3212
  }
3213

3214
  blockDataCleanup(pTaskInner->pResBlockDst);
6,333,270✔
3215
  bool hasNext = true;
6,329,337✔
3216
  while (1) {
784,801✔
3217
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
7,115,794✔
3218
    if (!hasNext) {
7,111,692✔
3219
      break;
6,324,802✔
3220
    }
3221
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
786,890✔
3222

3223
    SSDataBlock* pBlock = NULL;
785,177✔
3224
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
785,177✔
3225
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
784,989✔
3226
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
784,989✔
3227
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
784,989✔
UNCOV
3228
      break;
×
3229
    }
3230
  }
3231

3232
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
6,326,665✔
3233
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
6,332,273✔
3234
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
6,330,372✔
3235
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
6,330,184✔
3236
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
6,326,684✔
3237
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
6,327,074✔
3238
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
6,336,765✔
3239

3240
  if (!hasNext) {
6,336,375✔
3241
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
6,336,375✔
3242
  }
3243

3244
end:
6,335,316✔
3245
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,335,547✔
3246
  SRpcMsg rsp = {
6,335,961✔
3247
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3248
  tmsgSendRsp(&rsp);
6,336,375✔
3249
  blockDataDestroy(pBlockRes);
6,336,375✔
3250
  taosMemoryFree(pList);
6,336,168✔
3251
  return code;
6,336,168✔
3252
}
3253

3254
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
585,613✔
3255
  int32_t code = 0;
585,613✔
3256
  int32_t lino = 0;
585,613✔
3257
  void*   buf = NULL;
585,613✔
3258
  size_t  size = 0;
585,613✔
3259
  int32_t* slotIdList = NULL;
585,613✔
3260
  SArray* sortedCid = NULL;
585,613✔
3261
  SArray* schemas = NULL;
585,613✔
3262
  SSDataBlock*   pBlockRes = NULL;
585,613✔
3263
  
3264
  void* pTask = sStreamReaderInfo->pTask;
585,613✔
3265
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
585,613✔
3266
    req->tsdbDataReq.skey, req->tsdbDataReq.ekey, req->tsdbDataReq.uid, req->tsdbDataReq.ver);
3267
    
3268
  SStreamReaderTaskInner* pTaskInner = NULL;
585,613✔
3269
  int64_t key = req->tsdbDataReq.uid;
585,613✔
3270

3271
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
585,613✔
3272
    // sort cid and build slotIdList
3273
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
585,613✔
3274
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
585,613✔
3275
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
585,613✔
3276
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
585,613✔
3277
    taosArraySort(sortedCid, sortCid);
585,613✔
3278
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
2,300,594✔
3279
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
1,714,215✔
3280
      STREAM_CHECK_NULL_GOTO(cid, terrno);
1,714,981✔
3281
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
3,392,034✔
3282
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
3,389,736✔
3283
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
3,389,736✔
3284
        if (*cid == *cidSorted) {
3,389,736✔
3285
          slotIdList[j] = i;
1,714,981✔
3286
          break;
1,714,981✔
3287
        }
3288
      }
3289
    }
3290

3291
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas, &sStreamReaderInfo->storageApi));
585,613✔
3292
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
582,549✔
3293
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlockRes));
582,549✔
3294

3295
    taosArraySort(schemas, sortSSchema);
582,549✔
3296
    BUILD_OPTION(options, req->tsdbDataReq.suid, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
582,549✔
3297
                    req->tsdbDataReq.ekey, schemas, true, &slotIdList);
3298
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid, .groupId = 0};
582,549✔
3299
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, pBlockRes, &keyInfo, 1, &sStreamReaderInfo->storageApi));
582,549✔
3300
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
582,549✔
3301
    pTaskInner->pResBlockDst = pBlockRes;
582,549✔
3302
    pBlockRes = NULL;
582,549✔
3303
  } else {
UNCOV
3304
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
3305
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
3306
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
3307
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3308
  }
3309

3310
  blockDataCleanup(pTaskInner->pResBlockDst);
582,549✔
3311
  bool hasNext = true;
582,549✔
3312
  while (1) {
582,549✔
3313
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,165,098✔
3314
    if (!hasNext) {
1,165,098✔
3315
      break;
582,549✔
3316
    }
3317

3318
    SSDataBlock* pBlock = NULL;
582,549✔
3319
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
582,549✔
3320
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
582,549✔
3321
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
582,549✔
UNCOV
3322
      break;
×
3323
    }
3324
  }
3325
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
582,549✔
3326
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
582,549✔
3327
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
582,549✔
3328
  if (!hasNext) {
582,549✔
3329
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
582,549✔
3330
  }
3331

3332
end:
585,613✔
3333
  STREAM_PRINT_LOG_END_WITHID(code, lino);
585,613✔
3334
  SRpcMsg rsp = {
585,613✔
3335
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3336
  tmsgSendRsp(&rsp);
585,613✔
3337
  taosMemFree(slotIdList);
585,613✔
3338
  taosArrayDestroy(sortedCid);
585,613✔
3339
  taosArrayDestroy(schemas);
585,613✔
3340
  blockDataDestroy(pBlockRes);
585,613✔
3341
  return code;
585,613✔
3342
}
3343

3344
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
11,344,187✔
3345
  int32_t      code = 0;
11,344,187✔
3346
  int32_t      lino = 0;
11,344,187✔
3347
  void*        buf = NULL;
11,344,187✔
3348
  size_t       size = 0;
11,344,187✔
3349
  int64_t      lastVer = 0;
11,344,187✔
3350
  SSTriggerWalNewRsp resultRsp = {0};
11,344,187✔
3351

3352
  void* pTask = sStreamReaderInfo->pTask;
11,344,371✔
3353
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
11,344,167✔
3354

3355
  if (sStreamReaderInfo->metaBlock == NULL) {
11,344,340✔
3356
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
198,405✔
3357
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
198,405✔
3358
  }
3359
  blockDataEmpty(sStreamReaderInfo->metaBlock);
11,344,371✔
3360
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
11,343,689✔
3361
  resultRsp.ver = req->walMetaNewReq.lastVer;
11,343,689✔
3362
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
11,343,689✔
3363

3364
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
11,343,437✔
3365
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
11,343,730✔
3366
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
356,410✔
3367
  buf = rpcMallocCont(size);
356,410✔
3368
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
356,410✔
3369
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
356,410✔
3370
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
356,410✔
3371
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
356,410✔
3372

3373
end:
11,343,499✔
3374
  if (code == 0 && resultRsp.totalRows == 0) {
11,343,499✔
3375
    code = TSDB_CODE_STREAM_NO_DATA;
10,987,554✔
3376
    size = sizeof(int64_t) * 2;
10,987,554✔
3377
    buf = rpcMallocCont(size);
10,987,554✔
3378
    *(int64_t*)buf = resultRsp.ver;
10,986,327✔
3379
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
10,986,327✔
3380
  }
3381
  SRpcMsg rsp = {
11,341,972✔
3382
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3383
  tmsgSendRsp(&rsp);
11,342,969✔
3384
  if (code == TSDB_CODE_STREAM_NO_DATA){
11,343,632✔
3385
    code = 0;
10,987,222✔
3386
  }
3387
  STREAM_PRINT_LOG_END_WITHID(code, lino);
11,343,632✔
3388
  blockDataDestroy(resultRsp.deleteBlock);
11,344,949✔
3389
  blockDataDestroy(resultRsp.tableBlock);
11,344,183✔
3390

3391
  return code;
11,344,183✔
3392
}
3393
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,340,260✔
3394
  int32_t      code = 0;
3,340,260✔
3395
  int32_t      lino = 0;
3,340,260✔
3396
  void*        buf = NULL;
3,340,260✔
3397
  size_t       size = 0;
3,340,260✔
3398
  SSTriggerWalNewRsp resultRsp = {0};
3,340,260✔
3399
  
3400
  void* pTask = sStreamReaderInfo->pTask;
3,340,723✔
3401
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,340,489✔
3402

3403
  if (sStreamReaderInfo->metaBlock == NULL) {
3,340,705✔
3404
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
99,081✔
3405
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
99,081✔
3406
  }
3407

3408
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,339,799✔
3409
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
3,340,030✔
3410
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,339,605✔
3411
  resultRsp.checkAlter = true;
3,339,616✔
3412
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,339,616✔
3413
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
3,338,448✔
3414

3415
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,338,448✔
3416

3417
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,339,352✔
3418
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
130,561✔
3419
  buf = rpcMallocCont(size);
131,254✔
3420
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
131,254✔
3421
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
131,254✔
3422
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
131,254✔
3423
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
131,254✔
3424
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
131,254✔
3425
  printIndexHash(resultRsp.indexHash, pTask);
131,254✔
3426

3427
end:
3,340,045✔
3428
  if (resultRsp.totalRows == 0) {
3,339,351✔
3429
    code = TSDB_CODE_STREAM_NO_DATA;
3,208,559✔
3430
    size = sizeof(int64_t) * 2;
3,208,559✔
3431
    buf = rpcMallocCont(size);
3,208,559✔
3432
    *(int64_t*)buf = resultRsp.ver;
3,206,331✔
3433
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
3,206,331✔
3434
  }
3435
  SRpcMsg rsp = {
3,337,962✔
3436
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3437
  tmsgSendRsp(&rsp);
3,338,139✔
3438
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,339,861✔
3439
    code = 0;
3,208,607✔
3440
  }
3441
  blockDataDestroy(resultRsp.dataBlock);
3,339,861✔
3442
  blockDataDestroy(resultRsp.deleteBlock);
3,338,349✔
3443
  blockDataDestroy(resultRsp.tableBlock);
3,338,835✔
3444
  tSimpleHashCleanup(resultRsp.indexHash);
3,339,928✔
3445

3446
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,335,546✔
3447

3448
  return code;
3,337,035✔
3449
}
3450

3451
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
7,060,844✔
3452
  int32_t      code = 0;
7,060,844✔
3453
  int32_t      lino = 0;
7,060,844✔
3454
  void*        buf = NULL;
7,060,844✔
3455
  size_t       size = 0;
7,060,844✔
3456
  SSTriggerWalNewRsp resultRsp = {0};
7,060,844✔
3457

3458
  void* pTask = sStreamReaderInfo->pTask;
7,060,844✔
3459
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
7,060,844✔
3460

3461
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
7,060,844✔
3462
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,060,844✔
3463
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
7,058,546✔
3464
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,058,546✔
3465
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
7,059,312✔
3466

3467
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
7,059,312✔
3468
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
7,060,844✔
3469

3470
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
7,060,640✔
3471

3472
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
180,886✔
3473
  buf = rpcMallocCont(size);
180,886✔
3474
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
180,886✔
3475
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
180,886✔
3476
  printIndexHash(resultRsp.indexHash, pTask);
180,886✔
3477

3478
end:
7,060,640✔
3479
  if (resultRsp.totalRows == 0) {
7,060,844✔
3480
    buf = rpcMallocCont(sizeof(int64_t));
6,879,958✔
3481
    *(int64_t *)buf = resultRsp.ver;
6,878,958✔
3482
    size = sizeof(int64_t);
6,878,958✔
3483
    code = TSDB_CODE_STREAM_NO_DATA;
6,878,958✔
3484
  }
3485
  SRpcMsg rsp = {
7,059,844✔
3486
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3487
  tmsgSendRsp(&rsp);
7,059,844✔
3488
  if (code == TSDB_CODE_STREAM_NO_DATA){
7,060,844✔
3489
    code = 0;
6,879,958✔
3490
  }
3491

3492
  blockDataDestroy(resultRsp.dataBlock);
7,060,844✔
3493
  blockDataDestroy(resultRsp.deleteBlock);
7,060,078✔
3494
  blockDataDestroy(resultRsp.tableBlock);
7,060,078✔
3495
  tSimpleHashCleanup(resultRsp.indexHash);
7,060,844✔
3496
  tSimpleHashCleanup(resultRsp.uidHash);
7,060,409✔
3497
  STREAM_PRINT_LOG_END_WITHID(code, lino);
7,059,874✔
3498

3499
  return code;
7,060,640✔
3500
}
3501

3502
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
972,038✔
3503
  int32_t      code = 0;
972,038✔
3504
  int32_t      lino = 0;
972,038✔
3505
  void*        buf = NULL;
972,038✔
3506
  size_t       size = 0;
972,038✔
3507
  SSTriggerWalNewRsp resultRsp = {0};
972,038✔
3508
  SSDataBlock* pBlock1 = NULL;
972,038✔
3509
  SSDataBlock* pBlock2 = NULL;
972,038✔
3510
  
3511
  void* pTask = sStreamReaderInfo->pTask;
972,038✔
3512
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
972,038✔
3513

3514
  SSDataBlock* dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
972,038✔
3515
  STREAM_CHECK_RET_GOTO(createOneDataBlock(dataBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
971,807✔
3516
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
972,038✔
3517
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
972,038✔
3518
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
971,603✔
3519
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
971,603✔
3520
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
971,603✔
3521

3522
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
971,603✔
3523
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
972,038✔
3524

3525
  if (!sStreamReaderInfo->isVtableStream){
250,021✔
3526
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
148,915✔
3527
  
3528
    blockDataTransform(pBlock2, resultRsp.dataBlock);
148,915✔
3529
    blockDataDestroy(resultRsp.dataBlock);
148,915✔
3530
    resultRsp.dataBlock = pBlock2;
148,915✔
3531
    pBlock2 = NULL;
148,915✔
3532
  }
3533

3534
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
250,021✔
3535
  buf = rpcMallocCont(size);
250,021✔
3536
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
250,021✔
3537
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
250,021✔
3538
  printIndexHash(resultRsp.indexHash, pTask);
250,021✔
3539

3540
end:
972,038✔
3541
  if (resultRsp.totalRows == 0) {
972,038✔
3542
    buf = rpcMallocCont(sizeof(int64_t));
722,017✔
3543
    *(int64_t *)buf = resultRsp.ver;
722,017✔
3544
    size = sizeof(int64_t);
722,017✔
3545
    code = TSDB_CODE_STREAM_NO_DATA;
722,017✔
3546
  }
3547
  SRpcMsg rsp = {
972,038✔
3548
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3549
  tmsgSendRsp(&rsp);
972,038✔
3550
  if (code == TSDB_CODE_STREAM_NO_DATA){
972,038✔
3551
    code = 0;
722,017✔
3552
  }
3553

3554
  blockDataDestroy(pBlock1);
972,038✔
3555
  blockDataDestroy(pBlock2);
972,038✔
3556
  blockDataDestroy(resultRsp.dataBlock);
972,038✔
3557
  blockDataDestroy(resultRsp.deleteBlock);
971,834✔
3558
  blockDataDestroy(resultRsp.tableBlock);
971,834✔
3559
  tSimpleHashCleanup(resultRsp.indexHash);
972,038✔
3560
  tSimpleHashCleanup(resultRsp.uidHash);
972,038✔
3561
  STREAM_PRINT_LOG_END_WITHID(code, lino);
971,834✔
3562

3563
  return code;
972,242✔
3564
}
3565

3566
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
307,701✔
3567
  int32_t code = 0;
307,701✔
3568
  int32_t lino = 0;
307,701✔
3569
  void*   buf = NULL;
307,701✔
3570
  size_t  size = 0;
307,701✔
3571
  SArray** gInfo = NULL;
307,701✔
3572
  
3573
  void* pTask = sStreamReaderInfo->pTask;
307,701✔
3574
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
307,701✔
3575

3576
  gInfo = taosHashAcquire(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
307,701✔
3577
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
307,701✔
3578
  SStreamGroupInfo pGroupInfo = {0};
307,701✔
3579
  pGroupInfo.gInfo = *gInfo;
307,701✔
3580

3581
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
307,701✔
3582
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3583
  buf = rpcMallocCont(size);
307,701✔
3584
  STREAM_CHECK_NULL_GOTO(buf, terrno);
307,470✔
3585
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
307,470✔
3586
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3587
end:
307,470✔
3588
  taosHashRelease(sStreamReaderInfo->groupIdMap, gInfo);
307,470✔
3589
  if (code != 0) {
307,701✔
UNCOV
3590
    rpcFreeCont(buf);
×
UNCOV
3591
    buf = NULL;
×
UNCOV
3592
    size = 0;
×
3593
  }
3594
  STREAM_PRINT_LOG_END_WITHID(code, lino);
307,701✔
3595
  SRpcMsg rsp = {
307,701✔
3596
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3597
  tmsgSendRsp(&rsp);
307,701✔
3598

3599
  return code;
307,701✔
3600
}
3601

3602
static int32_t setVtableInfo(SVnode* pVnode, SArray* infos, SArray* cids, int64_t uid, uint64_t gid, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo) {
186,102✔
3603
  int32_t              code = 0;
186,102✔
3604
  int32_t              lino = 0;
186,102✔
3605
  void* pTask = sStreamReaderInfo->pTask;
186,102✔
3606

3607
  VTableInfo* vTable = taosArrayReserve(infos, 1);
186,102✔
3608
  STREAM_CHECK_NULL_GOTO(vTable, terrno);
186,102✔
3609
  vTable->uid = uid;
186,102✔
3610
  vTable->gId = gid;
186,102✔
3611

3612
  ST_TASK_DLOG("vgId:%d %s put vtable uid:%"PRId64, TD_VID(pVnode), __func__, uid);
186,102✔
3613

3614
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, ver, uid);
186,102✔
3615
  if (code != 0) {
186,102✔
UNCOV
3616
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
UNCOV
3617
    goto end;
×
3618
  }
3619
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
186,102✔
3620
    vTable->cols.nCols = metaReader->me.colRef.nCols;
10,774✔
3621
    vTable->cols.version = metaReader->me.colRef.version;
10,774✔
3622
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
10,774✔
3623
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
10,774✔
3624
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
64,644✔
3625
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
53,870✔
3626
    }
3627
  } else {
3628
    vTable->cols.nCols = taosArrayGetSize(cids);
175,328✔
3629
    vTable->cols.version = metaReader->me.colRef.version;
175,328✔
3630
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
175,328✔
3631
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
175,328✔
3632
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
667,381✔
3633
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
2,072,518✔
3634
        if (metaReader->me.colRef.pColRef[j].hasRef &&
1,896,497✔
3635
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
1,400,109✔
3636
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
316,032✔
3637
          break;
316,032✔
3638
        }
3639
      }
3640
    }
3641
  }
3642
  tDecoderClear(&metaReader->coder);
186,102✔
3643

3644
end:
186,102✔
3645
  return code;
186,102✔
3646
}
3647

3648
static int32_t getAllVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
77,380✔
3649
  int32_t              code = 0;
77,380✔
3650
  int32_t              lino = 0;
77,380✔
3651
  void* pTask = sStreamReaderInfo->pTask;
77,380✔
3652
  SArray*              pTableListArray = NULL;
77,380✔
3653

3654

3655
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
77,380✔
3656
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
77,380✔
3657

3658
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
77,380✔
3659
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
77,380✔
3660

3661
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
263,482✔
3662
    SStreamTableKeyInfo* pKeyInfo = taosArrayGetP(pTableListArray, i);
186,102✔
3663
    if (pKeyInfo == NULL || pKeyInfo->markedDeleted) {
186,102✔
UNCOV
3664
      continue;
×
3665
    }
3666
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, pKeyInfo->uid, pKeyInfo->groupId, ver, metaReader, sStreamReaderInfo);
186,102✔
3667
    if (code != 0) {
186,102✔
UNCOV
3668
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, pKeyInfo->uid, tstrerror(code));
×
UNCOV
3669
      code = 0;
×
UNCOV
3670
      continue;
×
3671
    }
3672
  }
3673

3674
end:
77,380✔
3675
  taosArrayDestroyP(pTableListArray, taosMemFree);
77,380✔
3676
  return code;
77,380✔
3677
}
3678

NEW
3679
static int32_t getSpicificVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* uids, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
×
3680
  int32_t              code = 0;
×
UNCOV
3681
  int32_t              lino = 0;
×
UNCOV
3682
  void* pTask = sStreamReaderInfo->pTask;
×
3683

UNCOV
3684
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(uids), sizeof(VTableInfo));
×
UNCOV
3685
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
×
3686

UNCOV
3687
  for (size_t i = 0; i < taosArrayGetSize(uids); i++) {
×
UNCOV
3688
    int64_t* uid = taosArrayGet(uids, i);
×
3689
    STREAM_CHECK_NULL_GOTO(uid, terrno);
×
3690

3691
    taosRLockLatch(&sStreamReaderInfo->lock);
×
3692
    uint64_t groupId = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, *uid);
×
UNCOV
3693
    taosRUnLockLatch(&sStreamReaderInfo->lock);
×
3694
    if (groupId == -1) {
×
3695
      ST_TASK_WLOG("vgId:%d %s uid:%"PRId64" not found in stream group", TD_VID(pVnode), __func__, *uid);
×
UNCOV
3696
      continue;
×
3697
    }
NEW
3698
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, *uid, groupId, ver, metaReader, sStreamReaderInfo);
×
3699
    if (code != 0) {
×
UNCOV
3700
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, *uid, tstrerror(code));
×
3701
      code = 0;
×
3702
      continue;
×
3703
    }
3704
  }
3705
  
3706
end:
×
UNCOV
3707
  return code;
×
3708
}
3709

3710
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
77,380✔
3711
  int32_t              code = 0;
77,380✔
3712
  int32_t              lino = 0;
77,380✔
3713
  void*                buf = NULL;
77,380✔
3714
  size_t               size = 0;
77,380✔
3715
  SStreamMsgVTableInfo vTableInfo = {0};
77,380✔
3716
  SMetaReader          metaReader = {0};
77,380✔
3717

3718
  void* pTask = sStreamReaderInfo->pTask;
77,380✔
3719
  ST_TASK_DLOG("vgId:%d %s start, version:%"PRId64, TD_VID(pVnode), __func__, req->virTableInfoReq.ver);
77,380✔
3720

3721
  SArray* cids = req->virTableInfoReq.cids;
77,380✔
3722
  STREAM_CHECK_NULL_GOTO(cids, terrno);
77,380✔
3723

3724
  if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
77,380✔
3725
    (void)atomic_val_compare_exchange_8(&sStreamReaderInfo->isVtableOnlyTs, 0, 1);
10,774✔
3726
  }
3727
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
77,380✔
3728

3729
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
77,380✔
3730
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
77,380✔
3731
  } else {
NEW
3732
    STREAM_CHECK_RET_GOTO(getSpicificVinfo(pVnode, &vTableInfo, req->virTableInfoReq.uids, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
×
3733
  }
3734
  ST_TASK_DLOG("vgId:%d %s end, size:%"PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(vTableInfo.infos));
77,380✔
3735
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
77,380✔
3736

3737
end:
77,380✔
3738
  tDestroySStreamMsgVTableInfo(&vTableInfo);
77,380✔
3739
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
77,380✔
3740
  STREAM_PRINT_LOG_END_WITHID(code, lino);
77,380✔
3741
  SRpcMsg rsp = {
77,380✔
3742
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3743
  tmsgSendRsp(&rsp);
77,380✔
3744
  return code;
77,380✔
3745
}
3746

3747
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
133,511✔
3748
  int32_t                   code = 0;
133,511✔
3749
  int32_t                   lino = 0;
133,511✔
3750
  void*                     buf = NULL;
133,511✔
3751
  size_t                    size = 0;
133,511✔
3752
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
133,511✔
3753
  SMetaReader               metaReader = {0};
133,511✔
3754
  void*                     pTask = sStreamReaderInfo->pTask;
133,511✔
3755

3756
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64, TD_VID(pVnode), __func__, req->origTableInfoReq.ver);
133,511✔
3757

3758
  SArray* cols = req->origTableInfoReq.cols;
133,511✔
3759
  STREAM_CHECK_NULL_GOTO(cols, terrno);
133,511✔
3760

3761
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
133,511✔
3762

3763
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
133,511✔
3764

3765
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
133,511✔
3766
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
492,639✔
3767
    OTableInfo*    oInfo = taosArrayGet(cols, i);
359,128✔
3768
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
359,128✔
3769
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
359,128✔
3770
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
359,128✔
3771
    code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionName(&metaReader, req->origTableInfoReq.ver, oInfo->refTableName);
359,128✔
3772
    if (code != 0) {
359,128✔
3773
      code = 0;
204✔
3774
      ST_TASK_ELOG("vgId:%d %s get table entry by name:%s failed, msg:%s", TD_VID(pVnode), __func__, oInfo->refTableName, tstrerror(code));
204✔
3775
      continue;
204✔
3776
    }
3777
    vTableInfo->uid = metaReader.me.uid;
358,924✔
3778
    ST_TASK_DLOG("vgId:%d %s get original uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
358,924✔
3779

3780
    SSchemaWrapper* sSchemaWrapper = NULL;
358,924✔
3781
    if (metaReader.me.type == TD_CHILD_TABLE) {
358,924✔
3782
      int64_t suid = metaReader.me.ctbEntry.suid;
357,083✔
3783
      vTableInfo->suid = suid;
357,083✔
3784
      tDecoderClear(&metaReader.coder);
357,083✔
3785
      STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->origTableInfoReq.ver, suid));
356,849✔
3786
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
356,849✔
3787
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
1,841✔
3788
      vTableInfo->suid = 0;
1,841✔
3789
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
1,841✔
3790
    } else {
UNCOV
3791
      ST_TASK_ELOG("invalid table type:%d", metaReader.me.type);
×
3792
    }
3793

3794
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
1,228,608✔
3795
      SSchema* s = sSchemaWrapper->pSchema + j;
1,228,395✔
3796
      if (strcmp(s->name, oInfo->refColName) == 0) {
1,228,608✔
3797
        vTableInfo->cid = s->colId;
358,924✔
3798
        break;
358,924✔
3799
      }
3800
    }
3801
    if (vTableInfo->cid == 0) {
358,924✔
UNCOV
3802
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
3803
              oInfo->refTableName);
3804
    }
3805
    tDecoderClear(&metaReader.coder);
358,924✔
3806
  }
3807

3808
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
133,511✔
3809

3810
end:
133,511✔
3811
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
133,511✔
3812
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
133,511✔
3813
  STREAM_PRINT_LOG_END_WITHID(code, lino);
133,280✔
3814
  SRpcMsg rsp = {
133,511✔
3815
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3816
  tmsgSendRsp(&rsp);
133,511✔
3817
  return code;
133,511✔
3818
}
3819

3820
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
909,922✔
3821
  int32_t                   code = 0;
909,922✔
3822
  int32_t                   lino = 0;
909,922✔
3823
  void*                     buf = NULL;
909,922✔
3824
  size_t                    size = 0;
909,922✔
3825
  SSDataBlock* pBlock = NULL;
909,922✔
3826

3827
  SMetaReader               metaReader = {0};
909,922✔
3828
  SMetaReader               metaReaderStable = {0};
909,922✔
3829
  int64_t streamId = req->base.streamId;
909,922✔
3830
  stsDebug("vgId:%d %s start, ver:%"PRId64, TD_VID(pVnode), __func__, req->virTablePseudoColReq.ver);
909,922✔
3831

3832
  SArray* cols = req->virTablePseudoColReq.cids;
909,922✔
3833
  STREAM_CHECK_NULL_GOTO(cols, terrno);
909,922✔
3834

3835
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
909,922✔
3836
  STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->virTablePseudoColReq.ver, req->virTablePseudoColReq.uid));
909,922✔
3837

3838
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
909,922✔
3839

3840
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
909,922✔
3841
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
909,156✔
3842
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
2,079✔
3843
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
2,079✔
3844
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
2,079✔
3845
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
2,079✔
3846
    pBlock->info.rows = 1;
2,079✔
3847
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
2,079✔
3848
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,079✔
3849
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
2,079✔
3850
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
907,077✔
3851
    int64_t suid = metaReader.me.ctbEntry.suid;
907,843✔
3852
    sStreamReaderInfo->storageApi.metaReaderFn.readerReleaseLock(&metaReader);
907,843✔
3853
    sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
907,843✔
3854

3855
    STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReaderStable, req->virTablePseudoColReq.ver, suid));
907,843✔
3856
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
907,843✔
3857
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
2,411,811✔
3858
      col_id_t* id = taosArrayGet(cols, i);
1,503,968✔
3859
      STREAM_CHECK_NULL_GOTO(id, terrno);
1,503,968✔
3860
      if (*id == -1) {
1,503,968✔
3861
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
898,651✔
3862
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
898,651✔
3863
        continue;
898,651✔
3864
      }
3865
      size_t j = 0;
605,317✔
3866
      for (; j < sSchemaWrapper->nCols; j++) {
1,172,943✔
3867
        SSchema* s = sSchemaWrapper->pSchema + j;
1,172,943✔
3868
        if (s->colId == *id) {
1,172,943✔
3869
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
605,317✔
3870
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
605,317✔
3871
          break;
605,317✔
3872
        }
3873
      }
3874
      if (j == sSchemaWrapper->nCols) {
605,317✔
UNCOV
3875
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
UNCOV
3876
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3877
      }
3878
    }
3879
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
907,843✔
3880
    pBlock->info.rows = 1;
907,843✔
3881
    
3882
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
2,411,811✔
3883
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
1,503,968✔
3884
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
1,503,968✔
3885

3886
      if (pDst->info.colId == -1) {
1,503,968✔
3887
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
898,651✔
3888
        continue;
898,651✔
3889
      }
3890
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
605,317✔
UNCOV
3891
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
UNCOV
3892
        continue;
×
3893
      }
3894

3895
      STagVal val = {0};
605,317✔
3896
      val.cid = pDst->info.colId;
605,317✔
3897
      const char* p = sStreamReaderInfo->storageApi.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
605,317✔
3898

3899
      char* data = NULL;
605,317✔
3900
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
605,317✔
3901
        data = tTagValToData((const STagVal*)p, false);
605,317✔
3902
      } else {
UNCOV
3903
        data = (char*)p;
×
3904
      }
3905

3906
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
605,317✔
3907
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3908

3909
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
605,317✔
3910
          (data != NULL)) {
3911
        taosMemoryFree(data);
561,236✔
3912
      }
3913
    }
3914
  } else {
UNCOV
3915
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
UNCOV
3916
    code = TSDB_CODE_INVALID_PARA;
×
UNCOV
3917
    goto end;
×
3918
  }
3919
  
3920
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
909,922✔
3921
  printDataBlock(pBlock, __func__, "", streamId);
909,922✔
3922
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
909,922✔
3923

3924
end:
909,922✔
3925
  if(size == 0){
909,922✔
3926
    code = TSDB_CODE_STREAM_NO_DATA;
×
3927
  }
3928
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReaderStable);
909,922✔
3929
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
909,688✔
3930
  STREAM_PRINT_LOG_END(code, lino);
909,922✔
3931
  SRpcMsg rsp = {
909,922✔
3932
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3933
  tmsgSendRsp(&rsp);
909,922✔
3934
  blockDataDestroy(pBlock);
909,922✔
3935
  return code;
909,922✔
3936
}
3937

3938
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
7,745,787✔
3939
  int32_t            code = 0;
7,745,787✔
3940
  int32_t            lino = 0;
7,745,787✔
3941
  void*              buf = NULL;
7,745,787✔
3942
  size_t             size = 0;
7,745,787✔
3943
  void*              taskAddr = NULL;
7,745,787✔
3944
  SArray*            pResList = NULL;
7,745,787✔
3945
  bool               hasNext = false;
7,745,787✔
3946

3947
  SResFetchReq req = {0};
7,745,787✔
3948
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
7,745,787✔
3949
                              TSDB_CODE_QRY_INVALID_INPUT);
3950
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
7,745,563✔
3951
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
7,745,787✔
3952

3953
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
7,745,787✔
3954
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
7,745,787✔
3955
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
7,745,787✔
3956
  sStreamReaderCalcInfo->rtInfo.execId = req.execId;
7,745,787✔
3957

3958
  void* pTask = sStreamReaderCalcInfo->pTask;
7,745,787✔
3959
  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,745,670✔
3960
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
3961

3962
  if (req.reset) {
7,745,787✔
3963
    int64_t uid = 0;
4,410,678✔
3964
    if (req.dynTbname) {
4,410,678✔
3965
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
124,603✔
3966
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
124,603✔
3967
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
124,603✔
3968
        if (pValue != NULL && pValue->isTbname) {
124,603✔
3969
          uid = pValue->uid;
124,603✔
3970
          break;
124,603✔
3971
        }
3972
      }
3973
    }
3974
    
3975
    SReadHandle handle = {0};
4,410,678✔
3976
    handle.vnode = pVnode;
4,410,678✔
3977
    handle.pMsgCb = &pVnode->msgCb;
4,410,678✔
3978
    handle.pWorkerCb = pInfo->workerCb;
4,410,678✔
3979
    handle.uid = uid;
4,410,678✔
3980
    handle.cacheSttStatis = true;
4,410,678✔
3981

3982
    initStorageAPI(&handle.api);
4,410,678✔
3983
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
4,410,446✔
3984
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
3,504,138✔
3985
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,510,612✔
3986
      if (node != NULL) {
3,510,612✔
3987
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
463,177✔
3988
      } else {
3989
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
3,047,435✔
3990
      }
3991

3992
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
3,510,612✔
3993
      if (node != NULL) {
3,510,612✔
3994
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
77,077✔
3995
      } else {
3996
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
3,433,535✔
3997
      }      
3998
    }
3999

4000
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
4,410,678✔
4001
    sStreamReaderCalcInfo->rtInfo.funcInfo.hasPlaceHolder = sStreamReaderCalcInfo->hasPlaceHolder;
4,410,678✔
4002
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
4,410,678✔
4003

4004
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
4,410,678✔
4005
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
665,423✔
4006
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
665,423✔
4007
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
4008
                                                    req.taskId));
4009
    } else {
4010
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
3,745,255✔
4011
    }
4012

4013
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
4,410,413✔
4014
  }
4015

4016
  if (req.pOpParam != NULL) {
7,745,531✔
4017
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
336,132✔
4018
  }
4019

4020
  pResList = taosArrayInit(4, POINTER_BYTES);
7,745,531✔
4021
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
7,745,357✔
4022
  uint64_t ts = 0;
7,745,357✔
4023
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
7,744,843✔
4024

4025
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
18,841,570✔
4026
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
11,097,170✔
4027
    if (pBlock == NULL) continue;
11,095,778✔
4028
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
11,095,778✔
4029
/*    
4030
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
4031
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
4032
      printDataBlock(pBlock, __func__, "fetch filter");
4033
    }
4034
*/    
4035
  }
4036

4037
end:
7,745,555✔
4038
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
7,745,787✔
4039
  taosArrayDestroy(pResList);
7,745,787✔
4040
  streamReleaseTask(taskAddr);
7,745,787✔
4041

4042
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
7,745,787✔
UNCOV
4043
    code = TDB_CODE_SUCCESS;
×
4044
  }
4045
  STREAM_PRINT_LOG_END(code, lino);
7,745,787✔
4046
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
7,745,787✔
4047
  tmsgSendRsp(&rsp);
7,745,787✔
4048
  tDestroySResFetchReq(&req);
7,744,766✔
4049
  if (TDB_CODE_SUCCESS != code) {
7,743,602✔
UNCOV
4050
    ST_TASK_ELOG("vgId:%d %s failed, code:%d - %s", TD_VID(pVnode), __func__,
×
4051
                 code, tstrerror(code));
4052
  }
4053
  return code;
7,743,602✔
4054
}
4055

4056
static int32_t initTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SVnode* pVnode) {
32,479,321✔
4057
  int32_t code = 0;
32,479,321✔
4058
  if (sStreamReaderInfo->tableList.pTableList != NULL) {  
32,479,321✔
4059
    return code;
32,181,650✔
4060
  }
4061
  taosWLockLatch(&sStreamReaderInfo->lock);
297,486✔
4062
  sStreamReaderInfo->pVnode = pVnode;
297,486✔
4063
  initStorageAPI(&sStreamReaderInfo->storageApi);
297,486✔
4064
  if (sStreamReaderInfo->tableList.pTableList == NULL) {
296,874✔
4065
    code = initStreamTableListInfo(&sStreamReaderInfo->tableList);
297,486✔
4066
    if (code == 0) {
297,486✔
4067
      code = generateTablistForStreamReader(pVnode, sStreamReaderInfo);
297,486✔
4068
      if (code != 0) {
297,486✔
UNCOV
4069
        qStreamDestroyTableInfo(&sStreamReaderInfo->tableList);
×
4070
      } else {
4071
        sStreamReaderInfo->tableList.version = pVnode->state.applied;
297,486✔
4072
        stDebug("vgId:%d %s init table list for stream reader, table num:%zu, version:%" PRId64,
297,486✔
4073
                TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList), sStreamReaderInfo->tableList.version);
4074
      }
4075
    }
4076
  }
4077
  taosWUnLockLatch(&sStreamReaderInfo->lock);
297,079✔
4078
  return code;
297,486✔
4079
}
4080

4081
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
40,367,164✔
4082
  int32_t                   code = 0;
40,367,164✔
4083
  int32_t                   lino = 0;
40,367,164✔
4084
  SSTriggerPullRequestUnion req = {0};
40,367,164✔
4085
  void*                     taskAddr = NULL;
40,369,622✔
4086
  bool                      sendRsp = false;
40,365,661✔
4087

4088
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
40,365,661✔
4089
  if (!syncIsReadyForRead(pVnode->sync)) {
40,367,989✔
4090
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
121,296✔
4091
    return 0;
121,296✔
4092
  }
4093

4094
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
40,248,484✔
4095
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
7,745,787✔
4096
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
32,502,697✔
4097
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
32,503,463✔
4098
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
32,503,463✔
4099
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
32,503,697✔
4100
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
32,501,119✔
4101
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId, pVnode->state.applied);
4102
    SStreamTriggerReaderInfo* sStreamReaderInfo = qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
32,501,885✔
4103
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
32,500,953✔
4104
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
32,478,042✔
4105
    sendRsp = true;
32,479,328✔
4106
    switch (req.base.type) {
32,479,328✔
4107
      case STRIGGER_PULL_SET_TABLE:
133,511✔
4108
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
133,511✔
4109
        break;
133,511✔
4110
      case STRIGGER_PULL_LAST_TS:
288,908✔
4111
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
288,908✔
4112
        break;
288,908✔
4113
      case STRIGGER_PULL_FIRST_TS:
247,153✔
4114
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
247,153✔
4115
        break;
247,153✔
4116
      case STRIGGER_PULL_TSDB_META:
460,123✔
4117
      case STRIGGER_PULL_TSDB_META_NEXT:
4118
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
460,123✔
4119
        break;
460,123✔
4120
      case STRIGGER_PULL_TSDB_TS_DATA:
169,992✔
4121
        if (sStreamReaderInfo->isVtableStream) {
169,992✔
4122
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
6,128✔
4123
        } else {
4124
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
163,864✔
4125
        }
4126
        break;
169,992✔
4127
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
112,390✔
4128
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4129
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
112,390✔
4130
        break;
56,195✔
4131
      case STRIGGER_PULL_TSDB_CALC_DATA:
6,336,168✔
4132
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4133
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
6,336,168✔
4134
        break;
6,335,961✔
4135
      case STRIGGER_PULL_TSDB_DATA:
585,613✔
4136
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4137
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
585,613✔
4138
        break;
582,549✔
4139
      case STRIGGER_PULL_GROUP_COL_VALUE:
307,701✔
4140
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
307,701✔
4141
        break;
307,701✔
4142
      case STRIGGER_PULL_VTABLE_INFO:
77,380✔
4143
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
77,380✔
4144
        break;
77,380✔
4145
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
909,922✔
4146
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
909,922✔
4147
        break;
909,922✔
4148
      case STRIGGER_PULL_OTABLE_INFO:
133,511✔
4149
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
133,511✔
4150
        break;
133,511✔
4151
      case STRIGGER_PULL_WAL_META_NEW:
11,344,371✔
4152
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
11,344,371✔
4153
        break;
11,343,417✔
4154
      case STRIGGER_PULL_WAL_DATA_NEW:
7,060,844✔
4155
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
7,060,844✔
4156
        break;
7,060,844✔
4157
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,340,144✔
4158
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,340,144✔
4159
        break;
3,339,565✔
4160
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
972,038✔
4161
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
972,038✔
4162
        break;
972,038✔
UNCOV
4163
      default:
×
UNCOV
4164
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
UNCOV
4165
        sendRsp = false;
×
UNCOV
4166
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4167
    }
4168
  } else {
UNCOV
4169
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
UNCOV
4170
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4171
  }
4172
end:
32,491,715✔
4173

4174
  streamReleaseTask(taskAddr);
32,500,916✔
4175

4176
  tDestroySTriggerPullRequest(&req);
32,502,027✔
4177
  STREAM_PRINT_LOG_END(code, lino);
32,494,793✔
4178
  if (!sendRsp) {
32,500,886✔
4179
    SRpcMsg rsp = {
45,822✔
4180
      .code = code,
4181
      .pCont = pMsg->info.rsp,
22,911✔
4182
      .contLen = pMsg->info.rspLen,
22,911✔
4183
      .info = pMsg->info,
4184
    };
4185
    tmsgSendRsp(&rsp);
22,911✔
4186
  }
4187
  return code;
32,501,364✔
4188
}
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