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

taosdata / TDengine / #5091

17 May 2026 01:15AM UTC coverage: 73.326% (-0.01%) from 73.34%
#5091

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281422 of 383795 relevant lines covered (73.33%)

136839186.86 hits per line

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

85.03
/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) {
8,093,418✔
65
  int64_t suid = 0;
8,093,418✔
66
  if (!sStreamReaderInfo->isVtableStream) {
8,093,418✔
67
    suid = sStreamReaderInfo->suid;
7,637,161✔
68
    goto end;
7,637,161✔
69
  }
70

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

75
  taosRLockLatch(&sStreamReaderInfo->lock);
456,257✔
76
  SStreamTableMapElement* element = taosHashGet(sStreamReaderInfo->vSetTableList.uIdMap, &pList->uid, LONG_BYTES);  
456,257✔
77
  if (element != 0) {
456,257✔
78
    suid = element->table->groupId;
263,661✔
79
    taosRUnLockLatch(&sStreamReaderInfo->lock);
263,661✔
80
    goto end;
263,661✔
81
  }
82
  taosRUnLockLatch(&sStreamReaderInfo->lock);
192,596✔
83

84
end:
8,093,418✔
85
  return suid;
8,093,418✔
86
}
87

88
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
8,187,466✔
89

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

94
  if (*c1 < *c2) {
2,445,046✔
95
    return -1;
2,427,602✔
96
  } else if (*c1 > *c2) {
17,444✔
97
    return 1;
17,444✔
98
  }
99

100
  return 0;
×
101
}
102

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

107
  if (c1->colId < c2->colId) {
2,431,862✔
108
    return -1;
2,414,418✔
109
  } else if (c1->colId > c2->colId) {
17,444✔
110
    return 1;
17,444✔
111
  }
112

113
  return 0;
×
114
}
115

116
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
44,856,031✔
117
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
44,856,031✔
118
  if (pSrc == NULL) {
44,859,535✔
119
    return terrno;
×
120
  }
121

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
44,859,535✔
123
  return 0;
44,861,183✔
124
}
125

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

132
  return code;
10,906,417✔
133
}
134

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

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

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

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
5,623,672✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
5,623,672✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
2,721,937✔
165
      suid == sStreamReaderInfo->suid) {
1,020,103✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
12,365✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
12,365✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
12,365✔
169
    if (gid == (uint64_t)-1) return true;
12,365✔
170
  }
171
  return false;
5,612,191✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
14,347,290✔
175
  int32_t  ret = false;
14,347,290✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
14,347,290✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
8,414,522✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
3,943,912✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
9,873,788✔
181
  if (*id == -1) goto end;
9,874,594✔
182
  ret = true;
6,253,744✔
183

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

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

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
76,019,974✔
194
  bool ret = false;
76,019,974✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
76,019,974✔
196
  if (sStreamReaderInfo->isVtableStream) {
76,034,065✔
197
    int64_t tmp[2] = {suid, uid};
61,719,861✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
61,720,685✔
199
      *id = uid;
16,177,616✔
200
      ret = true;
16,177,616✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
14,312,035✔
204
  }
205

206
end:
76,033,812✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
76,033,812✔
208
  return ret;
76,037,804✔
209
}
210

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

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

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

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

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

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

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
9,811,104✔
301
  int32_t code = 0;
9,811,104✔
302
  int32_t lino = 0;
9,811,104✔
303
  void*   buf = NULL;
9,811,104✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
9,811,104✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
2,633,647✔
306
  buf = rpcMallocCont(dataEncodeSize);
2,633,647✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
2,633,647✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
2,633,647✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
2,633,647✔
310
  *data = buf;
2,633,647✔
311
  *size = dataEncodeSize;
2,633,647✔
312
  buf = NULL;
2,633,647✔
313
end:
9,813,766✔
314
  rpcFreeCont(buf);
9,813,766✔
315
  return code;
9,811,830✔
316
}
317

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

322
  void*   buf = NULL;
155,432✔
323

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

336
  char* dataBuf = (char*)buf;
155,165✔
337
  *((int32_t*)(dataBuf)) = blockNum;
155,165✔
338
  dataBuf += INT_BYTES;
155,165✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
362,743✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
207,578✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
207,578✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
207,578✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
207,578✔
344
    dataBuf += actualLen;
207,578✔
345
  }
346
  *data = buf;
155,432✔
347
  *size = INT_BYTES + dataEncodeBufSize;
155,432✔
348
  buf = NULL;
155,432✔
349
end:
155,432✔
350
  rpcFreeCont(buf);
155,432✔
351
  return code;
155,432✔
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) {
10,874,362✔
375
  int32_t code = 0;
10,874,362✔
376
  int32_t lino = 0;
10,874,362✔
377
  int32_t index = 0;
10,874,362✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
10,874,362✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
10,874,626✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
10,874,626✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
10,874,626✔
382

383
end:
10,874,072✔
384
  return code;
10,874,072✔
385
}
386

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

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

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

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

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

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

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

451
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
3,490✔
452

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

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

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

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

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

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

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

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

554
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
73,246✔
555
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
36,623✔
556
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
36,623✔
557
    uint64_t id = 0;
36,623✔
558
    if(!uidInTableListOrigin(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id)) {
36,623✔
559
      continue;
35,601✔
560
    }
561

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

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

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

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

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

641
  if (taosArrayGetSize(uidList) == 0) {
102,794✔
642
    return 0;
67,524✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
35,270✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
35,270✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

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

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

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

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

672
  if (sStreamReaderInfo->isVtableStream) {
77,028✔
673
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
6,016✔
674
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
6,016✔
675
  }
676
  
677
  SVCreateTbReq* pCreateReq = NULL;
77,028✔
678
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
154,056✔
679
    pCreateReq = req.pReqs + iReq;
77,028✔
680
    if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
77,028✔
681
      ST_TASK_DLOG("stream reader scan create table jump, %s", pCreateReq->name);
67,524✔
682
      continue;
67,524✔
683
    }
684
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
9,504✔
685
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
19,008✔
686
  }
687
  
688
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
77,028✔
689
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
77,028✔
690
  if (sStreamReaderInfo->isVtableStream) {
77,028✔
691
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
6,016✔
692
  }
693

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

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

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

722
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,633✔
723
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,633✔
724
end:
5,544,095✔
725
  taosArrayDestroy(uidList);
5,546,914✔
726
  taosArrayDestroy(tableList);
5,546,104✔
727
  return code;
5,546,104✔
728
}
729

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

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

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

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

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

788
  col_id_t colId = 0;
540✔
789
  getAlterColId(sStreamReaderInfo->pVnode, uid, pReq->colName, &colId);
540✔
790
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 0 && !isColIdInList(sStreamReaderInfo->triggerCols, colId)) {
540✔
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);
540✔
796
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
540✔
797

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

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

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

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

821
end:
24,673✔
822
  return code;
24,673✔
823
}
824

825
static SArray* getTableListForAlterSuperTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SVAlterTbReq* pReq){
24,133✔
826
  int32_t code = 0;
24,133✔
827
  int32_t lino = 0;
24,133✔
828
  void* pTask = sStreamReaderInfo->pTask;
24,133✔
829
  SArray* uidList = taosArrayInit(8, sizeof(tb_uid_t));
24,133✔
830
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
24,133✔
831
  for (int32_t i = 0; i < taosArrayGetSize(pReq->tables); i++) {
48,266✔
832
    SUpdateTableTagVal *pTable = taosArrayGet(pReq->tables, i);
24,133✔
833
    uint64_t uid = 0;
24,133✔
834
    code = checkAlter(sStreamReaderInfo, pTable->tbName, pReq->action, &uid);
24,133✔
835
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
24,133✔
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);
24,133✔
841
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, (const void *)&uid), terrno);
24,133✔
842
  }
843

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

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

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

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

874
  if (rsp->checkAlter && taosArrayGetSize(uidListDel) > 0 && rsp->totalDataRows > 0) {
24,133✔
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));
24,133✔
882
  if (sStreamReaderInfo->isVtableStream) {
24,133✔
883
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
1,687✔
884
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
1,687✔
885
  }
886
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
24,133✔
887

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

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

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

905
  ST_TASK_DLOG("%s start", __func__);
41,410✔
906

907
  SVAlterTbReq req = {0};
41,410✔
908
  tDecoderInit(&decoder, data, len);
41,410✔
909
  
910
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
41,410✔
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 && 
41,410✔
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;
30,070✔
916
  if (req.action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || req.action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
30,070✔
917
    STREAM_CHECK_CONDITION_GOTO(!sStreamReaderInfo->isVtableStream, TDB_CODE_SUCCESS);
5,937✔
918
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
540✔
919
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
540✔
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));
540✔
925
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
24,133✔
926
    uidList = getTableListForAlterSuperTable(sStreamReaderInfo, &req);
24,133✔
927
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
24,133✔
928
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
24,133✔
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__);
24,673✔
943

944
end:
41,410✔
945
  destroyAlterTbReq(&req);
41,410✔
946

947
  taosArrayDestroy(uidList);
41,410✔
948
  tDecoderClear(&decoder);
41,410✔
949
  STREAM_PRINT_LOG_END_WITHID(code, lino);
41,410✔
950
  return code;
41,410✔
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) {
57,891,972✔
996
  int32_t code = 0;
57,891,972✔
997
  int32_t lino = 0;
57,891,972✔
998
  WalMetaResult walMeta = {0};
57,891,972✔
999
  SSubmitTbData submitTbData = {0};
57,892,796✔
1000
  
1001
  if (tStartDecode(pCoder) < 0) {
57,891,972✔
1002
    code = TSDB_CODE_INVALID_MSG;
×
1003
    TSDB_CHECK_CODE(code, lino, end);
×
1004
  }
1005

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

1014
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1015
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
57,890,079✔
1016
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
4,414,210✔
1017
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
4,413,940✔
1018
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
4,413,940✔
1019
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
4,414,480✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
57,888,470✔
1024
    code = TSDB_CODE_INVALID_MSG;
×
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
57,889,156✔
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)){
57,889,156✔
1033
    goto end;
49,124,155✔
1034
  }
1035
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
8,767,088✔
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,767,088✔
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,767,088✔
1070
    if (tDecodeU64v(pCoder, &nRow) < 0) {
8,766,744✔
1071
      code = TSDB_CODE_INVALID_MSG;
×
1072
      TSDB_CHECK_CODE(code, lino, end);
×
1073
    }
1074

1075
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
18,874,934✔
1076
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
10,108,250✔
1077
      pCoder->pos += pRow->len;
10,108,460✔
1078
      if (iRow == 0){
10,108,460✔
1079
#ifndef NO_UNALIGNED_ACCESS
1080
        walMeta.skey = pRow->ts;
8,766,474✔
1081
#else
1082
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1083
#endif
1084
      }
1085
      if (iRow == nRow - 1) {
10,108,460✔
1086
#ifndef NO_UNALIGNED_ACCESS
1087
        walMeta.ekey = pRow->ts;
8,766,474✔
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,766,534✔
1096
  if (data != NULL) {
8,767,568✔
1097
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
1,096✔
1098
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
1,096✔
1099
  } else {
1100
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
8,766,472✔
1101
  }
1102

1103
end:
57,885,407✔
1104
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
57,889,599✔
1105
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
57,887,719✔
1106
  tEndDecode(pCoder);
57,887,719✔
1107
  return code;
57,888,775✔
1108
}
1109

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

1117
  tDecoderInit(&decoder, data, len);
57,891,675✔
1118
  if (tStartDecode(&decoder) < 0) {
57,889,015✔
1119
    code = TSDB_CODE_INVALID_MSG;
×
1120
    TSDB_CHECK_CODE(code, lino, end);
×
1121
  }
1122

1123
  uint64_t nSubmitTbData = 0;
57,890,876✔
1124
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
57,888,688✔
1125
    code = TSDB_CODE_INVALID_MSG;
×
1126
    TSDB_CHECK_CODE(code, lino, end);
×
1127
  }
1128

1129
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
57,888,688✔
1130
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
57,887,644✔
1131

1132
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
115,777,282✔
1133
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
57,889,564✔
1134
  }
1135
  tEndDecode(&decoder);
57,887,718✔
1136

1137
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
57,887,912✔
1138
  int32_t iter = 0;
57,888,255✔
1139
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
57,887,456✔
1140
  while (px != NULL) {
66,654,451✔
1141
    WalMetaResult* pMeta = (WalMetaResult*)px;
8,766,202✔
1142
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
8,766,202✔
1143
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
8,765,648✔
1144
    rsp->totalRows++;
8,766,231✔
1145
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
8,766,472✔
1146
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1147
    px = tSimpleHashIterate(gidHash, px, &iter);
8,766,472✔
1148
  }
1149
end:
57,888,249✔
1150
  tDecoderClear(&decoder);
57,887,940✔
1151
  tSimpleHashCleanup( gidHash);
57,888,911✔
1152
  return code;
57,881,285✔
1153
}
1154

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

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

1170
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
504,873✔
1171

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

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

1182
  schemas = taosArrayInit(8, sizeof(SSchema));
375,110✔
1183
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
375,350✔
1184

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

1191
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
375,350✔
1192

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

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

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

1205
  SDecoder dcoder = {0};
775,771✔
1206
  tDecoderInit(&dcoder, data, len);
775,771✔
1207
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
775,771✔
1208
    if (rsp->deleteBlock == NULL) {
34,328✔
1209
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
12,176✔
1210
    }
1211
      
1212
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
34,328✔
1213
  } else if (msgType == TDMT_VND_DROP_TABLE && 
741,443✔
1214
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
57,923✔
1215
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
36,623✔
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)) {
704,820✔
1219
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
77,028✔
1220
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
627,792✔
1221
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1222
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
596,998✔
1223
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
41,410✔
1224
  }
1225

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

1236
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
25,410,115✔
1237
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
25,407,852✔
1238
  code = walReaderSeekVer(pWalReader, rsp->ver);
25,407,852✔
1239
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
25,408,897✔
1240
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
13,529,307✔
1241
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
1242
      rsp->verTime = 0;
×
1243
    } else {
1244
      rsp->verTime = taosGetTimestampUs();
13,527,580✔
1245
    }
1246
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
13,529,433✔
1247
    code = TSDB_CODE_SUCCESS;
13,530,707✔
1248
    goto end;
13,530,707✔
1249
  }
1250
  STREAM_CHECK_RET_GOTO(code);
11,879,590✔
1251

1252
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
11,879,590✔
1253
  while (1) {
58,454,755✔
1254
    code = walNextValidMsg(pWalReader, true);
70,333,865✔
1255
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
70,331,991✔
1256
      rsp->verTime = taosGetTimestampUs();
11,876,640✔
1257
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
11,876,640✔
1258
      code = TSDB_CODE_SUCCESS;
11,876,640✔
1259
      goto end;
11,876,640✔
1260
    }
1261
    STREAM_CHECK_RET_GOTO(code);
58,455,106✔
1262
    rsp->ver = pWalReader->curVersion;
58,455,106✔
1263
    SWalCont* wCont = &pWalReader->pHead->head;
58,454,543✔
1264
    rsp->verTime = wCont->ingestTs;
58,455,376✔
1265
    if (wCont->ingestTs / 1000 > ctime) break;
58,458,610✔
1266
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
58,458,123✔
1267
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
58,345,232✔
1268
    int64_t ver = wCont->version;
58,457,367✔
1269

1270
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
58,455,998✔
1271
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1272
    if (wCont->msgType == TDMT_VND_SUBMIT) {
58,458,569✔
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) {
57,894,355✔
1275
        rsp->ver--;
2,950✔
1276
        break;
2,950✔
1277
      }
1278
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
57,891,405✔
1279
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
57,890,851✔
1280
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
57,890,851✔
1281
    } else {
1282
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
566,106✔
1283
    }
1284

1285
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
58,452,297✔
1286
      break;
×
1287
    }
1288
  }
1289

1290
end:
25,410,297✔
1291
  walCloseReader(pWalReader);
25,410,297✔
1292
  return code;
25,410,297✔
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) {
45,444,516✔
1296
  int32_t     code = 0;
45,444,516✔
1297
  int32_t     lino = 0;
45,444,516✔
1298
  SMetaReader mr = {0};
45,444,516✔
1299
  SArray* tagCache = NULL;
45,449,204✔
1300
  char* data = NULL;
45,449,579✔
1301

1302
  if (lock != NULL) taosWLockLatch(lock);
45,449,622✔
1303
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
45,462,699✔
1304
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,601,469✔
1305
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,601,469✔
1306
  if (uidData == NULL) {
2,601,469✔
1307
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,578,395✔
1308
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,578,395✔
1309
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,578,395✔
1310
      taosArrayDestroy(tagCache);
×
1311
      code = terrno;
×
1312
      goto end;
×
1313
    }
1314
  } else {
1315
    tagCache = *(SArray**)uidData;
23,074✔
1316
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
23,074✔
1317
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
23,074✔
1318
  }
1319
  
1320
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,601,469✔
1321
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,601,469✔
1322
  api->metaReaderFn.readerReleaseLock(&mr);
2,600,354✔
1323
  STREAM_CHECK_RET_GOTO(code);
2,600,736✔
1324
  
1325
  for (int32_t j = 0; j < numOfExpr; ++j) {
8,912,624✔
1326
    const SExprInfo* pExpr1 = &pExprInfo[j];
6,319,876✔
1327
    int32_t functionId = pExpr1->pExpr->_function.functionId;
6,319,525✔
1328
    col_id_t cid = 0;
6,320,186✔
1329
    // this is to handle the tbname
1330
    if (fmIsScanPseudoColumnFunc(functionId)) {
6,320,186✔
1331
      int32_t fType = pExpr1->pExpr->_function.functionType;
760,347✔
1332
      if (fType == FUNCTION_TYPE_TBNAME) {
760,347✔
1333
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
760,347✔
1334
        STREAM_CHECK_NULL_GOTO(data, terrno);
760,347✔
1335
        STR_TO_VARSTR(data, mr.me.name)
760,347✔
1336
      }
1337
      cid = -1;
760,070✔
1338
    } else {  // these are tags
1339
      const char* p = NULL;
5,559,599✔
1340
      char* pData = NULL;
5,559,599✔
1341
      int8_t type = pExpr1->base.resSchema.type;
5,559,599✔
1342
      int32_t len = pExpr1->base.resSchema.bytes;
5,559,180✔
1343
      STagVal tagVal = {0};
5,559,839✔
1344
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
5,559,420✔
1345
      cid = tagVal.cid;
5,559,509✔
1346
      if (colId != 0 && cid != colId) {
5,559,509✔
1347
        continue;
1,492✔
1348
      }
1349
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
5,558,017✔
1350

1351
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
5,556,107✔
1352
        pData = tTagValToData((const STagVal*)p, false);
5,552,957✔
1353
      } else {
1354
        pData = (char*)p;
3,150✔
1355
      }
1356

1357
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
5,557,530✔
1358
        if (type == TSDB_DATA_TYPE_JSON) {
2,780,750✔
1359
          len = getJsonValueLen(pData);
×
1360
        }
1361
        data = taosMemoryCalloc(1, len);
2,780,750✔
1362
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,781,031✔
1363
        (void)memcpy(data, pData, len);
2,781,031✔
1364
      } else {
1365
        data = pData;
2,776,780✔
1366
      }
1367
    }
1368
    if (uidData == NULL){
6,317,341✔
1369
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
12,547,342✔
1370
    } else {
1371
      void* pre = taosArrayGetP(tagCache, j);
44,174✔
1372
      taosMemoryFree(pre);
44,174✔
1373
      taosArraySet(tagCache, j, &data);
44,174✔
1374
    }
1375
    data = NULL;
6,317,881✔
1376
  }
1377

1378
end:
45,460,663✔
1379
  taosMemoryFree(data);
45,460,007✔
1380
  api->metaReaderFn.clearReader(&mr);
45,445,202✔
1381
  if (lock != NULL) taosWUnLockLatch(lock);
45,445,077✔
1382
  return code;
45,452,908✔
1383
}
1384

1385
int32_t fillTag(SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr,
349,710,362✔
1386
                uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, SRWLatch* lock) {
1387
  int32_t     code = 0;
349,710,362✔
1388
  int32_t     lino = 0;
349,710,362✔
1389
  SArray* tagCache = NULL;
349,710,362✔
1390
  if (numOfExpr == 0) {
349,710,362✔
1391
    return TSDB_CODE_SUCCESS;
42,211,030✔
1392
  }
1393

1394
  taosRLockLatch(lock);
307,499,332✔
1395
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
307,517,617✔
1396
  if (uidData == NULL) {
307,504,442✔
1397
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1398
  } else {
1399
    tagCache = *(SArray**)uidData;
307,504,442✔
1400
    if(taosArrayGetSize(tagCache) != numOfExpr) {
307,510,810✔
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) {
1,005,550,378✔
1407
    const SExprInfo* pExpr1 = &pExprInfo[j];
698,030,191✔
1408
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
698,033,226✔
1409

1410
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
698,042,621✔
1411
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
698,030,514✔
1412
    int32_t functionId = pExpr1->pExpr->_function.functionId;
698,030,514✔
1413

1414
    // this is to handle the tbname
1415
    if (fmIsScanPseudoColumnFunc(functionId)) {
697,928,223✔
1416
      int32_t fType = pExpr1->pExpr->_function.functionType;
4,233,955✔
1417
      if (fType == FUNCTION_TYPE_TBNAME) {
4,233,685✔
1418
        pColInfoData->info.colId = -1;
4,233,685✔
1419
      }
1420
    } 
1421
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
697,994,516✔
1422

1423
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
697,996,501✔
1424
    if (isNullVal) {
697,999,401✔
1425
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1426
    } else {
1427
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
697,999,401✔
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);
694,575,043✔
1433
      STREAM_CHECK_RET_GOTO(code);
698,036,255✔
1434
    }
1435
  }
1436
end:
307,520,187✔
1437
  taosRUnLockLatch(lock);
307,520,534✔
1438
  return code;
307,516,759✔
1439
}
1440

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

1446
  void* pTask = info->pTask;
4,109,922✔
1447
  ST_TASK_DLOG("%s start. rows:%" PRIu32 ",uid:%"PRIu64, __func__,  numOfRows, uid);
4,110,459✔
1448
  
1449
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
4,109,919✔
1450
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
4,110,462✔
1451
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
4,110,192✔
1452
  
1453
  code = fillTag(metaCache, pExprInfo, numOfExpr, uid, pBlock, currentRow, numOfRows, numOfBlocks, &info->lock);
4,110,192✔
1454
  STREAM_CHECK_RET_GOTO(code);
4,111,002✔
1455

1456
end:
4,111,002✔
1457
  return code;
4,111,002✔
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) {
24,061,524✔
1506
  int32_t code = 0;
24,061,524✔
1507
  int32_t lino = 0;
24,061,524✔
1508
  int64_t id[2] = {suid, uid};
24,061,524✔
1509
  taosRLockLatch(&sStreamReaderInfo->lock);
24,061,524✔
1510
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
24,061,524✔
1511
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
24,061,524✔
1512
  SSHashObj* uInfo = *(SSHashObj **)px;
24,061,524✔
1513
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
24,061,524✔
1514
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
24,061,524✔
1515
  if (tmp != NULL) {
24,061,254✔
1516
    *colId = *tmp;
22,089,721✔
1517
  } else {
1518
    *colId = -1;
1,971,533✔
1519
  }
1520

1521
end:
24,061,524✔
1522
  taosRUnLockLatch(&sStreamReaderInfo->lock);
24,061,254✔
1523
  return code;
24,061,254✔
1524
}
1525

1526
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
11,549,543✔
1527
  int32_t code = 0;
11,549,543✔
1528
  int32_t lino = 0;
11,549,543✔
1529
  int64_t id = suid != 0 ? suid : uid;
11,549,543✔
1530
  if (sStreamReaderInfo->isVtableStream) {
11,549,543✔
1531
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
7,731,394✔
1532
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
7,731,394✔
1533
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
70,224✔
1534
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
70,224✔
1535
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
70,224✔
1536
      if (code != 0) {
70,224✔
1537
        taosMemoryFree(*schema);
×
1538
        goto end;
×
1539
      }
1540
    } else {
1541
      *schema = *schemaTmp;
7,661,170✔
1542
    }
1543
  } else {
1544
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
3,817,342✔
1545
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
110,961✔
1546
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
110,961✔
1547
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
110,961✔
1548
    }
1549
    *schema = sStreamReaderInfo->triggerTableSchema;
3,818,956✔
1550
  }
1551
  
1552
end:
11,550,076✔
1553
  return code;
11,550,346✔
1554
}
1555

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

1565
  if (tStartDecode(pCoder) < 0) {
12,531,629✔
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};
12,532,144✔
1572
  uint8_t       version = 0;
12,531,334✔
1573
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
12,532,957✔
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;
12,532,957✔
1579
  submitTbData.flags = submitTbData.flags & 0xff;
12,532,957✔
1580
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1581
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
12,532,957✔
1582
    if (tStartDecode(pCoder) < 0) {
65,879✔
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);
65,879✔
1588
  }
1589

1590
  // submit data
1591
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
12,531,604✔
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) {
12,531,337✔
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);
12,531,337✔
1603

1604
  if (rsp->uidHash != NULL) {
12,531,337✔
1605
    uint64_t* gid = tSimpleHashGet(rsp->uidHash, &submitTbData.uid, LONG_BYTES);
9,464,316✔
1606
    STREAM_CHECK_CONDITION_GOTO(gid == NULL, TDB_CODE_SUCCESS);
9,464,586✔
1607
    ST_TASK_DLOG("%s get uid gid from uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, submitTbData.uid, submitTbData.suid, *gid);
9,464,586✔
1608
    id = *gid;
9,464,586✔
1609
  } else {
1610
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
3,068,368✔
1611
  }
1612

1613
  walMeta.id = id;
11,549,536✔
1614
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
11,549,536✔
1615

1616
  if (ranges != NULL){
11,550,083✔
1617
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
9,464,586✔
1618
    if (timerange == NULL) goto end;;
9,464,586✔
1619
    int64_t* pRange = (int64_t*)timerange;
9,464,586✔
1620
    window.skey = pRange[0];
9,464,586✔
1621
    window.ekey = pRange[1];
9,464,586✔
1622
    ST_TASK_DLOG("%s get time range from ranges, uid:%" PRId64 ", suid:%" PRId64 ", gid:%" PRIu64 ", skey:%" PRId64 ", ekey:%" PRId64,
9,463,776✔
1623
      __func__, submitTbData.uid, submitTbData.suid, id, window.skey, window.ekey);
1624
  }
1625
  
1626
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
11,550,623✔
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;
11,550,623✔
1633
  STREAM_CHECK_RET_GOTO(getSchemas(pVnode, submitTbData.suid, submitTbData.uid, submitTbData.sver, sStreamReaderInfo, &schema));
11,549,273✔
1634

1635
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
11,549,806✔
1636
  int32_t blockStart = 0;
11,550,626✔
1637
  int32_t numOfRows = 0;
11,550,626✔
1638
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
11,550,086✔
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;
11,550,086✔
1722
    if (tDecodeU64v(pCoder, &nRow) < 0) {
11,548,466✔
1723
      code = TSDB_CODE_INVALID_MSG;
×
1724
      TSDB_CHECK_CODE(code, lino, end);
×
1725
    }
1726
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
24,707,978✔
1727
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
13,158,374✔
1728
      pCoder->pos += pRow->len;
13,159,724✔
1729

1730
      if (iRow == 0){
13,159,724✔
1731
#ifndef NO_UNALIGNED_ACCESS
1732
        walMeta.skey = pRow->ts;
11,550,086✔
1733
#else
1734
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1735
#endif
1736
      }
1737
      if (iRow == nRow - 1) {
13,159,187✔
1738
#ifndef NO_UNALIGNED_ACCESS
1739
        walMeta.ekey = pRow->ts;
11,547,929✔
1740
#else
1741
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1742
#endif
1743
      }
1744

1745
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
13,159,727✔
1746
        continue;
10,450✔
1747
      }
1748
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
13,147,390✔
1749
      blockStart = pSlice->currentRowIdx;
13,147,149✔
1750
     
1751
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
81,522,718✔
1752
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
68,370,634✔
1753
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
68,372,818✔
1754
        if (pColData->info.colId <= -1) {
68,372,818✔
1755
          pColData->hasNull = true;
23,244,865✔
1756
          continue;
23,244,865✔
1757
        }
1758
        int16_t colId = 0;
45,136,888✔
1759
        if (sStreamReaderInfo->isVtableStream){
45,137,155✔
1760
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
24,061,254✔
1761
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
24,058,782✔
1762
        } else {
1763
          colId = pColData->info.colId;
21,075,343✔
1764
        }
1765
        
1766
        SColVal colVal = {0};
45,134,370✔
1767
        int32_t sourceIdx = 0;
45,137,944✔
1768
        while (1) {
1769
          if (sourceIdx >= schema->numOfCols) {
122,899,497✔
1770
            break;
10,219,100✔
1771
          }
1772
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
112,709,018✔
1773
          if (colVal.cid == colId) {
112,679,013✔
1774
            break;
34,917,460✔
1775
          }
1776
          sourceIdx++;
77,761,553✔
1777
        }
1778
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
45,136,560✔
1779
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
32,292,033✔
1780
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
50,607✔
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, 
50,336✔
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)));
32,241,426✔
1785
          }
1786
        } else {
1787
          colDataSetNULL(pColData, blockStart + numOfRows);
12,844,527✔
1788
        }
1789
      }
1790
      
1791
      numOfRows++;
13,149,062✔
1792
    }
1793
  }
1794

1795
  if (numOfRows > 0) {
11,549,604✔
1796
    if (!sStreamReaderInfo->isVtableStream) {
11,549,604✔
1797
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, rsp->isCalc, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
3,818,210✔
1798
    }
1799
    
1800
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
11,550,385✔
1801
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
11,550,477✔
1802
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
11,550,477✔
1803

1804
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
11,548,812✔
1805
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
11,548,812✔
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;
11,548,812✔
1809
    pBlock->info.rows += numOfRows;
11,550,382✔
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;
11,549,038✔
1816

1817
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
2,085,262✔
1818
  if (data != NULL) {
2,085,259✔
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)));
2,085,259✔
1823
  }
1824

1825
end:
12,528,370✔
1826
  if (code != 0) {                                                             \
12,532,147✔
1827
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
241✔
1828
  }
1829
  tEndDecode(pCoder);
12,532,147✔
1830
  return code;
12,532,951✔
1831
}
1832
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
12,530,246✔
1833
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1834
  int32_t  code = 0;
12,530,246✔
1835
  int32_t  lino = 0;
12,530,246✔
1836
  SDecoder decoder = {0};
12,530,246✔
1837
  SSHashObj* gidHash = NULL;
12,531,070✔
1838
  void* pTask = sStreamReaderInfo->pTask;
12,531,070✔
1839

1840
  tDecoderInit(&decoder, data, len);
12,531,340✔
1841
  if (tStartDecode(&decoder) < 0) {
12,532,411✔
1842
    code = TSDB_CODE_INVALID_MSG;
×
1843
    TSDB_CHECK_CODE(code, lino, end);
×
1844
  }
1845

1846
  uint64_t nSubmitTbData = 0;
12,531,867✔
1847
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
12,530,806✔
1848
    code = TSDB_CODE_INVALID_MSG;
×
1849
    TSDB_CHECK_CODE(code, lino, end);
×
1850
  }
1851

1852
  if (rsp->metaBlock != NULL){
12,530,806✔
1853
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,067,030✔
1854
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
3,066,754✔
1855
  }
1856

1857
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
25,064,050✔
1858
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
12,531,607✔
1859
  }
1860

1861
  tEndDecode(&decoder);
12,532,443✔
1862

1863
  if (rsp->metaBlock != NULL){
12,531,900✔
1864
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
3,068,394✔
1865
    int32_t iter = 0;
3,067,314✔
1866
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
3,067,314✔
1867
    while (px != NULL) {
5,152,312✔
1868
      WalMetaResult* pMeta = (WalMetaResult*)px;
2,085,262✔
1869
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
2,085,262✔
1870
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
2,085,796✔
1871
      rsp->totalRows++;
2,085,796✔
1872
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
2,086,066✔
1873
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1874
      px = tSimpleHashIterate(gidHash, px, &iter);
2,086,066✔
1875
    }
1876
  }
1877
  
1878

1879
end:
12,527,777✔
1880
  tSimpleHashCleanup(gidHash);
12,531,607✔
1881
  tDecoderClear(&decoder);
12,532,466✔
1882
  return code;
12,532,414✔
1883
}
1884

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

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

1896
  SSubmitTbData submitTbData = {0};
15,048,086✔
1897
  uint8_t       version = 0;
15,047,558✔
1898
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
15,047,825✔
1899
    code = TSDB_CODE_INVALID_MSG;
×
1900
    TSDB_CHECK_CODE(code, lino, end);
×
1901
  }
1902
  version = (submitTbData.flags >> 8) & 0xff;
15,047,825✔
1903
  submitTbData.flags = submitTbData.flags & 0xff;
15,047,825✔
1904

1905
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1906
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
15,047,825✔
1907
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,132,434✔
1908
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,131,887✔
1909
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,131,887✔
1910
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
1,132,166✔
1911
  }
1912

1913
  // submit data
1914
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
15,045,413✔
1915
    code = TSDB_CODE_INVALID_MSG;
×
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  if (tDecodeI64(pCoder, uid) < 0) {
15,043,778✔
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);
15,043,778✔
1923
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
15,043,501✔
1924
  if (rsp->uidHash != NULL) {
11,555,179✔
1925
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
9,464,586✔
1926
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
9,464,316✔
1927
  }
1928
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
11,553,815✔
1929

1930
  if (ranges != NULL){
11,553,815✔
1931
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
9,463,492✔
1932
    if (timerange == NULL) goto end;;
9,464,586✔
1933
    int64_t* pRange = (int64_t*)timerange;
9,464,586✔
1934
    window.skey = pRange[0];
9,464,586✔
1935
    window.ekey = pRange[1];
9,464,586✔
1936
  }
1937
  
1938
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
11,555,176✔
1939
    code = TSDB_CODE_INVALID_MSG;
×
1940
    TSDB_CHECK_CODE(code, lino, end);
×
1941
  }
1942

1943
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
11,555,176✔
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;
11,555,176✔
1970
    if (tDecodeU64v(pCoder, &nRow) < 0) {
11,554,087✔
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) { 
11,554,087✔
1976
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
20,212,310✔
1977
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
10,748,911✔
1978
        pCoder->pos += pRow->len;
10,748,626✔
1979
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
10,748,911✔
1980
          continue;
10,720✔
1981
        }
1982
        (*numOfRows)++;
10,738,461✔
1983
      }
1984
    } else {
1985
      (*numOfRows) = nRow;
2,090,148✔
1986
    }
1987
  }
1988
  
1989
end:
15,047,377✔
1990
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
15,046,211✔
1991
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
15,045,759✔
1992
  tEndDecode(pCoder);
15,045,212✔
1993
  return code;
15,046,190✔
1994
}
1995

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

2002
  tDecoderInit(&decoder, data, len);
15,047,548✔
2003
  if (tStartDecode(&decoder) < 0) {
15,047,018✔
2004
    code = TSDB_CODE_INVALID_MSG;
×
2005
    TSDB_CHECK_CODE(code, lino, end);
×
2006
  }
2007

2008
  uint64_t nSubmitTbData = 0;
15,047,580✔
2009
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
15,046,035✔
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);
15,046,035✔
2014

2015
  for (int32_t i = 0; i < nSubmitTbData; i++) {
30,091,084✔
2016
    uint64_t gid = -1;
15,045,950✔
2017
    int64_t  uid = 0;
15,044,860✔
2018
    int32_t numOfRows = 0;
15,046,198✔
2019
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
15,045,931✔
2020
    if (numOfRows <= 0) {
15,047,285✔
2021
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
3,492,646✔
2022
      continue;
3,492,376✔
2023
    }
2024
    rsp->totalRows += numOfRows;
11,554,639✔
2025
    rsp->totalDataRows += numOfRows;
11,554,891✔
2026

2027
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
11,554,624✔
2028
    if (pSlice != NULL) {
11,554,636✔
2029
      pSlice->numRows += numOfRows;
10,686,039✔
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);
10,685,505✔
2031
      pSlice->gId = gid;
10,685,505✔
2032
    } else {
2033
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
868,597✔
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);
869,404✔
2035
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
869,689✔
2036
    } 
2037
  }
2038

2039
  tEndDecode(&decoder);
15,045,134✔
2040

2041
end:
15,047,552✔
2042
  tDecoderClear(&decoder);
15,046,208✔
2043
  return code;
15,047,561✔
2044
}
2045

2046
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
742,551✔
2047
  void*   pe = NULL;
742,551✔
2048
  int32_t iter = 0;
742,551✔
2049
  int32_t index = 0;
742,551✔
2050
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
1,611,685✔
2051
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
869,404✔
2052
    pInfo->startRowIdx = index;
869,404✔
2053
    pInfo->currentRowIdx = index;
869,404✔
2054
    index += pInfo->numRows;
869,134✔
2055
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
1,543,673✔
2056
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2057
  }
2058
}
742,821✔
2059

2060
static void printIndexHash(SSHashObj* indexHash, void* pTask){
742,580✔
2061
  if (qDebugFlag & DEBUG_TRACE) {
742,580✔
2062
    void*   pe = NULL;
10,578✔
2063
    int32_t iter = 0;
10,578✔
2064
    while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
25,150✔
2065
      SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
14,572✔
2066
      ST_TASK_TLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
14,826✔
2067
      pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2068
    }
2069
  }
2070
}
742,580✔
2071

2072
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
14,503✔
2073
  void*   pe = NULL;
14,503✔
2074
  int32_t iter = 0;
14,503✔
2075
  int32_t index = 0;
14,503✔
2076
  int32_t pIndex = 0;
14,503✔
2077
  int8_t* pIndicator = (int8_t*)pRet->pData;
14,503✔
2078
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
30,857✔
2079
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
16,354✔
2080
    pInfo->startRowIdx = index;
16,354✔
2081
    int32_t size = pInfo->numRows;
16,354✔
2082
    for (int32_t i = 0; i < pInfo->numRows; i++) {
223,167✔
2083
      if (pIndicator && !pIndicator[pIndex++]) {
206,813✔
2084
        size--;
69,077✔
2085
      }
2086
    }
2087
    pInfo->numRows = size;
16,354✔
2088
    index += pInfo->numRows;
16,354✔
2089
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
16,354✔
2090
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2091
  }
2092
}
14,503✔
2093

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

2099
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
6,273,739✔
2100
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
6,271,544✔
2101
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
5,534,200✔
2102
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
2103
      resultRsp->verTime = 0;
×
2104
    } else {
2105
      resultRsp->verTime = taosGetTimestampUs();
5,533,681✔
2106
    }
2107
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
5,534,191✔
2108
    code = TSDB_CODE_SUCCESS;
5,535,840✔
2109
    goto end;
5,535,840✔
2110
  }
2111
  STREAM_CHECK_RET_GOTO(code);
737,344✔
2112

2113
  while (1) {
5,793,444✔
2114
    code = walNextValidMsg(pWalReader, true);
6,530,788✔
2115
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
6,529,704✔
2116
      resultRsp->verTime = taosGetTimestampUs();
737,884✔
2117
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
737,884✔
2118
      code = TSDB_CODE_SUCCESS;
737,884✔
2119
      goto end;
737,884✔
2120
    }
2121
    STREAM_CHECK_RET_GOTO(code);
5,791,552✔
2122
    resultRsp->ver = pWalReader->curVersion;
5,791,552✔
2123
    SWalCont* wCont = &pWalReader->pHead->head;
5,793,388✔
2124
    resultRsp->verTime = wCont->ingestTs;
5,792,370✔
2125
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
5,793,454✔
2126
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
5,792,191✔
2127
    int64_t ver = wCont->version;
5,792,000✔
2128
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
5,790,458✔
2129
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2130
    if (wCont->msgType == TDMT_VND_SUBMIT) {
5,792,919✔
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) {
5,583,494✔
2133
        resultRsp->ver--;
×
2134
        break;
×
2135
      }
2136
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
5,583,758✔
2137
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
5,584,295✔
2138
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
5,584,028✔
2139
    } else {
2140
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
209,665✔
2141
    }
2142

2143
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
5,788,703✔
2144
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
5,788,703✔
2145
      break;
2146
    }
2147
  }
2148
  
2149
end:
×
2150
  STREAM_PRINT_LOG_END(code, lino);
6,273,724✔
2151
  return code;
6,274,016✔
2152
}
2153

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

2160
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
28,851,680✔
2161
    int64_t *ver = taosArrayGet(versions, i);
9,464,586✔
2162
    if (ver == NULL) continue;
9,464,586✔
2163

2164
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
9,464,586✔
2165
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
9,464,316✔
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));
9,464,316✔
2171

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

2176
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
9,464,319✔
2177
  }
2178
  
2179
end:
19,386,318✔
2180
  return code;
19,386,318✔
2181
}
2182

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

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

2191
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
742,580✔
2192
    filterIndexHash(resultRsp->indexHash, pRet);
14,503✔
2193
  }
2194

2195
end:
742,310✔
2196
  colDataDestroy(pRet);
742,580✔
2197
  taosMemoryFree(pRet);
742,580✔
2198
  return code;
742,580✔
2199
}
2200

2201
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
6,273,492✔
2202
                                    SSTriggerWalNewRsp* resultRsp) {
2203
  int32_t      code = 0;
6,273,492✔
2204
  int32_t      lino = 0;
6,273,492✔
2205
  void* pTask = sStreamReaderInfo->pTask;
6,273,492✔
2206
                                        
2207
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
6,273,666✔
2208
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
6,270,631✔
2209
  blockDataEmpty(resultRsp->dataBlock);
6,270,631✔
2210
  blockDataEmpty(resultRsp->metaBlock);
6,269,252✔
2211
  int64_t lastVer = resultRsp->ver;                                      
6,269,550✔
2212
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
6,269,820✔
2213
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
6,274,286✔
2214

2215
  buildIndexHash(resultRsp->indexHash, pTask);
173,508✔
2216
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
173,508✔
2217
  while(lastVer < resultRsp->ver) {
3,293,860✔
2218
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
3,121,351✔
2219
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
3,120,570✔
2220
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
52,983✔
2221
      continue;
52,983✔
2222
    }
2223
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
3,067,857✔
2224
    SWalCont* wCont = &pWalReader->pHead->head;
3,067,584✔
2225
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
3,067,854✔
2226
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
3,068,095✔
2227
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
3,068,095✔
2228
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
3,068,095✔
2229
  }
2230

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

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

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

2247
  void* pTask = sStreamReaderInfo->pTask;
19,387,442✔
2248
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
19,387,918✔
2249
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
19,386,000✔
2250
  
2251
  if (taosArrayGetSize(versions) > 0) {
19,386,000✔
2252
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
569,313✔
2253
  }
2254
  
2255
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
19,386,000✔
2256
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
19,386,318✔
2257

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

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

2264
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
10,032,819✔
2265
    int64_t *ver = taosArrayGet(versions, i);
9,463,776✔
2266
    if (ver == NULL) continue;
9,464,046✔
2267
    ST_TASK_TLOG("vgId:%d %s scan wal process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, *ver, walGetAppliedVer(pWalReader->pWal));
9,464,046✔
2268

2269
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
9,464,046✔
2270
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
9,464,316✔
2271
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
2272
      continue;
×
2273
    }
2274
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
9,464,316✔
2275
    SWalCont* wCont = &pWalReader->pHead->head;
9,463,776✔
2276
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
9,464,316✔
2277
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
9,463,222✔
2278

2279
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
9,464,586✔
2280
  }
2281
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2282
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
569,313✔
2283
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
569,313✔
2284

2285
end:
19,384,670✔
2286
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
19,384,670✔
2287
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
2288
  walCloseReader(pWalReader);
19,385,494✔
2289
  return code;
19,387,648✔
2290
}
2291

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

2302
  SSchemaWrapper* sSchemaWrapper = NULL;
630,334✔
2303
  if (metaReader.me.type == TD_CHILD_TABLE) {
630,334✔
2304
    int64_t suid = metaReader.me.ctbEntry.suid;
630,334✔
2305
    tDecoderClear(&metaReader.coder);
630,334✔
2306
    STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, suid));
630,334✔
2307
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
630,334✔
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++) {
3,733,359✔
2315
    SSchema* s = sSchemaWrapper->pSchema + j;
3,103,025✔
2316
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
6,206,050✔
2317
  }
2318

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

2329
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
630,334✔
2330
  int32_t code = 0;
630,334✔
2331
  int32_t lino = 0;
630,334✔
2332
  size_t  schemaLen = taosArrayGetSize(schemas);
630,334✔
2333
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
630,334✔
2334
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
2,471,515✔
2335
    col_id_t* id = taosArrayGet(cols, i);
1,841,181✔
2336
    STREAM_CHECK_NULL_GOTO(id, terrno);
1,841,181✔
2337
    for (size_t i = 0; i < schemaLen; i++) {
4,829,596✔
2338
      SSchema* s = taosArrayGet(schemas, i);
4,829,596✔
2339
      STREAM_CHECK_NULL_GOTO(s, terrno);
4,829,596✔
2340
      if (*id == s->colId) {
4,829,596✔
2341
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
1,841,181✔
2342
        break;
1,841,181✔
2343
      }
2344
    }
2345
  }
2346
  taosArrayPopFrontBatch(schemas, schemaLen);
630,334✔
2347

2348
end:
630,334✔
2349
  return code;
630,334✔
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,
607,463✔
2476
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
2477
  int32_t code = 0;
607,463✔
2478
  int32_t lino = 0;
607,463✔
2479
  void* pTask = sStreamReaderCalcInfo->pTask;
607,463✔
2480
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
607,463✔
2481
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
607,463✔
2482
  
2483
  if (req->pStRtFuncInfo->withExternalWindow) {
607,463✔
2484
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
446,916✔
2485
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
446,916✔
2486
    sStreamReaderCalcInfo->tmpRtFuncInfo.isWindowTrigger = req->pStRtFuncInfo->isWindowTrigger;
446,916✔
2487
    sStreamReaderCalcInfo->tmpRtFuncInfo.precision = req->pStRtFuncInfo->precision;
446,916✔
2488

2489
    SSTriggerCalcParam* pFirst = NULL;
446,916✔
2490
    SSTriggerCalcParam* pLast = NULL;
446,916✔
2491
    if (req->pStRtFuncInfo->isMultiGroupCalc) {
446,916✔
2492
      SSTriggerGroupReadInfo* pGrp = taosArrayGet(req->pStRtFuncInfo->curGrpRead, 0);
×
2493
      pFirst = &pGrp->firstParam;
×
2494
      pLast = &pGrp->lastParam;
×
2495
    } else {
2496
      pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
446,916✔
2497
      pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
446,916✔
2498
      STREAM_CHECK_NULL_GOTO(pFirst, terrno);
446,916✔
2499
      STREAM_CHECK_NULL_GOTO(pLast, terrno);
446,916✔
2500
    }
2501

2502
    if (!node->needCalc) {
446,916✔
2503
      pWin->skey = pFirst->wstart;
334,886✔
2504
      pWin->ekey = pLast->wend;
334,886✔
2505
      *pValid = true;
334,886✔
2506
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
334,886✔
2507
        pWin->ekey--;
188,301✔
2508
      }
2509
    } else {
2510
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
112,030✔
2511
      memcpy(pTmp, pFirst, sizeof(*pTmp));
112,030✔
2512

2513
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
112,030✔
2514
      if (*pValid) {
112,030✔
2515
        int64_t skey = pWin->skey;
112,030✔
2516

2517
        memcpy(pTmp, pLast, sizeof(*pTmp));
112,030✔
2518
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
112,030✔
2519

2520
        if (*pValid) {
112,030✔
2521
          pWin->skey = skey;
112,030✔
2522
        }
2523
      }
2524
      pWin->ekey--;
112,030✔
2525
    }
2526
  } else {
2527
    if (!node->needCalc) {
160,547✔
2528
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
112,041✔
2529
      pWin->skey = pCurr->wstart;
112,041✔
2530
      pWin->ekey = pCurr->wend;
112,041✔
2531
      *pValid = true;
112,041✔
2532
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
112,041✔
2533
        pWin->ekey--;
57,215✔
2534
      }
2535
    } else {
2536
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
48,506✔
2537
      pWin->ekey--;
48,506✔
2538
    }
2539
  }
2540

2541
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
607,463✔
2542
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
2543

2544
end:
5,388✔
2545

2546
  if (code) {
607,463✔
2547
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
2548
  }
2549
  
2550
  return code;
607,463✔
2551
}
2552

2553
static int32_t createDataBlockTsUid(SSDataBlock** pBlockRet, uint32_t numOfRows) {
630,487✔
2554
  int32_t      code = 0;
630,487✔
2555
  int32_t      lino = 0;
630,487✔
2556
  SSDataBlock* pBlock = NULL;
630,487✔
2557
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
630,727✔
2558
  SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID);
630,727✔
2559
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
630,727✔
2560
  idata = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID + 1);
630,457✔
2561
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
630,727✔
2562
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, numOfRows));
630,727✔
2563

2564
end:
630,727✔
2565
  STREAM_PRINT_LOG_END(code, lino)
630,727✔
2566
  if (code != TSDB_CODE_SUCCESS) {
630,727✔
2567
    blockDataDestroy(pBlock);
×
2568
    pBlock = NULL;
×
2569
  }
2570
  *pBlockRet = pBlock;
630,727✔
2571
  return code;
630,727✔
2572
}
2573

2574
static int32_t processTsOutPutAllTables(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
370,492✔
2575
  int32_t code = 0;
370,492✔
2576
  int32_t lino = 0;
370,492✔
2577
  void* pTask = sStreamReaderInfo->pTask;
370,492✔
2578

2579
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
370,492✔
2580
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
370,492✔
2581
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
370,492✔
2582
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
370,492✔
2583
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
1,032,750✔
2584
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
1,324,516✔
2585
      continue;
×
2586
    }
2587
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
662,258✔
2588
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
662,258✔
2589
    if (order == TSDB_ORDER_ASC) {
662,258✔
2590
      tsInfo->ts = INT64_MAX;
345,669✔
2591
    } else {
2592
      tsInfo->ts = INT64_MIN;
316,589✔
2593
    }
2594
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
662,258✔
2595
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
662,258✔
2596
      tsInfo->ts = ts;
345,669✔
2597
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
316,589✔
2598
      tsInfo->ts = ts;
316,589✔
2599
    }
2600
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
662,258✔
2601
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
662,258✔
2602
  }
2603

2604
end:
370,492✔
2605
  return code;
370,492✔
2606
}
2607

2608
static int32_t processTsOutPutOneGroup(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
124,859✔
2609
  int32_t code = 0;
124,859✔
2610
  int32_t lino = 0;
124,859✔
2611
  void* pTask = sStreamReaderInfo->pTask;
124,859✔
2612

2613
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
124,859✔
2614
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
124,589✔
2615
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
124,319✔
2616
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
124,859✔
2617
  if (order == TSDB_ORDER_ASC) {
124,859✔
2618
    tsInfo->ts = INT64_MAX;
95,190✔
2619
  } else {
2620
    tsInfo->ts = INT64_MIN;
29,669✔
2621
  }
2622

2623
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
124,589✔
2624
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
124,859✔
2625
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
266,944✔
2626
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
285,250✔
2627
      continue;
×
2628
    }
2629
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
142,355✔
2630
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
141,818✔
2631
      tsInfo->ts = ts;
95,190✔
2632
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
46,091✔
2633
      tsInfo->ts = ts;
29,669✔
2634
    }
2635
  }
2636
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
124,589✔
2637
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
124,859✔
2638
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
124,859✔
2639

2640
end:
35,241✔
2641
  return code;
124,859✔
2642
}
2643

2644
static int32_t processTsOutPutAllGroups(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
9,728✔
2645
  int32_t code = 0;
9,728✔
2646
  int32_t lino = 0;
9,728✔
2647
  STableKeyInfo* pList = NULL;
9,728✔
2648
  StreamTableListInfo     tableInfo = {0};
9,728✔
2649

2650
  void* pTask = sStreamReaderInfo->pTask;
9,728✔
2651
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
9,728✔
2652

2653
  SSHashObj*   uidTsHash = tSimpleHashInit(pResBlock->info.rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
9,728✔
2654
  STREAM_CHECK_NULL_GOTO(uidTsHash, terrno);
9,728✔
2655
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
9,728✔
2656
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
9,728✔
2657
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
30,508✔
2658
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
41,560✔
2659
      continue;
×
2660
    }
2661
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
20,780✔
2662
    int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
20,780✔
2663
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(uidTsHash, &uid, LONG_BYTES, &ts, LONG_BYTES));
20,780✔
2664
  }
2665
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(sStreamReaderInfo), sizeof(STsInfo));
9,728✔
2666
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
9,728✔
2667
  while (true) {
19,848✔
2668
    int32_t        pNum = 0;
29,576✔
2669
    int64_t        suid = 0;
29,576✔
2670
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
29,576✔
2671
    if(pNum == 0) break;
29,576✔
2672
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
20,540✔
2673
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
20,540✔
2674
    if (order == TSDB_ORDER_ASC) {
20,540✔
2675
      tsInfo->ts = INT64_MAX;
9,700✔
2676
    } else {
2677
      tsInfo->ts = INT64_MIN;
10,840✔
2678
    }
2679
    for (int32_t i = 0; i < pNum; i++) {
40,838✔
2680
      int64_t uid = pList[i].uid;
20,990✔
2681
      int64_t *ts = tSimpleHashGet(uidTsHash, &uid, LONG_BYTES);
20,990✔
2682
      STREAM_CHECK_NULL_GOTO(ts, terrno);
20,990✔
2683
      if (order == TSDB_ORDER_ASC && *ts < tsInfo->ts) {
20,298✔
2684
        tsInfo->ts = *ts;
9,700✔
2685
      } else if (order == TSDB_ORDER_DESC && *ts > tsInfo->ts) {
10,598✔
2686
        tsInfo->ts = *ts;
10,148✔
2687
      }
2688
    }
2689
    int64_t uid = pList[0].uid;
19,848✔
2690
    tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
19,848✔
2691
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
19,848✔
2692
    taosMemoryFreeClear(pList);
19,848✔
2693
  }
2694

2695
end:
9,728✔
2696
  qStreamDestroyTableInfo(&tableInfo);
9,728✔
2697
  taosMemoryFreeClear(pList);
9,728✔
2698
  tSimpleHashCleanup(uidTsHash);
9,728✔
2699
  return code;
9,728✔
2700
}
2701

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

2704
static int32_t getAllTs(SVnode* pVnode, SSDataBlock*  pResBlock, SStreamReaderTaskInner* pTaskInner, STableKeyInfo* pList, int32_t pNum) {
491,193✔
2705
  int32_t code = 0;
491,193✔
2706
  int32_t lino = 0;
491,193✔
2707

2708
  stDebug("%s getAllTs enter: pNum:%d suid:%"PRId64" order:%d skey:%"PRId64" ekey:%"PRId64" verRange:[%"PRId64",%"PRId64"]",
491,193✔
2709
          pTaskInner->idStr, pNum, pTaskInner->options->suid, pTaskInner->options->order,
2710
          pTaskInner->options->twindows.skey, pTaskInner->options->twindows.ekey,
2711
          (int64_t)-1, pTaskInner->options->ver);
2712
  for (int32_t i = 0; i < pNum; i++) {
1,817,560✔
2713
    stDebug("%s getAllTs table[%d]: uid:%"PRId64, pTaskInner->idStr, i, pList[i].uid);
1,326,367✔
2714
  }
2715

2716
  STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdCreateFirstLastTsIter(pVnode, &pTaskInner->options->twindows, &(SVersionRange){.minVer = -1, .maxVer = pTaskInner->options->ver},
491,193✔
2717
                                                pTaskInner->options->suid, pList, pNum, pTaskInner->options->order, &pTaskInner->pReader, pTaskInner->idStr));
2718
  bool hasNext = true;
490,923✔
2719
  int32_t iterCount = 0;
491,193✔
2720
  while(1){
2721
    STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdNextFirstLastTsBlock(pTaskInner->pReader, pResBlock, &hasNext));
491,193✔
2722
    stDebug("%s getAllTs iter[%d]: hasNext:%d pResBlock->info.rows:%"PRId64, pTaskInner->idStr, iterCount++, hasNext, pResBlock->info.rows);
490,923✔
2723
    STREAM_CHECK_CONDITION_GOTO(!hasNext, TDB_CODE_SUCCESS);
490,923✔
2724
  }
2725

2726
end:
490,923✔
2727
  stDebug("%s getAllTs done: code:%d pResBlock->info.rows:%"PRId64, pTaskInner->idStr, code, pResBlock ? pResBlock->info.rows : -1);
490,923✔
2728
  pTaskInner->storageApi->tsdReader.tsdDestroyFirstLastTsIter(pTaskInner->pReader);
490,923✔
2729
  pTaskInner->pReader = NULL;
490,653✔
2730
  return code;
490,653✔
2731
}
2732

2733
static int32_t processTsVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
298,767✔
2734
                                  SStreamReaderTaskInner* pTaskInner) {
2735
  int32_t code = 0;
298,767✔
2736
  int32_t lino = 0;
298,767✔
2737
  STableKeyInfo* pList = NULL;
298,767✔
2738
  StreamTableListInfo     tableInfo = {0};
298,767✔
2739

2740
  void* pTask = sStreamReaderInfo->pTask;
298,767✔
2741
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
298,767✔
2742

2743
  SSDataBlock*  pResBlock = NULL;
298,767✔
2744
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, qStreamGetTableListNum(sStreamReaderInfo)));
298,767✔
2745

2746
  while (true) {
158,963✔
2747
    int32_t        pNum = 0;
457,730✔
2748
    int64_t        suid = 0;
457,730✔
2749
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
457,730✔
2750
    if(pNum == 0) break;
458,000✔
2751
    pTaskInner->options->suid = suid;
159,233✔
2752
    STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
159,233✔
2753
    taosMemoryFreeClear(pList);
158,963✔
2754
  }
2755

2756
  STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, pTaskInner->options->order));
298,767✔
2757

2758
end:
298,767✔
2759
  qStreamDestroyTableInfo(&tableInfo);
298,767✔
2760
  taosMemoryFreeClear(pList);
298,767✔
2761
  blockDataDestroy(pResBlock);
298,767✔
2762
  STREAM_PRINT_LOG_END_WITHID(code, lino);
298,767✔
2763
  return code;
298,767✔
2764
}
2765

2766
static int32_t processTsNonVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
320,129✔
2767
                                  SStreamReaderTaskInner* pTaskInner) {
2768
  int32_t code = 0;
320,129✔
2769
  int32_t lino = 0;
320,129✔
2770
  STableKeyInfo* pList = NULL;
320,129✔
2771
  void* pTask = sStreamReaderInfo->pTask;
320,129✔
2772

2773
  SSDataBlock*  pResBlock = NULL;
320,129✔
2774

2775
  int32_t        pNum = 0;
320,129✔
2776
  int64_t        suid = 0;
320,129✔
2777
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, 0, &pList, &pNum));
320,129✔
2778
  ST_TASK_DLOG("vgId:%d %s qStreamGetTableList returned pNum:%d", TD_VID(pVnode), __func__, pNum);
319,955✔
2779
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
320,129✔
2780
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
282,839✔
2781

2782
  pTaskInner->options->suid = sStreamReaderInfo->suid;
282,839✔
2783
  ST_TASK_DLOG("vgId:%d %s calling getAllTs: suid:%"PRId64" order:%d skey:%"PRId64" ekey:%"PRId64" ver:%"PRId64,
282,839✔
2784
               TD_VID(pVnode), __func__, pTaskInner->options->suid, pTaskInner->options->order,
2785
               pTaskInner->options->twindows.skey, pTaskInner->options->twindows.ekey, pTaskInner->options->ver);
2786
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
282,839✔
2787
  ST_TASK_DLOG("vgId:%d %s getAllTs done: pResBlock rows:%"PRId64, TD_VID(pVnode), __func__, pResBlock->info.rows);
282,839✔
2788
  int32_t order = pTaskInner->options->order;
282,839✔
2789
  if (pResBlock->info.rows == 0 && sStreamReaderInfo->groupByTbname) {
282,839✔
2790
    tsRsp->tsInfo = taosArrayInit(pNum, sizeof(STsInfo));
42,240✔
2791
    STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
42,240✔
2792
    for (int32_t i = 0; i < pNum; i++) {
156,375✔
2793
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
114,135✔
2794
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno);
114,135✔
2795
      tsInfo->gId = pList[i].uid;
114,135✔
2796
      tsInfo->ts = 0;
114,135✔
2797
      ST_TASK_DLOG("%s no data but return gId (uid):%" PRIu64 " for tbname partition", __func__, tsInfo->gId);
114,135✔
2798
    }
2799
    goto end;
42,240✔
2800
  }
2801

2802
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
240,599✔
2803

2804
  if (sStreamReaderInfo->groupByTbname) {
157,191✔
2805
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
71,725✔
2806
  } else if (sStreamReaderInfo->partitionCols == NULL) {
85,466✔
2807
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
75,738✔
2808
  } else {
2809
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
9,728✔
2810
  }                             
2811
end:
319,881✔
2812
  blockDataDestroy(pResBlock);
320,129✔
2813
  taosMemoryFreeClear(pList);
320,129✔
2814
  STREAM_PRINT_LOG_END_WITHID(code, lino);
320,129✔
2815
  return code;
320,129✔
2816
}
2817

2818
static int32_t processTsOnce(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
65,920✔
2819
                                  SStreamReaderTaskInner* pTaskInner, uint64_t gid) {
2820
  int32_t code = 0;
65,920✔
2821
  int32_t lino = 0;
65,920✔
2822
  STableKeyInfo* pList = NULL;
65,920✔
2823
  void* pTask = sStreamReaderInfo->pTask;
65,920✔
2824
  
2825
  SSDataBlock*  pResBlock = NULL;
65,920✔
2826

2827
  int32_t        pNum = 0;
65,650✔
2828
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
65,920✔
2829
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
65,920✔
2830
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
49,121✔
2831

2832
  pTaskInner->options->suid = sStreamReaderInfo->suid;
48,851✔
2833
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
49,121✔
2834
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
49,121✔
2835
  int32_t order = pTaskInner->options->order;
49,121✔
2836

2837
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
48,851✔
2838
end:
65,920✔
2839
  blockDataDestroy(pResBlock);
65,920✔
2840
  taosMemoryFreeClear(pList);
65,920✔
2841
  STREAM_PRINT_LOG_END_WITHID(code, lino);
65,650✔
2842
  return code;
65,650✔
2843
}
2844

2845
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
618,346✔
2846
                                  SStreamReaderTaskInner* pTaskInner) {
2847
  if (sStreamReaderInfo->isVtableStream) {
618,346✔
2848
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
298,767✔
2849
  }
2850

2851
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
320,129✔
2852
}
2853

2854
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
145,644✔
2855
  int32_t code = 0;
145,644✔
2856
  int32_t lino = 0;
145,644✔
2857
  void*   buf = NULL;
145,644✔
2858
  size_t  size = 0;
145,644✔
2859
  void* pTask = sStreamReaderInfo->pTask;
145,644✔
2860

2861
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d, appver:%"PRId64, TD_VID(pVnode), __func__,
145,889✔
2862
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc), pVnode->state.applied);
2863

2864
  taosWLockLatch(&sStreamReaderInfo->lock);
145,889✔
2865
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
145,889✔
2866
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
145,889✔
2867
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
145,889✔
2868
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
145,889✔
2869

2870
  qStreamClearTableInfo(&sStreamReaderInfo->vSetTableList);
145,889✔
2871
  STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->vSetTableList));
145,889✔
2872
  STREAM_CHECK_RET_GOTO(qBuildVTableList(sStreamReaderInfo));
145,889✔
2873
end:
145,889✔
2874
  taosWUnLockLatch(&sStreamReaderInfo->lock);
145,889✔
2875
  STREAM_PRINT_LOG_END_WITHID(code, lino);
145,889✔
2876
  SRpcMsg rsp = {
145,889✔
2877
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2878
  tmsgSendRsp(&rsp);
145,889✔
2879
  return code;
145,889✔
2880
}
2881

2882
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
352,184✔
2883
  int32_t                 code = 0;
352,184✔
2884
  int32_t                 lino = 0;
352,184✔
2885
  SStreamReaderTaskInner* pTaskInner = NULL;
352,184✔
2886
  SStreamTsResponse       tsRsp = {0};
352,598✔
2887
  void*                   buf = NULL;
352,598✔
2888
  size_t                  size = 0;
352,331✔
2889

2890
  void* pTask = sStreamReaderInfo->pTask;
352,331✔
2891

2892
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
352,331✔
2893

2894
  BUILD_OPTION(options, 0, sStreamReaderInfo->tableList.version, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, NULL, false, NULL);
352,331✔
2895
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
352,598✔
2896

2897
  tsRsp.ver = sStreamReaderInfo->tableList.version + 1;
352,358✔
2898

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

2913
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
332,218✔
2914
  int32_t                 code = 0;
332,218✔
2915
  int32_t                 lino = 0;
332,218✔
2916
  SStreamReaderTaskInner* pTaskInner = NULL;
332,218✔
2917
  SStreamTsResponse       tsRsp = {0};
332,218✔
2918
  void*                   buf = NULL;
332,218✔
2919
  size_t                  size = 0;
332,218✔
2920

2921
  void* pTask = sStreamReaderInfo->pTask;
332,218✔
2922
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64
331,948✔
2923
               " applied:%"PRId64" tableListNum:%d isVtable:%d groupByTbname:%d partitionCols:%p",
2924
               TD_VID(pVnode), __func__, req->firstTsReq.startTime, req->firstTsReq.ver, req->firstTsReq.gid,
2925
               pVnode->state.applied, qStreamGetTableListNum(sStreamReaderInfo),
2926
               sStreamReaderInfo->isVtableStream, sStreamReaderInfo->groupByTbname, sStreamReaderInfo->partitionCols);
2927
  int32_t        pNum = 0;
331,948✔
2928

2929
  tsRsp.ver = pVnode->state.applied;
331,948✔
2930

2931
  BUILD_OPTION(options, 0, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, NULL, false, NULL);
331,948✔
2932
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
331,948✔
2933

2934
  if (req->firstTsReq.gid != 0) {
332,218✔
2935
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
65,920✔
2936
  } else {
2937
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
266,298✔
2938
  }
2939

2940
end:
331,948✔
2941
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
332,218✔
2942
  code = buildTsRsp(&tsRsp, &buf, &size);
332,218✔
2943
  STREAM_PRINT_LOG_END_WITHID(code, lino);
331,681✔
2944
  SRpcMsg rsp = {
331,681✔
2945
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2946
  tmsgSendRsp(&rsp);
331,948✔
2947
  taosArrayDestroy(tsRsp.tsInfo);
332,218✔
2948
  taosMemoryFree(pTaskInner);
331,951✔
2949
  return code;
332,218✔
2950
}
2951

2952
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
504,873✔
2953
  int32_t code = 0;
504,873✔
2954
  int32_t lino = 0;
504,873✔
2955
  void*   buf = NULL;
504,873✔
2956
  size_t  size = 0;
504,873✔
2957
  STableKeyInfo* pList = NULL;
504,873✔
2958

2959
  void* pTask = sStreamReaderInfo->pTask;
504,873✔
2960
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64 ",skey:%" PRId64 ",ekey:%" PRId64 ",gid:%" PRId64, TD_VID(pVnode),
504,873✔
2961
               __func__, req->tsdbMetaReq.ver, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime,
2962
               req->tsdbMetaReq.gid);
2963

2964
  SStreamReaderTaskInner* pTaskInner = NULL;
504,873✔
2965
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
504,873✔
2966

2967
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
504,873✔
2968
    int32_t        pNum = 0;
504,873✔
2969
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbMetaReq.gid, &pList, &pNum));
504,873✔
2970
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, 
504,873✔
2971
                          sStreamReaderInfo->tsSchemas, true, NULL);
2972
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, pList, pNum, &sStreamReaderInfo->storageApi));
504,873✔
2973
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
504,873✔
2974
    
2975
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
504,873✔
2976
  } else {
2977
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2978
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2979
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2980
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2981
  }
2982

2983
  blockDataCleanup(pTaskInner->pResBlockDst);
504,873✔
2984
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
504,873✔
2985
  bool hasNext = true;
504,873✔
2986
  while (true) {
318,069✔
2987
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
822,942✔
2988
    if (!hasNext) {
822,942✔
2989
      break;
504,873✔
2990
    }
2991
    pTaskInner->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
318,069✔
2992
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
318,069✔
2993

2994
    int32_t index = 0;
318,069✔
2995
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
318,069✔
2996
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
318,069✔
2997
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
318,069✔
2998
    if (!sStreamReaderInfo->isVtableStream) {
318,069✔
2999
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
91,601✔
3000
    }
3001
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
318,069✔
3002

3003
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
318,069✔
3004
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3005
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3006
            pTaskInner->pResBlockDst->info.rows++;
318,069✔
3007
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
318,069✔
3008
      break;
×
3009
    }
3010
  }
3011

3012
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
504,873✔
3013
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
504,873✔
3014
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
504,873✔
3015
  if (!hasNext) {
504,873✔
3016
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
504,873✔
3017
  }
3018

3019
end:
504,873✔
3020
  STREAM_PRINT_LOG_END_WITHID(code, lino);
504,873✔
3021
  SRpcMsg rsp = {
504,873✔
3022
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3023
  tmsgSendRsp(&rsp);
504,873✔
3024
  taosMemoryFree(pList);
504,873✔
3025
  return code;
504,873✔
3026
}
3027

3028
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
84,163✔
3029
  int32_t                 code = 0;
84,163✔
3030
  int32_t                 lino = 0;
84,163✔
3031
  SStreamReaderTaskInner* pTaskInner = NULL;
84,163✔
3032
  void*                   buf = NULL;
84,163✔
3033
  size_t                  size = 0;
84,163✔
3034
  SSDataBlock*            pBlockRes = NULL;
84,163✔
3035

3036
  void* pTask = sStreamReaderInfo->pTask;
84,163✔
3037
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
84,163✔
3038
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3039
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3040

3041
  int32_t        pNum = 1;
84,163✔
3042
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
84,163✔
3043
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
84,163✔
3044
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
84,163✔
3045
               sStreamReaderInfo->triggerCols, false, NULL);
3046
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
84,163✔
3047
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
84,163✔
3048
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
84,163✔
3049

3050
  while (1) {
84,163✔
3051
    bool hasNext = false;
168,326✔
3052
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
168,326✔
3053
    if (!hasNext) {
168,326✔
3054
      break;
84,163✔
3055
    }
3056
    // if (!sStreamReaderInfo->isVtableStream){
3057
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
84,163✔
3058
    // }
3059

3060
    SSDataBlock* pBlock = NULL;
84,163✔
3061
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
84,163✔
3062
    if (pBlock != NULL && pBlock->info.rows > 0) {
84,163✔
3063
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
84,163✔
3064
          0, pBlock->info.rows, 1));
3065
    }
3066
    
3067
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
84,163✔
3068
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
84,163✔
3069
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
84,163✔
3070
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3071
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3072
  }
3073

3074
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
84,163✔
3075

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

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

3086
  releaseStreamTask(&pTaskInner);
84,163✔
3087
  return code;
84,163✔
3088
}
3089

3090
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,296✔
3091
  int32_t                 code = 0;
3,296✔
3092
  int32_t                 lino = 0;
3,296✔
3093
  SStreamReaderTaskInner* pTaskInner = NULL;
3,296✔
3094
  void*                   buf = NULL;
3,296✔
3095
  size_t                  size = 0;
3,296✔
3096
  SSDataBlock*            pBlockRes = NULL;
3,296✔
3097

3098
  void* pTask = sStreamReaderInfo->pTask;
3,296✔
3099
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
3,296✔
3100
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3101
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3102

3103
  int32_t        pNum = 1;
3,296✔
3104
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
3,296✔
3105
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
3,296✔
3106
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
3,296✔
3107
               sStreamReaderInfo->tsSchemas, true, NULL);
3108
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
3,296✔
3109
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
3,296✔
3110

3111
  while (1) {
3,296✔
3112
    bool hasNext = false;
6,592✔
3113
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
6,592✔
3114
    if (!hasNext) {
6,592✔
3115
      break;
3,296✔
3116
    }
3117

3118
    SSDataBlock* pBlock = NULL;
3,296✔
3119
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
3,296✔
3120
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
3,296✔
3121
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
3,296✔
3122
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
3123
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
3124
  }
3125

3126
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
3,296✔
3127
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
3,296✔
3128

3129
end:
3,296✔
3130
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,296✔
3131
  SRpcMsg rsp = {
3,296✔
3132
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3133
  tmsgSendRsp(&rsp);
3,296✔
3134
  blockDataDestroy(pBlockRes);
3,296✔
3135

3136
  releaseStreamTask(&pTaskInner);
3,296✔
3137
  return code;
3,296✔
3138
}
3139

3140
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
279,697✔
3141
  int32_t code = 0;
279,697✔
3142
  int32_t lino = 0;
279,697✔
3143
  void*   buf = NULL;
279,697✔
3144
  size_t  size = 0;
279,697✔
3145
  STableKeyInfo* pList = NULL;
279,697✔
3146
  SArray*        pResList = NULL;
279,697✔
3147
  SSDataBlock*   pBlockTmp = NULL;
279,697✔
3148

3149
  SStreamReaderTaskInner* pTaskInner = NULL;
279,697✔
3150
  void* pTask = sStreamReaderInfo->pTask;
279,697✔
3151
  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);
279,697✔
3152
  
3153
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
279,697✔
3154

3155
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
279,697✔
3156
    int32_t        pNum = 0;
98,432✔
3157
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbTriggerDataReq.gid, &pList, &pNum));
98,432✔
3158
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
98,432✔
3159
                 sStreamReaderInfo->triggerCols, false, NULL);
3160
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
98,432✔
3161
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
98,432✔
3162
  } else {
3163
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
181,265✔
3164
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
181,265✔
3165
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
57,000✔
3166
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
57,000✔
3167
  }
3168

3169
  blockDataCleanup(pTaskInner->pResBlockDst);
155,432✔
3170
  bool hasNext = true;
155,432✔
3171
  int32_t totalRows = 0;
155,432✔
3172
    
3173
  pResList = taosArrayInit(4, POINTER_BYTES);
155,432✔
3174
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
155,432✔
3175
  while (1) {
150,578✔
3176
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
306,010✔
3177
    if (!hasNext) {
306,010✔
3178
      break;
98,432✔
3179
    }
3180
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
207,578✔
3181
    // pTaskInner->pResBlockDst->info.id.groupId = pTaskInner->pResBlock->info.id.groupId;
3182

3183
    SSDataBlock* pBlock = NULL;
207,578✔
3184
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
207,578✔
3185
    if (pBlock != NULL && pBlock->info.rows > 0) {
207,578✔
3186
      STREAM_CHECK_RET_GOTO(
207,578✔
3187
        processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
3188
    }
3189
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
207,578✔
3190
    // STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3191
    ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
207,578✔
3192
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
207,578✔
3193
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
207,578✔
3194
    totalRows += blockDataGetNumOfRows(pBlockTmp);
207,578✔
3195
    pBlockTmp = NULL;
207,578✔
3196

3197
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
207,578✔
3198
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3199
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3200
    if (totalRows >= STREAM_RETURN_ROWS_NUM) {  //todo optimize send multi blocks in one group
207,578✔
3201
      break;
57,000✔
3202
    }
3203
  }
3204

3205
  STREAM_CHECK_RET_GOTO(buildArrayRsp(pResList, &buf, &size));
155,432✔
3206
  if (!hasNext) {
155,165✔
3207
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
98,165✔
3208
  }
3209

3210
end:
279,697✔
3211
  STREAM_PRINT_LOG_END_WITHID(code, lino);
279,160✔
3212
  SRpcMsg rsp = {
279,160✔
3213
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3214
  tmsgSendRsp(&rsp);
279,430✔
3215
  taosMemoryFree(pList);
279,697✔
3216
  blockDataDestroy(pBlockTmp);
279,697✔
3217
  taosArrayDestroyP(pResList, (FDelete)blockDataDestroy);
279,697✔
3218
  return code;
279,697✔
3219
}
3220

3221
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
7,402,896✔
3222
  int32_t code = 0;
7,402,896✔
3223
  int32_t lino = 0;
7,402,896✔
3224
  void*   buf = NULL;
7,402,896✔
3225
  size_t  size = 0;
7,402,896✔
3226
  SSDataBlock*   pBlockRes = NULL;
7,402,896✔
3227
  STableKeyInfo* pList = NULL;
7,402,896✔
3228

3229

3230
  void* pTask = sStreamReaderInfo->pTask;
7,402,896✔
3231
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
7,402,896✔
3232
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid, req->tsdbCalcDataReq.ver);
3233

3234
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
7,402,412✔
3235

3236
  SStreamReaderTaskInner* pTaskInner = NULL;
7,402,896✔
3237
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
7,402,896✔
3238

3239
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
7,402,654✔
3240
    int32_t        pNum = 0;
7,402,412✔
3241
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbCalcDataReq.gid, &pList, &pNum));
7,402,412✔
3242
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
7,402,896✔
3243
                 sStreamReaderInfo->triggerCols, false, NULL);
3244
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
7,402,654✔
3245

3246
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
7,397,330✔
3247
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
7,401,444✔
3248
  } else {
3249
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3250
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3251
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3252
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3253
  }
3254

3255
  blockDataCleanup(pTaskInner->pResBlockDst);
7,400,862✔
3256
  bool hasNext = true;
7,401,686✔
3257
  while (1) {
945,984✔
3258
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
8,345,008✔
3259
    if (!hasNext) {
8,343,072✔
3260
      break;
7,395,878✔
3261
    }
3262
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
947,194✔
3263

3264
    SSDataBlock* pBlock = NULL;
946,434✔
3265
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
946,434✔
3266
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
945,984✔
3267
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
946,434✔
3268
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
945,984✔
3269
      break;
×
3270
    }
3271
  }
3272

3273
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
7,396,120✔
3274
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
7,401,928✔
3275
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
7,398,056✔
3276
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
7,400,476✔
3277
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
7,397,572✔
3278
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
7,395,636✔
3279
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
7,402,654✔
3280

3281
  if (!hasNext) {
7,402,896✔
3282
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
7,402,896✔
3283
  }
3284

3285
end:
7,402,043✔
3286
  STREAM_PRINT_LOG_END_WITHID(code, lino);
7,400,960✔
3287
  SRpcMsg rsp = {
7,402,896✔
3288
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3289
  tmsgSendRsp(&rsp);
7,402,654✔
3290
  blockDataDestroy(pBlockRes);
7,402,896✔
3291
  taosMemoryFree(pList);
7,402,654✔
3292
  return code;
7,402,170✔
3293
}
3294

3295
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
633,630✔
3296
  int32_t code = 0;
633,630✔
3297
  int32_t lino = 0;
633,630✔
3298
  void*   buf = NULL;
633,630✔
3299
  size_t  size = 0;
633,630✔
3300
  int32_t* slotIdList = NULL;
633,630✔
3301
  SArray* sortedCid = NULL;
633,630✔
3302
  SArray* schemas = NULL;
633,630✔
3303
  SSDataBlock*   pBlockRes = NULL;
633,630✔
3304
  
3305
  void* pTask = sStreamReaderInfo->pTask;
633,630✔
3306
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
633,630✔
3307
    req->tsdbDataReq.skey, req->tsdbDataReq.ekey, req->tsdbDataReq.uid, req->tsdbDataReq.ver);
3308
    
3309
  SStreamReaderTaskInner* pTaskInner = NULL;
633,630✔
3310
  int64_t key = req->tsdbDataReq.uid;
633,630✔
3311

3312
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
633,630✔
3313
    // sort cid and build slotIdList
3314
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
633,630✔
3315
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
633,630✔
3316
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
633,630✔
3317
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
633,630✔
3318
    taosArraySort(sortedCid, sortCid);
633,630✔
3319
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
2,484,699✔
3320
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
1,851,069✔
3321
      STREAM_CHECK_NULL_GOTO(cid, terrno);
1,851,069✔
3322
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
3,658,365✔
3323
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
3,658,365✔
3324
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
3,658,365✔
3325
        if (*cid == *cidSorted) {
3,658,365✔
3326
          slotIdList[j] = i;
1,851,069✔
3327
          break;
1,851,069✔
3328
        }
3329
      }
3330
    }
3331

3332
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas, &sStreamReaderInfo->storageApi));
633,630✔
3333
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
630,334✔
3334
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlockRes));
630,334✔
3335

3336
    taosArraySort(schemas, sortSSchema);
630,334✔
3337
    BUILD_OPTION(options, req->tsdbDataReq.suid, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
630,334✔
3338
                    req->tsdbDataReq.ekey, schemas, true, &slotIdList);
3339
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid, .groupId = 0};
630,334✔
3340
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, pBlockRes, &keyInfo, 1, &sStreamReaderInfo->storageApi));
630,334✔
3341
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
630,334✔
3342
    pTaskInner->pResBlockDst = pBlockRes;
630,334✔
3343
    pBlockRes = NULL;
630,334✔
3344
  } else {
3345
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3346
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3347
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3348
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3349
  }
3350

3351
  blockDataCleanup(pTaskInner->pResBlockDst);
630,334✔
3352
  bool hasNext = true;
630,334✔
3353
  while (1) {
630,334✔
3354
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,260,668✔
3355
    if (!hasNext) {
1,259,844✔
3356
      break;
630,334✔
3357
    }
3358

3359
    SSDataBlock* pBlock = NULL;
629,510✔
3360
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
630,334✔
3361
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
630,334✔
3362
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
630,334✔
3363
      break;
×
3364
    }
3365
  }
3366
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
630,334✔
3367
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
630,334✔
3368
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
630,334✔
3369
  if (!hasNext) {
630,334✔
3370
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
630,334✔
3371
  }
3372

3373
end:
632,806✔
3374
  STREAM_PRINT_LOG_END_WITHID(code, lino);
633,630✔
3375
  SRpcMsg rsp = {
633,630✔
3376
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3377
  tmsgSendRsp(&rsp);
633,630✔
3378
  taosMemFree(slotIdList);
633,630✔
3379
  taosArrayDestroy(sortedCid);
633,630✔
3380
  taosArrayDestroy(schemas);
633,630✔
3381
  blockDataDestroy(pBlockRes);
633,630✔
3382
  return code;
633,630✔
3383
}
3384

3385
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
25,410,297✔
3386
  int32_t      code = 0;
25,410,297✔
3387
  int32_t      lino = 0;
25,410,297✔
3388
  void*        buf = NULL;
25,410,297✔
3389
  size_t       size = 0;
25,410,297✔
3390
  int64_t      lastVer = 0;
25,410,297✔
3391
  SSTriggerWalNewRsp resultRsp = {0};
25,410,297✔
3392

3393
  void* pTask = sStreamReaderInfo->pTask;
25,410,297✔
3394
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
25,410,061✔
3395

3396
  if (sStreamReaderInfo->metaBlock == NULL) {
25,410,297✔
3397
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
221,306✔
3398
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
221,306✔
3399
  }
3400
  blockDataEmpty(sStreamReaderInfo->metaBlock);
25,410,297✔
3401
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
25,409,905✔
3402
  resultRsp.ver = req->walMetaNewReq.lastVer;
25,409,905✔
3403
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
25,409,905✔
3404

3405
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
25,410,297✔
3406
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
25,410,297✔
3407
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
437,851✔
3408
  buf = rpcMallocCont(size);
437,851✔
3409
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
437,851✔
3410
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
437,581✔
3411
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
437,851✔
3412
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
437,581✔
3413

3414
end:
25,410,297✔
3415
  if (code == 0 && resultRsp.totalRows == 0) {
25,410,297✔
3416
    code = TSDB_CODE_STREAM_NO_DATA;
24,972,446✔
3417
    size = sizeof(int64_t) * 2;
24,972,446✔
3418
    buf = rpcMallocCont(size);
24,972,446✔
3419
    *(int64_t*)buf = resultRsp.ver;
24,971,721✔
3420
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
24,971,721✔
3421
  }
3422
  SRpcMsg rsp = {
25,410,087✔
3423
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3424
  tmsgSendRsp(&rsp);
25,410,027✔
3425
  if (code == TSDB_CODE_STREAM_NO_DATA){
25,408,784✔
3426
    code = 0;
24,970,561✔
3427
  }
3428
  STREAM_PRINT_LOG_END_WITHID(code, lino);
25,408,784✔
3429
  blockDataDestroy(resultRsp.deleteBlock);
25,409,021✔
3430
  blockDataDestroy(resultRsp.tableBlock);
25,410,297✔
3431

3432
  return code;
25,410,297✔
3433
}
3434
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
6,274,016✔
3435
  int32_t      code = 0;
6,274,016✔
3436
  int32_t      lino = 0;
6,274,016✔
3437
  void*        buf = NULL;
6,274,016✔
3438
  size_t       size = 0;
6,274,016✔
3439
  SSTriggerWalNewRsp resultRsp = {0};
6,274,016✔
3440
  
3441
  void* pTask = sStreamReaderInfo->pTask;
6,273,746✔
3442
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
6,273,327✔
3443

3444
  if (sStreamReaderInfo->metaBlock == NULL) {
6,273,568✔
3445
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
141,868✔
3446
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
141,868✔
3447
  }
3448

3449
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
6,274,286✔
3450
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
6,274,016✔
3451
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
6,271,204✔
3452
  resultRsp.checkAlter = true;
6,273,266✔
3453
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
6,273,266✔
3454
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
6,272,979✔
3455

3456
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
6,272,979✔
3457

3458
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
6,271,926✔
3459
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
172,225✔
3460
  buf = rpcMallocCont(size);
173,267✔
3461
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
173,267✔
3462
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
173,267✔
3463
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
173,000✔
3464
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
173,267✔
3465
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
173,000✔
3466
  printIndexHash(resultRsp.indexHash, pTask);
173,000✔
3467

3468
end:
6,273,209✔
3469
  if (resultRsp.totalRows == 0) {
6,273,212✔
3470
    code = TSDB_CODE_STREAM_NO_DATA;
6,099,704✔
3471
    size = sizeof(int64_t) * 2;
6,099,704✔
3472
    buf = rpcMallocCont(size);
6,099,704✔
3473
    *(int64_t*)buf = resultRsp.ver;
6,098,351✔
3474
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
6,098,351✔
3475
  }
3476
  SRpcMsg rsp = {
6,272,425✔
3477
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3478
  tmsgSendRsp(&rsp);
6,273,238✔
3479
  if (code == TSDB_CODE_STREAM_NO_DATA){
6,273,765✔
3480
    code = 0;
6,100,257✔
3481
  }
3482
  blockDataDestroy(resultRsp.dataBlock);
6,273,765✔
3483
  blockDataDestroy(resultRsp.deleteBlock);
6,269,852✔
3484
  blockDataDestroy(resultRsp.tableBlock);
6,269,433✔
3485
  tSimpleHashCleanup(resultRsp.indexHash);
6,269,433✔
3486

3487
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,270,715✔
3488

3489
  return code;
6,271,236✔
3490
}
3491

3492
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
17,396,856✔
3493
  int32_t      code = 0;
17,396,856✔
3494
  int32_t      lino = 0;
17,396,856✔
3495
  void*        buf = NULL;
17,396,856✔
3496
  size_t       size = 0;
17,396,856✔
3497
  SSTriggerWalNewRsp resultRsp = {0};
17,396,856✔
3498

3499
  void* pTask = sStreamReaderInfo->pTask;
17,396,856✔
3500
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
17,396,856✔
3501

3502
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
17,396,856✔
3503
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
17,395,762✔
3504
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
17,394,668✔
3505
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
17,394,668✔
3506
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
17,395,762✔
3507

3508
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
17,395,762✔
3509
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
17,396,586✔
3510

3511
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
17,396,856✔
3512

3513
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
281,447✔
3514
  buf = rpcMallocCont(size);
281,447✔
3515
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
281,447✔
3516
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
281,447✔
3517
  printIndexHash(resultRsp.indexHash, pTask);
281,447✔
3518

3519
end:
17,396,856✔
3520
  if (resultRsp.totalRows == 0) {
17,396,856✔
3521
    buf = rpcMallocCont(sizeof(int64_t));
17,115,409✔
3522
    *(int64_t *)buf = resultRsp.ver;
17,115,139✔
3523
    size = sizeof(int64_t);
17,115,139✔
3524
    code = TSDB_CODE_STREAM_NO_DATA;
17,115,139✔
3525
  }
3526
  SRpcMsg rsp = {
17,396,586✔
3527
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3528
  tmsgSendRsp(&rsp);
17,396,856✔
3529
  if (code == TSDB_CODE_STREAM_NO_DATA){
17,396,856✔
3530
    code = 0;
17,115,409✔
3531
  }
3532

3533
  blockDataDestroy(resultRsp.dataBlock);
17,396,856✔
3534
  blockDataDestroy(resultRsp.deleteBlock);
17,393,290✔
3535
  blockDataDestroy(resultRsp.tableBlock);
17,395,492✔
3536
  tSimpleHashCleanup(resultRsp.indexHash);
17,396,856✔
3537
  tSimpleHashCleanup(resultRsp.uidHash);
17,394,668✔
3538
  STREAM_PRINT_LOG_END_WITHID(code, lino);
17,394,668✔
3539

3540
  return code;
17,396,586✔
3541
}
3542

3543
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,991,062✔
3544
  int32_t      code = 0;
1,991,062✔
3545
  int32_t      lino = 0;
1,991,062✔
3546
  void*        buf = NULL;
1,991,062✔
3547
  size_t       size = 0;
1,991,062✔
3548
  SSTriggerWalNewRsp resultRsp = {0};
1,991,062✔
3549
  SSDataBlock* pBlock1 = NULL;
1,991,062✔
3550
  SSDataBlock* pBlock2 = NULL;
1,991,062✔
3551
  
3552
  void* pTask = sStreamReaderInfo->pTask;
1,991,062✔
3553
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
1,990,238✔
3554

3555
  SSDataBlock* dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
1,990,238✔
3556
  STREAM_CHECK_RET_GOTO(createOneDataBlock(dataBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
1,991,062✔
3557
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
1,991,062✔
3558
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
1,991,062✔
3559
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
1,991,062✔
3560
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
1,991,062✔
3561
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
1,991,062✔
3562

3563
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
1,991,062✔
3564
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
1,991,062✔
3565

3566
  if (!sStreamReaderInfo->isVtableStream){
287,866✔
3567
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
175,582✔
3568
  
3569
    blockDataTransform(pBlock2, resultRsp.dataBlock);
175,582✔
3570
    blockDataDestroy(resultRsp.dataBlock);
175,582✔
3571
    resultRsp.dataBlock = pBlock2;
175,582✔
3572
    pBlock2 = NULL;
175,582✔
3573
  }
3574

3575
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
287,866✔
3576
  buf = rpcMallocCont(size);
287,866✔
3577
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
287,866✔
3578
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
287,866✔
3579
  printIndexHash(resultRsp.indexHash, pTask);
287,596✔
3580

3581
end:
1,990,792✔
3582
  if (resultRsp.totalRows == 0) {
1,990,792✔
3583
    buf = rpcMallocCont(sizeof(int64_t));
1,703,196✔
3584
    *(int64_t *)buf = resultRsp.ver;
1,703,196✔
3585
    size = sizeof(int64_t);
1,703,196✔
3586
    code = TSDB_CODE_STREAM_NO_DATA;
1,703,196✔
3587
  }
3588
  SRpcMsg rsp = {
1,990,792✔
3589
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3590
  tmsgSendRsp(&rsp);
1,991,062✔
3591
  if (code == TSDB_CODE_STREAM_NO_DATA){
1,991,062✔
3592
    code = 0;
1,703,196✔
3593
  }
3594

3595
  blockDataDestroy(pBlock1);
1,991,062✔
3596
  blockDataDestroy(pBlock2);
1,991,062✔
3597
  blockDataDestroy(resultRsp.dataBlock);
1,991,062✔
3598
  blockDataDestroy(resultRsp.deleteBlock);
1,991,062✔
3599
  blockDataDestroy(resultRsp.tableBlock);
1,991,062✔
3600
  tSimpleHashCleanup(resultRsp.indexHash);
1,991,062✔
3601
  tSimpleHashCleanup(resultRsp.uidHash);
1,991,062✔
3602
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,991,062✔
3603

3604
  return code;
1,991,062✔
3605
}
3606

3607
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
360,355✔
3608
  int32_t code = 0;
360,355✔
3609
  int32_t lino = 0;
360,355✔
3610
  void*   buf = NULL;
360,355✔
3611
  size_t  size = 0;
360,355✔
3612
  SArray** gInfo = NULL;
360,355✔
3613
  
3614
  void* pTask = sStreamReaderInfo->pTask;
360,355✔
3615
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
360,355✔
3616

3617
  gInfo = taosHashAcquire(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
360,355✔
3618
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
360,355✔
3619
  SStreamGroupInfo pGroupInfo = {0};
360,355✔
3620
  pGroupInfo.gInfo = *gInfo;
360,355✔
3621

3622
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
360,355✔
3623
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3624
  buf = rpcMallocCont(size);
360,355✔
3625
  STREAM_CHECK_NULL_GOTO(buf, terrno);
360,355✔
3626
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
360,355✔
3627
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3628
end:
360,355✔
3629
  taosHashRelease(sStreamReaderInfo->groupIdMap, gInfo);
360,355✔
3630
  if (code != 0) {
360,355✔
3631
    rpcFreeCont(buf);
×
3632
    buf = NULL;
×
3633
    size = 0;
×
3634
  }
3635
  STREAM_PRINT_LOG_END_WITHID(code, lino);
360,355✔
3636
  SRpcMsg rsp = {
360,355✔
3637
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3638
  tmsgSendRsp(&rsp);
360,355✔
3639

3640
  return code;
360,355✔
3641
}
3642

3643
static int32_t setVtableInfo(SVnode* pVnode, SArray* infos, SArray* cids, int64_t uid, uint64_t gid, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo) {
203,026✔
3644
  int32_t              code = 0;
203,026✔
3645
  int32_t              lino = 0;
203,026✔
3646
  void* pTask = sStreamReaderInfo->pTask;
203,026✔
3647

3648
  VTableInfo* vTable = taosArrayReserve(infos, 1);
203,026✔
3649
  STREAM_CHECK_NULL_GOTO(vTable, terrno);
203,026✔
3650
  vTable->uid = uid;
203,026✔
3651
  vTable->gId = gid;
203,026✔
3652

3653
  ST_TASK_DLOG("vgId:%d %s put vtable uid:%"PRId64, TD_VID(pVnode), __func__, uid);
203,026✔
3654

3655
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, ver, uid);
203,026✔
3656
  if (code != 0) {
203,026✔
3657
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
3658
    goto end;
×
3659
  }
3660
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
203,026✔
3661
    vTable->cols.nCols = metaReader->me.colRef.nCols;
11,676✔
3662
    vTable->cols.version = metaReader->me.colRef.version;
11,676✔
3663
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
11,676✔
3664
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
11,676✔
3665
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
70,056✔
3666
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
58,380✔
3667
    }
3668
  } else {
3669
    vTable->cols.nCols = taosArrayGetSize(cids);
191,350✔
3670
    vTable->cols.version = metaReader->me.colRef.version;
191,350✔
3671
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
191,350✔
3672
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
191,350✔
3673
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
726,756✔
3674
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
2,256,106✔
3675
        if (metaReader->me.colRef.pColRef[j].hasRef &&
2,063,946✔
3676
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
1,523,485✔
3677
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
343,246✔
3678
          break;
343,246✔
3679
        }
3680
      }
3681
    }
3682
  }
3683
  tDecoderClear(&metaReader->coder);
203,026✔
3684

3685
end:
203,026✔
3686
  return code;
203,026✔
3687
}
3688

3689
static int32_t getAllVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
83,022✔
3690
  int32_t              code = 0;
83,022✔
3691
  int32_t              lino = 0;
83,022✔
3692
  void* pTask = sStreamReaderInfo->pTask;
83,022✔
3693
  SArray*              pTableListArray = NULL;
83,022✔
3694

3695

3696
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
83,022✔
3697
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
83,022✔
3698

3699
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
83,022✔
3700
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
83,022✔
3701

3702
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
286,048✔
3703
    SStreamTableKeyInfo* pKeyInfo = taosArrayGetP(pTableListArray, i);
203,026✔
3704
    if (pKeyInfo == NULL || pKeyInfo->markedDeleted) {
203,026✔
3705
      continue;
×
3706
    }
3707
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, pKeyInfo->uid, pKeyInfo->groupId, ver, metaReader, sStreamReaderInfo);
203,026✔
3708
    if (code != 0) {
203,026✔
3709
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, pKeyInfo->uid, tstrerror(code));
×
3710
      code = 0;
×
3711
      continue;
×
3712
    }
3713
  }
3714

3715
end:
83,022✔
3716
  taosArrayDestroyP(pTableListArray, taosMemFree);
83,022✔
3717
  return code;
83,022✔
3718
}
3719

3720
static int32_t getSpicificVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* uids, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
×
3721
  int32_t              code = 0;
×
3722
  int32_t              lino = 0;
×
3723
  void* pTask = sStreamReaderInfo->pTask;
×
3724

3725
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(uids), sizeof(VTableInfo));
×
3726
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
×
3727

3728
  for (size_t i = 0; i < taosArrayGetSize(uids); i++) {
×
3729
    int64_t* uid = taosArrayGet(uids, i);
×
3730
    STREAM_CHECK_NULL_GOTO(uid, terrno);
×
3731

3732
    taosRLockLatch(&sStreamReaderInfo->lock);
×
3733
    uint64_t groupId = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, *uid);
×
3734
    taosRUnLockLatch(&sStreamReaderInfo->lock);
×
3735
    if (groupId == -1) {
×
3736
      ST_TASK_WLOG("vgId:%d %s uid:%"PRId64" not found in stream group", TD_VID(pVnode), __func__, *uid);
×
3737
      continue;
×
3738
    }
3739
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, *uid, groupId, ver, metaReader, sStreamReaderInfo);
×
3740
    if (code != 0) {
×
3741
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, *uid, tstrerror(code));
×
3742
      code = 0;
×
3743
      continue;
×
3744
    }
3745
  }
3746
  
3747
end:
×
3748
  return code;
×
3749
}
3750

3751
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
83,022✔
3752
  int32_t              code = 0;
83,022✔
3753
  int32_t              lino = 0;
83,022✔
3754
  void*                buf = NULL;
83,022✔
3755
  size_t               size = 0;
83,022✔
3756
  SStreamMsgVTableInfo vTableInfo = {0};
83,022✔
3757
  SMetaReader          metaReader = {0};
83,022✔
3758

3759
  void* pTask = sStreamReaderInfo->pTask;
83,022✔
3760
  ST_TASK_DLOG("vgId:%d %s start, version:%"PRId64, TD_VID(pVnode), __func__, req->virTableInfoReq.ver);
83,022✔
3761

3762
  SArray* cids = req->virTableInfoReq.cids;
83,022✔
3763
  STREAM_CHECK_NULL_GOTO(cids, terrno);
83,022✔
3764

3765
  if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
83,022✔
3766
    (void)atomic_val_compare_exchange_8(&sStreamReaderInfo->isVtableOnlyTs, 0, 1);
11,676✔
3767
  }
3768
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
83,022✔
3769

3770
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
83,022✔
3771
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
83,022✔
3772
  } else {
3773
    STREAM_CHECK_RET_GOTO(getSpicificVinfo(pVnode, &vTableInfo, req->virTableInfoReq.uids, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
×
3774
  }
3775
  ST_TASK_DLOG("vgId:%d %s end, size:%"PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(vTableInfo.infos));
83,022✔
3776
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
83,022✔
3777

3778
end:
83,022✔
3779
  tDestroySStreamMsgVTableInfo(&vTableInfo);
83,022✔
3780
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
83,022✔
3781
  STREAM_PRINT_LOG_END_WITHID(code, lino);
83,022✔
3782
  SRpcMsg rsp = {
83,022✔
3783
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3784
  tmsgSendRsp(&rsp);
83,022✔
3785
  return code;
83,022✔
3786
}
3787

3788
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
145,889✔
3789
  int32_t                   code = 0;
145,889✔
3790
  int32_t                   lino = 0;
145,889✔
3791
  void*                     buf = NULL;
145,889✔
3792
  size_t                    size = 0;
145,889✔
3793
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
145,889✔
3794
  SMetaReader               metaReader = {0};
145,889✔
3795
  void*                     pTask = sStreamReaderInfo->pTask;
145,889✔
3796

3797
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64, TD_VID(pVnode), __func__, req->origTableInfoReq.ver);
145,889✔
3798

3799
  SArray* cols = req->origTableInfoReq.cols;
145,889✔
3800
  STREAM_CHECK_NULL_GOTO(cols, terrno);
145,889✔
3801

3802
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
145,889✔
3803

3804
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
145,889✔
3805

3806
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
145,889✔
3807
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
535,839✔
3808
    OTableInfo*    oInfo = taosArrayGet(cols, i);
389,950✔
3809
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
389,950✔
3810
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
389,950✔
3811
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
389,950✔
3812
    code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionName(&metaReader, req->origTableInfoReq.ver, oInfo->refTableName);
389,950✔
3813
    if (code != 0) {
389,950✔
3814
      code = 0;
241✔
3815
      ST_TASK_ELOG("vgId:%d %s get table entry by name:%s failed, msg:%s", TD_VID(pVnode), __func__, oInfo->refTableName, tstrerror(code));
241✔
3816
      continue;
241✔
3817
    }
3818
    vTableInfo->uid = metaReader.me.uid;
389,709✔
3819
    ST_TASK_DLOG("vgId:%d %s get original uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
389,709✔
3820

3821
    SSchemaWrapper* sSchemaWrapper = NULL;
389,709✔
3822
    if (metaReader.me.type == TD_CHILD_TABLE) {
389,709✔
3823
      int64_t suid = metaReader.me.ctbEntry.suid;
387,562✔
3824
      vTableInfo->suid = suid;
387,562✔
3825
      tDecoderClear(&metaReader.coder);
387,562✔
3826
      STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->origTableInfoReq.ver, suid));
387,562✔
3827
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
387,562✔
3828
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
2,147✔
3829
      vTableInfo->suid = 0;
2,147✔
3830
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
2,147✔
3831
    } else {
3832
      ST_TASK_ELOG("invalid table type:%d", metaReader.me.type);
×
3833
    }
3834

3835
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
1,339,223✔
3836
      SSchema* s = sSchemaWrapper->pSchema + j;
1,339,223✔
3837
      if (strcmp(s->name, oInfo->refColName) == 0) {
1,339,223✔
3838
        vTableInfo->cid = s->colId;
389,709✔
3839
        break;
389,709✔
3840
      }
3841
    }
3842
    if (vTableInfo->cid == 0) {
389,709✔
3843
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
3844
              oInfo->refTableName);
3845
    }
3846
    tDecoderClear(&metaReader.coder);
389,709✔
3847
  }
3848

3849
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
145,889✔
3850

3851
end:
145,889✔
3852
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
145,889✔
3853
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
145,889✔
3854
  STREAM_PRINT_LOG_END_WITHID(code, lino);
145,889✔
3855
  SRpcMsg rsp = {
145,889✔
3856
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3857
  tmsgSendRsp(&rsp);
145,889✔
3858
  return code;
145,889✔
3859
}
3860

3861
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,192,318✔
3862
  int32_t                   code = 0;
1,192,318✔
3863
  int32_t                   lino = 0;
1,192,318✔
3864
  void*                     buf = NULL;
1,192,318✔
3865
  size_t                    size = 0;
1,192,318✔
3866
  SSDataBlock* pBlock = NULL;
1,192,318✔
3867

3868
  SMetaReader               metaReader = {0};
1,192,318✔
3869
  SMetaReader               metaReaderStable = {0};
1,192,318✔
3870
  int64_t streamId = req->base.streamId;
1,192,318✔
3871
  stsDebug("vgId:%d %s start, ver:%"PRId64, TD_VID(pVnode), __func__, req->virTablePseudoColReq.ver);
1,192,318✔
3872

3873
  SArray* cols = req->virTablePseudoColReq.cids;
1,192,318✔
3874
  STREAM_CHECK_NULL_GOTO(cols, terrno);
1,192,318✔
3875

3876
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
1,192,318✔
3877
  STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->virTablePseudoColReq.ver, req->virTablePseudoColReq.uid));
1,192,318✔
3878

3879
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
1,192,318✔
3880

3881
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
1,192,318✔
3882
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
1,192,318✔
3883
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
2,430✔
3884
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
2,430✔
3885
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
2,430✔
3886
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
2,430✔
3887
    pBlock->info.rows = 1;
2,430✔
3888
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
2,430✔
3889
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,430✔
3890
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
2,430✔
3891
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
1,189,888✔
3892
    int64_t suid = metaReader.me.ctbEntry.suid;
1,189,888✔
3893
    sStreamReaderInfo->storageApi.metaReaderFn.readerReleaseLock(&metaReader);
1,189,888✔
3894
    sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
1,189,888✔
3895

3896
    STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReaderStable, req->virTablePseudoColReq.ver, suid));
1,189,888✔
3897
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
1,189,888✔
3898
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
3,142,606✔
3899
      col_id_t* id = taosArrayGet(cols, i);
1,952,718✔
3900
      STREAM_CHECK_NULL_GOTO(id, terrno);
1,952,718✔
3901
      if (*id == -1) {
1,952,718✔
3902
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
1,182,472✔
3903
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
1,182,472✔
3904
        continue;
1,182,472✔
3905
      }
3906
      size_t j = 0;
770,246✔
3907
      for (; j < sSchemaWrapper->nCols; j++) {
1,493,319✔
3908
        SSchema* s = sSchemaWrapper->pSchema + j;
1,493,319✔
3909
        if (s->colId == *id) {
1,493,319✔
3910
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
770,246✔
3911
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
770,246✔
3912
          break;
770,246✔
3913
        }
3914
      }
3915
      if (j == sSchemaWrapper->nCols) {
770,246✔
3916
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3917
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3918
      }
3919
    }
3920
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
1,189,888✔
3921
    pBlock->info.rows = 1;
1,189,888✔
3922
    
3923
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
3,142,606✔
3924
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
1,952,718✔
3925
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
1,952,718✔
3926

3927
      if (pDst->info.colId == -1) {
1,952,718✔
3928
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
1,182,472✔
3929
        continue;
1,182,472✔
3930
      }
3931
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
770,246✔
3932
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3933
        continue;
×
3934
      }
3935

3936
      STagVal val = {0};
770,246✔
3937
      val.cid = pDst->info.colId;
770,246✔
3938
      const char* p = sStreamReaderInfo->storageApi.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
770,246✔
3939

3940
      char* data = NULL;
770,246✔
3941
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
770,246✔
3942
        data = tTagValToData((const STagVal*)p, false);
770,246✔
3943
      } else {
3944
        data = (char*)p;
×
3945
      }
3946

3947
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
770,246✔
3948
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3949

3950
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
770,246✔
3951
          (data != NULL)) {
3952
        taosMemoryFree(data);
717,438✔
3953
      }
3954
    }
3955
  } else {
3956
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3957
    code = TSDB_CODE_INVALID_PARA;
×
3958
    goto end;
×
3959
  }
3960
  
3961
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
1,192,318✔
3962
  printDataBlock(pBlock, __func__, "", streamId);
1,192,318✔
3963
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
1,192,318✔
3964

3965
end:
1,192,318✔
3966
  if(size == 0){
1,192,318✔
3967
    code = TSDB_CODE_STREAM_NO_DATA;
×
3968
  }
3969
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReaderStable);
1,192,318✔
3970
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
1,192,318✔
3971
  STREAM_PRINT_LOG_END(code, lino);
1,192,318✔
3972
  SRpcMsg rsp = {
1,192,318✔
3973
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3974
  tmsgSendRsp(&rsp);
1,192,318✔
3975
  blockDataDestroy(pBlock);
1,192,318✔
3976
  return code;
1,192,318✔
3977
}
3978

3979
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
8,131,591✔
3980
  int32_t            code = 0;
8,131,591✔
3981
  int32_t            lino = 0;
8,131,591✔
3982
  void*              buf = NULL;
8,131,591✔
3983
  size_t             size = 0;
8,131,877✔
3984
  void*              taskAddr = NULL;
8,131,877✔
3985
  SArray*            pResList = NULL;
8,131,877✔
3986
  bool               hasNext = false;
8,131,877✔
3987
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = NULL;
8,131,877✔
3988

3989
  SResFetchReq req = {0};
8,131,877✔
3990
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
8,131,877✔
3991
                              TSDB_CODE_QRY_INVALID_INPUT);
3992
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
8,131,567✔
3993
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
8,131,877✔
3994

3995
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
8,131,877✔
3996
  sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
8,131,877✔
3997
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
8,131,877✔
3998
  sStreamReaderCalcInfo->rtInfo.execId = req.execId;
8,131,877✔
3999

4000
  void* pTask = sStreamReaderCalcInfo->pTask;
8,131,877✔
4001
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
8,131,877✔
4002
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
4003

4004
  if (req.reset) {
8,131,877✔
4005
    int64_t uid = 0;
4,747,044✔
4006
    if (req.dynTbname && !req.pStRtFuncInfo->isMultiGroupCalc) {
4,747,044✔
4007
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
155,729✔
4008
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
155,729✔
4009
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
155,729✔
4010
        if (pValue != NULL && pValue->isTbname) {
155,729✔
4011
          uid = pValue->uid;
155,729✔
4012
          break;
155,729✔
4013
        }
4014
      }
4015
    }
4016
    
4017
    SReadHandle handle = {0};
4,747,044✔
4018
    handle.vnode = pVnode;
4,747,044✔
4019
    handle.pMsgCb = &pVnode->msgCb;
4,747,044✔
4020
    handle.pWorkerCb = pInfo->workerCb;
4,747,044✔
4021
    handle.uid = uid;
4,747,044✔
4022
    handle.cacheSttStatis = true;
4,747,044✔
4023

4024
    initStorageAPI(&handle.api);
4,747,044✔
4025
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
4,746,734✔
4026
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
3,716,515✔
4027
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,832,012✔
4028
      if (node != NULL) {
3,831,702✔
4029
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
521,377✔
4030
      } else {
4031
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
3,310,325✔
4032
      }
4033

4034
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
3,831,702✔
4035
      if (node != NULL) {
3,831,702✔
4036
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
86,086✔
4037
      } else {
4038
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
3,745,616✔
4039
      }      
4040
    }
4041

4042
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
4,746,734✔
4043
    sStreamReaderCalcInfo->rtInfo.funcInfo.hasPlaceHolder = sStreamReaderCalcInfo->hasPlaceHolder;
4,747,044✔
4044
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
4,747,044✔
4045

4046
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
4,747,044✔
4047
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
691,114✔
4048
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
691,114✔
4049
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
4050
                                                    req.taskId));
4051
      STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
691,114✔
4052
    } else {
4053
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
4,055,930✔
4054
    }
4055

4056
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
4,747,044✔
4057
  }
4058

4059
  if (req.pOpParam != NULL) {
8,131,877✔
4060
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
345,358✔
4061
  }
4062

4063
  pResList = taosArrayInit(4, POINTER_BYTES);
8,131,877✔
4064
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
8,131,877✔
4065
  uint64_t ts = 0;
8,131,877✔
4066
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
8,131,432✔
4067

4068
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
19,885,698✔
4069
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
11,755,457✔
4070
    if (pBlock == NULL) continue;
11,755,457✔
4071
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
11,755,457✔
4072
/*    
4073
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
4074
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
4075
      printDataBlock(pBlock, __func__, "fetch filter");
4076
    }
4077
*/    
4078
  }
4079

4080
end:
8,131,591✔
4081
  code = streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision);
8,131,877✔
4082

4083
  if (sStreamReaderCalcInfo && sStreamReaderCalcInfo->rtInfo.funcInfo.isMultiGroupCalc) {
8,131,877✔
4084
    sStreamReaderCalcInfo->rtInfo.funcInfo.pStreamPesudoFuncVals = NULL;
×
4085
    sStreamReaderCalcInfo->rtInfo.funcInfo.pStreamPartColVals = NULL;
×
4086
  }
4087
  
4088
  taosArrayDestroy(pResList);
8,131,877✔
4089
  streamReleaseTask(taskAddr);
8,131,877✔
4090
  
4091
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
8,131,877✔
4092
    code = TDB_CODE_SUCCESS;
×
4093
  }
4094
  STREAM_PRINT_LOG_END(code, lino);
8,131,877✔
4095
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
8,131,877✔
4096
  tmsgSendRsp(&rsp);
8,131,877✔
4097
  tDestroySResFetchReq(&req);
8,131,021✔
4098
  if (TDB_CODE_SUCCESS != code) {
8,131,569✔
4099
    ST_TASK_ELOG("vgId:%d %s failed, code:%d - %s", TD_VID(pVnode), __func__,
×
4100
                 code, tstrerror(code));
4101
  }
4102
  return code;
8,131,569✔
4103
}
4104

4105
static int32_t initTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SVnode* pVnode) {
62,591,981✔
4106
  int32_t code = 0;
62,591,981✔
4107
  if (sStreamReaderInfo->tableList.pTableList != NULL) {  
62,591,981✔
4108
    return code;
62,228,006✔
4109
  }
4110
  taosWLockLatch(&sStreamReaderInfo->lock);
363,431✔
4111
  sStreamReaderInfo->pVnode = pVnode;
363,431✔
4112
  initStorageAPI(&sStreamReaderInfo->storageApi);
363,431✔
4113
  if (sStreamReaderInfo->tableList.pTableList == NULL) {
363,139✔
4114
    code = initStreamTableListInfo(&sStreamReaderInfo->tableList);
363,139✔
4115
    if (code == 0) {
363,431✔
4116
      code = generateTablistForStreamReader(pVnode, sStreamReaderInfo);
363,431✔
4117
      if (code != 0) {
363,431✔
4118
        qStreamDestroyTableInfo(&sStreamReaderInfo->tableList);
×
4119
      } else {
4120
        sStreamReaderInfo->tableList.version = pVnode->state.applied;
363,431✔
4121
        stDebug("vgId:%d %s init table list for stream reader, table num:%zu, version:%" PRId64,
363,431✔
4122
                TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList), sStreamReaderInfo->tableList.version);
4123
      }
4124
    }
4125
  }
4126
  taosWUnLockLatch(&sStreamReaderInfo->lock);
363,431✔
4127
  return code;
363,431✔
4128
}
4129

4130
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
70,928,470✔
4131
  int32_t                   code = 0;
70,928,470✔
4132
  int32_t                   lino = 0;
70,928,470✔
4133
  SSTriggerPullRequestUnion req = {0};
70,928,470✔
4134
  void*                     taskAddr = NULL;
70,929,412✔
4135
  bool                      sendRsp = false;
70,925,706✔
4136

4137
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
70,925,706✔
4138
  if (!syncIsReadyForRead(pVnode->sync)) {
70,928,737✔
4139
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
179,735✔
4140
    return 0;
179,511✔
4141
  }
4142

4143
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
70,750,503✔
4144
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
8,131,877✔
4145
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
62,618,451✔
4146
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
62,619,405✔
4147
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
62,619,405✔
4148
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
62,619,675✔
4149
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
62,617,578✔
4150
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId, pVnode->state.applied);
4151
    SStreamTriggerReaderInfo* sStreamReaderInfo = qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
62,619,071✔
4152
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
62,615,726✔
4153
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
62,588,685✔
4154
    sendRsp = true;
62,591,437✔
4155
    switch (req.base.type) {
62,591,437✔
4156
      case STRIGGER_PULL_SET_TABLE:
145,889✔
4157
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
145,889✔
4158
        break;
145,889✔
4159
      case STRIGGER_PULL_LAST_TS:
352,598✔
4160
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
352,598✔
4161
        break;
352,598✔
4162
      case STRIGGER_PULL_FIRST_TS:
331,948✔
4163
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
331,948✔
4164
        break;
332,218✔
4165
      case STRIGGER_PULL_TSDB_META:
504,873✔
4166
      case STRIGGER_PULL_TSDB_META_NEXT:
4167
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
504,873✔
4168
        break;
504,873✔
4169
      case STRIGGER_PULL_TSDB_TS_DATA:
87,459✔
4170
        if (sStreamReaderInfo->isVtableStream) {
87,459✔
4171
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
3,296✔
4172
        } else {
4173
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
84,163✔
4174
        }
4175
        break;
87,459✔
4176
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
279,697✔
4177
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4178
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
279,697✔
4179
        break;
155,432✔
4180
      case STRIGGER_PULL_TSDB_CALC_DATA:
7,402,896✔
4181
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4182
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
7,402,896✔
4183
        break;
7,401,444✔
4184
      case STRIGGER_PULL_TSDB_DATA:
633,630✔
4185
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4186
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
633,630✔
4187
        break;
630,334✔
4188
      case STRIGGER_PULL_GROUP_COL_VALUE:
360,355✔
4189
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
360,355✔
4190
        break;
360,355✔
4191
      case STRIGGER_PULL_VTABLE_INFO:
83,022✔
4192
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
83,022✔
4193
        break;
83,022✔
4194
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
1,192,318✔
4195
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,192,318✔
4196
        break;
1,192,318✔
4197
      case STRIGGER_PULL_OTABLE_INFO:
145,889✔
4198
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
145,889✔
4199
        break;
145,889✔
4200
      case STRIGGER_PULL_WAL_META_NEW:
25,410,297✔
4201
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
25,410,297✔
4202
        break;
25,409,473✔
4203
      case STRIGGER_PULL_WAL_DATA_NEW:
17,396,856✔
4204
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
17,396,856✔
4205
        break;
17,396,586✔
4206
      case STRIGGER_PULL_WAL_META_DATA_NEW:
6,273,202✔
4207
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
6,273,202✔
4208
        break;
6,273,778✔
4209
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
1,991,062✔
4210
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,991,062✔
4211
        break;
1,991,062✔
4212
      default:
×
4213
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
4214
        sendRsp = false;
796✔
4215
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
796✔
4216
    }
4217
  } else {
4218
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
4219
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4220
  }
4221
end:
62,610,271✔
4222

4223
  streamReleaseTask(taskAddr);
62,618,878✔
4224

4225
  tDestroySTriggerPullRequest(&req);
62,619,419✔
4226
  STREAM_PRINT_LOG_END(code, lino);
62,615,331✔
4227
  if (!sendRsp) {
62,619,549✔
4228
    SRpcMsg rsp = {
54,082✔
4229
      .code = code,
4230
      .pCont = pMsg->info.rsp,
27,041✔
4231
      .contLen = pMsg->info.rspLen,
27,041✔
4232
      .info = pMsg->info,
4233
    };
4234
    tmsgSendRsp(&rsp);
27,041✔
4235
  }
4236
  return code;
62,619,549✔
4237
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc