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

taosdata / TDengine / #5006

29 Mar 2026 04:32AM UTC coverage: 72.274% (+0.1%) from 72.152%
#5006

push

travis-ci

web-flow
refactor: do some internal refactor for TDgpt. (#34955)

253711 of 351039 relevant lines covered (72.27%)

131490495.89 hits per line

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

83.72
/source/dnode/vnode/src/vnd/vnodeStream.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

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

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

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

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

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

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

75
  taosRLockLatch(&sStreamReaderInfo->lock);
380,874✔
76
  SStreamTableMapElement* element = taosHashGet(sStreamReaderInfo->vSetTableList.uIdMap, &pList->uid, LONG_BYTES);  
380,874✔
77
  if (element != 0) {
380,874✔
78
    suid = element->table->groupId;
219,366✔
79
    taosRUnLockLatch(&sStreamReaderInfo->lock);
219,366✔
80
    goto end;
219,366✔
81
  }
82
  taosRUnLockLatch(&sStreamReaderInfo->lock);
161,508✔
83

84
end:
6,869,857✔
85
  return suid;
6,869,857✔
86
}
87

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

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

94
  if (*c1 < *c2) {
1,497,428✔
95
    return -1;
1,485,902✔
96
  } else if (*c1 > *c2) {
11,526✔
97
    return 1;
11,526✔
98
  }
99

100
  return 0;
×
101
}
102

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

107
  if (c1->colId < c2->colId) {
1,479,068✔
108
    return -1;
1,467,542✔
109
  } else if (c1->colId > c2->colId) {
11,526✔
110
    return 1;
11,526✔
111
  }
112

113
  return 0;
×
114
}
115

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

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
41,027,457✔
123
  return 0;
41,023,273✔
124
}
125

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

132
  return code;
9,003,725✔
133
}
134

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

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

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

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
4,577,310✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
4,577,310✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
2,191,682✔
165
      suid == sStreamReaderInfo->suid) {
803,240✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
10,364✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
10,364✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
10,364✔
169
    if (gid == (uint64_t)-1) return true;
10,364✔
170
  }
171
  return false;
4,568,243✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
12,123,609✔
175
  int32_t  ret = false;
12,123,609✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
12,123,609✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
6,916,607✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
3,443,761✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
8,651,075✔
181
  if (*id == -1) goto end;
8,648,580✔
182
  ret = true;
5,354,730✔
183

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

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

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
55,555,231✔
194
  bool ret = false;
55,555,231✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
55,555,231✔
196
  if (sStreamReaderInfo->isVtableStream) {
55,560,487✔
197
    int64_t tmp[2] = {suid, uid};
43,467,912✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
43,467,912✔
199
      *id = uid;
14,876,333✔
200
      ret = true;
14,876,333✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
12,095,557✔
204
  }
205

206
end:
55,554,934✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
55,554,934✔
208
  return ret;
55,560,303✔
209
}
210

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

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

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

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

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

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

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
7,859,259✔
301
  int32_t code = 0;
7,859,259✔
302
  int32_t lino = 0;
7,859,259✔
303
  void*   buf = NULL;
7,859,259✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
7,859,259✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
1,809,329✔
306
  buf = rpcMallocCont(dataEncodeSize);
1,809,329✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
1,809,329✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
1,809,329✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
1,809,329✔
310
  *data = buf;
1,809,329✔
311
  *size = dataEncodeSize;
1,809,329✔
312
  buf = NULL;
1,809,329✔
313
end:
7,862,101✔
314
  rpcFreeCont(buf);
7,862,101✔
315
  return code;
7,858,244✔
316
}
317

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

322
  void*   buf = NULL;
55,624✔
323

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

336
  char* dataBuf = (char*)buf;
55,624✔
337
  *((int32_t*)(dataBuf)) = blockNum;
55,624✔
338
  dataBuf += INT_BYTES;
55,624✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
116,363✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
60,739✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
60,739✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
60,739✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
60,739✔
344
    dataBuf += actualLen;
60,739✔
345
  }
346
  *data = buf;
55,624✔
347
  *size = INT_BYTES + dataEncodeBufSize;
55,624✔
348
  buf = NULL;
55,624✔
349
end:
55,624✔
350
  rpcFreeCont(buf);
55,624✔
351
  return code;
55,624✔
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,854,069✔
375
  int32_t code = 0;
9,854,069✔
376
  int32_t lino = 0;
9,854,069✔
377
  int32_t index = 0;
9,854,069✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
9,854,069✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
9,855,675✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
9,856,210✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
9,856,899✔
382

383
end:
9,855,675✔
384
  return code;
9,855,675✔
385
}
386

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

641
  if (taosArrayGetSize(uidList) == 0) {
46,298✔
642
    return 0;
17,146✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
29,152✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
29,152✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

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

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

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

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

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

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

704
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq, int64_t ver) {
4,552,686✔
705
  int32_t  code = 0;
4,552,686✔
706
  int32_t  lino = 0;
4,552,686✔
707
  void*    pTask = sStreamReaderInfo->pTask;
4,552,686✔
708
  SArray*  uidList = NULL;
4,552,400✔
709
  SArray*  tableList = NULL;
4,552,400✔
710

711
  ST_TASK_DLOG("%s start, name:%s uid:%"PRId64, __func__, pCreateReq->name, pCreateReq->uid);
4,552,395✔
712
  if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false) ||
4,554,632✔
713
      ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
1,933✔
714
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
4,551,629✔
715
    goto end;
4,551,629✔
716
  }
717
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,401✔
718
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,401✔
719
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
2,802✔
720
  ST_TASK_DLOG("stream reader scan auto create table %s", pCreateReq->name);
1,401✔
721

722
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,401✔
723
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,401✔
724
end:
4,550,705✔
725
  taosArrayDestroy(uidList);
4,553,030✔
726
  taosArrayDestroy(tableList);
4,552,570✔
727
  return code;
4,552,104✔
728
}
729

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

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

759
void getAlterColId(void* pVnode, int64_t uid, const char* colName, col_id_t* colId) {
458✔
760
  SSchemaWrapper *pSchema = metaGetTableSchema(((SVnode *)pVnode)->pMeta, uid, -1, 1, NULL, 0);
458✔
761
  if (pSchema == NULL) {
458✔
762
    return;
×
763
  }
764
  for (int32_t i = 0; i < pSchema->nCols; i++) {
1,145✔
765
    if (strncmp(pSchema->pSchema[i].name, colName, TSDB_COL_NAME_LEN) == 0) {
1,145✔
766
      *colId = pSchema->pSchema[i].colId;
458✔
767
      break;
458✔
768
    }
769
  }
770
  tDeleteSchemaWrapper(pSchema);
771
  return;
458✔
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, 
458✔
776
                                       SVAlterTbReq* pReq, uint64_t uid, int64_t ver) {
777
  int32_t code = 0;
458✔
778
  int32_t lino = 0;
458✔
779
  void* pTask = sStreamReaderInfo->pTask;
458✔
780
  SArray* uidListAdd = NULL;
458✔
781

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

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

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

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

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

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

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

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

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

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

844
end:
19,852✔
845
  if (code != 0) {
19,852✔
846
    ST_TASK_ELOG("%s failed,code:%d", __func__, code);
×
847
    taosArrayDestroy(uidList);
×
848
    uidList = NULL;
×
849
  }
850
  return uidList;
19,852✔
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,852✔
855
                                    SArray* uidList, int64_t ver) {
856
  int32_t code = 0;
19,852✔
857
  int32_t lino = 0;
19,852✔
858
  void* pTask = sStreamReaderInfo->pTask;
19,852✔
859
  SArray* uidListAdd = NULL;
19,852✔
860
  SArray* uidListDel = NULL;
19,852✔
861
  SArray* tableList = NULL;
19,852✔
862

863
  if (sStreamReaderInfo->isVtableStream) {
19,852✔
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,852✔
869
  STREAM_CHECK_NULL_GOTO(uidListDel, terrno);
19,852✔
870

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

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

881
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
19,852✔
882
  if (sStreamReaderInfo->isVtableStream) {
19,852✔
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,852✔
887

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

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

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

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

907
  SVAlterTbReq req = {0};
34,548✔
908
  tDecoderInit(&decoder, data, len);
34,548✔
909
  
910
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
34,548✔
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,548✔
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;
24,888✔
916
  if (req.action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || req.action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
24,888✔
917
    STREAM_CHECK_CONDITION_GOTO(!sStreamReaderInfo->isVtableStream, TDB_CODE_SUCCESS);
5,036✔
918
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
458✔
919
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
458✔
920
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", req.tbName);
×
921
      code = 0;
×
922
      goto end;
×
923
    }
924
    STREAM_CHECK_RET_GOTO(scanAlterTableColumnRef(sStreamReaderInfo, rsp, &req, uid, ver));
458✔
925
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
19,852✔
926
    uidList = getTableListForAlterSuperTable(sStreamReaderInfo, &req);
19,852✔
927
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
19,852✔
928
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
19,852✔
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;
×
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));
×
939
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
×
940
  }
941

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

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

947
  taosArrayDestroy(uidList);
34,318✔
948
  tDecoderClear(&decoder);
34,548✔
949
  STREAM_PRINT_LOG_END_WITHID(code, lino);
34,548✔
950
  return code;
34,548✔
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,415,454✔
996
  int32_t code = 0;
39,415,454✔
997
  int32_t lino = 0;
39,415,454✔
998
  WalMetaResult walMeta = {0};
39,415,454✔
999
  SSubmitTbData submitTbData = {0};
39,420,044✔
1000
  
1001
  if (tStartDecode(pCoder) < 0) {
39,420,062✔
1002
    code = TSDB_CODE_INVALID_MSG;
×
1003
    TSDB_CHECK_CODE(code, lino, end);
×
1004
  }
1005

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

1014
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1015
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
39,419,553✔
1016
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
3,711,314✔
1017
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
3,710,854✔
1018
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
3,710,854✔
1019
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
3,711,142✔
1020
  }
1021

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

1032
  if (!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
39,419,861✔
1033
    goto end;
31,366,419✔
1034
  }
1035
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
8,052,608✔
1036
    code = TSDB_CODE_INVALID_MSG;
×
1037
    TSDB_CHECK_CODE(code, lino, end);
×
1038
  }
1039

1040
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
8,052,608✔
1041
    uint64_t nColData = 0;
×
1042
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1043
      code = TSDB_CODE_INVALID_MSG;
×
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;
×
1051
      TSDB_CHECK_CODE(code, lino, end);
×
1052
    }
1053

1054
    if (colData.flag != HAS_VALUE) {
×
1055
      code = TSDB_CODE_INVALID_MSG;
×
1056
      TSDB_CHECK_CODE(code, lino, end);
×
1057
    }
1058
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
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;
×
1065
        TSDB_CHECK_CODE(code, lino, end);
×
1066
      }
1067
    }
1068
  } else {
1069
    uint64_t nRow = 0;
8,052,608✔
1070
    if (tDecodeU64v(pCoder, &nRow) < 0) {
8,053,571✔
1071
      code = TSDB_CODE_INVALID_MSG;
×
1072
      TSDB_CHECK_CODE(code, lino, end);
×
1073
    }
1074

1075
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
17,229,084✔
1076
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,175,315✔
1077
      pCoder->pos += pRow->len;
9,176,485✔
1078
      if (iRow == 0){
9,176,485✔
1079
#ifndef NO_UNALIGNED_ACCESS
1080
        walMeta.skey = pRow->ts;
8,053,571✔
1081
#else
1082
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1083
#endif
1084
      }
1085
      if (iRow == nRow - 1) {
9,176,485✔
1086
#ifndef NO_UNALIGNED_ACCESS
1087
        walMeta.ekey = pRow->ts;
8,053,571✔
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,052,806✔
1096
  if (data != NULL) {
8,052,897✔
1097
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
940✔
1098
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
940✔
1099
  } else {
1100
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
8,051,957✔
1101
  }
1102

1103
end:
39,411,715✔
1104
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
39,418,765✔
1105
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
39,417,028✔
1106
  tEndDecode(pCoder);
39,417,028✔
1107
  return code;
39,416,295✔
1108
}
1109

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

1117
  tDecoderInit(&decoder, data, len);
39,419,125✔
1118
  if (tStartDecode(&decoder) < 0) {
39,417,541✔
1119
    code = TSDB_CODE_INVALID_MSG;
×
1120
    TSDB_CHECK_CODE(code, lino, end);
×
1121
  }
1122

1123
  uint64_t nSubmitTbData = 0;
39,417,939✔
1124
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
39,418,590✔
1125
    code = TSDB_CODE_INVALID_MSG;
×
1126
    TSDB_CHECK_CODE(code, lino, end);
×
1127
  }
1128

1129
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
39,418,590✔
1130
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
39,416,809✔
1131

1132
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
78,835,836✔
1133
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
39,417,082✔
1134
  }
1135
  tEndDecode(&decoder);
39,418,754✔
1136

1137
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
39,417,900✔
1138
  int32_t iter = 0;
39,415,933✔
1139
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
39,415,473✔
1140
  while (px != NULL) {
47,467,414✔
1141
    WalMetaResult* pMeta = (WalMetaResult*)px;
8,050,641✔
1142
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
8,050,641✔
1143
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
8,051,636✔
1144
    rsp->totalRows++;
8,051,636✔
1145
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
8,051,636✔
1146
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1147
    px = tSimpleHashIterate(gidHash, px, &iter);
8,051,636✔
1148
  }
1149
end:
39,416,773✔
1150
  tDecoderClear(&decoder);
39,416,750✔
1151
  tSimpleHashCleanup( gidHash);
39,416,222✔
1152
  return code;
39,415,072✔
1153
}
1154

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

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

1170
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
429,875✔
1171

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

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

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

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

1191
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
307,298✔
1192

1193
end:
307,054✔
1194
  taosArrayDestroy(schemas);
307,054✔
1195
  return code;
307,298✔
1196
}
1197

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

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

1205
  SDecoder dcoder = {0};
496,301✔
1206
  tDecoderInit(&dcoder, data, len);
496,301✔
1207
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
496,301✔
1208
    if (rsp->deleteBlock == NULL) {
29,764✔
1209
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
10,610✔
1210
    }
1211
      
1212
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
29,764✔
1213
  } else if (msgType == TDMT_VND_DROP_TABLE && 
466,537✔
1214
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
50,482✔
1215
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
32,365✔
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)) {
434,172✔
1219
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
25,045✔
1220
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
409,127✔
1221
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1222
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
383,111✔
1223
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
34,548✔
1224
  }
1225

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

1236
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
11,872,081✔
1237
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
11,871,371✔
1238
  code = walReaderSeekVer(pWalReader, rsp->ver);
11,871,371✔
1239
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
11,870,107✔
1240
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
6,590,725✔
1241
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
1242
      rsp->verTime = 0;
×
1243
    } else {
1244
      rsp->verTime = taosGetTimestampUs();
6,592,041✔
1245
    }
1246
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
6,590,524✔
1247
    code = TSDB_CODE_SUCCESS;
6,592,501✔
1248
    goto end;
6,592,501✔
1249
  }
1250
  STREAM_CHECK_RET_GOTO(code);
5,279,382✔
1251

1252
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
5,279,382✔
1253
  while (1) {
39,792,917✔
1254
    code = walNextValidMsg(pWalReader, true);
45,071,176✔
1255
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
45,074,992✔
1256
      rsp->verTime = taosGetTimestampUs();
5,277,080✔
1257
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
5,277,080✔
1258
      code = TSDB_CODE_SUCCESS;
5,277,080✔
1259
      goto end;
5,277,080✔
1260
    }
1261
    STREAM_CHECK_RET_GOTO(code);
39,798,349✔
1262
    rsp->ver = pWalReader->curVersion;
39,798,349✔
1263
    SWalCont* wCont = &pWalReader->pHead->head;
39,800,323✔
1264
    rsp->verTime = wCont->ingestTs;
39,800,599✔
1265
    if (wCont->ingestTs / 1000 > ctime) break;
39,800,861✔
1266
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
39,799,129✔
1267
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
39,800,177✔
1268
    int64_t ver = wCont->version;
39,798,261✔
1269

1270
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
39,799,727✔
1271
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1272
    if (wCont->msgType == TDMT_VND_SUBMIT) {
39,799,757✔
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,421,188✔
1275
        rsp->ver--;
2,500✔
1276
        break;
2,500✔
1277
      }
1278
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
39,417,693✔
1279
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
39,418,458✔
1280
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
39,418,207✔
1281
    } else {
1282
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
380,480✔
1283
    }
1284

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

1290
end:
11,872,081✔
1291
  walCloseReader(pWalReader);
11,872,081✔
1292
  return code;
11,871,679✔
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) {
40,492,545✔
1296
  int32_t     code = 0;
40,492,545✔
1297
  int32_t     lino = 0;
40,492,545✔
1298
  SMetaReader mr = {0};
40,492,545✔
1299
  SArray* tagCache = NULL;
40,496,175✔
1300
  char* data = NULL;
40,514,990✔
1301

1302
  if (lock != NULL) taosWLockLatch(lock);
40,515,979✔
1303
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
40,529,299✔
1304
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,282,279✔
1305
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,283,027✔
1306
  if (uidData == NULL) {
2,282,635✔
1307
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,264,145✔
1308
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,264,145✔
1309
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,264,145✔
1310
      taosArrayDestroy(tagCache);
×
1311
      code = terrno;
×
1312
      goto end;
×
1313
    }
1314
  } else {
1315
    tagCache = *(SArray**)uidData;
18,490✔
1316
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
18,490✔
1317
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
18,490✔
1318
  }
1319
  
1320
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,282,635✔
1321
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,282,635✔
1322
  api->metaReaderFn.readerReleaseLock(&mr);
2,281,675✔
1323
  STREAM_CHECK_RET_GOTO(code);
2,281,954✔
1324
  
1325
  for (int32_t j = 0; j < numOfExpr; ++j) {
7,916,564✔
1326
    const SExprInfo* pExpr1 = &pExprInfo[j];
5,641,503✔
1327
    int32_t functionId = pExpr1->pExpr->_function.functionId;
5,641,929✔
1328
    col_id_t cid = 0;
5,642,610✔
1329
    // this is to handle the tbname
1330
    if (fmIsScanPseudoColumnFunc(functionId)) {
5,642,610✔
1331
      int32_t fType = pExpr1->pExpr->_function.functionType;
637,302✔
1332
      if (fType == FUNCTION_TYPE_TBNAME) {
637,088✔
1333
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
637,088✔
1334
        STREAM_CHECK_NULL_GOTO(data, terrno);
637,302✔
1335
        STR_TO_VARSTR(data, mr.me.name)
637,302✔
1336
      }
1337
      cid = -1;
636,876✔
1338
    } else {  // these are tags
1339
      const char* p = NULL;
5,005,172✔
1340
      char* pData = NULL;
5,005,172✔
1341
      int8_t type = pExpr1->base.resSchema.type;
5,005,172✔
1342
      int32_t len = pExpr1->base.resSchema.bytes;
5,005,407✔
1343
      STagVal tagVal = {0};
5,006,074✔
1344
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
5,005,767✔
1345
      cid = tagVal.cid;
5,005,767✔
1346
      if (colId != 0 && cid != colId) {
5,005,767✔
1347
        continue;
1,017✔
1348
      }
1349
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
5,004,750✔
1350

1351
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
5,003,624✔
1352
        pData = tTagValToData((const STagVal*)p, false);
5,001,044✔
1353
      } else {
1354
        pData = (char*)p;
2,580✔
1355
      }
1356

1357
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
5,003,349✔
1358
        if (type == TSDB_DATA_TYPE_JSON) {
2,511,303✔
1359
          len = getJsonValueLen(pData);
×
1360
        }
1361
        data = taosMemoryCalloc(1, len);
2,511,303✔
1362
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,512,407✔
1363
        (void)memcpy(data, pData, len);
2,512,407✔
1364
      } else {
1365
        data = pData;
2,492,046✔
1366
      }
1367
    }
1368
    if (uidData == NULL){
5,641,074✔
1369
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
11,210,581✔
1370
    } else {
1371
      void* pre = taosArrayGetP(tagCache, j);
35,759✔
1372
      taosMemoryFree(pre);
35,759✔
1373
      taosArraySet(tagCache, j, &data);
35,759✔
1374
    }
1375
    data = NULL;
5,639,611✔
1376
  }
1377

1378
end:
40,526,813✔
1379
  taosMemoryFree(data);
40,497,730✔
1380
  api->metaReaderFn.clearReader(&mr);
40,519,485✔
1381
  if (lock != NULL) taosWUnLockLatch(lock);
40,520,808✔
1382
  return code;
40,528,765✔
1383
}
1384

1385
int32_t fillTag(SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr,
110,336,991✔
1386
                uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, SRWLatch* lock) {
1387
  int32_t     code = 0;
110,336,991✔
1388
  int32_t     lino = 0;
110,336,991✔
1389
  SArray* tagCache = NULL;
110,336,991✔
1390
  if (numOfExpr == 0) {
110,336,991✔
1391
    return TSDB_CODE_SUCCESS;
37,694,381✔
1392
  }
1393

1394
  taosRLockLatch(lock);
72,642,610✔
1395
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
72,751,447✔
1396
  if (uidData == NULL) {
72,748,411✔
1397
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1398
  } else {
1399
    tagCache = *(SArray**)uidData;
72,748,411✔
1400
    if(taosArrayGetSize(tagCache) != numOfExpr) {
72,743,390✔
1401
      stError("%s numOfExpr:%d,tagCache size:%zu", __func__, numOfExpr, taosArrayGetSize(tagCache));
×
1402
      tagCache = NULL;
×
1403
    }
1404
  }
1405
  
1406
  for (int32_t j = 0; j < numOfExpr; ++j) {
310,226,149✔
1407
    const SExprInfo* pExpr1 = &pExprInfo[j];
237,484,488✔
1408
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
237,421,736✔
1409

1410
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
237,499,800✔
1411
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
237,491,681✔
1412
    int32_t functionId = pExpr1->pExpr->_function.functionId;
237,491,681✔
1413

1414
    // this is to handle the tbname
1415
    if (fmIsScanPseudoColumnFunc(functionId)) {
237,506,181✔
1416
      int32_t fType = pExpr1->pExpr->_function.functionType;
3,632,762✔
1417
      if (fType == FUNCTION_TYPE_TBNAME) {
3,632,762✔
1418
        pColInfoData->info.colId = -1;
3,632,532✔
1419
      }
1420
    } 
1421
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
237,441,630✔
1422

1423
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
237,426,537✔
1424
    if (isNullVal) {
237,427,591✔
1425
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1426
    } else {
1427
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
237,427,591✔
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);
237,709,241✔
1433
      STREAM_CHECK_RET_GOTO(code);
237,502,164✔
1434
    }
1435
  }
1436
end:
72,741,661✔
1437
  taosRUnLockLatch(lock);
72,741,661✔
1438
  return code;
72,751,693✔
1439
}
1440

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

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

1456
end:
3,525,599✔
1457
  return code;
3,525,599✔
1458
}
1459

1460
int32_t getRowRange(SColData* pCol, STimeWindow* window, int32_t* rowStart, int32_t* rowEnd, int32_t* nRows) {
×
1461
  int32_t code = 0;
×
1462
  int32_t lino = 0;
×
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

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

1488
end:
×
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;
×
1494
  int32_t lino = 0;
×
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) {
22,005,491✔
1506
  int32_t code = 0;
22,005,491✔
1507
  int32_t lino = 0;
22,005,491✔
1508
  int64_t id[2] = {suid, uid};
22,005,491✔
1509
  taosRLockLatch(&sStreamReaderInfo->lock);
22,005,951✔
1510
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
22,007,078✔
1511
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
22,006,618✔
1512
  SSHashObj* uInfo = *(SSHashObj **)px;
22,006,618✔
1513
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
22,006,618✔
1514
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
22,006,618✔
1515
  if (tmp != NULL) {
22,005,698✔
1516
    *colId = *tmp;
20,220,806✔
1517
  } else {
1518
    *colId = -1;
1,784,892✔
1519
  }
1520

1521
end:
22,006,388✔
1522
  taosRUnLockLatch(&sStreamReaderInfo->lock);
22,005,721✔
1523
  return code;
22,006,618✔
1524
}
1525

1526
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
10,374,632✔
1527
  int32_t code = 0;
10,374,632✔
1528
  int32_t lino = 0;
10,374,632✔
1529
  int64_t id = suid != 0 ? suid : uid;
10,374,632✔
1530
  if (sStreamReaderInfo->isVtableStream) {
10,375,549✔
1531
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
7,077,765✔
1532
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
7,077,765✔
1533
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
63,718✔
1534
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
63,948✔
1535
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
63,948✔
1536
      if (code != 0) {
63,948✔
1537
        taosMemoryFree(*schema);
×
1538
        goto end;
×
1539
      }
1540
    } else {
1541
      *schema = *schemaTmp;
7,014,047✔
1542
    }
1543
  } else {
1544
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
3,297,785✔
1545
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
81,907✔
1546
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
81,907✔
1547
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
81,907✔
1548
    }
1549
    *schema = sStreamReaderInfo->triggerTableSchema;
3,297,791✔
1550
  }
1551
  
1552
end:
10,375,551✔
1553
  return code;
10,375,780✔
1554
}
1555

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

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

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

1590
  // submit data
1591
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
11,378,094✔
1592
    ST_TASK_ELOG("vgId:%d %s invalid submit data suid", TD_VID(pVnode), __func__);
×
1593
    code = TSDB_CODE_INVALID_MSG;
×
1594
    TSDB_CHECK_CODE(code, lino, end);
×
1595
  }
1596
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
11,377,857✔
1597
    ST_TASK_ELOG("vgId:%d %s invalid submit data uid", TD_VID(pVnode), __func__);
×
1598
    code = TSDB_CODE_INVALID_MSG;
×
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,377,857✔
1603

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

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

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

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

1635
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
10,376,239✔
1636
  int32_t blockStart = 0;
10,376,476✔
1637
  int32_t numOfRows = 0;
10,376,476✔
1638
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,376,240✔
1639
    uint64_t nColData = 0;
×
1640
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1641
      ST_TASK_ELOG("vgId:%d %s invalid submit data nColData", TD_VID(pVnode), __func__);
×
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);
×
1648
    if (code) {
×
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__);
×
1656
      code = TSDB_CODE_INVALID_MSG;
×
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

1663
    int32_t rowStart = 0;
×
1664
    int32_t rowEnd = 0;
×
1665
    STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, &numOfRows));
×
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;
×
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

1685
      int16_t colId = 0;
×
1686
      if (sStreamReaderInfo->isVtableStream){
×
1687
        STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
×
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
      
1693
      uint64_t j = 1;
×
1694
      for (; j < nColData; j++) {
×
1695
        int16_t cid = 0;
×
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
        }
1710
        code = tDecodeColData(version, pCoder, &colData, true);
×
1711
        if (code) {
×
1712
          code = TSDB_CODE_INVALID_MSG;
×
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,376,240✔
1722
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,375,786✔
1723
      code = TSDB_CODE_INVALID_MSG;
×
1724
      TSDB_CHECK_CODE(code, lino, end);
×
1725
    }
1726
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
21,993,205✔
1727
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
11,618,516✔
1728
      pCoder->pos += pRow->len;
11,618,287✔
1729

1730
      if (iRow == 0){
11,618,059✔
1731
#ifndef NO_UNALIGNED_ACCESS
1732
        walMeta.skey = pRow->ts;
10,375,094✔
1733
#else
1734
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1735
#endif
1736
      }
1737
      if (iRow == nRow - 1) {
11,618,982✔
1738
#ifndef NO_UNALIGNED_ACCESS
1739
        walMeta.ekey = pRow->ts;
10,375,788✔
1740
#else
1741
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1742
#endif
1743
      }
1744

1745
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
11,619,900✔
1746
        continue;
7,706✔
1747
      }
1748
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
11,611,046✔
1749
      blockStart = pSlice->currentRowIdx;
11,611,046✔
1750
     
1751
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
71,889,730✔
1752
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
60,275,215✔
1753
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
60,279,045✔
1754
        if (pColData->info.colId <= -1) {
60,279,045✔
1755
          pColData->hasNull = true;
20,565,320✔
1756
          continue;
20,566,314✔
1757
        }
1758
        int16_t colId = 0;
39,721,179✔
1759
        if (sStreamReaderInfo->isVtableStream){
39,721,638✔
1760
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
22,005,307✔
1761
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
22,006,388✔
1762
        } else {
1763
          colId = pColData->info.colId;
17,717,250✔
1764
        }
1765
        
1766
        SColVal colVal = {0};
39,722,737✔
1767
        int32_t sourceIdx = 0;
39,722,967✔
1768
        while (1) {
1769
          if (sourceIdx >= schema->numOfCols) {
108,532,478✔
1770
            break;
8,774,054✔
1771
          }
1772
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
99,759,408✔
1773
          if (colVal.cid == colId) {
99,759,144✔
1774
            break;
30,949,633✔
1775
          }
1776
          sourceIdx++;
68,809,511✔
1777
        }
1778
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
39,723,687✔
1779
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
28,489,465✔
1780
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
26,441✔
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, 
25,944✔
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,463,024✔
1785
          }
1786
        } else {
1787
          colDataSetNULL(pColData, blockStart + numOfRows);
11,234,222✔
1788
        }
1789
      }
1790
      
1791
      numOfRows++;
11,609,713✔
1792
    }
1793
  }
1794

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

1804
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
10,376,038✔
1805
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
10,376,038✔
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,376,245✔
1809
    pBlock->info.rows += numOfRows;
10,376,016✔
1810
  } else {
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,376,016✔
1816

1817
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,784,135✔
1818
  if (data != NULL) {
1,783,906✔
1819
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
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,783,906✔
1823
  }
1824

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

1840
  tDecoderInit(&decoder, data, len);
11,379,240✔
1841
  if (tStartDecode(&decoder) < 0) {
11,376,182✔
1842
    code = TSDB_CODE_INVALID_MSG;
×
1843
    TSDB_CHECK_CODE(code, lino, end);
×
1844
  }
1845

1846
  uint64_t nSubmitTbData = 0;
11,377,649✔
1847
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
11,378,106✔
1848
    code = TSDB_CODE_INVALID_MSG;
×
1849
    TSDB_CHECK_CODE(code, lino, end);
×
1850
  }
1851

1852
  if (rsp->metaBlock != NULL){
11,378,106✔
1853
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
2,786,454✔
1854
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
2,786,436✔
1855
  }
1856

1857
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
22,756,401✔
1858
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
11,378,318✔
1859
  }
1860

1861
  tEndDecode(&decoder);
11,378,083✔
1862

1863
  if (rsp->metaBlock != NULL){
11,379,698✔
1864
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
2,788,277✔
1865
    int32_t iter = 0;
2,786,910✔
1866
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
2,787,140✔
1867
    while (px != NULL) {
4,571,507✔
1868
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,784,594✔
1869
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,784,594✔
1870
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,784,365✔
1871
      rsp->totalRows++;
1,784,365✔
1872
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,784,594✔
1873
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1874
      px = tSimpleHashIterate(gidHash, px, &iter);
1,784,594✔
1875
    }
1876
  }
1877
  
1878

1879
end:
11,375,382✔
1880
  tSimpleHashCleanup(gidHash);
11,378,565✔
1881
  tDecoderClear(&decoder);
11,379,928✔
1882
  return code;
11,379,928✔
1883
}
1884

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

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

1896
  SSubmitTbData submitTbData = {0};
13,327,708✔
1897
  uint8_t       version = 0;
13,327,937✔
1898
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
13,328,395✔
1899
    code = TSDB_CODE_INVALID_MSG;
×
1900
    TSDB_CHECK_CODE(code, lino, end);
×
1901
  }
1902
  version = (submitTbData.flags >> 8) & 0xff;
13,328,395✔
1903
  submitTbData.flags = submitTbData.flags & 0xff;
13,328,395✔
1904

1905
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1906
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
13,328,395✔
1907
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
841,257✔
1908
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
841,355✔
1909
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
841,355✔
1910
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
841,486✔
1911
  }
1912

1913
  // submit data
1914
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
13,325,694✔
1915
    code = TSDB_CODE_INVALID_MSG;
×
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  if (tDecodeI64(pCoder, uid) < 0) {
13,327,731✔
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,327,731✔
1923
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
13,327,940✔
1924
  if (rsp->uidHash != NULL) {
10,376,247✔
1925
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
8,591,881✔
1926
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
8,591,422✔
1927
  }
1928
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,376,017✔
1929

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

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

1950
    SColData colData = {0};
×
1951
    code = tDecodeColData(version, pCoder, &colData, false);
×
1952
    if (code) {
×
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;
×
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) {
×
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,376,935✔
1970
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,376,247✔
1971
      code = TSDB_CODE_INVALID_MSG;
×
1972
      TSDB_CHECK_CODE(code, lino, end);
×
1973
    }
1974

1975
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
10,376,247✔
1976
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
18,218,139✔
1977
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,625,799✔
1978
        pCoder->pos += pRow->len;
9,625,799✔
1979
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
9,625,799✔
1980
          continue;
7,706✔
1981
        }
1982
        (*numOfRows)++;
9,618,094✔
1983
      }
1984
    } else {
1985
      (*numOfRows) = nRow;
1,784,137✔
1986
    }
1987
  }
1988
  
1989
end:
13,327,485✔
1990
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
13,327,486✔
1991
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
13,326,339✔
1992
  tEndDecode(pCoder);
13,326,333✔
1993
  return code;
13,325,901✔
1994
}
1995

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

2002
  tDecoderInit(&decoder, data, len);
13,327,255✔
2003
  if (tStartDecode(&decoder) < 0) {
13,324,045✔
2004
    code = TSDB_CODE_INVALID_MSG;
×
2005
    TSDB_CHECK_CODE(code, lino, end);
×
2006
  }
2007

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

2015
  for (int32_t i = 0; i < nSubmitTbData; i++) {
26,624,064✔
2016
    uint64_t gid = -1;
13,326,798✔
2017
    int64_t  uid = 0;
13,327,255✔
2018
    int32_t numOfRows = 0;
13,327,255✔
2019
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
13,327,714✔
2020
    if (numOfRows <= 0) {
13,326,571✔
2021
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
2,952,156✔
2022
      continue;
2,952,385✔
2023
    }
2024
    rsp->totalRows += numOfRows;
10,374,415✔
2025
    rsp->totalDataRows += numOfRows;
10,375,789✔
2026

2027
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
10,374,794✔
2028
    if (pSlice != NULL) {
10,375,327✔
2029
      pSlice->numRows += numOfRows;
9,771,534✔
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,771,534✔
2031
      pSlice->gId = gid;
9,771,534✔
2032
    } else {
2033
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
603,793✔
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);
603,793✔
2035
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
603,793✔
2036
    } 
2037
  }
2038

2039
  tEndDecode(&decoder);
13,297,266✔
2040

2041
end:
13,354,720✔
2042
  tDecoderClear(&decoder);
13,326,108✔
2043
  return code;
13,325,607✔
2044
}
2045

2046
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
478,809✔
2047
  void*   pe = NULL;
478,809✔
2048
  int32_t iter = 0;
478,809✔
2049
  int32_t index = 0;
478,809✔
2050
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
1,083,061✔
2051
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
604,252✔
2052
    pInfo->startRowIdx = index;
604,252✔
2053
    pInfo->currentRowIdx = index;
604,252✔
2054
    index += pInfo->numRows;
604,252✔
2055
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
1,043,108✔
2056
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2057
  }
2058
}
478,809✔
2059

2060
static void printIndexHash(SSHashObj* indexHash, void* pTask){
478,579✔
2061
  if (qDebugFlag & DEBUG_TRACE) {
478,579✔
2062
    void*   pe = NULL;
8,181✔
2063
    int32_t iter = 0;
8,181✔
2064
    while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
19,782✔
2065
      SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
11,601✔
2066
      ST_TASK_TLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
11,819✔
2067
      pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2068
    }
2069
  }
2070
}
478,579✔
2071

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

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

2099
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,340,071✔
2100
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,338,115✔
2101
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,866,679✔
2102
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
2103
      resultRsp->verTime = 0;
×
2104
    } else {
2105
      resultRsp->verTime = taosGetTimestampUs();
2,866,825✔
2106
    }
2107
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
2,867,193✔
2108
    code = TSDB_CODE_SUCCESS;
2,867,407✔
2109
    goto end;
2,867,407✔
2110
  }
2111
  STREAM_CHECK_RET_GOTO(code);
471,436✔
2112

2113
  while (1) {
4,850,051✔
2114
    code = walNextValidMsg(pWalReader, true);
5,321,487✔
2115
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,320,979✔
2116
      resultRsp->verTime = taosGetTimestampUs();
471,650✔
2117
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
471,650✔
2118
      code = TSDB_CODE_SUCCESS;
471,421✔
2119
      goto end;
471,421✔
2120
    }
2121
    STREAM_CHECK_RET_GOTO(code);
4,850,782✔
2122
    resultRsp->ver = pWalReader->curVersion;
4,850,782✔
2123
    SWalCont* wCont = &pWalReader->pHead->head;
4,850,767✔
2124
    resultRsp->verTime = wCont->ingestTs;
4,851,409✔
2125
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
4,851,209✔
2126
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
4,852,111✔
2127
    int64_t ver = wCont->version;
4,851,452✔
2128
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
4,851,682✔
2129
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2130
    if (wCont->msgType == TDMT_VND_SUBMIT) {
4,851,632✔
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,735,138✔
2133
        resultRsp->ver--;
×
2134
        break;
×
2135
      }
2136
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,735,368✔
2137
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,735,604✔
2138
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
4,736,520✔
2139
    } else {
2140
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
115,821✔
2141
    }
2142

2143
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
4,848,620✔
2144
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
4,849,591✔
2145
      break;
2146
    }
2147
  }
2148
  
2149
end:
×
2150
  STREAM_PRINT_LOG_END(code, lino);
3,338,139✔
2151
  return code;
3,338,369✔
2152
}
2153

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

2160
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
17,284,110✔
2161
    int64_t *ver = taosArrayGet(versions, i);
8,590,656✔
2162
    if (ver == NULL) continue;
8,591,421✔
2163

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

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

2176
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
8,591,191✔
2177
  }
2178
  
2179
end:
8,692,228✔
2180
  return code;
8,692,228✔
2181
}
2182

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

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

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

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

2201
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,339,082✔
2202
                                    SSTriggerWalNewRsp* resultRsp) {
2203
  int32_t      code = 0;
3,339,082✔
2204
  int32_t      lino = 0;
3,339,082✔
2205
  void* pTask = sStreamReaderInfo->pTask;
3,339,082✔
2206
                                        
2207
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,339,297✔
2208
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,338,078✔
2209
  blockDataEmpty(resultRsp->dataBlock);
3,338,078✔
2210
  blockDataEmpty(resultRsp->metaBlock);
3,335,112✔
2211
  int64_t lastVer = resultRsp->ver;                                      
3,336,625✔
2212
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,336,843✔
2213
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,337,908✔
2214

2215
  buildIndexHash(resultRsp->indexHash, pTask);
119,027✔
2216
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
119,027✔
2217
  while(lastVer < resultRsp->ver) {
2,950,506✔
2218
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
2,832,175✔
2219
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
2,829,641✔
2220
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
44,128✔
2221
      continue;
44,128✔
2222
    }
2223
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
2,786,672✔
2224
    SWalCont* wCont = &pWalReader->pHead->head;
2,786,436✔
2225
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
2,787,589✔
2226
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
2,787,146✔
2227
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
2,787,375✔
2228
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
2,788,061✔
2229
  }
2230

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

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

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

2247
  void* pTask = sStreamReaderInfo->pTask;
8,692,458✔
2248
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
8,692,458✔
2249
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
8,691,693✔
2250
  
2251
  if (taosArrayGetSize(versions) > 0) {
8,691,693✔
2252
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
359,782✔
2253
  }
2254
  
2255
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
8,692,993✔
2256
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
8,692,228✔
2257

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

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

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

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

2279
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
8,592,111✔
2280
  }
2281
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2282
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
360,547✔
2283
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
359,782✔
2284

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

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

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

2314
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
2,285,551✔
2315
    SSchema* s = sSchemaWrapper->pSchema + j;
1,897,706✔
2316
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
3,795,412✔
2317
  }
2318

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

2329
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
387,845✔
2330
  int32_t code = 0;
387,845✔
2331
  int32_t lino = 0;
387,845✔
2332
  size_t  schemaLen = taosArrayGetSize(schemas);
387,845✔
2333
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
387,845✔
2334
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
1,511,348✔
2335
    col_id_t* id = taosArrayGet(cols, i);
1,123,503✔
2336
    STREAM_CHECK_NULL_GOTO(id, terrno);
1,123,503✔
2337
    for (size_t i = 0; i < schemaLen; i++) {
2,939,244✔
2338
      SSchema* s = taosArrayGet(schemas, i);
2,939,244✔
2339
      STREAM_CHECK_NULL_GOTO(s, terrno);
2,939,244✔
2340
      if (*id == s->colId) {
2,939,244✔
2341
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
1,123,503✔
2342
        break;
1,123,503✔
2343
      }
2344
    }
2345
  }
2346
  taosArrayPopFrontBatch(schemas, schemaLen);
387,845✔
2347

2348
end:
387,845✔
2349
  return code;
387,845✔
2350
}
2351

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

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

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

2380
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
×
2381
  pVal1->datum.i = end;
×
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;
×
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));
×
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);
×
2420
    nodesDestroyNode((SNode*)op);
×
2421
    nodesDestroyNode((SNode*)op1);
×
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,
502,046✔
2476
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
2477
  int32_t code = 0;
502,046✔
2478
  int32_t lino = 0;
502,046✔
2479
  void* pTask = sStreamReaderCalcInfo->pTask;
502,046✔
2480
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
502,046✔
2481
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
502,046✔
2482
  
2483
  if (req->pStRtFuncInfo->withExternalWindow) {
502,046✔
2484
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
379,125✔
2485
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
379,125✔
2486
    sStreamReaderCalcInfo->tmpRtFuncInfo.isWindowTrigger = req->pStRtFuncInfo->isWindowTrigger;
379,125✔
2487
    sStreamReaderCalcInfo->tmpRtFuncInfo.precision = req->pStRtFuncInfo->precision;
379,125✔
2488

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

2494
    if (!node->needCalc) {
379,125✔
2495
      pWin->skey = pFirst->wstart;
268,839✔
2496
      pWin->ekey = pLast->wend;
268,839✔
2497
      *pValid = true;
268,839✔
2498
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
268,839✔
2499
        pWin->ekey--;
146,443✔
2500
      }
2501
    } else {
2502
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
110,286✔
2503
      memcpy(pTmp, pFirst, sizeof(*pTmp));
110,286✔
2504

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

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

2512
        if (*pValid) {
110,286✔
2513
          pWin->skey = skey;
110,286✔
2514
        }
2515
      }
2516
      pWin->ekey--;
110,286✔
2517
    }
2518
  } else {
2519
    if (!node->needCalc) {
122,921✔
2520
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
79,605✔
2521
      pWin->skey = pCurr->wstart;
79,605✔
2522
      pWin->ekey = pCurr->wend;
79,605✔
2523
      *pValid = true;
79,605✔
2524
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
79,605✔
2525
        pWin->ekey--;
31,712✔
2526
      }
2527
    } else {
2528
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
43,316✔
2529
      pWin->ekey--;
43,316✔
2530
    }
2531
  }
2532

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

2536
end:
4,596✔
2537

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

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

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

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

2571
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
277,477✔
2572
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
277,477✔
2573
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
277,477✔
2574
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
277,477✔
2575
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
831,547✔
2576
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
1,108,140✔
2577
      continue;
×
2578
    }
2579
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
554,070✔
2580
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
553,835✔
2581
    if (order == TSDB_ORDER_ASC) {
553,835✔
2582
      tsInfo->ts = INT64_MAX;
276,846✔
2583
    } else {
2584
      tsInfo->ts = INT64_MIN;
276,989✔
2585
    }
2586
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
554,070✔
2587
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
554,070✔
2588
      tsInfo->ts = ts;
276,846✔
2589
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
277,224✔
2590
      tsInfo->ts = ts;
277,224✔
2591
    }
2592
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
554,070✔
2593
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
554,070✔
2594
  }
2595

2596
end:
277,477✔
2597
  return code;
277,477✔
2598
}
2599

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

2605
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
84,692✔
2606
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
83,989✔
2607
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
83,988✔
2608
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
84,448✔
2609
  if (order == TSDB_ORDER_ASC) {
84,448✔
2610
    tsInfo->ts = INT64_MAX;
66,401✔
2611
  } else {
2612
    tsInfo->ts = INT64_MIN;
18,047✔
2613
  }
2614

2615
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
84,692✔
2616
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
84,218✔
2617
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
183,147✔
2618
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
199,696✔
2619
      continue;
×
2620
    }
2621
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
99,848✔
2622
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
99,848✔
2623
      tsInfo->ts = ts;
66,185✔
2624
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
33,663✔
2625
      tsInfo->ts = ts;
18,047✔
2626
    }
2627
  }
2628
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
84,462✔
2629
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
84,233✔
2630
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
84,692✔
2631

2632
end:
29,857✔
2633
  return code;
84,692✔
2634
}
2635

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

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

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

2687
end:
7,695✔
2688
  qStreamDestroyTableInfo(&tableInfo);
7,695✔
2689
  taosMemoryFreeClear(pList);
7,695✔
2690
  tSimpleHashCleanup(uidTsHash);
7,695✔
2691
  return code;
7,695✔
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) {
358,821✔
2697
  int32_t code = 0;
358,821✔
2698
  int32_t lino = 0;
358,821✔
2699

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

2708
end:
358,607✔
2709
  pTaskInner->storageApi->tsdReader.tsdDestroyFirstLastTsIter(pTaskInner->pReader);
358,607✔
2710
  pTaskInner->pReader = NULL;
357,867✔
2711
  return code;
358,103✔
2712
}
2713

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

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

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

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

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

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

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

2756
  int32_t        pNum = 0;
230,859✔
2757
  int64_t        suid = 0;
230,859✔
2758
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, 0, &pList, &pNum));
230,859✔
2759
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
230,859✔
2760
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
199,325✔
2761

2762
  pTaskInner->options->suid = sStreamReaderInfo->suid;
199,325✔
2763
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
199,325✔
2764
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
199,089✔
2765
  int32_t order = pTaskInner->options->order;
107,892✔
2766

2767
  if (sStreamReaderInfo->groupByTbname) {
107,892✔
2768
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
55,753✔
2769
  } else if (sStreamReaderInfo->partitionCols == NULL) {
52,139✔
2770
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
44,444✔
2771
  } else {
2772
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
7,695✔
2773
  }                             
2774
end:
230,384✔
2775
  blockDataDestroy(pResBlock);
230,491✔
2776
  taosMemoryFreeClear(pList);
229,989✔
2777
  STREAM_PRINT_LOG_END_WITHID(code, lino);
230,179✔
2778
  return code;
230,629✔
2779
}
2780

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

2790
  int32_t        pNum = 0;
53,277✔
2791
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
53,277✔
2792
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
53,277✔
2793
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
40,248✔
2794

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

2800
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
40,004✔
2801
end:
53,277✔
2802
  blockDataDestroy(pResBlock);
53,277✔
2803
  taosMemoryFreeClear(pList);
53,507✔
2804
  STREAM_PRINT_LOG_END_WITHID(code, lino);
53,048✔
2805
  return code;
53,048✔
2806
}
2807

2808
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
452,583✔
2809
                                  SStreamReaderTaskInner* pTaskInner) {
2810
  if (sStreamReaderInfo->isVtableStream) {
452,583✔
2811
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
221,724✔
2812
  }
2813

2814
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
230,859✔
2815
}
2816

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

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

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

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

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

2853
  void* pTask = sStreamReaderInfo->pTask;
287,836✔
2854

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

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

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

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

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

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

2888
  tsRsp.ver = pVnode->state.applied;
218,024✔
2889

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

2893
  if (req->firstTsReq.gid != 0) {
217,794✔
2894
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
53,047✔
2895
  } else {
2896
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
164,747✔
2897
  }
2898

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

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

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

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

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

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

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

2962
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
355,732✔
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++;
355,732✔
2966
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
355,732✔
2967
      break;
×
2968
    }
2969
  }
2970

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

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

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

2995
  void* pTask = sStreamReaderInfo->pTask;
167,076✔
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, 
167,076✔
2997
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2998
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2999

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

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

3019
    SSDataBlock* pBlock = NULL;
167,076✔
3020
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
167,076✔
3021
    if (pBlock != NULL && pBlock->info.rows > 0) {
167,076✔
3022
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
167,076✔
3023
          0, pBlock->info.rows, 1));
3024
    }
3025
    
3026
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
167,076✔
3027
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
167,076✔
3028
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
167,076✔
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);
167,076✔
3034

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

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

3045
  releaseStreamTask(&pTaskInner);
167,076✔
3046
  return code;
167,076✔
3047
}
3048

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

3057
  void* pTask = sStreamReaderInfo->pTask;
×
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, 
×
3059
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3060
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3061

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

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

3077
    SSDataBlock* pBlock = NULL;
×
3078
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
×
3079
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
×
3080
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
×
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);
×
3086
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
×
3087

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

3095
  releaseStreamTask(&pTaskInner);
×
3096
  return code;
×
3097
}
3098

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

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

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

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

3142
    SSDataBlock* pBlock = NULL;
60,739✔
3143
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
60,739✔
3144
    if (pBlock != NULL && pBlock->info.rows > 0) {
60,739✔
3145
      STREAM_CHECK_RET_GOTO(
60,739✔
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));
60,739✔
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);
60,739✔
3151
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
60,739✔
3152
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
60,739✔
3153
    totalRows += blockDataGetNumOfRows(pBlockTmp);
60,739✔
3154
    pBlockTmp = NULL;
60,739✔
3155

3156
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
60,739✔
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
60,739✔
3160
      break;
×
3161
    }
3162
  }
3163

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

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

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

3188

3189
  void* pTask = sStreamReaderInfo->pTask;
6,217,282✔
3190
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
6,217,282✔
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,217,079✔
3194

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

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

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

3214
  blockDataCleanup(pTaskInner->pResBlockDst);
6,216,267✔
3215
  bool hasNext = true;
6,213,831✔
3216
  while (1) {
779,690✔
3217
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
6,993,115✔
3218
    if (!hasNext) {
6,992,116✔
3219
      break;
6,212,613✔
3220
    }
3221
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
779,503✔
3222

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

3232
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
6,212,816✔
3233
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
6,215,049✔
3234
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
6,215,455✔
3235
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
6,215,658✔
3236
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
6,213,435✔
3237
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
6,215,252✔
3238
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
6,218,703✔
3239

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

3244
end:
6,217,079✔
3245
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,217,079✔
3246
  SRpcMsg rsp = {
6,217,485✔
3247
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3248
  tmsgSendRsp(&rsp);
6,217,052✔
3249
  blockDataDestroy(pBlockRes);
6,217,079✔
3250
  taosMemoryFree(pList);
6,217,282✔
3251
  return code;
6,217,079✔
3252
}
3253

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

3271
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
392,435✔
3272
    // sort cid and build slotIdList
3273
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
392,435✔
3274
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
392,435✔
3275
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
392,435✔
3276
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
392,435✔
3277
    taosArraySort(sortedCid, sortCid);
392,435✔
3278
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
1,529,708✔
3279
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
1,137,273✔
3280
      STREAM_CHECK_NULL_GOTO(cid, terrno);
1,137,273✔
3281
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
2,239,206✔
3282
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
2,239,206✔
3283
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
2,239,206✔
3284
        if (*cid == *cidSorted) {
2,239,206✔
3285
          slotIdList[j] = i;
1,137,273✔
3286
          break;
1,137,273✔
3287
        }
3288
      }
3289
    }
3290

3291
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas, &sStreamReaderInfo->storageApi));
392,435✔
3292
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
387,845✔
3293
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlockRes));
387,845✔
3294

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

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

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

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

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

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

3355
  if (sStreamReaderInfo->metaBlock == NULL) {
11,871,851✔
3356
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
197,381✔
3357
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
197,381✔
3358
  }
3359
  blockDataEmpty(sStreamReaderInfo->metaBlock);
11,872,081✔
3360
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
11,871,052✔
3361
  resultRsp.ver = req->walMetaNewReq.lastVer;
11,871,449✔
3362
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
11,871,679✔
3363

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

3373
end:
11,871,846✔
3374
  if (code == 0 && resultRsp.totalRows == 0) {
11,872,081✔
3375
    code = TSDB_CODE_STREAM_NO_DATA;
11,631,710✔
3376
    size = sizeof(int64_t) * 2;
11,631,710✔
3377
    buf = rpcMallocCont(size);
11,631,710✔
3378
    *(int64_t*)buf = resultRsp.ver;
11,631,480✔
3379
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
11,631,480✔
3380
  }
3381
  SRpcMsg rsp = {
11,871,851✔
3382
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3383
  tmsgSendRsp(&rsp);
11,872,081✔
3384
  if (code == TSDB_CODE_STREAM_NO_DATA){
11,871,667✔
3385
    code = 0;
11,631,296✔
3386
  }
3387
  STREAM_PRINT_LOG_END_WITHID(code, lino);
11,871,667✔
3388
  blockDataDestroy(resultRsp.deleteBlock);
11,872,081✔
3389
  blockDataDestroy(resultRsp.tableBlock);
11,871,391✔
3390

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

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

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

3415
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,337,921✔
3416

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

3427
end:
3,339,311✔
3428
  if (resultRsp.totalRows == 0) {
3,338,367✔
3429
    code = TSDB_CODE_STREAM_NO_DATA;
3,218,881✔
3430
    size = sizeof(int64_t) * 2;
3,218,881✔
3431
    buf = rpcMallocCont(size);
3,218,881✔
3432
    *(int64_t*)buf = resultRsp.ver;
3,216,936✔
3433
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
3,217,395✔
3434
  }
3435
  SRpcMsg rsp = {
3,337,800✔
3436
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3437
  tmsgSendRsp(&rsp);
3,338,812✔
3438
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,339,534✔
3439
    code = 0;
3,220,737✔
3440
  }
3441
  blockDataDestroy(resultRsp.dataBlock);
3,339,534✔
3442
  blockDataDestroy(resultRsp.deleteBlock);
3,338,566✔
3443
  blockDataDestroy(resultRsp.tableBlock);
3,339,140✔
3444
  tSimpleHashCleanup(resultRsp.indexHash);
3,338,445✔
3445

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

3448
  return code;
3,335,894✔
3449
}
3450

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

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

3461
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
7,657,871✔
3462
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,657,871✔
3463
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
7,657,871✔
3464
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,657,871✔
3465
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
7,657,106✔
3466

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

3470
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
7,657,871✔
3471

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

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

3492
  blockDataDestroy(resultRsp.dataBlock);
7,657,871✔
3493
  blockDataDestroy(resultRsp.deleteBlock);
7,657,871✔
3494
  blockDataDestroy(resultRsp.tableBlock);
7,657,871✔
3495
  tSimpleHashCleanup(resultRsp.indexHash);
7,657,871✔
3496
  tSimpleHashCleanup(resultRsp.uidHash);
7,657,871✔
3497
  STREAM_PRINT_LOG_END_WITHID(code, lino);
7,657,871✔
3498

3499
  return code;
7,657,871✔
3500
}
3501

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

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

3522
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
1,035,352✔
3523
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
1,035,352✔
3524

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

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

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

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

3563
  return code;
1,035,352✔
3564
}
3565

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

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

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

3599
  return code;
300,681✔
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) {
185,452✔
3603
  int32_t              code = 0;
185,452✔
3604
  int32_t              lino = 0;
185,452✔
3605
  void* pTask = sStreamReaderInfo->pTask;
185,452✔
3606

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

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

3614
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, ver, uid);
185,452✔
3615
  if (code != 0) {
185,452✔
3616
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
3617
    goto end;
×
3618
  }
3619
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
185,452✔
3620
    vTable->cols.nCols = metaReader->me.colRef.nCols;
10,761✔
3621
    vTable->cols.version = metaReader->me.colRef.version;
10,761✔
3622
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
10,761✔
3623
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
10,761✔
3624
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
64,566✔
3625
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
53,805✔
3626
    }
3627
  } else {
3628
    vTable->cols.nCols = taosArrayGetSize(cids);
174,691✔
3629
    vTable->cols.version = metaReader->me.colRef.version;
174,691✔
3630
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
174,691✔
3631
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
174,691✔
3632
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
664,945✔
3633
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
2,064,744✔
3634
        if (metaReader->me.colRef.pColRef[j].hasRef &&
1,889,366✔
3635
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
1,394,615✔
3636
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
315,080✔
3637
          break;
315,080✔
3638
        }
3639
      }
3640
    }
3641
  }
3642
  tDecoderClear(&metaReader->coder);
185,452✔
3643

3644
end:
185,452✔
3645
  return code;
185,452✔
3646
}
3647

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

3654

3655
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
75,034✔
3656
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
75,034✔
3657

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

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

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

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;
×
3681
  int32_t              lino = 0;
×
3682
  void* pTask = sStreamReaderInfo->pTask;
×
3683

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

3687
  for (size_t i = 0; i < taosArrayGetSize(uids); i++) {
×
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);
×
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);
×
3696
      continue;
×
3697
    }
3698
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, *uid, groupId, ver, metaReader, sStreamReaderInfo);
×
3699
    if (code != 0) {
×
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:
×
3707
  return code;
×
3708
}
3709

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

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

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

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

3729
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
75,034✔
3730
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
75,034✔
3731
  } else {
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));
75,034✔
3735
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
75,034✔
3736

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

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

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

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

3761
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
132,979✔
3762

3763
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
132,979✔
3764

3765
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
132,979✔
3766
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
491,103✔
3767
    OTableInfo*    oInfo = taosArrayGet(cols, i);
358,124✔
3768
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
358,124✔
3769
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
358,124✔
3770
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
358,124✔
3771
    code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionName(&metaReader, req->origTableInfoReq.ver, oInfo->refTableName);
358,124✔
3772
    if (code != 0) {
358,124✔
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;
357,920✔
3778
    ST_TASK_DLOG("vgId:%d %s get original uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
357,920✔
3779

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

3794
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
1,224,897✔
3795
      SSchema* s = sSchemaWrapper->pSchema + j;
1,224,897✔
3796
      if (strcmp(s->name, oInfo->refColName) == 0) {
1,224,667✔
3797
        vTableInfo->cid = s->colId;
357,690✔
3798
        break;
357,920✔
3799
      }
3800
    }
3801
    if (vTableInfo->cid == 0) {
357,920✔
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);
357,920✔
3806
  }
3807

3808
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
132,979✔
3809

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

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

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

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

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

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

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

3855
    STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReaderStable, req->virTablePseudoColReq.ver, suid));
658,767✔
3856
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
658,767✔
3857
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
1,702,462✔
3858
      col_id_t* id = taosArrayGet(cols, i);
1,043,695✔
3859
      STREAM_CHECK_NULL_GOTO(id, terrno);
1,043,695✔
3860
      if (*id == -1) {
1,043,695✔
3861
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
646,527✔
3862
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
646,527✔
3863
        continue;
646,527✔
3864
      }
3865
      size_t j = 0;
397,168✔
3866
      for (; j < sSchemaWrapper->nCols; j++) {
755,413✔
3867
        SSchema* s = sSchemaWrapper->pSchema + j;
755,413✔
3868
        if (s->colId == *id) {
755,413✔
3869
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
397,168✔
3870
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
397,168✔
3871
          break;
397,168✔
3872
        }
3873
      }
3874
      if (j == sSchemaWrapper->nCols) {
397,168✔
3875
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3876
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3877
      }
3878
    }
3879
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
658,767✔
3880
    pBlock->info.rows = 1;
658,767✔
3881
    
3882
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
1,702,462✔
3883
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
1,043,695✔
3884
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
1,043,695✔
3885

3886
      if (pDst->info.colId == -1) {
1,043,695✔
3887
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
646,527✔
3888
        continue;
646,527✔
3889
      }
3890
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
397,168✔
3891
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3892
        continue;
×
3893
      }
3894

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

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

3906
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
397,168✔
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) &&
397,168✔
3910
          (data != NULL)) {
3911
        taosMemoryFree(data);
353,070✔
3912
      }
3913
    }
3914
  } else {
3915
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3916
    code = TSDB_CODE_INVALID_PARA;
×
3917
    goto end;
×
3918
  }
3919
  
3920
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
660,835✔
3921
  printDataBlock(pBlock, __func__, "", streamId);
660,835✔
3922
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
660,835✔
3923

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

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

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

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

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

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

3982
    initStorageAPI(&handle.api);
4,168,159✔
3983
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
4,168,159✔
3984
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
3,302,123✔
3985
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,308,817✔
3986
      if (node != NULL) {
3,309,082✔
3987
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
424,815✔
3988
      } else {
3989
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
2,884,267✔
3990
      }
3991

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

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

4004
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
4,168,159✔
4005
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
605,557✔
4006
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
605,557✔
4007
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
4008
                                                    req.taskId));
4009
    } else {
4010
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
3,562,602✔
4011
    }
4012

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

4016
  if (req.pOpParam != NULL) {
7,493,481✔
4017
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
317,038✔
4018
  }
4019

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

4025
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
18,477,728✔
4026
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
10,985,780✔
4027
    if (pBlock == NULL) continue;
10,985,780✔
4028
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
10,985,780✔
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,493,851✔
4038
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
7,493,851✔
4039
  taosArrayDestroy(pResList);
7,493,983✔
4040
  streamReleaseTask(taskAddr);
7,493,983✔
4041

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

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

4081
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
40,611,635✔
4082
  int32_t                   code = 0;
40,611,635✔
4083
  int32_t                   lino = 0;
40,611,635✔
4084
  SSTriggerPullRequestUnion req = {0};
40,611,635✔
4085
  void*                     taskAddr = NULL;
40,612,202✔
4086
  bool                      sendRsp = false;
40,607,939✔
4087

4088
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
40,607,939✔
4089
  if (!syncIsReadyForRead(pVnode->sync)) {
40,611,204✔
4090
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
69,476✔
4091
    return 0;
69,476✔
4092
  }
4093

4094
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
40,542,504✔
4095
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
7,493,983✔
4096
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
33,048,725✔
4097
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
33,048,928✔
4098
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
33,048,928✔
4099
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
33,047,806✔
4100
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
33,046,169✔
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);
33,046,152✔
4103
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
33,047,335✔
4104
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
33,030,228✔
4105
    sendRsp = true;
33,030,210✔
4106
    switch (req.base.type) {
33,030,210✔
4107
      case STRIGGER_PULL_SET_TABLE:
132,979✔
4108
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
132,979✔
4109
        break;
132,979✔
4110
      case STRIGGER_PULL_LAST_TS:
287,836✔
4111
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
287,836✔
4112
        break;
287,836✔
4113
      case STRIGGER_PULL_FIRST_TS:
218,024✔
4114
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
218,024✔
4115
        break;
218,024✔
4116
      case STRIGGER_PULL_TSDB_META:
429,875✔
4117
      case STRIGGER_PULL_TSDB_META_NEXT:
4118
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
429,875✔
4119
        break;
429,875✔
4120
      case STRIGGER_PULL_TSDB_TS_DATA:
167,076✔
4121
        if (sStreamReaderInfo->isVtableStream) {
167,076✔
4122
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
4123
        } else {
4124
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
167,076✔
4125
        }
4126
        break;
167,076✔
4127
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
111,248✔
4128
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4129
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
111,248✔
4130
        break;
55,624✔
4131
      case STRIGGER_PULL_TSDB_CALC_DATA:
6,217,282✔
4132
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4133
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
6,217,282✔
4134
        break;
6,215,908✔
4135
      case STRIGGER_PULL_TSDB_DATA:
392,435✔
4136
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4137
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
392,435✔
4138
        break;
387,845✔
4139
      case STRIGGER_PULL_GROUP_COL_VALUE:
300,911✔
4140
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
300,911✔
4141
        break;
300,681✔
4142
      case STRIGGER_PULL_VTABLE_INFO:
75,034✔
4143
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
75,034✔
4144
        break;
75,034✔
4145
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
660,835✔
4146
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
660,835✔
4147
        break;
660,835✔
4148
      case STRIGGER_PULL_OTABLE_INFO:
132,979✔
4149
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
132,979✔
4150
        break;
132,979✔
4151
      case STRIGGER_PULL_WAL_META_NEW:
11,871,851✔
4152
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
11,871,851✔
4153
        break;
11,871,851✔
4154
      case STRIGGER_PULL_WAL_DATA_NEW:
7,657,437✔
4155
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
7,657,437✔
4156
        break;
7,657,871✔
4157
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,339,285✔
4158
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,339,285✔
4159
        break;
3,338,597✔
4160
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
1,035,352✔
4161
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,035,352✔
4162
        break;
1,035,352✔
4163
      default:
×
4164
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
4165
        sendRsp = false;
535✔
4166
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
535✔
4167
    }
4168
  } else {
4169
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
4170
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4171
  }
4172
end:
33,038,859✔
4173

4174
  streamReleaseTask(taskAddr);
33,045,534✔
4175

4176
  tDestroySTriggerPullRequest(&req);
33,049,360✔
4177
  STREAM_PRINT_LOG_END(code, lino);
33,043,143✔
4178
  if (!sendRsp) {
33,046,834✔
4179
    SRpcMsg rsp = {
34,214✔
4180
      .code = code,
4181
      .pCont = pMsg->info.rsp,
17,107✔
4182
      .contLen = pMsg->info.rspLen,
17,107✔
4183
      .info = pMsg->info,
4184
    };
4185
    tmsgSendRsp(&rsp);
17,107✔
4186
  }
4187
  return code;
33,045,723✔
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