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

taosdata / TDengine / #4834

31 Oct 2025 03:37AM UTC coverage: 58.764% (+0.2%) from 58.533%
#4834

push

travis-ci

SallyHuo-TAOS
Merge remote-tracking branch 'origin/cover/3.0' into cover/3.0

# Conflicts:
#	test/ci/run.sh

149869 of 324176 branches covered (46.23%)

Branch coverage included in aggregate %.

199000 of 269498 relevant lines covered (73.84%)

239175663.62 hits per line

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

68.93
/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 "nodes.h"
19
#include "osMemPool.h"
20
#include "osMemory.h"
21
#include "scalar.h"
22
#include "streamReader.h"
23
#include "taosdef.h"
24
#include "tarray.h"
25
#include "tcommon.h"
26
#include "tdatablock.h"
27
#include "tdb.h"
28
#include "tdef.h"
29
#include "tencode.h"
30
#include "tglobal.h"
31
#include "thash.h"
32
#include "tlist.h"
33
#include "tmsg.h"
34
#include "tsimplehash.h"
35
#include "vnd.h"
36
#include "vnode.h"
37
#include "vnodeInt.h"
38
#include "executor.h"
39

40
#define BUILD_OPTION(options, sStreamReaderInfo, _ver, _order, startTime, endTime, _schemas, _isSchema, _scanMode, \
41
                     _gid, _initReader, _mapInfo)                                                                        \
42
  SStreamTriggerReaderTaskInnerOptions options = {.suid = (_mapInfo == NULL ? sStreamReaderInfo->suid : 0),              \
43
                                                  .ver = _ver,                                                     \
44
                                                  .order = _order,                                                 \
45
                                                  .twindows = {.skey = startTime, .ekey = endTime},                \
46
                                                  .sStreamReaderInfo = sStreamReaderInfo,                     \
47
                                                  .schemas = _schemas,                                             \
48
                                                  .isSchema = _isSchema,                                           \
49
                                                  .scanMode = _scanMode,                                           \
50
                                                  .gid = _gid,                                                     \
51
                                                  .initReader = _initReader,                                       \
52
                                                  .mapInfo = _mapInfo};
53

54
typedef struct WalMetaResult {
55
  uint64_t    id;
56
  int64_t     skey;
57
  int64_t     ekey;
58
} WalMetaResult;
59

60
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
38,034,192✔
61

62
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas);
63

64
int32_t sortCid(const void *lp, const void *rp) {
2,799,084✔
65
  int16_t* c1 = (int16_t*)lp;
2,799,084✔
66
  int16_t* c2 = (int16_t*)rp;
2,799,084✔
67

68
  if (*c1 < *c2) {
2,799,084✔
69
    return -1;
2,776,234✔
70
  } else if (*c1 > *c2) {
22,850!
71
    return 1;
22,850✔
72
  }
73

74
  return 0;
×
75
}
76

77
int32_t sortSSchema(const void *lp, const void *rp) {
2,787,624✔
78
  SSchema* c1 = (SSchema*)lp;
2,787,624✔
79
  SSchema* c2 = (SSchema*)rp;
2,787,624✔
80

81
  if (c1->colId < c2->colId) {
2,787,624✔
82
    return -1;
2,766,066✔
83
  } else if (c1->colId > c2->colId) {
22,850!
84
    return 1;
22,850✔
85
  }
86

87
  return 0;
×
88
}
89

90
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
86,092,230✔
91
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
86,092,230✔
92
  if (pSrc == NULL) {
86,125,838!
93
    return terrno;
×
94
  }
95

96
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
86,125,838!
97
  return 0;
86,096,099✔
98
}
99

100
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
48,059,294✔
101
  int32_t code = pTask->api.tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
48,059,294✔
102
  if (code != TSDB_CODE_SUCCESS) {
48,042,918!
103
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
104
  }
105

106
  return code;
48,042,925✔
107
}
108

109
static int32_t getTableData(SStreamReaderTaskInner* pTask, SSDataBlock** ppRes) {
4,439,169✔
110
  return pTask->api.tsdReader.tsdReaderRetrieveDataBlock(pTask->pReader, ppRes, NULL);
4,439,169✔
111
}
112

113
static int32_t buildOTableInfoRsp(const SSTriggerOrigTableInfoRsp* rsp, void** data, size_t* size) {
305,262✔
114
  int32_t code = 0;
305,262✔
115
  int32_t lino = 0;
305,262✔
116
  void*   buf = NULL;
305,262✔
117
  int32_t len = tSerializeSTriggerOrigTableInfoRsp(NULL, 0, rsp);
305,262✔
118
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
306,531!
119
  buf = rpcMallocCont(len);
306,531✔
120
  STREAM_CHECK_NULL_GOTO(buf, terrno);
305,247!
121
  int32_t actLen = tSerializeSTriggerOrigTableInfoRsp(buf, len, rsp);
305,247✔
122
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
306,531!
123
  *data = buf;
306,531✔
124
  *size = len;
306,531✔
125
  buf = NULL;
306,531✔
126
end:
306,531✔
127
  rpcFreeCont(buf);
306,531✔
128
  return code;
305,262✔
129
}
130

131
static bool needRefreshTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
9,610,164✔
132
  if (sStreamReaderInfo->isVtableStream) {
9,610,164!
133
    int64_t id[2] = {suid, uid};
7,532,950✔
134
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id)) == NULL) {
7,532,942!
135
      return true;
7,523,982✔
136
    }
137
  } else {
138
    if (tableType != TD_CHILD_TABLE) {
2,077,214✔
139
      return false;
708,274✔
140
    }
141
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
1,368,940✔
142
        suid == sStreamReaderInfo->suid && 
837,792✔
143
        qStreamGetGroupId(sStreamReaderInfo->tableList, uid) == -1) {
29,610✔
144
      return true;
11,593✔
145
    }
146
  }
147
  return false;
1,367,698✔
148
}
149

150
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc){
121,344,326✔
151
  if (sStreamReaderInfo->isVtableStream) {
121,344,326!
152
    int64_t tmp[2] = {suid, uid};
86,062,462✔
153
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) == NULL) {
86,066,314✔
154
      return false;
43,372,987✔
155
    }
156
    *id = uid;
42,690,798✔
157
  } else {
158
    if (sStreamReaderInfo->tableList == NULL) return false;
35,294,689!
159

160
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
35,314,908✔
161
      if (suid != sStreamReaderInfo->suid) return false;
22,016,092✔
162
      if (sStreamReaderInfo->pTagCond == NULL) {
17,107,223✔
163
        if (sStreamReaderInfo->partitionCols == NULL){
14,942,208✔
164
          *id = 0;
53,336✔
165
        } else if (sStreamReaderInfo->groupByTbname){
14,887,588!
166
          *id= uid;
14,000,004✔
167
        } else {
168
          *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
887,584✔
169
          if (*id == -1) return false;
887,584!
170
        }
171
      } else {
172
        //*id= uid;
173
        *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
2,163,729✔
174
        if (*id == -1) return false;
2,165,020✔
175
      }
176
    } else {
177
      *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
13,309,088✔
178
      if(*id == -1) *id = uid;
13,306,520✔
179
      return uid == sStreamReaderInfo->uid;
13,305,249✔
180
    }
181
  }
182
  return true;
58,879,073✔
183
}
184

185
static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, bool isHistory) {
16,729,706✔
186
  int32_t                   code = 0;
16,729,706✔
187
  int32_t                   lino = 0;
16,729,706✔
188
  SNodeList* groupNew = NULL;                                      
16,729,706✔
189
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
16,734,727!
190

191
  SStorageAPI api = {0};
16,732,122✔
192
  initStorageAPI(&api);
16,732,122✔
193
  code = qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
16,730,865✔
194
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, 
195
                                         isHistory ? &sStreamReaderInfo->historyTableList : &sStreamReaderInfo->tableList,
196
                                         isHistory ? NULL : sStreamReaderInfo->groupIdMap);
197
  end:
16,734,727✔
198
  nodesDestroyList(groupNew);
16,733,436✔
199
  STREAM_PRINT_LOG_END(code, lino);
16,734,747!
200
  return code;
16,736,018✔
201
}
202

203
static int32_t buildVTableInfoRsp(const SStreamMsgVTableInfo* rsp, void** data, size_t* size) {
1,030,392✔
204
  int32_t code = 0;
1,030,392✔
205
  int32_t lino = 0;
1,030,392✔
206
  void*   buf = NULL;
1,030,392✔
207
  int32_t len = tSerializeSStreamMsgVTableInfo(NULL, 0, rsp);
1,030,392✔
208
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
1,030,392!
209
  buf = rpcMallocCont(len);
1,030,392✔
210
  STREAM_CHECK_NULL_GOTO(buf, terrno);
1,030,392!
211
  int32_t actLen = tSerializeSStreamMsgVTableInfo(buf, len, rsp);
1,030,392✔
212
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
1,030,392!
213
  *data = buf;
1,030,392✔
214
  *size = len;
1,030,392✔
215
  buf = NULL;
1,030,392✔
216
end:
1,030,392✔
217
  rpcFreeCont(buf);
1,030,392✔
218
  return code;
1,030,392✔
219
}
220

221
static int32_t buildTsRsp(const SStreamTsResponse* tsRsp, void** data, size_t* size) {
1,415,983✔
222
  int32_t code = 0;
1,415,983✔
223
  int32_t lino = 0;
1,415,983✔
224
  void*   buf = NULL;
1,415,983✔
225
  int32_t len = tSerializeSStreamTsResponse(NULL, 0, tsRsp);
1,415,983✔
226
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
1,414,720!
227
  buf = rpcMallocCont(len);
1,414,720✔
228
  STREAM_CHECK_NULL_GOTO(buf, terrno);
1,417,274!
229
  int32_t actLen = tSerializeSStreamTsResponse(buf, len, tsRsp);
1,417,274✔
230
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
1,415,983!
231
  *data = buf;
1,415,983✔
232
  *size = len;
1,415,983✔
233
  buf = NULL;
1,415,983✔
234
end:
1,415,983✔
235
  rpcFreeCont(buf);
1,415,983✔
236
  return code;
1,417,274✔
237
}
238

239

240
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
40,060,241✔
241
  int32_t code = 0;
40,060,241✔
242
  int32_t lino = 0;
40,060,241✔
243
  void*   buf = NULL;
40,060,241✔
244
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
40,060,241!
245
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
4,519,637✔
246
  buf = rpcMallocCont(dataEncodeSize);
4,519,636✔
247
  STREAM_CHECK_NULL_GOTO(buf, terrno);
4,514,654!
248
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
4,514,654✔
249
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
4,517,121!
250
  *data = buf;
4,517,121✔
251
  *size = dataEncodeSize;
4,517,121✔
252
  buf = NULL;
4,517,121✔
253
end:
40,061,480✔
254
  rpcFreeCont(buf);
40,061,480✔
255
  return code;
40,060,234✔
256
}
257

258
static int32_t resetTsdbReader(SStreamReaderTaskInner* pTask) {
3,392,207✔
259
  int32_t        pNum = 1;
3,392,207✔
260
  STableKeyInfo* pList = NULL;
3,392,207✔
261
  int32_t        code = 0;
3,392,207✔
262
  int32_t        lino = 0;
3,392,207✔
263
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(pTask->pTableList, pTask->currentGroupIndex, &pList, &pNum));
3,392,207!
264
  if (pList == NULL || pNum == 0) {
3,390,938!
265
    code = TSDB_CODE_INVALID_PARA;
×
266
    goto end;
×
267
  }
268
  STREAM_CHECK_RET_GOTO(pTask->api.tsdReader.tsdSetQueryTableList(pTask->pReader, pList, pNum));
3,390,938!
269

270
  cleanupQueryTableDataCond(&pTask->cond);
3,392,207✔
271
  uint64_t suid = pTask->options.sStreamReaderInfo->isVtableStream ? pList->groupId : pTask->options.suid;
3,392,207!
272
  STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTask->cond, pTask->options.order, pTask->options.schemas, true,
3,392,207!
273
                                                      pTask->options.twindows, suid, pTask->options.ver, NULL));
274
  STREAM_CHECK_RET_GOTO(pTask->api.tsdReader.tsdReaderResetStatus(pTask->pReader, &pTask->cond));
3,392,207!
275

276
end:
3,392,207✔
277
  STREAM_PRINT_LOG_END(code, lino);
3,392,207!
278
  return code;
3,392,207✔
279
}
280

281
static int32_t buildWalMetaBlock(SSDataBlock* pBlock, int8_t type, int64_t id, bool isVTable, int64_t uid,
×
282
                                 int64_t skey, int64_t ekey, int64_t ver, int64_t rows) {
283
  int32_t code = 0;
×
284
  int32_t lino = 0;
×
285
  int32_t index = 0;
×
286
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &type));
×
287
  if (!isVTable) {
×
288
    STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
×
289
  }
290
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &uid));
×
291
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
×
292
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
×
293
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
×
294
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &rows));
×
295

296
end:
×
297
  // STREAM_PRINT_LOG_END(code, lino)
298
  return code;
×
299
}
300

301
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
20,936,504✔
302
  int32_t code = 0;
20,936,504✔
303
  int32_t lino = 0;
20,936,504✔
304
  int32_t index = 0;
20,936,504✔
305
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
20,936,504!
306
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
20,937,787!
307
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
20,936,520!
308
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
20,936,600!
309

310
end:
20,939,171✔
311
  return code;
20,939,171✔
312
}
313

314
static int32_t buildDropTableBlock(SSDataBlock* pBlock, int64_t id, int64_t ver) {
1,310✔
315
  int32_t code = 0;
1,310✔
316
  int32_t lino = 0;
1,310✔
317
  int32_t index = 0;
1,310✔
318
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
1,310!
319
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
1,310!
320

321
end:
1,310✔
322
  return code;
1,310✔
323
}
324

325
static void buildTSchema(STSchema* pTSchema, int32_t ver, col_id_t colId, int8_t type, int32_t bytes) {
×
326
  pTSchema->numOfCols = 1;
×
327
  pTSchema->version = ver;
×
328
  pTSchema->columns[0].colId = colId;
×
329
  pTSchema->columns[0].type = type;
×
330
  pTSchema->columns[0].bytes = bytes;
×
331
}
×
332

333
static int32_t scanDeleteDataNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
148,696✔
334
                              int64_t ver) {
335
  int32_t    code = 0;
148,696✔
336
  int32_t    lino = 0;
148,696✔
337
  SDecoder   decoder = {0};
148,696✔
338
  SDeleteRes req = {0};
148,696✔
339
  void* pTask = sStreamReaderInfo->pTask;
148,696✔
340

341
  req.uidList = taosArrayInit(0, sizeof(tb_uid_t));
148,696✔
342
  tDecoderInit(&decoder, data, len);
148,696✔
343
  STREAM_CHECK_RET_GOTO(tDecodeDeleteRes(&decoder, &req));
148,696!
344
  STREAM_CHECK_CONDITION_GOTO((sStreamReaderInfo->tableType == TSDB_SUPER_TABLE && !sStreamReaderInfo->isVtableStream && req.suid != sStreamReaderInfo->suid), TDB_CODE_SUCCESS);
148,696!
345
  
346
  for (int32_t i = 0; i < taosArrayGetSize(req.uidList); i++) {
216,871✔
347
    uint64_t* uid = taosArrayGet(req.uidList, i);
124,493✔
348
    STREAM_CHECK_NULL_GOTO(uid, terrno);
124,493!
349
    uint64_t   id = 0;
124,493✔
350
    ST_TASK_ILOG("stream reader scan delete start data:uid %" PRIu64 ", skey %" PRIu64 ", ekey %" PRIu64, *uid, req.skey, req.ekey);
124,493!
351
    STREAM_CHECK_CONDITION_GOTO(!uidInTableList(sStreamReaderInfo, req.suid, *uid, &id, false), TDB_CODE_SUCCESS);
124,493✔
352
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->deleteBlock, ((SSDataBlock*)rsp->deleteBlock)->info.rows + 1));
92,378!
353
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->deleteBlock, id, req.skey, req.ekey, ver));
92,378!
354
    ((SSDataBlock*)rsp->deleteBlock)->info.rows++;
92,378✔
355
    rsp->totalRows++;
92,378✔
356
  }
357

358
end:
148,696✔
359
  taosArrayDestroy(req.uidList);
148,696✔
360
  tDecoderClear(&decoder);
148,696✔
361
  return code;
148,696✔
362
}
363

364
static int32_t scanDropTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
1,310✔
365
                             int64_t ver) {
366
  int32_t  code = 0;
1,310✔
367
  int32_t  lino = 0;
1,310✔
368
  SDecoder decoder = {0};
1,310✔
369
  void* pTask = sStreamReaderInfo->pTask;
1,310✔
370

371
  SVDropTbBatchReq req = {0};
1,310✔
372
  tDecoderInit(&decoder, data, len);
1,310✔
373
  STREAM_CHECK_RET_GOTO(tDecodeSVDropTbBatchReq(&decoder, &req));
1,310!
374

375
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
2,620✔
376
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
1,310✔
377
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
1,310!
378
    uint64_t id = 0;
1,310✔
379
    if(!uidInTableList(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id, false)) {
1,310!
380
      continue;
×
381
    }
382

383
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dropBlock, ((SSDataBlock*)rsp->dropBlock)->info.rows + 1));
1,310!
384
    STREAM_CHECK_RET_GOTO(buildDropTableBlock(rsp->dropBlock, id, ver));
1,310!
385
    ((SSDataBlock*)rsp->dropBlock)->info.rows++;
1,310✔
386
    rsp->totalRows++;
1,310✔
387
    ST_TASK_ILOG("stream reader scan drop uid %" PRId64 ", id %" PRIu64, pDropTbReq->uid, id);
1,310!
388
  }
389

390
end:
1,310✔
391
  tDecoderClear(&decoder);
1,310✔
392
  return code;
1,310✔
393
}
394

395
static int32_t reloadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo){
7,562,643✔
396
  (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
7,562,643✔
397
  qStreamDestroyTableList(sStreamReaderInfo->tableList);
7,562,643✔
398
  sStreamReaderInfo->tableList = NULL;
7,561,379✔
399
  int32_t code = generateTablistForStreamReader(sStreamReaderInfo->pVnode, sStreamReaderInfo, false);
7,561,379✔
400
  if (code == 0){
7,562,643!
401
    qStreamDestroyTableList(sStreamReaderInfo->historyTableList);
7,562,643✔
402
    sStreamReaderInfo->historyTableList = NULL;
7,562,643✔
403
    code = generateTablistForStreamReader(sStreamReaderInfo->pVnode, sStreamReaderInfo, true);
7,562,643✔
404
  }
405
  (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
7,561,374✔
406
  return code;
7,562,643✔
407
}
408

409
static int32_t scanCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
125,368✔
410
  int32_t  code = 0;
125,368✔
411
  int32_t  lino = 0;
125,368✔
412
  SDecoder decoder = {0};
125,368✔
413
  void* pTask = sStreamReaderInfo->pTask;
125,368✔
414

415
  SVCreateTbBatchReq req = {0};
125,368✔
416
  tDecoderInit(&decoder, data, len);
125,368✔
417
  
418
  STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbBatchReq(&decoder, &req));
125,368!
419

420
  bool found = false;
125,368✔
421
  SVCreateTbReq* pCreateReq = NULL;
125,368✔
422
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
190,691✔
423
    pCreateReq = req.pReqs + iReq;
125,368✔
424
    if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
125,368✔
425
      ST_TASK_ILOG("stream reader scan create table jump, %s", pCreateReq->name);
65,323!
426
      continue;
65,323✔
427
    }
428
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
60,045!
429

430
    found = true;
60,045✔
431
    break;
60,045✔
432
  }
433
  STREAM_CHECK_CONDITION_GOTO(!found, TDB_CODE_SUCCESS);
125,368✔
434

435
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
60,045!
436
end:
125,368✔
437
  tDeleteSVCreateTbBatchReq(&req);
125,368✔
438
  tDecoderClear(&decoder);
125,368✔
439
  return code;
125,368✔
440
}
441

442
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq) {
9,480,944✔
443
  int32_t  code = 0;
9,480,944✔
444
  int32_t  lino = 0;
9,480,944✔
445
  void*    pTask = sStreamReaderInfo->pTask;
9,480,944✔
446
  if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
9,486,178✔
447
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
2,009,365✔
448
    goto end;
2,010,649✔
449
  }
450
  ST_TASK_ILOG("stream reader scan auto create table %s", pCreateReq->name);
7,475,530✔
451

452
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
7,476,814!
453
end:
7,475,530✔
454
  return code;
9,486,179✔
455
}
456

457
static int32_t scanAlterTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
157,754✔
458
  int32_t  code = 0;
157,754✔
459
  int32_t  lino = 0;
157,754✔
460
  SDecoder decoder = {0};
157,754✔
461
  void* pTask = sStreamReaderInfo->pTask;
157,754✔
462

463
  SVAlterTbReq req = {0};
157,754✔
464
  tDecoderInit(&decoder, data, len);
157,754✔
465
  
466
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
157,754!
467
  STREAM_CHECK_CONDITION_GOTO(req.action != TSDB_ALTER_TABLE_UPDATE_TAG_VAL && req.action != TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL, TDB_CODE_SUCCESS);
157,754!
468

469
  ETableType tbType = 0;
42,236✔
470
  uint64_t suid = 0;
42,236✔
471
  STREAM_CHECK_RET_GOTO(metaGetTableTypeSuidByName(sStreamReaderInfo->pVnode, req.tbName, &tbType, &suid));
42,236!
472
  STREAM_CHECK_CONDITION_GOTO(tbType != TSDB_CHILD_TABLE, TDB_CODE_SUCCESS);
42,236!
473
  STREAM_CHECK_CONDITION_GOTO(suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
42,236✔
474

475
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
27,068!
476
  ST_TASK_ILOG("stream reader scan alter table %s", req.tbName);
27,068!
477

478
end:
157,754✔
479
  taosArrayDestroy(req.pMultiTag);
157,754✔
480
  tDecoderClear(&decoder);
157,754✔
481
  return code;
157,754✔
482
}
483

484
// static int32_t scanAlterSTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
485
//   int32_t  code = 0;
486
//   int32_t  lino = 0;
487
//   SDecoder decoder = {0};
488
//   SMAlterStbReq reqAlter = {0};
489
//   SVCreateStbReq req = {0};
490
//   tDecoderInit(&decoder, data, len);
491
//   void* pTask = sStreamReaderInfo->pTask;
492
  
493
//   STREAM_CHECK_RET_GOTO(tDecodeSVCreateStbReq(&decoder, &req));
494
//   STREAM_CHECK_CONDITION_GOTO(req.suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
495
//   if (req.alterOriData != 0) {
496
//     STREAM_CHECK_RET_GOTO(tDeserializeSMAlterStbReq(req.alterOriData, req.alterOriDataLen, &reqAlter));
497
//     STREAM_CHECK_CONDITION_GOTO(reqAlter.alterType != TSDB_ALTER_TABLE_DROP_TAG && reqAlter.alterType != TSDB_ALTER_TABLE_UPDATE_TAG_NAME, TDB_CODE_SUCCESS);
498
//   }
499
  
500
//   STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
501

502
//   ST_TASK_ILOG("stream reader scan alter suid %" PRId64, req.suid);
503
// end:
504
//   tFreeSMAltertbReq(&reqAlter);
505
//   tDecoderClear(&decoder);
506
//   return code;
507
// }
508

509
static int32_t scanDropSTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
×
510
  int32_t  code = 0;
×
511
  int32_t  lino = 0;
×
512
  SDecoder decoder = {0};
×
513
  void* pTask = sStreamReaderInfo->pTask;
×
514

515
  SVDropStbReq req = {0};
×
516
  tDecoderInit(&decoder, data, len);
×
517
  STREAM_CHECK_RET_GOTO(tDecodeSVDropStbReq(&decoder, &req));
×
518
  STREAM_CHECK_CONDITION_GOTO(req.suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
×
519
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
×
520

521
  ST_TASK_ILOG("stream reader scan drop suid %" PRId64, req.suid);
×
522
end:
×
523
  tDecoderClear(&decoder);
×
524
  return code;
×
525
}
526

527
static int32_t scanSubmitTbDataForMeta(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* gidHash) {
60,476,982✔
528
  int32_t code = 0;
60,476,982✔
529
  int32_t lino = 0;
60,476,982✔
530
  WalMetaResult walMeta = {0};
60,476,982✔
531
  SSubmitTbData submitTbData = {0};
60,469,304✔
532
  
533
  if (tStartDecode(pCoder) < 0) {
60,471,872!
534
    code = TSDB_CODE_INVALID_MSG;
×
535
    TSDB_CHECK_CODE(code, lino, end);
×
536
  }
537

538
  uint8_t       version = 0;
60,488,458✔
539
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
60,483,346!
540
    code = TSDB_CODE_INVALID_MSG;
×
541
    TSDB_CHECK_CODE(code, lino, end);
×
542
  }
543
  version = (submitTbData.flags >> 8) & 0xff;
60,483,346✔
544
  submitTbData.flags = submitTbData.flags & 0xff;
60,483,346✔
545

546
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
547
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
60,483,346✔
548
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
7,799,235!
549
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
7,799,261!
550
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
7,799,261!
551
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
7,801,803!
552
  }
553

554
  // submit data
555
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
60,480,812!
556
    code = TSDB_CODE_INVALID_MSG;
×
557
    TSDB_CHECK_CODE(code, lino, end);
×
558
  }
559
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
60,479,511!
560
    code = TSDB_CODE_INVALID_MSG;
×
561
    TSDB_CHECK_CODE(code, lino, end);
×
562
  }
563

564
  if (!uidInTableList(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
60,479,511✔
565
    goto end;
44,972,081✔
566
  }
567
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
15,506,196!
568
    code = TSDB_CODE_INVALID_MSG;
×
569
    TSDB_CHECK_CODE(code, lino, end);
×
570
  }
571

572
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
15,506,196!
573
    uint64_t nColData = 0;
×
574
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
575
      code = TSDB_CODE_INVALID_MSG;
×
576
      TSDB_CHECK_CODE(code, lino, end);
×
577
    }
578

579
    SColData colData = {0};
×
580
    code = tDecodeColData(version, pCoder, &colData, false);
×
581
    if (code) {
×
582
      code = TSDB_CODE_INVALID_MSG;
×
583
      TSDB_CHECK_CODE(code, lino, end);
×
584
    }
585

586
    if (colData.flag != HAS_VALUE) {
×
587
      code = TSDB_CODE_INVALID_MSG;
×
588
      TSDB_CHECK_CODE(code, lino, end);
×
589
    }
590
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
591
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
592

593
    for (uint64_t i = 1; i < nColData; i++) {
×
594
      code = tDecodeColData(version, pCoder, &colData, true);
×
595
      if (code) {
×
596
        code = TSDB_CODE_INVALID_MSG;
×
597
        TSDB_CHECK_CODE(code, lino, end);
×
598
      }
599
    }
600
  } else {
601
    uint64_t nRow = 0;
15,506,196✔
602
    if (tDecodeU64v(pCoder, &nRow) < 0) {
15,503,628!
603
      code = TSDB_CODE_INVALID_MSG;
×
604
      TSDB_CHECK_CODE(code, lino, end);
×
605
    }
606

607
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
37,500,788✔
608
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
21,989,529✔
609
      pCoder->pos += pRow->len;
21,997,160✔
610
      if (iRow == 0){
21,998,444✔
611
#ifndef NO_UNALIGNED_ACCESS
612
        walMeta.skey = pRow->ts;
15,504,810✔
613
#else
614
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
615
#endif
616
      }
617
      if (iRow == nRow - 1) {
21,998,444✔
618
#ifndef NO_UNALIGNED_ACCESS
619
        walMeta.ekey = pRow->ts;
15,507,467✔
620
#else
621
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
622
#endif
623
      }
624
    }
625
  }
626

627
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
15,499,674✔
628
  if (data != NULL) {
15,503,513!
629
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
630
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
631
  } else {
632
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
15,503,513!
633
  }
634

635
end:
60,461,216✔
636
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
60,470,413✔
637
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
60,462,663!
638
  tEndDecode(pCoder);
60,462,663✔
639
  return code;
60,470,514✔
640
}
641

642
static int32_t scanSubmitDataForMeta(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len, int64_t ver) {
60,487,144✔
643
  int32_t  code = 0;
60,487,144✔
644
  int32_t  lino = 0;
60,487,144✔
645
  SDecoder decoder = {0};
60,487,144✔
646
  SSHashObj* gidHash = NULL;
60,483,305✔
647
  void* pTask = sStreamReaderInfo->pTask;
60,483,305✔
648

649
  tDecoderInit(&decoder, data, len);
60,488,428✔
650
  if (tStartDecode(&decoder) < 0) {
60,484,563!
651
    code = TSDB_CODE_INVALID_MSG;
×
652
    TSDB_CHECK_CODE(code, lino, end);
×
653
  }
654

655
  uint64_t nSubmitTbData = 0;
60,483,379✔
656
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
60,479,455!
657
    code = TSDB_CODE_INVALID_MSG;
×
658
    TSDB_CHECK_CODE(code, lino, end);
×
659
  }
660

661
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
60,479,455✔
662
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
60,466,807!
663

664
  for (int32_t i = 0; i < nSubmitTbData; i++) {
120,943,776✔
665
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash));
60,469,375!
666
  }
667
  tEndDecode(&decoder);
60,474,401✔
668

669
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
60,470,569!
670
  int32_t iter = 0;
60,450,260✔
671
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
60,449,099✔
672
  while (px != NULL) {
75,986,872✔
673
    WalMetaResult* pMeta = (WalMetaResult*)px;
15,504,823✔
674
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
15,504,823!
675
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
15,507,467✔
676
    rsp->totalRows++;
15,508,751✔
677
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
15,507,471✔
678
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
679
    px = tSimpleHashIterate(gidHash, px, &iter);
15,510,115✔
680
  }
681
end:
60,482,049✔
682
  tDecoderClear(&decoder);
60,484,604✔
683
  tSimpleHashCleanup( gidHash);
60,474,449✔
684
  return code;
60,477,010✔
685
}
686

687
static int32_t createBlockForTsdbMeta(SSDataBlock** pBlock, bool isVTable) {
1,331,487✔
688
  int32_t code = 0;
1,331,487✔
689
  int32_t lino = 0;
1,331,487✔
690
  SArray* schemas = taosArrayInit(8, sizeof(SSchema));
1,331,487✔
691
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
1,331,487!
692

693
  int32_t index = 1;
1,331,487✔
694
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // skey
1,331,487!
695
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // ekey
1,331,487!
696
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
1,331,487!
697
  if (!isVTable) {
1,331,487✔
698
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_UBIGINT, LONG_BYTES, index++))  // gid
196,475!
699
  }
700
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))     // nrows
1,331,487!
701

702
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
1,331,487!
703

704
end:
1,331,487✔
705
  taosArrayDestroy(schemas);
1,331,487✔
706
  return code;
1,331,487✔
707
}
708

709
static int32_t createBlockForWalMetaNew(SSDataBlock** pBlock) {
857,730✔
710
  int32_t code = 0;
857,730✔
711
  int32_t lino = 0;
857,730✔
712
  SArray* schemas = NULL;
857,730✔
713

714
  schemas = taosArrayInit(8, sizeof(SSchema));
857,730✔
715
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
857,730!
716

717
  int32_t index = 0;
857,730✔
718
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid non vtable/uid vtable
857,730!
719
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // skey
857,730!
720
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ekey
857,730!
721
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
857,730!
722

723
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
857,730!
724

725
end:
857,730✔
726
  taosArrayDestroy(schemas);
857,730✔
727
  return code;
857,730✔
728
}
729

730
static int32_t createBlockForDropTable(SSDataBlock** pBlock) {
1,310✔
731
  int32_t code = 0;
1,310✔
732
  int32_t lino = 0;
1,310✔
733
  SArray* schemas = NULL;
1,310✔
734

735
  schemas = taosArrayInit(8, sizeof(SSchema));
1,310✔
736
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
1,310!
737

738
  int32_t index = 0;
1,310✔
739
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid non vtable/uid vtable
1,310!
740
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
1,310!
741

742
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
1,310!
743

744
end:
1,310✔
745
  taosArrayDestroy(schemas);
1,310✔
746
  return code;
1,310✔
747
}
748

749
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int32_t ver) {
1,311,594✔
750
  int32_t code = 0;
1,311,594✔
751
  int32_t lino = 0;
1,311,594✔
752
  SDecoder dcoder = {0};
1,311,594✔
753
  tDecoderInit(&dcoder, data, len);
1,311,594✔
754
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
1,311,594✔
755
    if (rsp->deleteBlock == NULL) {
148,696✔
756
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
53,638!
757
    }
758
      
759
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
148,696!
760
  } else if (msgType == TDMT_VND_DROP_TABLE && sStreamReaderInfo->deleteOutTbl != 0) {
1,162,898✔
761
    if (rsp->dropBlock == NULL) {
1,310!
762
      STREAM_CHECK_RET_GOTO(createBlockForDropTable((SSDataBlock**)&rsp->dropBlock));
1,310!
763
    }
764
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
1,310!
765
  } else if (msgType == TDMT_VND_DROP_STB) {
1,161,588!
766
    STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
×
767
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
1,161,588✔
768
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, data, len));
125,368!
769
  } else if (msgType == TDMT_VND_ALTER_STB) {
1,036,220✔
770
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
771
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
834,171✔
772
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, data, len));
157,754!
773
  }
774

775
  end:
1,311,594✔
776
  tDecoderClear(&dcoder);
1,311,594✔
777
  return code;
1,311,594✔
778
}
779
static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
19,776,032✔
780
                       int64_t ctime) {
781
  int32_t code = 0;
19,776,032✔
782
  int32_t lino = 0;
19,776,032✔
783
  void* pTask = sStreamReaderInfo->pTask;
19,776,032✔
784

785
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
19,774,748✔
786
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
19,768,284!
787
  code = walReaderSeekVer(pWalReader, rsp->ver);
19,768,284✔
788
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
19,744,013✔
789
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
14,876,634!
790
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
791
    }
792
    ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
14,897,113✔
793
    code = TSDB_CODE_SUCCESS;
14,899,681✔
794
    goto end;
14,899,681✔
795
  }
796
  STREAM_CHECK_RET_GOTO(code);
4,867,379!
797

798
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
4,867,379!
799
  while (1) {
61,287,632✔
800
    code = walNextValidMsg(pWalReader, true);
66,149,901✔
801
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){\
66,143,210✔
802
      ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
4,866,045✔
803
      code = TSDB_CODE_SUCCESS;
4,871,215✔
804
      goto end;
4,871,215✔
805
    }
806
    STREAM_CHECK_RET_GOTO(code);
61,277,165!
807
    rsp->ver = pWalReader->curVersion;
61,277,165✔
808
    SWalCont* wCont = &pWalReader->pHead->head;
61,281,100✔
809
    rsp->verTime = wCont->ingestTs;
61,270,731✔
810
    if (wCont->ingestTs / 1000 > ctime) break;
61,275,973!
811
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
61,272,078✔
812
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
61,277,178✔
813
    int64_t ver = wCont->version;
61,286,208✔
814

815
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
61,283,708✔
816
      TD_VID(pVnode), ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
817
    if (wCont->msgType == TDMT_VND_SUBMIT) {
61,293,975✔
818
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
60,487,131✔
819
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
60,484,576✔
820
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
60,487,144!
821
    } else {
822
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
800,445!
823
    }
824

825
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
61,282,548!
826
      break;
×
827
    }
828
  }
829

830
end:
19,770,896✔
831
  walCloseReader(pWalReader);
19,770,896✔
832
  return code;
19,773,464✔
833
}
834

835
static int32_t processTag(SVnode* pVnode, SStreamTriggerReaderInfo* info, bool isCalc, SStorageAPI* api, 
10,372,002✔
836
  uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks) {
837
  int32_t     code = 0;
10,372,002✔
838
  int32_t     lino = 0;
10,372,002✔
839
  SMetaReader mr = {0};
10,372,002✔
840
  SArray* tagCache = NULL;
10,373,585✔
841

842
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
10,372,295!
843
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
10,369,715!
844
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
10,370,815!
845
  if (numOfExpr == 0) {
10,372,196!
846
    return TSDB_CODE_SUCCESS;
×
847
  }
848

849
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
10,372,196✔
850
  if (uidData == NULL) {
10,374,881✔
851
    api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
428,925✔
852
    code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
428,925✔
853
    api->metaReaderFn.readerReleaseLock(&mr);
428,925✔
854
    STREAM_CHECK_RET_GOTO(code);
428,925!
855

856
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
428,925✔
857
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
428,826!
858
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
428,826!
859
      taosArrayDestroyP(tagCache, taosMemFree);
×
860
      code = terrno;
×
861
      goto end;
×
862
    }
863
  } else {
864
    tagCache = *(SArray**)uidData;
9,945,956✔
865
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
9,945,857!
866
  }
867
  
868
  for (int32_t j = 0; j < numOfExpr; ++j) {
28,286,686✔
869
    const SExprInfo* pExpr1 = &pExprInfo[j];
17,912,013✔
870
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
17,914,561✔
871

872
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
17,914,557✔
873
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
17,912,098!
874
    int32_t functionId = pExpr1->pExpr->_function.functionId;
17,912,098✔
875

876
    // this is to handle the tbname
877
    if (fmIsScanPseudoColumnFunc(functionId)) {
17,911,997✔
878
      int32_t fType = pExpr1->pExpr->_function.functionType;
10,368,459✔
879
      if (fType == FUNCTION_TYPE_TBNAME) {
10,372,315!
880
        char   buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
10,372,315✔
881
        if (uidData == NULL) {
10,374,871✔
882
          STR_TO_VARSTR(buf, mr.me.name)
428,925!
883
          char* tbname = taosStrdup(mr.me.name);
428,925!
884
          STREAM_CHECK_NULL_GOTO(tbname, terrno);
428,925!
885
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno);
857,850!
886
        } else {
887
          char* tbname = taosArrayGetP(tagCache, j);
9,945,946✔
888
          STR_TO_VARSTR(buf, tbname)
9,943,185!
889
        }
890
        code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false);
10,376,068✔
891
        // stInfo("set pseudo column tbname:%s currentRow:%d, numOfRows:%d, dstSlotId:%d, totalRows:%"PRId64" for uid:%" PRIu64 ", %p,%p", buf + VARSTR_HEADER_SIZE, 
892
        //   currentRow, numOfRows, dstSlotId, pBlock->info.rows, uid, pColInfoData, pColInfoData->pData);
893
        pColInfoData->info.colId = -1;
10,371,911✔
894
      }
895
    } else {  // these are tags
896
      char* data = NULL;
7,544,923✔
897
      const char* p = NULL;
7,544,923✔
898
      STagVal tagVal = {0};
7,544,923✔
899
      if (uidData == NULL) {
7,544,923✔
900
        tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
333,370✔
901
        p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
333,370✔
902

903
        if (pColInfoData->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
333,370!
904
          data = tTagValToData((const STagVal*)p, false);
333,370✔
905
        } else {
906
          data = (char*)p;
×
907
        }
908

909
        if (data == NULL) {
333,370!
910
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
×
911
        } else {
912
          int32_t len = pColInfoData->info.bytes;
333,370✔
913
          if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
333,370!
914
            len = calcStrBytesByType(pColInfoData->info.type, (char*)data);
104,705✔
915
          }
916
          char* pData = taosMemoryCalloc(1, len);
333,370!
917
          STREAM_CHECK_NULL_GOTO(pData, terrno);
333,370!
918
          (void)memcpy(pData, data, len);
333,370!
919
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno);
666,740!
920
        }
921
      } else {
922
        data = taosArrayGetP(tagCache, j);
7,211,553✔
923
      }
924

925
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
7,544,923!
926
      if (isNullVal) {
7,544,923!
927
        colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
928
      } else {
929
        for (uint32_t i = 0; i < numOfRows && !IS_VAR_DATA_TYPE(pColInfoData->info.type); i++){
14,575,823!
930
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
7,030,900!
931
        }
932
        code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false);
7,546,209✔
933
        if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
7,546,209!
934
          taosMemoryFree(data);
104,705!
935
        }
936
        STREAM_CHECK_RET_GOTO(code);
7,546,209!
937
      }
938
    }
939
  }
940

941
end:
10,382,399✔
942
  api->metaReaderFn.clearReader(&mr);
10,376,068✔
943
  return code;
10,369,652✔
944
}
945

946
int32_t getRowRange(SColData* pCol, STimeWindow* window, int32_t* rowStart, int32_t* rowEnd, int32_t* nRows) {
×
947
  int32_t code = 0;
×
948
  int32_t lino = 0;
×
949
  *nRows = 0;
×
950
  *rowStart = 0;
×
951
  *rowEnd = pCol->nVal;
×
952
  if (window != NULL) {
×
953
    SColVal colVal = {0};
×
954
    *rowStart = -1;
×
955
    *rowEnd = -1;
×
956
    for (int32_t k = 0; k < pCol->nVal; k++) {
×
957
      STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, k, &colVal));
×
958
      int64_t ts = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
×
959
      if (ts >= window->skey && *rowStart == -1) {
×
960
        *rowStart = k;
×
961
      }
962
      if (ts > window->ekey && *rowEnd == -1) {
×
963
        *rowEnd = k;
×
964
      }
965
    }
966
    STREAM_CHECK_CONDITION_GOTO(*rowStart == -1 || *rowStart == *rowEnd, TDB_CODE_SUCCESS);
×
967

968
    if (*rowStart != -1 && *rowEnd == -1) {
×
969
      *rowEnd = pCol->nVal;
×
970
    }
971
  }
972
  *nRows = *rowEnd - *rowStart;
×
973

974
end:
×
975
  return code;
×
976
}
977

978
static int32_t setColData(int64_t rows, int32_t rowStart, int32_t rowEnd, SColData* colData, SColumnInfoData* pColData) {
×
979
  int32_t code = 0;
×
980
  int32_t lino = 0;
×
981
  for (int32_t k = rowStart; k < rowEnd; k++) {
×
982
    SColVal colVal = {0};
×
983
    STREAM_CHECK_RET_GOTO(tColDataGetValue(colData, k, &colVal));
×
984
    STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, rows + k, VALUE_GET_DATUM(&colVal.value, colVal.value.type),
×
985
                                        !COL_VAL_IS_VALUE(&colVal)));
986
  }
987
  end:
×
988
  return code;
×
989
}
990

991
static int32_t scanSubmitTbData(SVnode* pVnode, SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, 
28,330,856✔
992
  STSchema** schemas, SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
993
  int32_t code = 0;
28,330,856✔
994
  int32_t lino = 0;
28,330,856✔
995
  uint64_t id = 0;
28,330,856✔
996
  WalMetaResult walMeta = {0};
28,333,409✔
997
  void* pTask = sStreamReaderInfo->pTask;
28,335,977✔
998
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
28,335,987✔
999

1000
  if (tStartDecode(pCoder) < 0) {
28,325,726!
1001
    code = TSDB_CODE_INVALID_MSG;
×
1002
    TSDB_CHECK_CODE(code, lino, end);
×
1003
  }
1004

1005
  SSubmitTbData submitTbData = {0};
28,342,397✔
1006
  uint8_t       version = 0;
28,342,397✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
28,320,592!
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
28,320,592✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
28,320,592✔
1013
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1014
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
28,320,592✔
1015
    if (tStartDecode(pCoder) < 0) {
82,500!
1016
      code = TSDB_CODE_INVALID_MSG;
×
1017
      TSDB_CHECK_CODE(code, lino, end);
×
1018
    }
1019
    tEndDecode(pCoder);
82,500✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
28,329,569!
1024
    code = TSDB_CODE_INVALID_MSG;
×
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
28,332,034!
1028
    code = TSDB_CODE_INVALID_MSG;
×
1029
    TSDB_CHECK_CODE(code, lino, end);
×
1030
  }
1031

1032
  STREAM_CHECK_CONDITION_GOTO(!uidInTableList(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
28,332,034✔
1033

1034
  walMeta.id = id;
24,079,468✔
1035
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
24,079,468✔
1036

1037
  if (ranges != NULL){
24,088,458✔
1038
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
18,754,270✔
1039
    if (timerange == NULL) goto end;;
18,754,264!
1040
    int64_t* pRange = (int64_t*)timerange;
18,754,264✔
1041
    window.skey = pRange[0];
18,754,264✔
1042
    window.ekey = pRange[1];
18,754,264✔
1043
  }
1044
  
1045
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
24,092,312!
1046
    code = TSDB_CODE_INVALID_MSG;
×
1047
    TSDB_CHECK_CODE(code, lino, end);
×
1048
  }
1049

1050
  STSchema*    schema = NULL;
24,092,312✔
1051
  if (sStreamReaderInfo->isVtableStream) {
24,092,312!
1052
    if (*schemas == NULL) {
13,952,768!
1053
      *schemas = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
13,954,052✔
1054
      STREAM_CHECK_NULL_GOTO(*schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
13,957,952!
1055
    }
1056
    schema = *schemas;
13,960,472✔
1057
  } else {
1058
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != submitTbData.sver) {
10,134,408✔
1059
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
269,591!
1060
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
269,591✔
1061
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
268,307!
1062
    }
1063
    schema = sStreamReaderInfo->triggerTableSchema;
10,131,840✔
1064
  }
1065
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &submitTbData.uid, LONG_BYTES);
24,092,312✔
1066
  STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
24,089,643!
1067
  int32_t blockStart = pSlice->currentRowIdx;
24,089,643✔
1068

1069
  int32_t numOfRows = 0;
24,089,643✔
1070
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
24,085,804!
1071
    uint64_t nColData = 0;
×
1072
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1073
      code = TSDB_CODE_INVALID_MSG;
×
1074
      TSDB_CHECK_CODE(code, lino, end);
×
1075
    }
1076

1077
    SColData colData = {0};
×
1078
    code = tDecodeColData(version, pCoder, &colData, false);
×
1079
    if (code) {
×
1080
      code = TSDB_CODE_INVALID_MSG;
×
1081
      TSDB_CHECK_CODE(code, lino, end);
×
1082
    }
1083

1084
    if (colData.flag != HAS_VALUE) {
×
1085
      code = TSDB_CODE_INVALID_MSG;
×
1086
      TSDB_CHECK_CODE(code, lino, end);
×
1087
    }
1088
    
1089
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
1090
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
1091

1092
    int32_t rowStart = 0;
×
1093
    int32_t rowEnd = 0;
×
1094
    STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, &numOfRows));
×
1095
    STREAM_CHECK_CONDITION_GOTO(numOfRows <= 0, TDB_CODE_SUCCESS);
×
1096

1097
    int32_t pos = pCoder->pos;
×
1098
    for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {
×
1099
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
×
1100
      STREAM_CHECK_NULL_GOTO(pColData, terrno);
×
1101
      if (pColData->info.colId <= -1) {
×
1102
        pColData->hasNull = true;
×
1103
        continue;
×
1104
      }
1105
      if (pColData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
×
1106
        STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colData, pColData));
×
1107
        continue;
×
1108
      }
1109

1110
      pCoder->pos = pos;
×
1111

1112
      int16_t colId = 0;
×
1113
      if (sStreamReaderInfo->isVtableStream){
×
1114
        int64_t id[2] = {submitTbData.suid, submitTbData.uid};
×
1115
        void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
×
1116
        STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
×
1117
        SSHashObj* uInfo = *(SSHashObj **)px;
×
1118
        STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
×
1119
        int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
×
1120
        if (tmp != NULL) {
×
1121
          colId = *tmp;
×
1122
        } else {
1123
          colId = -1;
×
1124
        }
1125
      } else {
1126
        colId = pColData->info.colId;
×
1127
      }
1128
      
1129
      uint64_t j = 1;
×
1130
      for (; j < nColData; j++) {
×
1131
        int16_t cid = 0;
×
1132
        int32_t posTmp = pCoder->pos;
×
1133
        pCoder->pos += INT_BYTES;
×
1134
        if ((code = tDecodeI16v(pCoder, &cid))) return code;
×
1135
        pCoder->pos = posTmp;
×
1136
        if (cid == colId) {
×
1137
          SColData colDataTmp = {0};
×
1138
          code = tDecodeColData(version, pCoder, &colDataTmp, false);
×
1139
          if (code) {
×
1140
            code = TSDB_CODE_INVALID_MSG;
×
1141
            TSDB_CHECK_CODE(code, lino, end);
×
1142
          }
1143
          STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colDataTmp, pColData));
×
1144
          break;
×
1145
        }
1146
        code = tDecodeColData(version, pCoder, &colData, true);
×
1147
        if (code) {
×
1148
          code = TSDB_CODE_INVALID_MSG;
×
1149
          TSDB_CHECK_CODE(code, lino, end);
×
1150
        }
1151
      }
1152
      if (j == nColData) {
×
1153
        colDataSetNNULL(pColData, blockStart, numOfRows);
×
1154
      }
1155
    }
1156
  } else {
1157
    uint64_t nRow = 0;
24,085,804✔
1158
    if (tDecodeU64v(pCoder, &nRow) < 0) {
24,091,036!
1159
      code = TSDB_CODE_INVALID_MSG;
×
1160
      TSDB_CHECK_CODE(code, lino, end);
×
1161
    }
1162
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
54,759,198✔
1163
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
30,660,288✔
1164
      pCoder->pos += pRow->len;
30,668,048✔
1165

1166
      if (iRow == 0){
30,669,332✔
1167
#ifndef NO_UNALIGNED_ACCESS
1168
        walMeta.skey = pRow->ts;
24,089,673✔
1169
#else
1170
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1171
#endif
1172
      }
1173
      if (iRow == nRow - 1) {
30,671,971✔
1174
#ifndef NO_UNALIGNED_ACCESS
1175
        walMeta.ekey = pRow->ts;
24,092,312✔
1176
#else
1177
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1178
#endif
1179
      }
1180

1181
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
30,662,908!
1182
        continue;
44,597✔
1183
      }
1184
     
1185
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
203,819,309✔
1186
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
173,185,804✔
1187
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
173,177,845!
1188
        if (pColData->info.colId <= -1) {
173,177,845✔
1189
          pColData->hasNull = true;
56,050,137✔
1190
          continue;
56,052,816✔
1191
        }
1192
        int16_t colId = 0;
117,159,771✔
1193
        if (sStreamReaderInfo->isVtableStream){
117,159,771!
1194
          int64_t id[2] = {submitTbData.suid, submitTbData.uid};
41,259,147✔
1195
          void* px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
41,255,321!
1196
          STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
41,268,117!
1197
          SSHashObj* uInfo = *(SSHashObj**)px;
41,268,117✔
1198
          STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
41,261,697!
1199
          int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
41,261,697✔
1200
          if (tmp != NULL) {
41,270,644✔
1201
            colId = *tmp;
37,758,592✔
1202
          } else {
1203
            colId = -1;
3,512,052✔
1204
          }
1205
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
41,271,928!
1206
        } else {
1207
          colId = pColData->info.colId;
75,904,347✔
1208
        }
1209
        
1210
        SColVal colVal = {0};
117,171,205✔
1211
        int32_t sourceIdx = 0;
117,173,773✔
1212
        while (1) {
1213
          if (sourceIdx >= schema->numOfCols) {
319,055,913✔
1214
            break;
42,338,604✔
1215
          }
1216
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
276,690,247!
1217
          if (colVal.cid == colId) {
276,721,178✔
1218
            break;
74,839,038✔
1219
          }
1220
          sourceIdx++;
201,882,140✔
1221
        }
1222
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
117,177,642✔
1223
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
70,677,567!
1224
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
134,021!
1225
            // ST_TASK_ILOG("%s vtable colId:%d, i:%d, colData:%p, data:%s, len:%d, rowIndex:%d, offset:%d, uid:%" PRId64, __func__, colId, i, pColData, 
1226
            //   (const char*)colVal.value.pData, colVal.value.nData, blockStart+ numOfRows, pColData->varmeta.offset[blockStart+ numOfRows], submitTbData.uid);
1227
          } else {
1228
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
70,543,576!
1229
          }
1230
        } else {
1231
          colDataSetNULL(pColData, blockStart + numOfRows);
46,500,075!
1232
        }
1233
      }
1234
      
1235
      numOfRows++;
30,623,565✔
1236
    }
1237
  }
1238

1239
  if (numOfRows > 0) {
24,089,772!
1240
    if (!sStreamReaderInfo->isVtableStream) {
24,089,772✔
1241
      SStorageAPI  api = {0};
10,130,549✔
1242
      initStorageAPI(&api);
10,129,157✔
1243
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
10,130,257!
1244
    }
1245
    
1246
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
24,084,568✔
1247
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
24,079,376!
1248
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
24,079,376!
1249
  }
1250

1251
  ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
24,083,297✔
1252
    ", uid:%" PRId64 ", ver:%d, row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1253
    id, submitTbData.uid, submitTbData.sver, pSlice->currentRowIdx, numOfRows);
1254
  pSlice->currentRowIdx += numOfRows;
24,087,206✔
1255
  pBlock->info.rows += numOfRows;
24,088,453✔
1256
  
1257
  if (gidHash == NULL) goto end;
24,091,028✔
1258

1259
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
5,336,758✔
1260
  if (data != NULL) {
5,336,756!
1261
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
1262
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
1263
  } else {
1264
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
5,336,756!
1265
  }
1266

1267
end:
28,322,090✔
1268
  if (code != 0) {                                                             \
28,336,001!
1269
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1270
  }
1271
  tEndDecode(pCoder);
28,336,001✔
1272
  return code;
28,329,553✔
1273
}
1274
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
28,324,429✔
1275
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1276
  int32_t  code = 0;
28,324,429✔
1277
  int32_t  lino = 0;
28,324,429✔
1278
  STSchema* schemas = NULL;
28,324,429✔
1279
  SDecoder decoder = {0};
28,330,829✔
1280
  SSHashObj* gidHash = NULL;
28,339,821✔
1281
  void* pTask = sStreamReaderInfo->pTask;
28,339,821✔
1282

1283
  tDecoderInit(&decoder, data, len);
28,337,266✔
1284
  if (tStartDecode(&decoder) < 0) {
28,316,693!
1285
    code = TSDB_CODE_INVALID_MSG;
×
1286
    TSDB_CHECK_CODE(code, lino, end);
×
1287
  }
1288

1289
  uint64_t nSubmitTbData = 0;
28,335,971✔
1290
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
28,333,414!
1291
    code = TSDB_CODE_INVALID_MSG;
×
1292
    TSDB_CHECK_CODE(code, lino, end);
×
1293
  }
1294

1295
  if (rsp->metaBlock != NULL){
28,333,414✔
1296
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
9,584,269✔
1297
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
9,577,876!
1298
  }
1299

1300
  for (int32_t i = 0; i < nSubmitTbData; i++) {
56,656,598✔
1301
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, &schemas, ranges, gidHash, rsp, ver));
28,319,330!
1302
  }
1303

1304
  tEndDecode(&decoder);
28,337,268✔
1305

1306
  if (rsp->metaBlock != NULL){
28,337,264✔
1307
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
9,586,846!
1308
    int32_t iter = 0;
9,567,542✔
1309
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
9,567,542✔
1310
    while (px != NULL) {
14,915,893✔
1311
      WalMetaResult* pMeta = (WalMetaResult*)px;
5,336,756✔
1312
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
5,336,756!
1313
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
5,338,042✔
1314
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
5,339,326✔
1315
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1316
      px = tSimpleHashIterate(gidHash, px, &iter);
5,339,326✔
1317
    }
1318
  }
1319
  
1320

1321
end:
28,319,483✔
1322
  taosMemoryFree(schemas);
28,338,545!
1323
  tSimpleHashCleanup(gidHash);
28,334,679✔
1324
  tDecoderClear(&decoder);
28,337,265✔
1325
  return code;
28,335,978✔
1326
}
1327

1328
static int32_t scanSubmitTbDataPre(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* ranges, 
32,435,939✔
1329
  uint64_t* gid, int64_t* uid, int32_t* numOfRows, bool isCalc) {
1330
  int32_t code = 0;
32,435,939✔
1331
  int32_t lino = 0;
32,435,939✔
1332
  void* pTask = sStreamReaderInfo->pTask;
32,435,939✔
1333

1334
  if (tStartDecode(pCoder) < 0) {
32,439,892!
1335
    code = TSDB_CODE_INVALID_MSG;
×
1336
    TSDB_CHECK_CODE(code, lino, end);
×
1337
  }
1338

1339
  SSubmitTbData submitTbData = {0};
32,443,762✔
1340
  uint8_t       version = 0;
32,445,048✔
1341
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
32,437,336!
1342
    code = TSDB_CODE_INVALID_MSG;
×
1343
    TSDB_CHECK_CODE(code, lino, end);
×
1344
  }
1345
  version = (submitTbData.flags >> 8) & 0xff;
32,437,336✔
1346
  submitTbData.flags = submitTbData.flags & 0xff;
32,437,336✔
1347

1348
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1349
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
32,437,336✔
1350
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,683,000!
1351
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,676,975!
1352
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,676,975!
1353
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
1,681,702!
1354
  }
1355

1356
  // submit data
1357
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
32,443,773!
1358
    code = TSDB_CODE_INVALID_MSG;
×
1359
    TSDB_CHECK_CODE(code, lino, end);
×
1360
  }
1361
  if (tDecodeI64(pCoder, uid) < 0) {
32,432,199!
1362
    code = TSDB_CODE_INVALID_MSG;
×
1363
    TSDB_CHECK_CODE(code, lino, end);
×
1364
  }
1365

1366
  STREAM_CHECK_CONDITION_GOTO(!uidInTableList(sStreamReaderInfo, submitTbData.suid, *uid, gid, isCalc), TDB_CODE_SUCCESS);
32,432,199✔
1367

1368
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
24,088,452✔
1369

1370
  if (ranges != NULL){
24,089,736✔
1371
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
18,752,980✔
1372
    if (timerange == NULL) goto end;;
18,754,263!
1373
    int64_t* pRange = (int64_t*)timerange;
18,754,263✔
1374
    window.skey = pRange[0];
18,754,263✔
1375
    window.ekey = pRange[1];
18,754,263✔
1376
  }
1377
  
1378
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
24,092,325!
1379
    code = TSDB_CODE_INVALID_MSG;
×
1380
    TSDB_CHECK_CODE(code, lino, end);
×
1381
  }
1382

1383
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
24,092,325!
1384
    uint64_t nColData = 0;
×
1385
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1386
      code = TSDB_CODE_INVALID_MSG;
×
1387
      TSDB_CHECK_CODE(code, lino, end);
×
1388
    }
1389

1390
    SColData colData = {0};
×
1391
    code = tDecodeColData(version, pCoder, &colData, false);
×
1392
    if (code) {
×
1393
      code = TSDB_CODE_INVALID_MSG;
×
1394
      TSDB_CHECK_CODE(code, lino, end);
×
1395
    }
1396

1397
    if (colData.flag != HAS_VALUE) {
×
1398
      code = TSDB_CODE_INVALID_MSG;
×
1399
      TSDB_CHECK_CODE(code, lino, end);
×
1400
    }
1401
    int32_t rowStart = 0;
×
1402
    int32_t rowEnd = 0;
×
1403
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) {
×
1404
      STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, numOfRows));
×
1405
    } else {
1406
      (*numOfRows) = colData.nVal;
×
1407
    } 
1408
  } else {
1409
    uint64_t nRow = 0;
24,092,325✔
1410
    if (tDecodeU64v(pCoder, &nRow) < 0) {
24,092,325!
1411
      code = TSDB_CODE_INVALID_MSG;
×
1412
      TSDB_CHECK_CODE(code, lino, end);
×
1413
    }
1414

1415
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
24,092,325!
1416
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
43,889,088✔
1417
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
25,134,805✔
1418
        pCoder->pos += pRow->len;
25,134,793✔
1419
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
25,134,805✔
1420
          continue;
44,597✔
1421
        }
1422
        (*numOfRows)++;
25,090,208✔
1423
      }
1424
    } else {
1425
      (*numOfRows) = nRow;
5,338,042✔
1426
    }
1427
  }
1428
  
1429
end:
32,446,255✔
1430
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
32,437,237✔
1431
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
32,441,068!
1432
  tEndDecode(pCoder);
32,437,209✔
1433
  return code;
32,433,260✔
1434
}
1435

1436
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
32,441,217✔
1437
  int32_t  code = 0;
32,441,217✔
1438
  int32_t  lino = 0;
32,441,217✔
1439
  SDecoder decoder = {0};
32,441,217✔
1440
  void* pTask = sStreamReaderInfo->pTask;
32,446,357✔
1441

1442
  tDecoderInit(&decoder, data, len);
32,443,688✔
1443
  if (tStartDecode(&decoder) < 0) {
32,398,629!
1444
    code = TSDB_CODE_INVALID_MSG;
×
1445
    TSDB_CHECK_CODE(code, lino, end);
×
1446
  }
1447

1448
  uint64_t nSubmitTbData = 0;
32,438,526✔
1449
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
32,435,959!
1450
    code = TSDB_CODE_INVALID_MSG;
×
1451
    TSDB_CHECK_CODE(code, lino, end);
×
1452
  }
1453

1454
  for (int32_t i = 0; i < nSubmitTbData; i++) {
64,873,160✔
1455
    uint64_t gid = -1;
32,430,914✔
1456
    int64_t  uid = 0;
32,430,914✔
1457
    int32_t numOfRows = 0;
32,434,777✔
1458
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp->isCalc));
32,433,491!
1459
    if (numOfRows <= 0) {
32,439,691✔
1460
      continue;
8,355,183✔
1461
    }
1462
    rsp->totalRows += numOfRows;
24,084,508✔
1463

1464
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &uid, LONG_BYTES);
24,092,028✔
1465
    if (pSlice != NULL) {
24,090,925✔
1466
      pSlice->numRows += numOfRows;
23,333,090✔
1467
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d", __func__, uid, gid, pSlice->numRows);
23,334,374✔
1468
      pSlice->gId = gid;
23,334,473✔
1469
    } else {
1470
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
757,835✔
1471
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d", __func__, uid, gid, tmp.numRows);
757,835✔
1472
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(sStreamReaderInfo->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
757,835!
1473
    } 
1474
  }
1475

1476
  tEndDecode(&decoder);
32,442,246✔
1477

1478
end:
32,434,656✔
1479
  tDecoderClear(&decoder);
32,439,796✔
1480
  return code;
32,446,337✔
1481
}
1482

1483
static void resetIndexHash(SSHashObj* indexHash){
22,234,260✔
1484
  void*   pe = NULL;
22,234,260✔
1485
  int32_t iter = 0;
22,234,260✔
1486
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
51,169,765✔
1487
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
28,949,554✔
1488
    pInfo->startRowIdx = 0;
28,949,554✔
1489
    pInfo->currentRowIdx = 0;
28,949,554✔
1490
    pInfo->numRows = 0;
28,912,349✔
1491
    pInfo->gId = -1;
28,923,872✔
1492
  }
1493
}
22,239,487✔
1494

1495
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
1,860,964✔
1496
  void*   pe = NULL;
1,860,964✔
1497
  int32_t iter = 0;
1,860,964✔
1498
  int32_t index = 0;
1,860,964✔
1499
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
6,862,789✔
1500
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
5,001,825✔
1501
    pInfo->startRowIdx = index;
5,001,825✔
1502
    pInfo->currentRowIdx = index;
5,001,825✔
1503
    index += pInfo->numRows;
5,001,825✔
1504
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
7,539,371!
1505
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1506
  }
1507
}
1,860,964✔
1508

1509
static void printIndexHash(SSHashObj* indexHash, void* pTask){
1,857,098✔
1510
  void*   pe = NULL;
1,857,098✔
1511
  int32_t iter = 0;
1,857,098✔
1512
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
6,851,198✔
1513
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
4,994,100✔
1514
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
7,531,646!
1515
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1516
  }
1517
}
1,857,098✔
1518

1519
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
43,413✔
1520
  void*   pe = NULL;
43,413✔
1521
  int32_t iter = 0;
43,413✔
1522
  int32_t index = 0;
43,413✔
1523
  int32_t pIndex = 0;
43,413✔
1524
  int8_t* pIndicator = (int8_t*)pRet->pData;
43,413✔
1525
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
122,717✔
1526
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
79,304✔
1527
    pInfo->startRowIdx = index;
79,304✔
1528
    int32_t size = pInfo->numRows;
79,304✔
1529
    for (int32_t i = 0; i < pInfo->numRows; i++) {
661,869✔
1530
      if (pIndicator && !pIndicator[pIndex++]) {
582,565!
1531
        size--;
206,799✔
1532
      }
1533
    }
1534
    pInfo->numRows = size;
79,304✔
1535
    index += pInfo->numRows;
79,304✔
1536
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
79,304!
1537
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1538
  }
1539
}
43,413✔
1540

1541
static int32_t prepareIndexMetaData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* resultRsp){
10,176,198✔
1542
  int32_t      code = 0;
10,176,198✔
1543
  int32_t      lino = 0;
10,176,198✔
1544
  void* pTask = sStreamReaderInfo->pTask;
10,176,198✔
1545

1546
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
10,181,345✔
1547
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
10,169,658✔
1548
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
8,818,484!
1549
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
1550
    }
1551
    ST_TASK_DLOG("%s scan wal error:%s",  __func__, tstrerror(code));
8,830,243✔
1552
    code = TSDB_CODE_SUCCESS;
8,826,400✔
1553
    goto end;
8,826,400✔
1554
  }
1555
  STREAM_CHECK_RET_GOTO(code);
1,351,174!
1556

1557
  while (1) {
14,198,080✔
1558
    code = walNextValidMsg(pWalReader, true);
15,549,254✔
1559
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
15,553,028✔
1560
      ST_TASK_DLOG("%s scan wal error:%s", __func__, tstrerror(code));
1,352,571✔
1561
      code = TSDB_CODE_SUCCESS;
1,355,141✔
1562
      goto end;
1,355,141✔
1563
    }
1564
    STREAM_CHECK_RET_GOTO(code);
14,200,457!
1565
    resultRsp->ver = pWalReader->curVersion;
14,200,457✔
1566
    SWalCont* wCont = &pWalReader->pHead->head;
14,199,167✔
1567
    resultRsp->verTime = wCont->ingestTs;
14,197,771✔
1568
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
14,200,442✔
1569
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
14,204,309✔
1570
    int64_t ver = wCont->version;
14,201,745✔
1571
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d", __func__,
14,203,027✔
1572
      ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1573
    if (wCont->msgType == TDMT_VND_SUBMIT) {
14,209,669✔
1574
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
13,685,645✔
1575
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
13,688,227✔
1576
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp));
13,689,515!
1577
    } else if (wCont->msgType == TDMT_VND_ALTER_TABLE && resultRsp->totalRows > 0) {
517,496✔
1578
      resultRsp->ver--;
5,056✔
1579
      break;
3,792✔
1580
    } else {
1581
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
512,440!
1582
    }
1583

1584
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
14,200,650✔
1585
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
14,200,650!
1586
      break;
×
1587
    }
1588
  }
1589
  
1590
end:
10,185,306✔
1591
  STREAM_PRINT_LOG_END(code, lino);
10,185,306!
1592
  return code;
10,183,923✔
1593
}
1594

1595
static int32_t prepareIndexData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, 
12,049,059✔
1596
  SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp){
1597
  int32_t      code = 0;
12,049,059✔
1598
  int32_t      lino = 0;
12,049,059✔
1599

1600
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
30,804,613✔
1601
    int64_t *ver = taosArrayGet(versions, i);
18,752,999✔
1602
    if (ver == NULL) continue;
18,755,554!
1603

1604
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
18,755,554!
1605
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
18,755,554!
1606
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1607
      continue;
×
1608
    }
1609
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
18,754,270!
1610

1611
    SWalCont* wCont = &pWalReader->pHead->head;
18,753,006✔
1612
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
18,753,006✔
1613
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
18,751,710✔
1614

1615
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp));
18,753,006!
1616
  }
1617
  
1618
end:
12,050,343✔
1619
  return code;
12,050,343✔
1620
}
1621

1622
static int32_t filterData(SSTriggerWalNewRsp* resultRsp, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,860,964✔
1623
  int32_t      code = 0;
1,860,964✔
1624
  int32_t       lino = 0;
1,860,964✔
1625
  SColumnInfoData* pRet = NULL;
1,860,964✔
1626

1627
  int64_t totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
1,860,964✔
1628
  STREAM_CHECK_RET_GOTO(qStreamFilter(((SSDataBlock*)resultRsp->dataBlock), sStreamReaderInfo->pFilterInfo, &pRet));
1,860,964!
1629

1630
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
1,858,396✔
1631
    filterIndexHash(sStreamReaderInfo->indexHash, pRet);
43,413✔
1632
  }
1633

1634
end:
1,859,680✔
1635
  colDataDestroy(pRet);
1,859,680✔
1636
  taosMemoryFree(pRet);
1,859,680!
1637
  return code;
1,859,680✔
1638
}
1639

1640
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
10,193,019✔
1641
                                    SSTriggerWalNewRsp* resultRsp) {
1642
  int32_t      code = 0;
10,193,019✔
1643
  int32_t      lino = 0;
10,193,019✔
1644
  void* pTask = sStreamReaderInfo->pTask;
10,193,019✔
1645
                                        
1646
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
10,195,589✔
1647
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
10,189,052!
1648
  resetIndexHash(sStreamReaderInfo->indexHash);
10,189,052✔
1649
  blockDataEmpty(resultRsp->dataBlock);
10,189,045✔
1650
  blockDataEmpty(resultRsp->metaBlock);
10,189,446✔
1651
  int64_t lastVer = resultRsp->ver;                                      
10,168,488✔
1652
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
10,169,772!
1653
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
10,186,495✔
1654

1655
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
441,973✔
1656
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
441,973!
1657
  while(lastVer < resultRsp->ver) {
10,357,127✔
1658
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
9,916,440!
1659
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
9,908,719✔
1660
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
329,601!
1661
      continue;
329,601✔
1662
    }
1663
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
9,581,686!
1664
    SWalCont* wCont = &pWalReader->pHead->head;
9,575,260✔
1665
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
9,579,119✔
1666
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
9,580,403✔
1667

1668
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
9,581,687!
1669
  }
1670

1671
  int32_t metaRows = resultRsp->totalRows - ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
441,973✔
1672
  STREAM_CHECK_RET_GOTO(filterData(resultRsp, sStreamReaderInfo));
441,973!
1673
  resultRsp->totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows + metaRows;
441,973✔
1674

1675
end:
10,189,063✔
1676
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
10,189,063✔
1677
          resultRsp->totalRows, resultRsp->ver, walGetAppliedVer(pWalReader->pWal));
1678
  walCloseReader(pWalReader);
10,189,063✔
1679
  return code;
10,189,146✔
1680
}
1681

1682
static int32_t processWalVerDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
12,050,343✔
1683
                                    SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
1684
  int32_t      code = 0;
12,050,343✔
1685
  int32_t      lino = 0;
12,050,343✔
1686

1687
  void* pTask = sStreamReaderInfo->pTask;
12,050,343✔
1688
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
12,050,343✔
1689
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
12,047,795!
1690
  
1691
  if (taosArrayGetSize(versions) > 0) {
12,047,795✔
1692
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
1,418,991✔
1693
  }
1694
  
1695
  resetIndexHash(sStreamReaderInfo->indexHash);
12,047,795✔
1696
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
12,050,343!
1697
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
12,049,070✔
1698

1699
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
1,418,991✔
1700

1701
  blockDataEmpty(rsp->dataBlock);
1,418,991✔
1702
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
1,418,991!
1703

1704
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
20,169,409✔
1705
    int64_t *ver = taosArrayGet(versions, i);
18,751,702✔
1706
    if (ver == NULL) continue;
18,747,850!
1707

1708
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
18,747,850!
1709
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
18,751,702!
1710
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1711
      continue;
×
1712
    }
1713
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
18,745,282!
1714
    SWalCont* wCont = &pWalReader->pHead->head;
18,749,128✔
1715
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
18,749,128✔
1716
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
18,752,980✔
1717

1718
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
18,752,980!
1719
  }
1720
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
1721
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
1,416,423!
1722
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
1,417,707✔
1723

1724
end:
12,047,786✔
1725
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
12,047,786✔
1726
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
1727
  walCloseReader(pWalReader);
12,047,786✔
1728
  return code;
12,050,343✔
1729
}
1730

1731
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas) {
786,347✔
1732
  int32_t code = 0;
786,347✔
1733
  int32_t lino = 0;
786,347✔
1734
  SMetaReader metaReader = {0};
786,347✔
1735
  SStorageAPI api = {0};
786,347✔
1736
  initStorageAPI(&api);
786,347✔
1737
  *schemas = taosArrayInit(8, sizeof(SSchema));
786,347✔
1738
  STREAM_CHECK_NULL_GOTO(*schemas, terrno);
786,347!
1739
  
1740
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
786,347✔
1741
  STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, uid));
786,347✔
1742

1743
  SSchemaWrapper* sSchemaWrapper = NULL;
783,805✔
1744
  if (metaReader.me.type == TD_CHILD_TABLE) {
783,805!
1745
    int64_t suid = metaReader.me.ctbEntry.suid;
783,805✔
1746
    tDecoderClear(&metaReader.coder);
783,805✔
1747
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
783,805!
1748
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
783,805✔
1749
  } else if (metaReader.me.type == TD_NORMAL_TABLE) {
×
1750
    sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
×
1751
  } else {
1752
    qError("invalid table type:%d", metaReader.me.type);
×
1753
  }
1754

1755
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
4,555,749✔
1756
    SSchema* s = sSchemaWrapper->pSchema + j;
3,771,944✔
1757
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
7,543,888!
1758
  }
1759

1760
end:
786,347✔
1761
  api.metaReaderFn.clearReader(&metaReader);
786,347✔
1762
  STREAM_PRINT_LOG_END(code, lino);
786,347!
1763
  if (code != 0)  {
786,347✔
1764
    taosArrayDestroy(*schemas);
2,542✔
1765
    *schemas = NULL;
2,542✔
1766
  }
1767
  return code;
786,347✔
1768
}
1769

1770
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
783,805✔
1771
  int32_t code = 0;
783,805✔
1772
  int32_t lino = 0;
783,805✔
1773
  size_t  schemaLen = taosArrayGetSize(schemas);
783,805✔
1774
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
783,805!
1775
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
2,951,289✔
1776
    col_id_t* id = taosArrayGet(cols, i);
2,167,484✔
1777
    STREAM_CHECK_NULL_GOTO(id, terrno);
2,167,484!
1778
    for (size_t i = 0; i < schemaLen; i++) {
5,600,084!
1779
      SSchema* s = taosArrayGet(schemas, i);
5,600,084✔
1780
      STREAM_CHECK_NULL_GOTO(s, terrno);
5,600,084!
1781
      if (*id == s->colId) {
5,600,084✔
1782
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
2,167,484!
1783
        break;
2,167,484✔
1784
      }
1785
    }
1786
  }
1787
  taosArrayPopFrontBatch(schemas, schemaLen);
783,805✔
1788

1789
end:
783,805✔
1790
  return code;
783,805✔
1791
}
1792

1793
static int32_t processWalVerDataVTable(SVnode* pVnode, SArray *cids, int64_t ver,
×
1794
  int64_t uid, STimeWindow* window, SSDataBlock** pBlock) {
1795
  int32_t      code = 0;
×
1796
  int32_t      lino = 0;
×
1797
  SArray*      schemas = NULL;
×
1798

1799
  SSDataBlock* pBlock2 = NULL;
×
1800

1801
  STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, uid, &schemas));
×
1802
  STREAM_CHECK_RET_GOTO(shrinkScheams(cids, schemas));
×
1803
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlock2));
×
1804

1805
  pBlock2->info.id.uid = uid;
×
1806

1807
  // STREAM_CHECK_RET_GOTO(scanWalOneVer(pVnode, pBlock2, ver, uid, window));
1808
  //printDataBlock(pBlock2, __func__, "");
1809

1810
  *pBlock = pBlock2;
×
1811
  pBlock2 = NULL;
×
1812

1813
end:
×
1814
  STREAM_PRINT_LOG_END(code, lino);
×
1815
  blockDataDestroy(pBlock2);
×
1816
  taosArrayDestroy(schemas);
×
1817
  return code;
×
1818
}
1819

1820
static int32_t createTSAndCondition(int64_t start, int64_t end, SLogicConditionNode** pCond,
×
1821
                                    STargetNode* pTargetNodeTs) {
1822
  int32_t code = 0;
×
1823
  int32_t lino = 0;
×
1824

1825
  SColumnNode*         pCol = NULL;
×
1826
  SColumnNode*         pCol1 = NULL;
×
1827
  SValueNode*          pVal = NULL;
×
1828
  SValueNode*          pVal1 = NULL;
×
1829
  SOperatorNode*       op = NULL;
×
1830
  SOperatorNode*       op1 = NULL;
×
1831
  SLogicConditionNode* cond = NULL;
×
1832

1833
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol));
×
1834
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
×
1835
  pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
×
1836
  pCol->node.resType.bytes = LONG_BYTES;
×
1837
  pCol->slotId = pTargetNodeTs->slotId;
×
1838
  pCol->dataBlockId = pTargetNodeTs->dataBlockId;
×
1839

1840
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pCol, (SNode**)&pCol1));
×
1841

1842
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal));
×
1843
  pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
×
1844
  pVal->node.resType.bytes = LONG_BYTES;
×
1845
  pVal->datum.i = start;
×
1846
  pVal->typeData = start;
×
1847

1848
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
×
1849
  pVal1->datum.i = end;
×
1850
  pVal1->typeData = end;
×
1851

1852
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op));
×
1853
  op->opType = OP_TYPE_GREATER_EQUAL;
×
1854
  op->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
1855
  op->node.resType.bytes = CHAR_BYTES;
×
1856
  op->pLeft = (SNode*)pCol;
×
1857
  op->pRight = (SNode*)pVal;
×
1858
  pCol = NULL;
×
1859
  pVal = NULL;
×
1860

1861
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op1));
×
1862
  op1->opType = OP_TYPE_LOWER_EQUAL;
×
1863
  op1->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
1864
  op1->node.resType.bytes = CHAR_BYTES;
×
1865
  op1->pLeft = (SNode*)pCol1;
×
1866
  op1->pRight = (SNode*)pVal1;
×
1867
  pCol1 = NULL;
×
1868
  pVal1 = NULL;
×
1869

1870
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
×
1871
  cond->condType = LOGIC_COND_TYPE_AND;
×
1872
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
1873
  cond->node.resType.bytes = CHAR_BYTES;
×
1874
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
×
1875
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op));
×
1876
  op = NULL;
×
1877
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op1));
×
1878
  op1 = NULL;
×
1879

1880
  *pCond = cond;
×
1881

1882
end:
×
1883
  if (code != 0) {
×
1884
    nodesDestroyNode((SNode*)pCol);
×
1885
    nodesDestroyNode((SNode*)pCol1);
×
1886
    nodesDestroyNode((SNode*)pVal);
×
1887
    nodesDestroyNode((SNode*)pVal1);
×
1888
    nodesDestroyNode((SNode*)op);
×
1889
    nodesDestroyNode((SNode*)op1);
×
1890
    nodesDestroyNode((SNode*)cond);
×
1891
  }
1892
  STREAM_PRINT_LOG_END(code, lino);
×
1893

1894
  return code;
×
1895
}
1896

1897
/*
1898
static int32_t createExternalConditions(SStreamRuntimeFuncInfo* data, SLogicConditionNode** pCond, STargetNode* pTargetNodeTs, STimeRangeNode* node) {
1899
  int32_t              code = 0;
1900
  int32_t              lino = 0;
1901
  SLogicConditionNode* pAndCondition = NULL;
1902
  SLogicConditionNode* cond = NULL;
1903

1904
  if (pTargetNodeTs == NULL) {
1905
    vError("stream reader %s no ts column", __func__);
1906
    return TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN;
1907
  }
1908
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
1909
  cond->condType = LOGIC_COND_TYPE_OR;
1910
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
1911
  cond->node.resType.bytes = CHAR_BYTES;
1912
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
1913

1914
  for (int i = 0; i < taosArrayGetSize(data->pStreamPesudoFuncVals); ++i) {
1915
    data->curIdx = i;
1916

1917
    SReadHandle handle = {0};
1918
    calcTimeRange(node, data, &handle.winRange, &handle.winRangeValid);
1919
    if (!handle.winRangeValid) {
1920
      stError("stream reader %s invalid time range, skey:%" PRId64 ", ekey:%" PRId64, __func__, handle.winRange.skey,
1921
              handle.winRange.ekey);
1922
      continue;
1923
    }
1924
    STREAM_CHECK_RET_GOTO(createTSAndCondition(handle.winRange.skey, handle.winRange.ekey, &pAndCondition, pTargetNodeTs));
1925
    stDebug("%s create condition skey:%" PRId64 ", eksy:%" PRId64, __func__, handle.winRange.skey, handle.winRange.ekey);
1926
    STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)pAndCondition));
1927
    pAndCondition = NULL;
1928
  }
1929

1930
  *pCond = cond;
1931

1932
end:
1933
  if (code != 0) {
1934
    nodesDestroyNode((SNode*)pAndCondition);
1935
    nodesDestroyNode((SNode*)cond);
1936
  }
1937
  STREAM_PRINT_LOG_END(code, lino);
1938

1939
  return code;
1940
}
1941
*/
1942

1943
static int32_t processCalaTimeRange(SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo, SResFetchReq* req,
1,253,765✔
1944
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
1945
  int32_t code = 0;
1,253,765✔
1946
  int32_t lino = 0;
1,253,765✔
1947
  void* pTask = sStreamReaderCalcInfo->pTask;
1,253,765✔
1948
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
1,253,765!
1949
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
1,253,765!
1950
  
1951
  if (req->pStRtFuncInfo->withExternalWindow) {
1,253,765✔
1952
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
449,247✔
1953
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
449,247✔
1954
    
1955
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
449,247✔
1956
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
449,247✔
1957
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
449,247!
1958
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
449,247!
1959

1960
    if (!node->needCalc) {
449,247✔
1961
      pWin->skey = pFirst->wstart;
297,940✔
1962
      pWin->ekey = pLast->wend;
297,940✔
1963
      *pValid = true;
297,940✔
1964
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
297,940✔
1965
        pWin->ekey--;
156,814✔
1966
      }
1967
    } else {
1968
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
151,307✔
1969
      memcpy(pTmp, pFirst, sizeof(*pTmp));
151,307!
1970

1971
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
151,307!
1972
      if (*pValid) {
151,307!
1973
        int64_t skey = pWin->skey;
151,307✔
1974

1975
        memcpy(pTmp, pLast, sizeof(*pTmp));
151,307!
1976
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
151,307!
1977

1978
        if (*pValid) {
151,307!
1979
          pWin->skey = skey;
151,307✔
1980
        }
1981
      }
1982
      pWin->ekey--;
151,307✔
1983
    }
1984
  } else {
1985
    if (!node->needCalc) {
804,518!
1986
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
194,438✔
1987
      pWin->skey = pCurr->wstart;
194,438✔
1988
      pWin->ekey = pCurr->wend;
194,438✔
1989
      *pValid = true;
194,438✔
1990
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
194,438✔
1991
        pWin->ekey--;
177,674✔
1992
      }
1993
    } else {
1994
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
610,080!
1995
      pWin->ekey--;
610,080✔
1996
    }
1997
  }
1998

1999
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
1,253,765!
2000
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
2001

2002
end:
41,138✔
2003

2004
  if (code) {
1,253,765!
2005
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
2006
  }
2007
  
2008
  return code;
1,253,765✔
2009
}
2010

2011
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
1,414,706✔
2012
                                  SStreamReaderTaskInner* pTaskInner) {
2013
  int32_t code = 0;
1,414,706✔
2014
  int32_t lino = 0;
1,414,706✔
2015

2016
  void* pTask = sStreamReaderInfo->pTask;
1,414,706✔
2017
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTaskInner->pTableList), sizeof(STsInfo));
1,415,990✔
2018
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
1,417,274!
2019
  while (true) {
3,392,207✔
2020
    bool hasNext = false;
4,809,481✔
2021
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
4,806,937!
2022
    if (hasNext) {
4,801,849!
2023
      pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
1,374,003✔
2024
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
1,372,670✔
2025
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
1,372,670!
2026
      if (pTaskInner->options.order == TSDB_ORDER_ASC) {
1,372,670✔
2027
        tsInfo->ts = pTaskInner->pResBlock->info.window.skey;
805,859✔
2028
      } else {
2029
        tsInfo->ts = pTaskInner->pResBlock->info.window.ekey;
568,103✔
2030
      }
2031
      tsInfo->gId = (sStreamReaderInfo->groupByTbname || sStreamReaderInfo->tableType != TSDB_SUPER_TABLE) ? 
2,926,830!
2032
                    pTaskInner->pResBlock->info.id.uid : qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
1,547,720✔
2033
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
1,375,248✔
2034
              tsInfo->gId, tsRsp->ver);
2035
    }
2036
    
2037
    pTaskInner->currentGroupIndex++;
4,803,094✔
2038
    if (pTaskInner->currentGroupIndex >= qStreamGetTableListGroupNum(pTaskInner->pTableList) || pTaskInner->options.gid != 0) {
4,801,837✔
2039
      break;
2040
    }
2041
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTaskInner));
3,390,923!
2042
  }
2043

2044
end:
1,410,910✔
2045
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,410,910!
2046
  return code;
1,415,983✔
2047
}
2048

2049
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
306,531✔
2050
  int32_t code = 0;
306,531✔
2051
  int32_t lino = 0;
306,531✔
2052
  void*   buf = NULL;
306,531✔
2053
  size_t  size = 0;
306,531✔
2054
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
306,531!
2055
  void* pTask = sStreamReaderInfo->pTask;
306,531✔
2056

2057
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d", TD_VID(pVnode), __func__,
306,531✔
2058
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc));
2059

2060
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
305,260✔
2061
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
306,531✔
2062
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
306,531!
2063
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
306,531!
2064

2065
  sStreamReaderInfo->isVtableStream = true;
306,531✔
2066
  sStreamReaderInfo->groupByTbname = true;
306,531✔
2067
end:
306,531✔
2068
  STREAM_PRINT_LOG_END_WITHID(code, lino);
306,531!
2069
  SRpcMsg rsp = {
306,531✔
2070
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2071
  tmsgSendRsp(&rsp);
306,531✔
2072
  return code;
306,531✔
2073
}
2074

2075
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
786,935✔
2076
  int32_t                 code = 0;
786,935✔
2077
  int32_t                 lino = 0;
786,935✔
2078
  SStreamReaderTaskInner* pTaskInner = NULL;
786,935✔
2079
  SStreamTsResponse       lastTsRsp = {0};
790,726✔
2080
  void*                   buf = NULL;
790,726✔
2081
  size_t                  size = 0;
790,726✔
2082

2083
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
790,726!
2084
  void* pTask = sStreamReaderInfo->pTask;
790,726✔
2085

2086
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
790,726✔
2087

2088
  BUILD_OPTION(options, sStreamReaderInfo, -1, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, sStreamReaderInfo->tsSchemas, true,
790,726✔
2089
               STREAM_SCAN_GROUP_ONE_BY_ONE, 0, true, sStreamReaderInfo->uidHashTrigger);
2090
  SStorageAPI api = {0};
790,726✔
2091
  initStorageAPI(&api);
790,726✔
2092
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
790,726!
2093

2094
  lastTsRsp.ver = pVnode->state.applied + 1;
790,733✔
2095

2096
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner));
790,733!
2097
  ST_TASK_DLOG("vgId:%d %s get result, ver:%" PRId64, TD_VID(pVnode), __func__, lastTsRsp.ver);
790,726✔
2098
  STREAM_CHECK_RET_GOTO(buildTsRsp(&lastTsRsp, &buf, &size))
790,726!
2099
  if (stDebugFlag & DEBUG_DEBUG) {
792,017✔
2100
    int32_t nInfo = taosArrayGetSize(lastTsRsp.tsInfo);
640,345✔
2101
    for (int32_t i = 0; i < nInfo; i++) {
1,157,068✔
2102
      STsInfo* tsInfo = TARRAY_GET_ELEM(lastTsRsp.tsInfo, i);
516,723✔
2103
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
516,723!
2104
    }
2105
  }
2106

2107
end:
792,017✔
2108
  STREAM_PRINT_LOG_END_WITHID(code, lino);
790,726!
2109
  SRpcMsg rsp = {
790,726✔
2110
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2111
  tmsgSendRsp(&rsp);
790,726✔
2112
  taosArrayDestroy(lastTsRsp.tsInfo);
792,017✔
2113
  releaseStreamTask(&pTaskInner);
792,017✔
2114
  return code;
790,744✔
2115
}
2116

2117
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
634,128✔
2118
  int32_t                 code = 0;
634,128✔
2119
  int32_t                 lino = 0;
634,128✔
2120
  SStreamReaderTaskInner* pTaskInner = NULL;
634,128✔
2121
  SStreamTsResponse       firstTsRsp = {0};
634,128✔
2122
  void*                   buf = NULL;
634,128✔
2123
  size_t                  size = 0;
634,128✔
2124

2125
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
634,128!
2126
  void* pTask = sStreamReaderInfo->pTask;
634,128✔
2127
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64, TD_VID(pVnode), __func__, req->firstTsReq.startTime, req->firstTsReq.ver, req->firstTsReq.gid);
634,128✔
2128
  BUILD_OPTION(options, sStreamReaderInfo, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, sStreamReaderInfo->tsSchemas, true,
634,128✔
2129
               STREAM_SCAN_GROUP_ONE_BY_ONE, req->firstTsReq.gid, true, sStreamReaderInfo->uidHashTrigger);
2130
  SStorageAPI api = {0};
634,128✔
2131
  initStorageAPI(&api);
634,128✔
2132
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
634,128✔
2133
  
2134
  firstTsRsp.ver = pVnode->state.applied;
625,257✔
2135
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &firstTsRsp, sStreamReaderInfo, pTaskInner));
625,257!
2136

2137
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(firstTsRsp.tsInfo), firstTsRsp.ver);
625,257✔
2138
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
625,257!
2139
  if (stDebugFlag & DEBUG_DEBUG) {
625,257✔
2140
    int32_t nInfo = taosArrayGetSize(firstTsRsp.tsInfo);
462,108✔
2141
    for (int32_t i = 0; i < nInfo; i++) {
1,062,449✔
2142
      STsInfo* tsInfo = TARRAY_GET_ELEM(firstTsRsp.tsInfo, i);
600,341✔
2143
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
600,341!
2144
    }
2145
  }
2146

2147
end:
634,128✔
2148
  STREAM_PRINT_LOG_END_WITHID(code, lino);
634,128!
2149
  SRpcMsg rsp = {
634,128✔
2150
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2151
  tmsgSendRsp(&rsp);
632,842✔
2152
  taosArrayDestroy(firstTsRsp.tsInfo);
634,128✔
2153
  releaseStreamTask(&pTaskInner);
634,128✔
2154
  return code;
634,128✔
2155
}
2156

2157
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,340,358✔
2158
  int32_t code = 0;
1,340,358✔
2159
  int32_t lino = 0;
1,340,358✔
2160
  void*   buf = NULL;
1,340,358✔
2161
  size_t  size = 0;
1,340,358✔
2162

2163
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
1,340,358!
2164
  void* pTask = sStreamReaderInfo->pTask;
1,340,358✔
2165
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
1,340,358✔
2166

2167
  SStreamReaderTaskInner* pTaskInner = NULL;
1,340,358✔
2168
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
1,340,358✔
2169

2170
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
1,340,358!
2171
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, sStreamReaderInfo->tsSchemas, true, 
1,340,358✔
2172
      (req->tsdbMetaReq.gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), req->tsdbMetaReq.gid, true, sStreamReaderInfo->uidHashTrigger);
2173
    SStorageAPI api = {0};
1,340,358✔
2174
    initStorageAPI(&api);
1,340,358✔
2175
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
1,340,358✔
2176
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
1,331,487!
2177
    
2178
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
1,331,487!
2179
  } else {
2180
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2181
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2182
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2183
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2184
  }
2185

2186
  blockDataCleanup(pTaskInner->pResBlockDst);
1,331,487✔
2187
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
1,331,487!
2188
  bool hasNext = true;
1,331,487✔
2189
  while (true) {
579,291✔
2190
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,910,778!
2191
    if (!hasNext) {
1,910,778!
2192
      break;
1,331,487✔
2193
    }
2194
    pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
579,291✔
2195
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
579,291✔
2196

2197
    int32_t index = 0;
579,291✔
2198
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
579,291!
2199
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
579,291!
2200
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
579,291!
2201
    if (!sStreamReaderInfo->isVtableStream) {
579,291!
2202
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
87,881!
2203
    }
2204
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
579,291!
2205

2206
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
579,291✔
2207
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2208
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2209
            pTaskInner->pResBlockDst->info.rows++;
579,291✔
2210
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
579,291!
2211
      break;
×
2212
    }
2213
  }
2214

2215
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
1,331,487✔
2216
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
1,331,487!
2217
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
1,331,487✔
2218
  if (!hasNext) {
1,331,487!
2219
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
1,331,487!
2220
  }
2221

2222
end:
1,340,358✔
2223
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,340,358!
2224
  SRpcMsg rsp = {
1,340,358✔
2225
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2226
  tmsgSendRsp(&rsp);
1,340,358✔
2227
  return code;
1,340,358✔
2228
}
2229

2230
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
46,778✔
2231
  int32_t                 code = 0;
46,778✔
2232
  int32_t                 lino = 0;
46,778✔
2233
  SStreamReaderTaskInner* pTaskInner = NULL;
46,778✔
2234
  void*                   buf = NULL;
46,778✔
2235
  size_t                  size = 0;
46,778✔
2236
  SSDataBlock*            pBlockRes = NULL;
46,778✔
2237

2238
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
46,778!
2239
  void* pTask = sStreamReaderInfo->pTask;
46,778✔
2240
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
46,778!
2241
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2242
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2243

2244
  BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
46,778✔
2245
               sStreamReaderInfo->triggerCols, false, STREAM_SCAN_ALL, 0, true, NULL);
2246
  options.uid = req->tsdbTsDataReq.uid;
46,778✔
2247
  SStorageAPI api = {0};
46,778✔
2248
  initStorageAPI(&api);
46,778✔
2249
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
46,778!
2250
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
46,778!
2251
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
46,778!
2252

2253
  while (1) {
46,778✔
2254
    bool hasNext = false;
93,556✔
2255
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
93,556!
2256
    if (!hasNext) {
93,556!
2257
      break;
46,778✔
2258
    }
2259
    if (!sStreamReaderInfo->isVtableStream){
46,778!
2260
      pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
46,778✔
2261
    }
2262

2263
    SSDataBlock* pBlock = NULL;
46,778✔
2264
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
46,778!
2265
    if (pBlock != NULL && pBlock->info.rows > 0) {
46,778!
2266
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, false, &api, pBlock->info.id.uid, pBlock,
46,778!
2267
          0, pBlock->info.rows, 1));
2268
    }
2269
    
2270
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
46,778!
2271
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
46,778!
2272
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
45,514!
2273
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2274
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2275
  }
2276

2277
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
46,778✔
2278

2279
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
46,778!
2280
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
46,778!
2281

2282
end:
46,778✔
2283
  STREAM_PRINT_LOG_END_WITHID(code, lino);
46,778!
2284
  SRpcMsg rsp = {
46,778✔
2285
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2286
  tmsgSendRsp(&rsp);
46,778✔
2287
  blockDataDestroy(pBlockRes);
46,778✔
2288

2289
  releaseStreamTask(&pTaskInner);
46,778✔
2290
  return code;
46,778✔
2291
}
2292

2293
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
5,084✔
2294
  int32_t                 code = 0;
5,084✔
2295
  int32_t                 lino = 0;
5,084✔
2296
  SStreamReaderTaskInner* pTaskInner = NULL;
5,084✔
2297
  void*                   buf = NULL;
5,084✔
2298
  size_t                  size = 0;
5,084✔
2299
  SSDataBlock*            pBlockRes = NULL;
5,084✔
2300

2301
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
5,084!
2302
  void* pTask = sStreamReaderInfo->pTask;
5,084✔
2303
  ST_TASK_ELOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
5,084!
2304
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2305
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2306

2307
  BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
5,084✔
2308
               sStreamReaderInfo->tsSchemas, true, STREAM_SCAN_ALL, 0, true, NULL);
2309
  options.suid = req->tsdbTsDataReq.suid;
5,084✔
2310
  options.uid = req->tsdbTsDataReq.uid;
5,084✔
2311
  SStorageAPI api = {0};
5,084✔
2312
  initStorageAPI(&api);
5,084✔
2313
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &api));
5,084!
2314
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
5,084!
2315

2316
  while (1) {
5,084✔
2317
    bool hasNext = false;
10,168✔
2318
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
10,168!
2319
    if (!hasNext) {
10,168!
2320
      break;
5,084✔
2321
    }
2322

2323
    SSDataBlock* pBlock = NULL;
5,084✔
2324
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
5,084!
2325
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
5,084!
2326
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
5,084!
2327
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
2328
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
2329
  }
2330

2331
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
5,084!
2332
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
5,084!
2333

2334
end:
5,084✔
2335
  STREAM_PRINT_LOG_END_WITHID(code, lino);
5,084!
2336
  SRpcMsg rsp = {
5,084✔
2337
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2338
  tmsgSendRsp(&rsp);
5,084✔
2339
  blockDataDestroy(pBlockRes);
5,084✔
2340

2341
  releaseStreamTask(&pTaskInner);
5,084✔
2342
  return code;
5,084✔
2343
}
2344

2345
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
378,383✔
2346
  int32_t code = 0;
378,383✔
2347
  int32_t lino = 0;
378,383✔
2348
  void*   buf = NULL;
378,383✔
2349
  size_t  size = 0;
378,383✔
2350

2351
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
378,383!
2352
  SStreamReaderTaskInner* pTaskInner = NULL;
378,383✔
2353
  void* pTask = sStreamReaderInfo->pTask;
378,383✔
2354
  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);
378,383✔
2355
  
2356
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
378,383✔
2357

2358
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
378,383✔
2359
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
182,118✔
2360
                 sStreamReaderInfo->triggerCols, false, (req->tsdbTriggerDataReq.gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), 
2361
                 req->tsdbTriggerDataReq.gid, true, NULL);
2362
    SStorageAPI api = {0};
182,118✔
2363
    initStorageAPI(&api);
182,118✔
2364
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
182,118!
2365

2366
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
182,118!
2367
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
182,118!
2368
  } else {
2369
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
196,265✔
2370
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
196,265!
2371
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
196,265✔
2372
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
196,265!
2373
  }
2374

2375
  blockDataCleanup(pTaskInner->pResBlockDst);
378,383✔
2376
  bool hasNext = true;
378,383✔
2377
  while (1) {
×
2378
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
378,383!
2379
    if (!hasNext) {
377,091!
2380
      break;
182,118✔
2381
    }
2382
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
194,973✔
2383
    pTaskInner->pResBlockDst->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
194,973✔
2384

2385
    SSDataBlock* pBlock = NULL;
194,973✔
2386
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
196,265!
2387
    if (pBlock != NULL && pBlock->info.rows > 0) {
194,973!
2388
      STREAM_CHECK_RET_GOTO(
194,973!
2389
        processTag(pVnode, sStreamReaderInfo, false, &pTaskInner->api, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
2390
    }
2391
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
196,265!
2392
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
196,265!
2393
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
193,687✔
2394
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2395
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2396
    if (pTaskInner->pResBlockDst->info.rows >= 0) { //todo
194,979!
2397
      break;
196,265✔
2398
    }
2399
  }
2400

2401
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
377,097!
2402
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
378,383✔
2403
  if (!hasNext) {
378,383!
2404
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
182,118!
2405
  }
2406

2407
end:
378,383✔
2408
  STREAM_PRINT_LOG_END_WITHID(code, lino);
377,097!
2409
  SRpcMsg rsp = {
377,097✔
2410
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2411
  tmsgSendRsp(&rsp);
378,383✔
2412

2413
  return code;
378,383✔
2414
}
2415

2416
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
36,314,188✔
2417
  int32_t code = 0;
36,314,188✔
2418
  int32_t lino = 0;
36,314,188✔
2419
  void*   buf = NULL;
36,314,188✔
2420
  size_t  size = 0;
36,315,451✔
2421
  SSDataBlock*            pBlockRes = NULL;
36,315,451✔
2422

2423
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
36,315,451!
2424
  void* pTask = sStreamReaderInfo->pTask;
36,315,451✔
2425
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
36,315,451✔
2426
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid, req->tsdbCalcDataReq.ver);
2427

2428
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
36,315,451!
2429

2430
  SStreamReaderTaskInner* pTaskInner = NULL;
36,315,451✔
2431
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
36,315,451✔
2432

2433
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
36,315,451!
2434
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
36,315,451✔
2435
                 sStreamReaderInfo->triggerCols, false, STREAM_SCAN_GROUP_ONE_BY_ONE, req->tsdbCalcDataReq.gid, true, NULL);
2436
    SStorageAPI api = {0};
36,315,451✔
2437
    initStorageAPI(&api);
36,315,451✔
2438
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
36,314,188✔
2439

2440
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
35,887,086!
2441
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
35,888,349!
2442
  } else {
2443
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2444
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2445
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2446
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2447
  }
2448

2449
  blockDataCleanup(pTaskInner->pResBlockDst);
35,888,349✔
2450
  bool hasNext = true;
35,887,086✔
2451
  while (1) {
3,414,757✔
2452
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
39,301,843!
2453
    if (!hasNext) {
39,280,582!
2454
      break;
35,874,543✔
2455
    }
2456
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
3,406,039✔
2457

2458
    SSDataBlock* pBlock = NULL;
3,407,282✔
2459
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
3,409,774!
2460
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
3,402,303!
2461
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3,406,040!
2462
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
3,411,019!
2463
      break;
×
2464
    }
2465
  }
2466

2467
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
35,875,789!
2468
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
35,887,103!
2469
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
35,878,314✔
2470
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
35,883,331!
2471
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
35,879,578✔
2472
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
35,888,349✔
2473
  if (!hasNext) {
35,888,349!
2474
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
35,888,349!
2475
  }
2476

2477
end:
36,310,435✔
2478
  STREAM_PRINT_LOG_END_WITHID(code, lino);
36,307,873!
2479
  SRpcMsg rsp = {
36,319,240✔
2480
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2481
  tmsgSendRsp(&rsp);
36,315,451✔
2482
  blockDataDestroy(pBlockRes);
36,310,399✔
2483
  return code;
36,312,925✔
2484
}
2485

2486
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
786,347✔
2487
  int32_t code = 0;
786,347✔
2488
  int32_t lino = 0;
786,347✔
2489
  void*   buf = NULL;
786,347✔
2490
  size_t  size = 0;
786,347✔
2491
  int32_t* slotIdList = NULL;
786,347✔
2492
  SArray* sortedCid = NULL;
786,347✔
2493
  SArray* schemas = NULL;
786,347✔
2494
  
2495
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
786,347!
2496
  void* pTask = sStreamReaderInfo->pTask;
786,347✔
2497
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
786,347✔
2498
    req->tsdbDataReq.skey, req->tsdbDataReq.ekey, req->tsdbDataReq.uid, req->tsdbDataReq.ver);
2499
    
2500
  SStreamReaderTaskInner* pTaskInner = NULL;
786,347✔
2501
  int64_t key = req->tsdbDataReq.uid;
786,347✔
2502

2503
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
786,347!
2504
    // sort cid and build slotIdList
2505
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
786,347!
2506
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
786,347!
2507
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
786,347✔
2508
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
786,347!
2509
    taosArraySort(sortedCid, sortCid);
786,347✔
2510
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
2,961,457✔
2511
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
2,175,110✔
2512
      STREAM_CHECK_NULL_GOTO(cid, terrno);
2,175,110!
2513
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
4,181,492!
2514
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
4,181,492✔
2515
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
4,181,492!
2516
        if (*cid == *cidSorted) {
4,181,492✔
2517
          slotIdList[j] = i;
2,175,110✔
2518
          break;
2,175,110✔
2519
        }
2520
      }
2521
    }
2522

2523
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas));
786,347✔
2524
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
783,805!
2525
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
783,805✔
2526
                    req->tsdbDataReq.ekey, schemas, true, STREAM_SCAN_ALL, 0, false, NULL);
2527

2528
    options.suid = req->tsdbDataReq.suid;
783,805✔
2529
    options.uid = req->tsdbDataReq.uid;
783,805✔
2530

2531
    SStorageAPI api = {0};
783,805✔
2532
    initStorageAPI(&api);
783,805✔
2533
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
783,805!
2534
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
783,805!
2535

2536
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid};
783,805✔
2537
    cleanupQueryTableDataCond(&pTaskInner->cond);
783,805✔
2538
    taosArraySort(pTaskInner->options.schemas, sortSSchema);
782,513✔
2539

2540
    STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTaskInner->cond, pTaskInner->options.order, pTaskInner->options.schemas,
783,805!
2541
                                                        pTaskInner->options.isSchema, pTaskInner->options.twindows,
2542
                                                        pTaskInner->options.suid, pTaskInner->options.ver, &slotIdList));
2543
    STREAM_CHECK_RET_GOTO(pTaskInner->api.tsdReader.tsdReaderOpen(pVnode, &pTaskInner->cond, &keyInfo, 1, pTaskInner->pResBlock,
783,805!
2544
                                                             (void**)&pTaskInner->pReader, pTaskInner->idStr, NULL));
2545
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pTaskInner->pResBlock, false, &pTaskInner->pResBlockDst));
783,805!
2546
  } else {
2547
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2548
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2549
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2550
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2551
  }
2552

2553
  blockDataCleanup(pTaskInner->pResBlockDst);
783,805✔
2554
  bool hasNext = true;
783,805✔
2555
  while (1) {
783,805✔
2556
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,567,610!
2557
    if (!hasNext) {
1,567,610!
2558
      break;
783,805✔
2559
    }
2560

2561
    SSDataBlock* pBlock = NULL;
783,805✔
2562
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
783,805!
2563
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
783,805!
2564
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
783,805!
2565
      break;
×
2566
    }
2567
  }
2568
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
783,805!
2569
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
783,805✔
2570
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
783,805✔
2571
  if (!hasNext) {
783,805!
2572
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
783,805!
2573
  }
2574

2575
end:
786,347✔
2576
  STREAM_PRINT_LOG_END_WITHID(code, lino);
786,347!
2577
  SRpcMsg rsp = {
786,347✔
2578
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2579
  tmsgSendRsp(&rsp);
786,347✔
2580
  taosMemFree(slotIdList);
786,347✔
2581
  taosArrayDestroy(sortedCid);
786,347✔
2582
  taosArrayDestroy(schemas);
786,347✔
2583
  return code;
786,347✔
2584
}
2585

2586
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
19,778,582✔
2587
  int32_t      code = 0;
19,778,582✔
2588
  int32_t      lino = 0;
19,778,582✔
2589
  void*        buf = NULL;
19,778,582✔
2590
  size_t       size = 0;
19,778,582✔
2591
  int64_t      lastVer = 0;
19,778,582✔
2592
  SSTriggerWalNewRsp resultRsp = {0};
19,778,582✔
2593

2594
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
19,778,535✔
2595
  void* pTask = sStreamReaderInfo->pTask;
19,774,748✔
2596
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
19,774,748✔
2597

2598
  if (sStreamReaderInfo->metaBlock == NULL) {
19,776,121✔
2599
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
553,708!
2600
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
553,708!
2601
  }
2602
  blockDataEmpty(sStreamReaderInfo->metaBlock);
19,778,600✔
2603
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
19,763,212✔
2604
  resultRsp.ver = req->walMetaNewReq.lastVer;
19,763,212✔
2605
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
19,768,348!
2606

2607
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
19,773,468✔
2608
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
19,773,464✔
2609
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, NULL);
726,904✔
2610
  buf = rpcMallocCont(size);
726,904✔
2611
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, NULL);
726,904✔
2612
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
726,904✔
2613

2614
end:
19,777,251✔
2615
  if (resultRsp.totalRows == 0) {
19,777,251✔
2616
    code = TSDB_CODE_STREAM_NO_DATA;
19,049,063✔
2617
    buf = rpcMallocCont(sizeof(int64_t));
19,049,063✔
2618
    *(int64_t *)buf = resultRsp.ver;
19,042,643✔
2619
    size = sizeof(int64_t);
19,043,927✔
2620
  }
2621
  SRpcMsg rsp = {
19,772,115✔
2622
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2623
  tmsgSendRsp(&rsp);
19,773,399✔
2624
  if (code == TSDB_CODE_STREAM_NO_DATA){
19,777,281✔
2625
    code = 0;
19,051,648✔
2626
  }
2627
  STREAM_PRINT_LOG_END_WITHID(code, lino);
19,777,281!
2628
  blockDataDestroy(resultRsp.deleteBlock);
19,779,803✔
2629
  blockDataDestroy(resultRsp.dropBlock);
19,779,823✔
2630

2631
  return code;
19,779,823✔
2632
}
2633
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
10,194,303✔
2634
  int32_t      code = 0;
10,194,303✔
2635
  int32_t      lino = 0;
10,194,303✔
2636
  void*        buf = NULL;
10,194,303✔
2637
  size_t       size = 0;
10,194,303✔
2638
  SSTriggerWalNewRsp resultRsp = {0};
10,194,303✔
2639
  
2640
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
10,196,873!
2641
  void* pTask = sStreamReaderInfo->pTask;
10,196,873✔
2642
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
10,196,873✔
2643

2644
  if (sStreamReaderInfo->metaBlock == NULL) {
10,196,873✔
2645
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
250,384!
2646
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
249,100!
2647
  }
2648
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
10,195,582✔
2649
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
10,196,873✔
2650
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
10,195,589✔
2651
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
10,193,019!
2652

2653
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
10,186,571✔
2654
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
439,391✔
2655
  buf = rpcMallocCont(size);
439,391✔
2656
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
439,391✔
2657
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
439,391✔
2658
  printDataBlock(sStreamReaderInfo->triggerBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
439,391✔
2659
  printDataBlock(resultRsp.dropBlock, __func__, "drop", ((SStreamTask*)pTask)->streamId);
439,391✔
2660
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
439,391✔
2661
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
439,391✔
2662

2663
end:
10,186,571✔
2664
  if (resultRsp.totalRows == 0) {
10,185,287✔
2665
    buf = rpcMallocCont(sizeof(int64_t));
9,754,916✔
2666
    *(int64_t *)buf = resultRsp.ver;
9,740,772✔
2667
    size = sizeof(int64_t);
9,735,625✔
2668
    code = TSDB_CODE_STREAM_NO_DATA;
9,735,625✔
2669
  }
2670
  SRpcMsg rsp = {
10,165,996✔
2671
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2672
  tmsgSendRsp(&rsp);
10,182,730✔
2673
  if (code == TSDB_CODE_STREAM_NO_DATA){
10,194,312✔
2674
    code = 0;
9,757,478✔
2675
  }
2676
  blockDataDestroy(resultRsp.deleteBlock);
10,194,312✔
2677
  blockDataDestroy(resultRsp.dropBlock);
10,188,186✔
2678

2679
  STREAM_PRINT_LOG_END_WITHID(code, lino);
10,183,056!
2680

2681
  return code;
10,186,873✔
2682
}
2683

2684
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
10,254,611✔
2685
  int32_t      code = 0;
10,254,611✔
2686
  int32_t      lino = 0;
10,254,611✔
2687
  void*        buf = NULL;
10,254,611✔
2688
  size_t       size = 0;
10,254,611✔
2689
  SSTriggerWalNewRsp resultRsp = {0};
10,254,611✔
2690

2691
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
10,254,611✔
2692
  void* pTask = sStreamReaderInfo->pTask;
10,252,069✔
2693
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
10,252,069✔
2694

2695
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
10,252,069✔
2696
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
10,252,069!
2697
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
10,250,785✔
2698

2699
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
10,250,785✔
2700

2701
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
479,792✔
2702
  buf = rpcMallocCont(size);
479,792✔
2703
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
479,792✔
2704
  printDataBlock(sStreamReaderInfo->triggerBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
479,792✔
2705
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
479,792✔
2706

2707
end:
10,253,327✔
2708
  if (resultRsp.totalRows == 0) {
10,254,611✔
2709
    buf = rpcMallocCont(sizeof(int64_t));
9,776,103✔
2710
    *(int64_t *)buf = resultRsp.ver;
9,776,103✔
2711
    size = sizeof(int64_t);
9,776,103✔
2712
    code = TSDB_CODE_STREAM_NO_DATA;
9,776,103✔
2713
  }
2714
  SRpcMsg rsp = {
10,254,611✔
2715
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2716
  tmsgSendRsp(&rsp);
10,257,179✔
2717
  if (code == TSDB_CODE_STREAM_NO_DATA){
10,254,611✔
2718
    code = 0;
9,774,819✔
2719
  }
2720

2721
  blockDataDestroy(resultRsp.deleteBlock);
10,254,611✔
2722
  blockDataDestroy(resultRsp.dropBlock);
10,255,895✔
2723
  STREAM_PRINT_LOG_END_WITHID(code, lino);
10,254,611!
2724

2725
  return code;
10,254,611✔
2726
}
2727

2728
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,798,274✔
2729
  int32_t      code = 0;
1,798,274✔
2730
  int32_t      lino = 0;
1,798,274✔
2731
  void*        buf = NULL;
1,798,274✔
2732
  size_t       size = 0;
1,798,274✔
2733
  SSTriggerWalNewRsp resultRsp = {0};
1,798,274✔
2734
  SSDataBlock* pBlock1 = NULL;
1,798,274✔
2735
  SSDataBlock* pBlock2 = NULL;
1,798,274✔
2736
  
2737
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
1,798,274!
2738
  void* pTask = sStreamReaderInfo->pTask;
1,798,274✔
2739
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
1,798,274✔
2740

2741
  resultRsp.dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
1,798,274!
2742
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
1,798,274!
2743
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
1,798,274!
2744
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
1,798,274✔
2745

2746
  if (!sStreamReaderInfo->isVtableStream){
939,199!
2747
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, true, &pBlock1));
663,942!
2748
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
662,658!
2749
  
2750
    blockDataTransform(pBlock2, pBlock1);
663,942✔
2751
    resultRsp.dataBlock = pBlock2;
663,942✔
2752
  }
2753

2754
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
939,199✔
2755
  buf = rpcMallocCont(size);
939,199✔
2756
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
939,199✔
2757
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
937,915✔
2758
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
937,915✔
2759

2760
end:
1,796,990✔
2761
  if (resultRsp.totalRows == 0) {
1,796,990✔
2762
    buf = rpcMallocCont(sizeof(int64_t));
859,075✔
2763
    *(int64_t *)buf = resultRsp.ver;
859,075✔
2764
    size = sizeof(int64_t);
859,075✔
2765
    code = TSDB_CODE_STREAM_NO_DATA;
859,075✔
2766
  }
2767
  SRpcMsg rsp = {
1,796,990✔
2768
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2769
  tmsgSendRsp(&rsp);
1,798,274✔
2770
  if (code == TSDB_CODE_STREAM_NO_DATA){
1,797,013✔
2771
    code = 0;
857,814✔
2772
  }
2773

2774
  blockDataDestroy(pBlock1);
1,797,013✔
2775
  blockDataDestroy(pBlock2);
1,798,274✔
2776
  blockDataDestroy(resultRsp.deleteBlock);
1,798,274✔
2777
  blockDataDestroy(resultRsp.dropBlock);
1,798,274✔
2778
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,797,013!
2779

2780
  return code;
1,797,013✔
2781
}
2782

2783
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
984,029✔
2784
  int32_t code = 0;
984,029✔
2785
  int32_t lino = 0;
984,029✔
2786
  void*   buf = NULL;
984,029✔
2787
  size_t  size = 0;
984,029✔
2788

2789
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
984,029!
2790
  void* pTask = sStreamReaderInfo->pTask;
984,029✔
2791
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
984,029✔
2792

2793
  SArray** gInfo = taosHashGet(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
984,029✔
2794
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
984,029!
2795
  SStreamGroupInfo pGroupInfo = {0};
984,029✔
2796
  pGroupInfo.gInfo = *gInfo;
984,029✔
2797

2798
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
984,029✔
2799
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
2800
  buf = rpcMallocCont(size);
984,029✔
2801
  STREAM_CHECK_NULL_GOTO(buf, terrno);
984,029!
2802
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
984,029✔
2803
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
2804
end:
984,029✔
2805
  if (code != 0) {
984,029!
2806
    rpcFreeCont(buf);
×
2807
    buf = NULL;
×
2808
    size = 0;
×
2809
  }
2810
  STREAM_PRINT_LOG_END_WITHID(code, lino);
984,029!
2811
  SRpcMsg rsp = {
984,029✔
2812
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2813
  tmsgSendRsp(&rsp);
984,029✔
2814

2815
  return code;
984,029✔
2816
}
2817

2818
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,030,392✔
2819
  int32_t              code = 0;
1,030,392✔
2820
  int32_t              lino = 0;
1,030,392✔
2821
  void*                buf = NULL;
1,030,392✔
2822
  size_t               size = 0;
1,030,392✔
2823
  SStreamMsgVTableInfo vTableInfo = {0};
1,030,392✔
2824
  SMetaReader          metaReader = {0};
1,030,392✔
2825
  SStorageAPI api = {0};
1,030,392✔
2826
  initStorageAPI(&api);
1,030,392✔
2827

2828
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
1,030,392!
2829
  void* pTask = sStreamReaderInfo->pTask;
1,030,392✔
2830
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
1,030,392✔
2831

2832
  SArray* cids = req->virTableInfoReq.cids;
1,030,392✔
2833
  STREAM_CHECK_NULL_GOTO(cids, terrno);
1,030,392!
2834

2835
  SArray* pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo->tableList);
1,030,392✔
2836
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
1,030,392!
2837

2838
  vTableInfo.infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
1,030,392✔
2839
  STREAM_CHECK_NULL_GOTO(vTableInfo.infos, terrno);
1,030,392!
2840
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
1,030,392✔
2841

2842
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
3,284,969✔
2843
    STableKeyInfo* pKeyInfo = taosArrayGet(pTableListArray, i);
2,254,577✔
2844
    if (pKeyInfo == NULL) {
2,254,577!
2845
      continue;
×
2846
    }
2847
    VTableInfo* vTable = taosArrayReserve(vTableInfo.infos, 1);
2,254,577✔
2848
    STREAM_CHECK_NULL_GOTO(vTable, terrno);
2,253,293!
2849
    vTable->uid = pKeyInfo->uid;
2,253,293✔
2850
    vTable->gId = pKeyInfo->groupId;
2,254,577✔
2851

2852
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
2,254,577✔
2853
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
2,254,577!
2854
      vTable->cols.nCols = metaReader.me.colRef.nCols;
140,857✔
2855
      vTable->cols.version = metaReader.me.colRef.version;
140,857✔
2856
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
140,857!
2857
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
845,142✔
2858
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
704,285!
2859
      }
2860
    } else {
2861
      vTable->cols.nCols = taosArrayGetSize(cids);
2,113,720✔
2862
      vTable->cols.version = metaReader.me.colRef.version;
2,113,720✔
2863
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
2,113,720!
2864
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
7,853,053✔
2865
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
24,156,239✔
2866
          if (metaReader.me.colRef.pColRef[j].hasRef &&
22,042,519!
2867
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
16,182,586✔
2868
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
3,625,613!
2869
            break;
3,625,613✔
2870
          }
2871
        }
2872
      }
2873
    }
2874
    tDecoderClear(&metaReader.coder);
2,254,577✔
2875
  }
2876
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
1,030,392✔
2877
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
1,030,392!
2878

2879
end:
1,030,392✔
2880
  tDestroySStreamMsgVTableInfo(&vTableInfo);
1,030,392✔
2881
  api.metaReaderFn.clearReader(&metaReader);
1,030,392✔
2882
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,030,392!
2883
  SRpcMsg rsp = {
1,030,392✔
2884
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2885
  tmsgSendRsp(&rsp);
1,030,392✔
2886
  return code;
1,030,392✔
2887
}
2888

2889
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req) {
306,531✔
2890
  int32_t                   code = 0;
306,531✔
2891
  int32_t                   lino = 0;
306,531✔
2892
  void*                     buf = NULL;
306,531✔
2893
  size_t                    size = 0;
306,531✔
2894
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
306,531✔
2895
  SMetaReader               metaReader = {0};
306,531✔
2896
  int64_t streamId = req->base.streamId;
306,531✔
2897
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
305,247✔
2898

2899
  SStorageAPI api = {0};
305,247✔
2900
  initStorageAPI(&api);
305,247✔
2901

2902
  SArray* cols = req->origTableInfoReq.cols;
306,531✔
2903
  STREAM_CHECK_NULL_GOTO(cols, terrno);
303,963!
2904

2905
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
303,963✔
2906

2907
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
306,531!
2908

2909
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
306,531✔
2910
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
1,045,621✔
2911
    OTableInfo*    oInfo = taosArrayGet(cols, i);
739,103✔
2912
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
739,090✔
2913
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
739,103!
2914
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
739,103!
2915
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByName(&metaReader, oInfo->refTableName));
739,103!
2916
    vTableInfo->uid = metaReader.me.uid;
737,819✔
2917
    stsDebug("vgId:%d %s uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
739,103✔
2918

2919
    SSchemaWrapper* sSchemaWrapper = NULL;
737,806✔
2920
    if (metaReader.me.type == TD_CHILD_TABLE) {
737,806✔
2921
      int64_t suid = metaReader.me.ctbEntry.suid;
732,670✔
2922
      vTableInfo->suid = suid;
732,670✔
2923
      tDecoderClear(&metaReader.coder);
735,238✔
2924
      STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
733,954!
2925
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
735,238✔
2926
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
5,136!
2927
      vTableInfo->suid = 0;
5,136✔
2928
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
5,136✔
2929
    } else {
2930
      stError("invalid table type:%d", metaReader.me.type);
×
2931
    }
2932

2933
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
2,686,414✔
2934
      SSchema* s = sSchemaWrapper->pSchema + j;
2,686,401✔
2935
      if (strcmp(s->name, oInfo->refColName) == 0) {
2,681,291!
2936
        vTableInfo->cid = s->colId;
739,103✔
2937
        break;
737,806✔
2938
      }
2939
    }
2940
    if (vTableInfo->cid == 0) {
737,819!
2941
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
2942
              oInfo->refTableName);
2943
    }
2944
    tDecoderClear(&metaReader.coder);
740,374✔
2945
  }
2946

2947
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
306,531!
2948

2949
end:
305,262✔
2950
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
305,262✔
2951
  api.metaReaderFn.clearReader(&metaReader);
305,262✔
2952
  STREAM_PRINT_LOG_END(code, lino);
305,262!
2953
  SRpcMsg rsp = {
306,531✔
2954
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2955
  tmsgSendRsp(&rsp);
305,247✔
2956
  return code;
306,531✔
2957
}
2958

2959
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req) {
1,636,390✔
2960
  int32_t                   code = 0;
1,636,390✔
2961
  int32_t                   lino = 0;
1,636,390✔
2962
  void*                     buf = NULL;
1,636,390✔
2963
  size_t                    size = 0;
1,636,390✔
2964
  SSDataBlock* pBlock = NULL;
1,636,390✔
2965

2966
  SMetaReader               metaReader = {0};
1,636,390✔
2967
  SMetaReader               metaReaderStable = {0};
1,636,390✔
2968
  int64_t streamId = req->base.streamId;
1,636,390✔
2969
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
1,636,390✔
2970

2971
  SStorageAPI api = {0};
1,636,390✔
2972
  initStorageAPI(&api);
1,636,390✔
2973

2974
  SArray* cols = req->virTablePseudoColReq.cids;
1,636,390✔
2975
  STREAM_CHECK_NULL_GOTO(cols, terrno);
1,636,390!
2976

2977
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
1,636,390✔
2978
  STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, req->virTablePseudoColReq.uid));
1,636,390!
2979

2980
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
1,636,390!
2981

2982
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
1,636,390!
2983
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
1,636,390✔
2984
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
8,988!
2985
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
8,988✔
2986
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
8,988!
2987
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
8,988!
2988
    pBlock->info.rows = 1;
8,988✔
2989
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
8,988✔
2990
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
8,988!
2991
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
8,988!
2992
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
1,627,402!
2993
    int64_t suid = metaReader.me.ctbEntry.suid;
1,627,402✔
2994
    api.metaReaderFn.readerReleaseLock(&metaReader);
1,627,402✔
2995
    api.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &api.metaFn);
1,627,402✔
2996

2997
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
1,627,402!
2998
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
1,627,402✔
2999
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
4,185,327✔
3000
      col_id_t* id = taosArrayGet(cols, i);
2,557,925✔
3001
      STREAM_CHECK_NULL_GOTO(id, terrno);
2,556,633!
3002
      if (*id == -1) {
2,556,633✔
3003
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
1,624,860✔
3004
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
1,624,860!
3005
        continue;
1,624,860✔
3006
      }
3007
      size_t j = 0;
933,065✔
3008
      for (; j < sSchemaWrapper->nCols; j++) {
1,677,661!
3009
        SSchema* s = sSchemaWrapper->pSchema + j;
1,677,661✔
3010
        if (s->colId == *id) {
1,677,661✔
3011
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
933,065✔
3012
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
933,065!
3013
          break;
933,065✔
3014
        }
3015
      }
3016
      if (j == sSchemaWrapper->nCols) {
933,065!
3017
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3018
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3019
      }
3020
    }
3021
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
1,627,402!
3022
    pBlock->info.rows = 1;
1,627,402✔
3023
    
3024
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
4,185,327✔
3025
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
2,557,925✔
3026
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,557,925!
3027

3028
      if (pDst->info.colId == -1) {
2,557,925✔
3029
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
1,624,860!
3030
        continue;
1,624,860✔
3031
      }
3032
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
933,065!
3033
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3034
        continue;
×
3035
      }
3036

3037
      STagVal val = {0};
933,065✔
3038
      val.cid = pDst->info.colId;
933,065✔
3039
      const char* p = api.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
933,065✔
3040

3041
      char* data = NULL;
933,065✔
3042
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
933,065!
3043
        data = tTagValToData((const STagVal*)p, false);
933,065✔
3044
      } else {
3045
        data = (char*)p;
×
3046
      }
3047

3048
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
933,065!
3049
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3050

3051
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
933,065!
3052
          (data != NULL)) {
3053
        taosMemoryFree(data);
700,181!
3054
      }
3055
    }
3056
  } else {
3057
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3058
    code = TSDB_CODE_INVALID_PARA;
×
3059
    goto end;
×
3060
  }
3061
  
3062
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
1,636,390✔
3063
  printDataBlock(pBlock, __func__, "", streamId);
1,636,390✔
3064
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
1,636,390!
3065

3066
end:
1,635,119✔
3067
  if(size == 0){
1,636,390!
3068
    code = TSDB_CODE_STREAM_NO_DATA;
×
3069
  }
3070
  api.metaReaderFn.clearReader(&metaReaderStable);
1,636,390✔
3071
  api.metaReaderFn.clearReader(&metaReader);
1,636,390✔
3072
  STREAM_PRINT_LOG_END(code, lino);
1,635,119!
3073
  SRpcMsg rsp = {
1,635,119✔
3074
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3075
  tmsgSendRsp(&rsp);
1,636,390✔
3076
  blockDataDestroy(pBlock);
1,636,390✔
3077
  return code;
1,636,390✔
3078
}
3079

3080
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg) {
21,486,435✔
3081
  int32_t            code = 0;
21,486,435✔
3082
  int32_t            lino = 0;
21,486,435✔
3083
  void*              buf = NULL;
21,486,435✔
3084
  size_t             size = 0;
21,486,435✔
3085
  void*              taskAddr = NULL;
21,486,435✔
3086
  SArray*            pResList = NULL;
21,486,435✔
3087
  bool               hasNext = false;
21,486,435✔
3088

3089
  SResFetchReq req = {0};
21,486,435✔
3090
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
21,486,435!
3091
                              TSDB_CODE_QRY_INVALID_INPUT);
3092
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
21,486,435✔
3093
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
21,486,435!
3094

3095
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
21,486,435!
3096
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
21,486,435✔
3097
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
21,486,435!
3098
  void* pTask = sStreamReaderCalcInfo->pTask;
21,486,435✔
3099
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
21,486,435!
3100
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
3101

3102
  if (req.reset) {
21,486,435✔
3103
    int64_t uid = 0;
21,372,994✔
3104
    if (req.dynTbname) {
21,372,994!
3105
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
211,247✔
3106
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
211,247!
3107
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
211,247✔
3108
        if (pValue != NULL && pValue->isTbname) {
211,247!
3109
          uid = pValue->uid;
211,247✔
3110
          break;
211,247✔
3111
        }
3112
      }
3113
    }
3114
    
3115
    SReadHandle handle = {0};
21,372,994✔
3116
    handle.vnode = pVnode;
21,372,994✔
3117
    handle.uid = uid;
21,372,994✔
3118

3119
    initStorageAPI(&handle.api);
21,372,994✔
3120
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
21,372,994✔
3121
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
19,752,865✔
3122
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
18,227,795✔
3123
      if (node != NULL) {
18,226,483✔
3124
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
1,253,765!
3125
      } else {
3126
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
16,972,718✔
3127
      }
3128

3129
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
18,226,483✔
3130
      if (node != NULL) {
18,227,795!
3131
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
×
3132
      } else {
3133
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
18,227,795✔
3134
      }      
3135
    }
3136

3137
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
21,372,994!
3138
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
21,372,994✔
3139

3140
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
21,372,994✔
3141
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
961,327✔
3142
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
961,327✔
3143
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
3144
                                                    req.taskId));
3145
    } else {
3146
      handle.version = pVnode->state.applied;
20,411,667✔
3147
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
20,411,667!
3148
    }
3149

3150
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
21,369,128!
3151
  }
3152

3153
  if (req.pOpParam != NULL) {
21,481,285✔
3154
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, req.pOpParam);
1,046,903✔
3155
  }
3156
  
3157
  pResList = taosArrayInit(4, POINTER_BYTES);
21,481,285✔
3158
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
21,482,569!
3159
  uint64_t ts = 0;
21,482,569✔
3160
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
21,482,569✔
3161

3162
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
46,198,326✔
3163
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
24,720,892✔
3164
    if (pBlock == NULL) continue;
24,719,620!
3165
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
24,719,620✔
3166
/*    
3167
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
3168
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
3169
      printDataBlock(pBlock, __func__, "fetch filter");
3170
    }
3171
*/    
3172
  }
3173

3174
end:
21,486,435✔
3175
  ST_TASK_DLOG("vgId:%d %s start to build rsp", TD_VID(pVnode), __func__);
21,486,435✔
3176
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
21,486,435!
3177
  ST_TASK_DLOG("vgId:%d %s end:", TD_VID(pVnode), __func__);
21,486,435✔
3178

3179
  taosArrayDestroy(pResList);
21,486,435✔
3180
  streamReleaseTask(taskAddr);
21,486,435✔
3181

3182
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
21,486,435!
3183
    code = TDB_CODE_SUCCESS;
×
3184
  }
3185
  STREAM_PRINT_LOG_END(code, lino);
21,486,435!
3186
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
21,486,435✔
3187
  tmsgSendRsp(&rsp);
21,486,435✔
3188
  tDestroySResFetchReq(&req);
21,484,189✔
3189
  return code;
21,485,139✔
3190
}
3191

3192
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
108,124,799✔
3193
  int32_t                   code = 0;
108,124,799✔
3194
  int32_t                   lino = 0;
108,124,799✔
3195
  SSTriggerPullRequestUnion req = {0};
108,124,799✔
3196
  void*                     taskAddr = NULL;
108,127,348✔
3197

3198
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
108,113,040✔
3199
  if (!syncIsReadyForRead(pVnode->sync)) {
108,122,958✔
3200
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
49,856✔
3201
    return 0;
49,856✔
3202
  }
3203

3204
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
108,077,041✔
3205
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
21,486,435✔
3206
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
86,588,038!
3207
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
86,591,911✔
3208
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
86,593,197✔
3209
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
86,589,338!
3210
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
86,574,103✔
3211
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId);
3212
    SStreamTriggerReaderInfo* sStreamReaderInfo = (STRIGGER_PULL_OTABLE_INFO == req.base.type) ? NULL : qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
86,579,145✔
3213
    if (sStreamReaderInfo != NULL) {  
86,599,676✔
3214
      (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
86,267,587✔
3215
      if (sStreamReaderInfo->tableList == NULL) {
86,274,013✔
3216
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, false));  
805,366!
3217
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, true));
804,075!
3218
        STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamReaderInfo->pConditions, &sStreamReaderInfo->pFilterInfo, 0, NULL));
804,075!
3219
      }
3220
      (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
86,271,466✔
3221
      sStreamReaderInfo->pVnode = pVnode;
86,265,024✔
3222
    }
3223
    switch (req.base.type) {
86,581,713!
3224
      case STRIGGER_PULL_SET_TABLE:
306,531✔
3225
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
306,531!
3226
        break;
306,531✔
3227
      case STRIGGER_PULL_LAST_TS:
790,726✔
3228
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
790,726!
3229
        break;
792,017✔
3230
      case STRIGGER_PULL_FIRST_TS:
634,128✔
3231
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
634,128✔
3232
        break;
625,257✔
3233
      case STRIGGER_PULL_TSDB_META:
1,340,358✔
3234
      case STRIGGER_PULL_TSDB_META_NEXT:
3235
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,340,358✔
3236
        break;
1,331,487✔
3237
      case STRIGGER_PULL_TSDB_TS_DATA:
51,862✔
3238
        if (sStreamReaderInfo->isVtableStream) {
51,862!
3239
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
5,084!
3240
        } else {
3241
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
46,778!
3242
        }
3243
        break;
51,862✔
3244
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
378,383✔
3245
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
3246
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
378,383!
3247
        break;
378,383✔
3248
      case STRIGGER_PULL_TSDB_CALC_DATA:
36,315,451✔
3249
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
3250
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
36,315,451✔
3251
        break;
35,880,771✔
3252
      case STRIGGER_PULL_TSDB_DATA:
786,347✔
3253
      case STRIGGER_PULL_TSDB_DATA_NEXT:
3254
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
786,347✔
3255
        break;
783,805✔
3256
      case STRIGGER_PULL_GROUP_COL_VALUE:
984,029✔
3257
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
984,029!
3258
        break;
984,029✔
3259
      case STRIGGER_PULL_VTABLE_INFO:
1,030,392✔
3260
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,030,392!
3261
        break;
1,030,392✔
3262
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
1,636,390✔
3263
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req));
1,636,390!
3264
        break;
1,636,390✔
3265
      case STRIGGER_PULL_OTABLE_INFO:
306,531✔
3266
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req));
306,531!
3267
        break;
306,531✔
3268
      case STRIGGER_PULL_WAL_META_NEW:
19,778,535✔
3269
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
19,778,535!
3270
        break;
19,779,819✔
3271
      case STRIGGER_PULL_WAL_DATA_NEW:
10,254,611✔
3272
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
10,254,611!
3273
        break;
10,254,611✔
3274
      case STRIGGER_PULL_WAL_META_DATA_NEW:
10,189,165✔
3275
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
10,189,165!
3276
        break;
10,193,021✔
3277
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
1,798,274✔
3278
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,798,274!
3279
        break;
1,798,274✔
3280
      default:
×
3281
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
3282
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3283
        break;
×
3284
    }
3285
  } else {
3286
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
3287
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3288
  }
3289
end:
86,554,876✔
3290

3291
  streamReleaseTask(taskAddr);
86,583,092✔
3292

3293
  tDestroySTriggerPullRequest(&req);
86,580,507✔
3294
  STREAM_PRINT_LOG_END(code, lino);
86,556,156!
3295
  return code;
86,562,476✔
3296
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc