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

taosdata / TDengine / #4805

17 Oct 2025 09:36AM UTC coverage: 61.141% (+0.2%) from 60.905%
#4805

push

travis-ci

web-flow
Merge da5cd734f into 7e74ade39

155483 of 324487 branches covered (47.92%)

Branch coverage included in aggregate %.

152 of 185 new or added lines in 22 files covered. (82.16%)

2677 existing lines in 112 files now uncovered.

207754 of 269610 relevant lines covered (77.06%)

126849241.18 hits per line

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

68.71
/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

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

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

59
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
16,087,262✔
60

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

63
int32_t sortCid(const void *lp, const void *rp) {
957,422✔
64
  int16_t* c1 = (int16_t*)lp;
957,422✔
65
  int16_t* c2 = (int16_t*)rp;
957,422✔
66

67
  if (*c1 < *c2) {
957,422✔
68
    return -1;
953,782✔
69
  } else if (*c1 > *c2) {
3,640!
70
    return 1;
3,640✔
71
  }
72

73
  return 0;
×
74
}
75

76
int32_t sortSSchema(const void *lp, const void *rp) {
953,782✔
77
  SSchema* c1 = (SSchema*)lp;
953,782✔
78
  SSchema* c2 = (SSchema*)rp;
953,782✔
79

80
  if (c1->colId < c2->colId) {
953,782✔
81
    return -1;
950,142✔
82
  } else if (c1->colId > c2->colId) {
3,640!
83
    return 1;
3,640✔
84
  }
85

86
  return 0;
×
87
}
88

89
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
31,393,998✔
90
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
31,393,998✔
91
  if (pSrc == NULL) {
31,414,936!
92
    return terrno;
×
93
  }
94

95
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
31,414,936!
96
  return 0;
31,396,972✔
97
}
98

99
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
20,141,812✔
100
  int32_t code = pTask->api.tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
20,141,812✔
101
  if (code != TSDB_CODE_SUCCESS) {
20,141,799!
102
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
103
  }
104

105
  return code;
20,139,095✔
106
}
107

108
static int32_t getTableData(SStreamReaderTaskInner* pTask, SSDataBlock** ppRes) {
1,724,950✔
109
  return pTask->api.tsdReader.tsdReaderRetrieveDataBlock(pTask->pReader, ppRes, NULL);
1,724,950✔
110
}
111

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

130
static bool needRefreshTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
3,270,824✔
131
  if (sStreamReaderInfo->isVtableStream) {
3,270,824!
132
    int64_t id[2] = {suid, uid};
2,634,307✔
133
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id)) == NULL) {
2,634,307!
134
      return true;
2,630,462✔
135
    }
136
  } else {
137
    if (tableType != TD_CHILD_TABLE) {
637,066✔
138
      return false;
192,440✔
139
    }
140
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
444,626✔
141
        suid == sStreamReaderInfo->suid && 
267,298✔
142
        qStreamGetGroupId(sStreamReaderInfo->tableList, uid) == -1) {
11,070✔
143
      return true;
3,359✔
144
    }
145
  }
146
  return false;
444,558✔
147
}
148

149
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc){
44,458,858✔
150
  if (sStreamReaderInfo->isVtableStream) {
44,458,858!
151
    int64_t tmp[2] = {suid, uid};
31,278,798✔
152
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) == NULL) {
31,277,248✔
153
      return false;
15,571,536✔
154
    }
155
    *id = uid;
15,711,137✔
156
  } else {
157
    if (sStreamReaderInfo->tableList == NULL) return false;
13,198,568!
158

159
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
13,217,303✔
160
      if (suid != sStreamReaderInfo->suid) return false;
8,258,146✔
161
      if (sStreamReaderInfo->pTagCond == NULL) {
6,370,438✔
162
        if (sStreamReaderInfo->partitionCols == NULL){
5,444,872✔
163
          *id = 0;
22,840✔
164
        } else if (sStreamReaderInfo->groupByTbname){
5,420,934!
165
          *id= uid;
5,412,278✔
166
        } else {
167
          *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
8,656✔
168
          if (*id == -1) return false;
8,656!
169
        }
170
      } else {
171
        //*id= uid;
172
        *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
926,115✔
173
        if (*id == -1) return false;
926,115✔
174
      }
175
    } else {
176
      *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
4,970,721✔
177
      if(*id == -1) *id = uid;
4,970,839✔
178
      return uid == sStreamReaderInfo->uid;
4,970,839✔
179
    }
180
  }
181
  return true;
21,690,988✔
182
}
183

184
static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, bool isHistory) {
5,892,567✔
185
  int32_t                   code = 0;
5,892,567✔
186
  int32_t                   lino = 0;
5,892,567✔
187
  SNodeList* groupNew = NULL;                                      
5,892,567✔
188
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
5,894,656!
189

190
  SStorageAPI api = {0};
5,895,118✔
191
  initStorageAPI(&api);
5,895,118✔
192
  code = qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
5,894,066✔
193
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, 
194
                                         isHistory ? &sStreamReaderInfo->historyTableList : &sStreamReaderInfo->tableList,
195
                                         isHistory ? NULL : sStreamReaderInfo->groupIdMap);
196
  end:
5,895,205✔
197
  nodesDestroyList(groupNew);
5,895,660✔
198
  STREAM_PRINT_LOG_END(code, lino);
5,895,111!
199
  return code;
5,895,111✔
200
}
201

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

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

238

239
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
16,866,977✔
240
  int32_t code = 0;
16,866,977✔
241
  int32_t lino = 0;
16,866,977✔
242
  void*   buf = NULL;
16,866,977✔
243
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
16,866,977!
244
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
1,704,137✔
245
  buf = rpcMallocCont(dataEncodeSize);
1,703,624✔
246
  STREAM_CHECK_NULL_GOTO(buf, terrno);
1,703,624!
247
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
1,703,624✔
248
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
1,704,137!
249
  *data = buf;
1,704,137✔
250
  *size = dataEncodeSize;
1,703,624✔
251
  buf = NULL;
1,704,137✔
252
end:
16,869,646✔
253
  rpcFreeCont(buf);
16,869,646✔
254
  return code;
16,867,516✔
255
}
256

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

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

275
end:
1,444,383✔
276
  STREAM_PRINT_LOG_END(code, lino);
1,444,383!
277
  return code;
1,444,383✔
278
}
279

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

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

300
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
7,597,185✔
301
  int32_t code = 0;
7,597,185✔
302
  int32_t lino = 0;
7,597,185✔
303
  int32_t index = 0;
7,597,185✔
304
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
7,597,185!
305
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
7,593,335!
306
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
7,593,333!
307
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
7,594,448!
308

309
end:
7,594,980✔
310
  return code;
7,594,980✔
311
}
312

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

320
end:
569✔
321
  return code;
569✔
322
}
323

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

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

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

357
end:
60,708✔
358
  taosArrayDestroy(req.uidList);
60,708✔
359
  tDecoderClear(&decoder);
60,708✔
360
  return code;
60,708✔
361
}
362

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

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

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

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

389
end:
569✔
390
  tDecoderClear(&decoder);
569✔
391
  return code;
569✔
392
}
393

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

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

414
  SVCreateTbBatchReq req = {0};
37,386✔
415
  tDecoderInit(&decoder, data, len);
37,386✔
416
  
417
  STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbBatchReq(&decoder, &req));
37,386!
418

419
  bool found = false;
37,386✔
420
  SVCreateTbReq* pCreateReq = NULL;
37,386✔
421
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
59,902✔
422
    pCreateReq = req.pReqs + iReq;
37,386✔
423
    if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
37,386✔
424
      ST_TASK_ILOG("stream reader scan create table jump, %s", pCreateReq->name);
22,516!
425
      continue;
22,516✔
426
    }
427
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
14,870!
428

429
    found = true;
14,870✔
430
    break;
14,870✔
431
  }
432
  STREAM_CHECK_CONDITION_GOTO(!found, TDB_CODE_SUCCESS);
37,386✔
433

434
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
14,870!
435
end:
37,386✔
436
  tDeleteSVCreateTbBatchReq(&req);
37,386✔
437
  tDecoderClear(&decoder);
37,386✔
438
  return code;
37,386✔
439
}
440

441
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq) {
3,233,438✔
442
  int32_t  code = 0;
3,233,438✔
443
  int32_t  lino = 0;
3,233,438✔
444
  void*    pTask = sStreamReaderInfo->pTask;
3,233,438✔
445
  if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
3,233,438✔
446
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
614,388✔
447
    goto end;
615,036✔
448
  }
449
  ST_TASK_ILOG("stream reader scan auto create table %s", pCreateReq->name);
2,618,951!
450

451
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
2,618,951!
452
end:
2,618,951✔
453
  return code;
3,233,987✔
454
}
455

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

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

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

474
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
10,002!
475
  ST_TASK_ILOG("stream reader scan alter table %s", req.tbName);
10,002!
476

477
end:
65,772✔
478
  taosArrayDestroy(req.pMultiTag);
65,772✔
479
  tDecoderClear(&decoder);
65,772✔
480
  return code;
65,772✔
481
}
482

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

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

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

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

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

526
static int32_t scanSubmitTbDataForMeta(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* gidHash) {
21,865,879✔
527
  int32_t code = 0;
21,865,879✔
528
  int32_t lino = 0;
21,865,879✔
529
  WalMetaResult walMeta = {0};
21,865,879✔
530
  SSubmitTbData submitTbData = {0};
21,865,136✔
531
  
532
  if (tStartDecode(pCoder) < 0) {
21,865,142!
533
    code = TSDB_CODE_INVALID_MSG;
×
534
    TSDB_CHECK_CODE(code, lino, end);
×
535
  }
536

537
  uint8_t       version = 0;
21,869,693✔
538
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
21,871,502!
539
    code = TSDB_CODE_INVALID_MSG;
×
540
    TSDB_CHECK_CODE(code, lino, end);
×
541
  }
542
  version = (submitTbData.flags >> 8) & 0xff;
21,871,502✔
543
  submitTbData.flags = submitTbData.flags & 0xff;
21,871,502✔
544

545
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
546
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
21,871,502✔
547
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
2,752,672!
548
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
2,752,576!
549
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
2,752,576!
550
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
2,753,127!
551
  }
552

553
  // submit data
554
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
21,865,592!
555
    code = TSDB_CODE_INVALID_MSG;
×
556
    TSDB_CHECK_CODE(code, lino, end);
×
557
  }
558
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
21,866,968!
559
    code = TSDB_CODE_INVALID_MSG;
×
560
    TSDB_CHECK_CODE(code, lino, end);
×
561
  }
562

563
  if (!uidInTableList(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
21,866,968✔
564
    goto end;
16,252,782✔
565
  }
566
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
5,618,085!
567
    code = TSDB_CODE_INVALID_MSG;
×
568
    TSDB_CHECK_CODE(code, lino, end);
×
569
  }
570

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

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

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

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

606
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
13,976,083✔
607
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
8,357,004✔
608
      pCoder->pos += pRow->len;
8,357,004✔
609
      if (iRow == 0){
8,356,453✔
610
#ifndef NO_UNALIGNED_ACCESS
611
        walMeta.skey = pRow->ts;
5,619,079✔
612
#else
613
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
614
#endif
615
      }
616
      if (iRow == nRow - 1) {
8,357,004✔
617
#ifndef NO_UNALIGNED_ACCESS
618
        walMeta.ekey = pRow->ts;
5,619,630✔
619
#else
620
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
621
#endif
622
      }
623
    }
624
  }
625

626
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
5,619,079✔
627
  if (data != NULL) {
5,617,977!
628
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
629
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
630
  } else {
631
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
5,617,977!
632
  }
633

634
end:
21,854,274✔
635
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
21,869,861✔
636
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
21,866,036!
637
  tEndDecode(pCoder);
21,866,036✔
638
  return code;
21,870,042✔
639
}
640

641
static int32_t scanSubmitDataForMeta(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len, int64_t ver) {
21,870,513✔
642
  int32_t  code = 0;
21,870,513✔
643
  int32_t  lino = 0;
21,870,513✔
644
  SDecoder decoder = {0};
21,870,513✔
645
  SSHashObj* gidHash = NULL;
21,870,519✔
646
  void* pTask = sStreamReaderInfo->pTask;
21,870,519✔
647

648
  tDecoderInit(&decoder, data, len);
21,869,519✔
649
  if (tStartDecode(&decoder) < 0) {
21,864,494!
650
    code = TSDB_CODE_INVALID_MSG;
×
651
    TSDB_CHECK_CODE(code, lino, end);
×
652
  }
653

654
  uint64_t nSubmitTbData = 0;
21,867,681✔
655
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
21,871,861!
656
    code = TSDB_CODE_INVALID_MSG;
×
657
    TSDB_CHECK_CODE(code, lino, end);
×
658
  }
659

660
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
21,871,861✔
661
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
21,863,873!
662

663
  for (int32_t i = 0; i < nSubmitTbData; i++) {
43,733,915✔
664
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash));
21,863,957!
665
  }
666
  tEndDecode(&decoder);
21,869,958✔
667

668
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
21,866,874!
669
  int32_t iter = 0;
21,863,347✔
670
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
21,865,521✔
671
  while (px != NULL) {
27,477,250✔
672
    WalMetaResult* pMeta = (WalMetaResult*)px;
5,616,989✔
673
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
5,616,989!
674
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
5,618,540✔
675
    rsp->totalRows++;
5,618,540✔
676
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
5,619,085✔
677
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
678
    px = tSimpleHashIterate(gidHash, px, &iter);
5,619,085✔
679
  }
680
end:
21,860,261✔
681
  tDecoderClear(&decoder);
21,863,345✔
682
  tSimpleHashCleanup( gidHash);
21,868,609✔
683
  return code;
21,864,705✔
684
}
685

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

692
  int32_t index = 1;
557,413✔
693
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // skey
557,413!
694
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // ekey
557,413!
695
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
557,413!
696
  if (!isVTable) {
557,413✔
697
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_UBIGINT, LONG_BYTES, index++))  // gid
80,567!
698
  }
699
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))     // nrows
557,413!
700

701
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
557,413!
702

703
end:
557,413✔
704
  taosArrayDestroy(schemas);
557,413✔
705
  return code;
557,413✔
706
}
707

708
static int32_t createBlockForWalMetaNew(SSDataBlock** pBlock) {
322,773✔
709
  int32_t code = 0;
322,773✔
710
  int32_t lino = 0;
322,773✔
711
  SArray* schemas = NULL;
322,773✔
712

713
  schemas = taosArrayInit(8, sizeof(SSchema));
322,773✔
714
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
324,918!
715

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

722
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
324,918!
723

724
end:
324,918✔
725
  taosArrayDestroy(schemas);
324,918✔
726
  return code;
324,918✔
727
}
728

729
static int32_t createBlockForDropTable(SSDataBlock** pBlock) {
569✔
730
  int32_t code = 0;
569✔
731
  int32_t lino = 0;
569✔
732
  SArray* schemas = NULL;
569✔
733

734
  schemas = taosArrayInit(8, sizeof(SSchema));
569✔
735
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
569!
736

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

741
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
569!
742

743
end:
569✔
744
  taosArrayDestroy(schemas);
569✔
745
  return code;
569✔
746
}
747

748
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int32_t ver) {
393,313✔
749
  int32_t code = 0;
393,313✔
750
  int32_t lino = 0;
393,313✔
751
  SDecoder dcoder = {0};
393,313✔
752
  tDecoderInit(&dcoder, data, len);
393,313✔
753
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
393,313✔
754
    if (rsp->deleteBlock == NULL) {
60,708✔
755
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
20,911!
756
    }
757
      
758
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
60,708!
759
  } else if (msgType == TDMT_VND_DROP_TABLE && sStreamReaderInfo->deleteOutTbl != 0) {
332,605✔
760
    if (rsp->dropBlock == NULL) {
569!
761
      STREAM_CHECK_RET_GOTO(createBlockForDropTable((SSDataBlock**)&rsp->dropBlock));
569!
762
    }
763
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
569!
764
  } else if (msgType == TDMT_VND_DROP_STB) {
332,036!
765
    STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
×
766
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
332,036✔
767
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, data, len));
37,386!
768
  } else if (msgType == TDMT_VND_ALTER_STB) {
294,650✔
769
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
770
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
263,866✔
771
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, data, len));
65,772!
772
  }
773

774
  end:
393,313✔
775
  tDecoderClear(&dcoder);
393,313✔
776
  return code;
393,313✔
777
}
778
static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
7,229,526✔
779
                       int64_t ctime) {
780
  int32_t code = 0;
7,229,526✔
781
  int32_t lino = 0;
7,229,526✔
782
  void* pTask = sStreamReaderInfo->pTask;
7,229,526✔
783

784
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
7,231,706✔
785
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
7,225,201!
786
  code = walReaderSeekVer(pWalReader, rsp->ver);
7,225,201✔
787
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
7,219,716✔
788
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
5,429,322!
789
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
790
    }
791
    ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
5,430,500✔
792
    code = TSDB_CODE_SUCCESS;
5,436,047✔
793
    goto end;
5,436,047✔
794
  }
795
  STREAM_CHECK_RET_GOTO(code);
1,790,394!
796

797
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
1,790,394!
798
  while (1) {
22,108,216✔
799
    code = walNextValidMsg(pWalReader, true);
23,896,989✔
800
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){\
23,897,484✔
801
      ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
1,790,478✔
802
      code = TSDB_CODE_SUCCESS;
1,790,943✔
803
      goto end;
1,790,943✔
804
    }
805
    STREAM_CHECK_RET_GOTO(code);
22,107,006!
806
    rsp->ver = pWalReader->curVersion;
22,107,006✔
807
    SWalCont* wCont = &pWalReader->pHead->head;
22,108,455✔
808
    rsp->verTime = wCont->ingestTs;
22,108,545✔
809
    if (wCont->ingestTs / 1000 > ctime) break;
22,107,679!
810
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
22,105,995✔
811
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
22,108,128✔
812
    int64_t ver = wCont->version;
22,109,749✔
813

814
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
22,111,176✔
815
      TD_VID(pVnode), ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
816
    if (wCont->msgType == TDMT_VND_SUBMIT) {
22,045,207✔
817
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
21,866,872✔
818
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
21,869,603✔
819
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
21,870,693!
820
    } else {
821
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
241,146!
822
    }
823

824
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
22,109,300!
825
      break;
×
826
    }
827
  }
828

829
end:
7,226,990✔
830
  walCloseReader(pWalReader);
7,226,990✔
831
  return code;
7,224,163✔
832
}
833

834
static int32_t processTag(SVnode* pVnode, SStreamTriggerReaderInfo* info, bool isCalc, SStorageAPI* api, 
3,849,533✔
835
  uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks) {
836
  int32_t     code = 0;
3,849,533✔
837
  int32_t     lino = 0;
3,849,533✔
838
  SMetaReader mr = {0};
3,849,533✔
839
  SArray* tagCache = NULL;
3,850,631✔
840

841
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
3,851,185!
842
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
3,847,898!
843
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
3,847,320!
844
  if (numOfExpr == 0) {
3,848,989!
845
    return TSDB_CODE_SUCCESS;
×
846
  }
847

848
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
3,848,989✔
849
  if (uidData == NULL) {
3,850,636✔
850
    api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
162,398✔
851
    code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
162,398✔
852
    api->metaReaderFn.readerReleaseLock(&mr);
162,398✔
853
    STREAM_CHECK_RET_GOTO(code);
162,398!
854

855
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
162,398✔
856
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
162,398!
857
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
162,398!
858
      taosArrayDestroyP(tagCache, taosMemFree);
×
859
      code = terrno;
×
860
      goto end;
×
861
    }
862
  } else {
863
    tagCache = *(SArray**)uidData;
3,688,238✔
864
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
3,682,733!
865
  }
866
  
867
  for (int32_t j = 0; j < numOfExpr; ++j) {
10,602,798✔
868
    const SExprInfo* pExpr1 = &pExprInfo[j];
6,748,880✔
869
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
6,749,429✔
870

871
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
6,753,605✔
872
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
6,756,367!
873
    int32_t functionId = pExpr1->pExpr->_function.functionId;
6,756,367✔
874

875
    // this is to handle the tbname
876
    if (fmIsScanPseudoColumnFunc(functionId)) {
6,758,981✔
877
      int32_t fType = pExpr1->pExpr->_function.functionType;
3,849,324✔
878
      if (fType == FUNCTION_TYPE_TBNAME) {
3,850,070!
879
        char   buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
3,850,636✔
880
        if (uidData == NULL) {
3,851,729✔
881
          STR_TO_VARSTR(buf, mr.me.name)
162,398!
882
          char* tbname = taosStrdup(mr.me.name);
162,398!
883
          STREAM_CHECK_NULL_GOTO(tbname, terrno);
162,398!
884
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno);
324,796!
885
        } else {
886
          char* tbname = taosArrayGetP(tagCache, j);
3,689,331✔
887
          STR_TO_VARSTR(buf, tbname)
3,688,238!
888
        }
889
        for (uint32_t i = 0; i < numOfRows; i++){
11,379,416✔
890
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
7,527,704!
891
        }
892
        code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false);
3,851,712✔
893
        pColInfoData->info.colId = -1;
3,852,623✔
894
      }
895
    } else {  // these are tags
896
      char* data = NULL;
2,902,296✔
897
      const char* p = NULL;
2,902,291✔
898
      STagVal tagVal = {0};
2,902,291✔
899
      if (uidData == NULL) {
2,900,634✔
900
        tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
133,442✔
901
        p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
133,442✔
902

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

909
        if (data == NULL) {
133,442!
910
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
×
911
        } else {
912
          int32_t len = pColInfoData->info.bytes;
133,442✔
913
          if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
133,442!
914
            len = calcStrBytesByType(pColInfoData->info.type, (char*)data);
43,199✔
915
          }
916
          char* pData = taosMemoryCalloc(1, len);
133,442!
917
          STREAM_CHECK_NULL_GOTO(pData, terrno);
133,442!
918
          (void)memcpy(pData, data, len);
133,442!
919
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno);
266,884!
920
        }
921
      } else {
922
        data = taosArrayGetP(tagCache, j);
2,767,192✔
923
      }
924

925
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
2,903,953!
926
      if (isNullVal) {
2,901,742!
927
        colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
928
      } else {
929
        for (uint32_t i = 0; i < numOfRows; i++){
19,936,002✔
930
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
17,033,716!
931
        }
932
        code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false);
2,902,286✔
933
        if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
2,903,394!
934
          taosMemoryFree(data);
43,199!
935
        }
936
        STREAM_CHECK_RET_GOTO(code);
2,901,183!
937
      }
938
    }
939
  }
940

941
end:
3,852,785✔
942
  api->metaReaderFn.clearReader(&mr);
3,852,623✔
943
  return code;
3,852,269✔
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, 
10,642,800✔
992
  STSchema** schemas, SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
993
  int32_t code = 0;
10,642,800✔
994
  int32_t lino = 0;
10,642,800✔
995
  uint64_t id = 0;
10,642,800✔
996
  WalMetaResult walMeta = {0};
10,646,362✔
997
  void* pTask = sStreamReaderInfo->pTask;
10,651,296✔
998
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
10,651,292✔
999

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

1005
  SSubmitTbData submitTbData = {0};
10,655,133✔
1006
  uint8_t       version = 0;
10,655,682✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
10,650,740!
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
10,650,740✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
10,650,740✔
1013
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1014
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
10,650,740✔
1015
    if (tStartDecode(pCoder) < 0) {
21,731!
1016
      code = TSDB_CODE_INVALID_MSG;
×
1017
      TSDB_CHECK_CODE(code, lino, end);
×
1018
    }
1019
    tEndDecode(pCoder);
21,731✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
10,649,102!
1024
    code = TSDB_CODE_INVALID_MSG;
×
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
10,654,584!
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);
10,654,584✔
1033

1034
  walMeta.id = id;
8,941,077✔
1035
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
8,941,077✔
1036

1037
  if (ranges != NULL){
8,944,265✔
1038
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
7,004,063✔
1039
    if (timerange == NULL) goto end;;
7,005,696!
1040
    int64_t* pRange = (int64_t*)timerange;
7,005,696✔
1041
    window.skey = pRange[0];
7,005,696✔
1042
    window.ekey = pRange[1];
7,005,696✔
1043
  }
1044
  
1045
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
8,942,630!
1046
    code = TSDB_CODE_INVALID_MSG;
×
1047
    TSDB_CHECK_CODE(code, lino, end);
×
1048
  }
1049

1050
  if (*schemas == NULL) {
8,942,630✔
1051
    *schemas = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
8,939,438✔
1052
    STREAM_CHECK_NULL_GOTO(*schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
8,938,857!
1053
  }
1054

1055
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &submitTbData.uid, LONG_BYTES);
8,946,896✔
1056
  STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
8,942,606!
1057
  int32_t blockStart = pSlice->currentRowIdx;
8,942,606✔
1058

1059
  int32_t numOfRows = 0;
8,942,606✔
1060
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
8,939,297!
1061
    uint64_t nColData = 0;
×
1062
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1063
      code = TSDB_CODE_INVALID_MSG;
×
1064
      TSDB_CHECK_CODE(code, lino, end);
×
1065
    }
1066

1067
    SColData colData = {0};
×
1068
    code = tDecodeColData(version, pCoder, &colData, false);
×
1069
    if (code) {
×
1070
      code = TSDB_CODE_INVALID_MSG;
×
1071
      TSDB_CHECK_CODE(code, lino, end);
×
1072
    }
1073

1074
    if (colData.flag != HAS_VALUE) {
×
1075
      code = TSDB_CODE_INVALID_MSG;
×
1076
      TSDB_CHECK_CODE(code, lino, end);
×
1077
    }
1078
    
1079
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
1080
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
1081

1082
    int32_t rowStart = 0;
×
1083
    int32_t rowEnd = 0;
×
1084
    STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, &numOfRows));
×
1085
    STREAM_CHECK_CONDITION_GOTO(numOfRows <= 0, TDB_CODE_SUCCESS);
×
1086

1087
    int32_t pos = pCoder->pos;
×
1088
    for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {
×
1089
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
×
1090
      STREAM_CHECK_NULL_GOTO(pColData, terrno);
×
1091
      if (pColData->info.colId <= -1) {
×
1092
        pColData->hasNull = true;
×
1093
        continue;
×
1094
      }
1095
      if (pColData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
×
1096
        STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colData, pColData));
×
1097
        continue;
×
1098
      }
1099

1100
      pCoder->pos = pos;
×
1101

1102
      int16_t colId = 0;
×
1103
      if (sStreamReaderInfo->isVtableStream){
×
1104
        int64_t id[2] = {submitTbData.suid, submitTbData.uid};
×
1105
        void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
×
1106
        STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
×
1107
        SSHashObj* uInfo = *(SSHashObj **)px;
×
1108
        STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
×
1109
        int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
×
1110
        if (tmp != NULL) {
×
1111
          colId = *tmp;
×
1112
        } else {
1113
          colId = -1;
×
1114
        }
1115
      } else {
1116
        colId = pColData->info.colId;
×
1117
      }
1118
      
1119
      uint64_t j = 1;
×
1120
      for (; j < nColData; j++) {
×
1121
        int16_t cid = 0;
×
1122
        int32_t posTmp = pCoder->pos;
×
1123
        pCoder->pos += INT_BYTES;
×
1124
        if ((code = tDecodeI16v(pCoder, &cid))) return code;
×
1125
        pCoder->pos = posTmp;
×
1126
        if (cid == colId) {
×
1127
          SColData colDataTmp = {0};
×
1128
          code = tDecodeColData(version, pCoder, &colDataTmp, false);
×
1129
          if (code) {
×
1130
            code = TSDB_CODE_INVALID_MSG;
×
1131
            TSDB_CHECK_CODE(code, lino, end);
×
1132
          }
1133
          STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colDataTmp, pColData));
×
1134
          break;
×
1135
        }
1136
        code = tDecodeColData(version, pCoder, &colData, true);
×
1137
        if (code) {
×
1138
          code = TSDB_CODE_INVALID_MSG;
×
1139
          TSDB_CHECK_CODE(code, lino, end);
×
1140
        }
1141
      }
1142
      if (j == nColData) {
×
1143
        colDataSetNNULL(pColData, blockStart, numOfRows);
×
1144
      }
1145
    }
1146
  } else {
1147
    uint64_t nRow = 0;
8,939,297✔
1148
    if (tDecodeU64v(pCoder, &nRow) < 0) {
8,942,030!
1149
      code = TSDB_CODE_INVALID_MSG;
×
1150
      TSDB_CHECK_CODE(code, lino, end);
×
1151
    }
1152
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
20,614,583✔
1153
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
11,660,464✔
1154
      pCoder->pos += pRow->len;
11,665,399✔
1155

1156
      if (iRow == 0){
11,668,688✔
1157
#ifndef NO_UNALIGNED_ACCESS
1158
        walMeta.skey = pRow->ts;
8,940,941✔
1159
#else
1160
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1161
#endif
1162
      }
1163
      if (iRow == nRow - 1) {
11,667,598✔
1164
#ifndef NO_UNALIGNED_ACCESS
1165
        walMeta.ekey = pRow->ts;
8,940,949✔
1166
#else
1167
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1168
#endif
1169
      }
1170

1171
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
11,660,550✔
1172
        continue;
16,683✔
1173
      }
1174
     
1175
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
79,194,840✔
1176
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
67,536,872✔
1177
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
67,534,315!
1178
        if (pColData->info.colId <= -1) {
67,534,315✔
1179
          pColData->hasNull = true;
21,314,277✔
1180
          continue;
21,313,728✔
1181
        }
1182
        int16_t colId = 0;
46,232,795✔
1183
        if (sStreamReaderInfo->isVtableStream){
46,232,795!
1184
          int64_t id[2] = {submitTbData.suid, submitTbData.uid};
15,681,560✔
1185
          void* px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
15,682,111!
1186
          STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
15,684,015!
1187
          SSHashObj* uInfo = *(SSHashObj**)px;
15,684,015✔
1188
          STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
15,683,470!
1189
          int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
15,683,470✔
1190
          if (tmp != NULL) {
15,681,925✔
1191
            colId = *tmp;
14,138,425✔
1192
          } else {
1193
            colId = -1;
1,543,500✔
1194
          }
1195
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
15,684,021!
1196
        } else {
1197
          colId = pColData->info.colId;
30,555,620✔
1198
        }
1199
        
1200
        SColVal colVal = {0};
46,232,499✔
1201
        int32_t sourceIdx = 0;
46,130,009✔
1202
        while (1) {
1203
          if (sourceIdx >= (*schemas)->numOfCols) {
120,925,292✔
1204
            break;
17,645,451✔
1205
          }
1206
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, *schemas, sourceIdx, &colVal));
103,379,681!
1207
          if (colVal.cid == colId) {
103,393,496✔
1208
            break;
28,598,213✔
1209
          }
1210
          sourceIdx++;
74,795,283✔
1211
        }
1212
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
46,243,664✔
1213
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
26,984,929!
1214
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
42,779!
1215
          } else {
1216
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
26,942,150!
1217
          }
1218
        } else {
1219
          colDataSetNULL(pColData, blockStart + numOfRows);
19,258,735!
1220
        }
1221
      }
1222
      
1223
      numOfRows++;
11,655,870✔
1224
    }
1225
  }
1226

1227
  if (numOfRows > 0) {
8,945,351!
1228
    if (!sStreamReaderInfo->isVtableStream) {
8,945,351✔
1229
      SStorageAPI  api = {0};
3,751,323✔
1230
      initStorageAPI(&api);
3,750,225✔
1231
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
3,750,215!
1232
    }
1233
    
1234
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
8,940,939✔
1235
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
8,943,222!
1236
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
8,943,222!
1237
  }
1238

1239
  ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
8,945,795✔
1240
    ", uid:%" PRId64 ", ver:%d, row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1241
    id, submitTbData.uid, submitTbData.sver, pSlice->currentRowIdx, numOfRows);
1242
  pSlice->currentRowIdx += numOfRows;
8,946,998✔
1243
  pBlock->info.rows += numOfRows;
8,944,799✔
1244
  
1245
  if (gidHash == NULL) goto end;
8,945,349✔
1246

1247
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,939,104✔
1248
  if (data != NULL) {
1,939,104!
1249
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
1250
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
1251
  } else {
1252
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
1,939,104!
1253
  }
1254

1255
end:
10,640,353✔
1256
  if (code != 0) {                                                             \
10,649,091!
1257
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1258
  }
1259
  tEndDecode(pCoder);
10,649,091✔
1260
  return code;
10,645,784✔
1261
}
1262
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
10,632,620✔
1263
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1264
  int32_t  code = 0;
10,632,620✔
1265
  int32_t  lino = 0;
10,632,620✔
1266
  STSchema* schemas = NULL;
10,632,620✔
1267
  SDecoder decoder = {0};
10,640,851✔
1268
  SSHashObj* gidHash = NULL;
10,648,003✔
1269
  void* pTask = sStreamReaderInfo->pTask;
10,648,003✔
1270

1271
  tDecoderInit(&decoder, data, len);
10,649,655✔
1272
  if (tStartDecode(&decoder) < 0) {
10,650,731!
1273
    code = TSDB_CODE_INVALID_MSG;
×
1274
    TSDB_CHECK_CODE(code, lino, end);
×
1275
  }
1276

1277
  uint64_t nSubmitTbData = 0;
10,653,481✔
1278
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
10,643,579!
1279
    code = TSDB_CODE_INVALID_MSG;
×
1280
    TSDB_CHECK_CODE(code, lino, end);
×
1281
  }
1282

1283
  if (rsp->metaBlock != NULL){
10,643,579✔
1284
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,643,923✔
1285
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
3,646,682!
1286
  }
1287

1288
  for (int32_t i = 0; i < nSubmitTbData; i++) {
21,288,378✔
1289
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, &schemas, ranges, gidHash, rsp, ver));
10,645,809!
1290
  }
1291

1292
  tEndDecode(&decoder);
10,642,569✔
1293

1294
  if (rsp->metaBlock != NULL){
10,646,893✔
1295
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
3,647,239!
1296
    int32_t iter = 0;
3,640,077✔
1297
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
3,643,386✔
1298
    while (px != NULL) {
5,583,044✔
1299
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,938,006✔
1300
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,938,006!
1301
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,935,256✔
1302
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,937,457✔
1303
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1304
      px = tSimpleHashIterate(gidHash, px, &iter);
1,937,457✔
1305
    }
1306
  }
1307
  
1308

1309
end:
10,643,175✔
1310
  taosMemoryFree(schemas);
10,651,839!
1311
  tSimpleHashCleanup(gidHash);
10,650,189✔
1312
  tDecoderClear(&decoder);
10,647,990✔
1313
  return code;
10,656,231✔
1314
}
1315

1316
static int32_t scanSubmitTbDataPre(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* ranges, 
11,909,179✔
1317
  uint64_t* gid, int64_t* uid, int32_t* numOfRows, bool isCalc) {
1318
  int32_t code = 0;
11,909,179✔
1319
  int32_t lino = 0;
11,909,179✔
1320
  void* pTask = sStreamReaderInfo->pTask;
11,909,179✔
1321

1322
  if (tStartDecode(pCoder) < 0) {
11,920,738!
1323
    code = TSDB_CODE_INVALID_MSG;
×
1324
    TSDB_CHECK_CODE(code, lino, end);
×
1325
  }
1326

1327
  SSubmitTbData submitTbData = {0};
11,930,215✔
1328
  uint8_t       version = 0;
11,930,215✔
1329
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
11,926,771!
1330
    code = TSDB_CODE_INVALID_MSG;
×
1331
    TSDB_CHECK_CODE(code, lino, end);
×
1332
  }
1333
  version = (submitTbData.flags >> 8) & 0xff;
11,926,771✔
1334
  submitTbData.flags = submitTbData.flags & 0xff;
11,926,771✔
1335

1336
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1337
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
11,926,771✔
1338
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
481,409!
1339
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
480,311!
1340
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
480,311!
1341
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
480,306!
1342
  }
1343

1344
  // submit data
1345
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
11,903,758!
1346
    code = TSDB_CODE_INVALID_MSG;
×
1347
    TSDB_CHECK_CODE(code, lino, end);
×
1348
  }
1349
  if (tDecodeI64(pCoder, uid) < 0) {
11,926,299!
1350
    code = TSDB_CODE_INVALID_MSG;
×
1351
    TSDB_CHECK_CODE(code, lino, end);
×
1352
  }
1353

1354
  STREAM_CHECK_CONDITION_GOTO(!uidInTableList(sStreamReaderInfo, submitTbData.suid, *uid, gid, isCalc), TDB_CODE_SUCCESS);
11,926,299✔
1355

1356
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
8,943,724✔
1357

1358
  if (ranges != NULL){
8,944,263✔
1359
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
7,006,257✔
1360
    if (timerange == NULL) goto end;;
7,004,089!
1361
    int64_t* pRange = (int64_t*)timerange;
7,004,089✔
1362
    window.skey = pRange[0];
7,004,089✔
1363
    window.ekey = pRange[1];
7,006,245✔
1364
  }
1365
  
1366
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
8,944,785!
1367
    code = TSDB_CODE_INVALID_MSG;
×
1368
    TSDB_CHECK_CODE(code, lino, end);
×
1369
  }
1370

1371
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
8,944,785!
1372
    uint64_t nColData = 0;
×
1373
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1374
      code = TSDB_CODE_INVALID_MSG;
×
1375
      TSDB_CHECK_CODE(code, lino, end);
×
1376
    }
1377

1378
    SColData colData = {0};
×
1379
    code = tDecodeColData(version, pCoder, &colData, false);
×
1380
    if (code) {
×
1381
      code = TSDB_CODE_INVALID_MSG;
×
1382
      TSDB_CHECK_CODE(code, lino, end);
×
1383
    }
1384

1385
    if (colData.flag != HAS_VALUE) {
×
1386
      code = TSDB_CODE_INVALID_MSG;
×
1387
      TSDB_CHECK_CODE(code, lino, end);
×
1388
    }
1389
    int32_t rowStart = 0;
×
1390
    int32_t rowEnd = 0;
×
1391
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) {
×
1392
      STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, numOfRows));
×
1393
    } else {
1394
      (*numOfRows) = colData.nVal;
×
1395
    } 
1396
  } else {
1397
    uint64_t nRow = 0;
8,944,785✔
1398
    if (tDecodeU64v(pCoder, &nRow) < 0) {
8,943,249!
1399
      code = TSDB_CODE_INVALID_MSG;
×
1400
      TSDB_CHECK_CODE(code, lino, end);
×
1401
    }
1402

1403
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
8,943,249!
1404
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
16,688,440✔
1405
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,681,748✔
1406
        pCoder->pos += pRow->len;
9,681,613✔
1407
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
9,683,746✔
1408
          continue;
16,683✔
1409
        }
1410
        (*numOfRows)++;
9,666,497✔
1411
      }
1412
    } else {
1413
      (*numOfRows) = nRow;
1,938,555✔
1414
    }
1415
  }
1416
  
1417
end:
11,933,483✔
1418
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
11,927,988✔
1419
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
11,928,658!
1420
  tEndDecode(pCoder);
11,928,104✔
1421
  return code;
11,924,708✔
1422
}
1423

1424
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
11,911,428✔
1425
  int32_t  code = 0;
11,911,428✔
1426
  int32_t  lino = 0;
11,911,428✔
1427
  SDecoder decoder = {0};
11,911,428✔
1428
  void* pTask = sStreamReaderInfo->pTask;
11,921,367✔
1429

1430
  tDecoderInit(&decoder, data, len);
11,916,929✔
1431
  if (tStartDecode(&decoder) < 0) {
11,920,279!
1432
    code = TSDB_CODE_INVALID_MSG;
×
1433
    TSDB_CHECK_CODE(code, lino, end);
×
1434
  }
1435

1436
  uint64_t nSubmitTbData = 0;
11,920,205✔
1437
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
11,926,906!
1438
    code = TSDB_CODE_INVALID_MSG;
×
1439
    TSDB_CHECK_CODE(code, lino, end);
×
1440
  }
1441

1442
  for (int32_t i = 0; i < nSubmitTbData; i++) {
23,852,252✔
1443
    uint64_t gid = -1;
11,920,197✔
1444
    int64_t  uid = 0;
11,922,401✔
1445
    int32_t numOfRows = 0;
11,928,460✔
1446
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp->isCalc));
11,929,014!
1447
    if (numOfRows <= 0) {
11,924,159✔
1448
      continue;
2,988,156✔
1449
    }
1450
    rsp->totalRows += numOfRows;
8,936,003✔
1451

1452
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &uid, LONG_BYTES);
8,942,593✔
1453
    if (pSlice != NULL) {
8,944,797✔
1454
      pSlice->numRows += numOfRows;
8,662,794✔
1455
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d", __func__, uid, gid, pSlice->numRows);
8,662,799✔
1456
      pSlice->gId = gid;
8,663,365✔
1457
    } else {
1458
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
282,003✔
1459
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d", __func__, uid, gid, tmp.numRows);
282,003✔
1460
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(sStreamReaderInfo->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
282,003!
1461
    } 
1462
  }
1463

1464
  tEndDecode(&decoder);
11,932,055✔
1465

1466
end:
11,928,109✔
1467
  tDecoderClear(&decoder);
11,929,746✔
1468
  return code;
11,927,532✔
1469
}
1470

1471
static void resetIndexHash(SSHashObj* indexHash){
7,569,450✔
1472
  void*   pe = NULL;
7,569,450✔
1473
  int32_t iter = 0;
7,569,450✔
1474
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
17,525,856✔
1475
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
9,964,122✔
1476
    pInfo->startRowIdx = 0;
9,964,122✔
1477
    pInfo->currentRowIdx = 0;
9,963,573✔
1478
    pInfo->numRows = 0;
9,947,177✔
1479
    pInfo->gId = -1;
9,949,915✔
1480
  }
1481
}
7,571,082✔
1482

1483
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
689,750✔
1484
  void*   pe = NULL;
689,750✔
1485
  int32_t iter = 0;
689,750✔
1486
  int32_t index = 0;
689,750✔
1487
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
2,484,683✔
1488
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
1,794,933✔
1489
    pInfo->startRowIdx = index;
1,794,933✔
1490
    pInfo->currentRowIdx = index;
1,794,933✔
1491
    index += pInfo->numRows;
1,794,933✔
1492
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
2,573,588!
1493
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1494
  }
1495
}
689,750✔
1496

1497
static void printIndexHash(SSHashObj* indexHash, void* pTask){
688,642✔
1498
  void*   pe = NULL;
688,642✔
1499
  int32_t iter = 0;
688,642✔
1500
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
2,481,913✔
1501
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
1,793,271✔
1502
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
2,572,468!
1503
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1504
  }
1505
}
688,642✔
1506

1507
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
17,787✔
1508
  void*   pe = NULL;
17,787✔
1509
  int32_t iter = 0;
17,787✔
1510
  int32_t index = 0;
17,787✔
1511
  int32_t pIndex = 0;
17,787✔
1512
  int8_t* pIndicator = (int8_t*)pRet->pData;
17,787✔
1513
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
50,882✔
1514
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
33,095✔
1515
    pInfo->startRowIdx = index;
33,095✔
1516
    int32_t size = pInfo->numRows;
33,095✔
1517
    for (int32_t i = 0; i < pInfo->numRows; i++) {
266,882✔
1518
      if (pIndicator && !pIndicator[pIndex++]) {
233,787!
1519
        size--;
83,229✔
1520
      }
1521
    }
1522
    pInfo->numRows = size;
33,095✔
1523
    index += pInfo->numRows;
33,095✔
1524
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
33,095!
1525
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1526
  }
1527
}
17,787✔
1528

1529
static int32_t prepareIndexMetaData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* resultRsp){
3,488,986✔
1530
  int32_t      code = 0;
3,488,986✔
1531
  int32_t      lino = 0;
3,488,986✔
1532
  void* pTask = sStreamReaderInfo->pTask;
3,488,986✔
1533

1534
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,490,084✔
1535
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,488,981✔
1536
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,929,480!
1537
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
1538
    }
1539
    ST_TASK_DLOG("%s scan wal error:%s",  __func__, tstrerror(code));
2,934,422✔
1540
    code = TSDB_CODE_SUCCESS;
2,932,221✔
1541
    goto end;
2,932,221✔
1542
  }
1543
  STREAM_CHECK_RET_GOTO(code);
559,501!
1544

1545
  while (1) {
5,079,979✔
1546
    code = walNextValidMsg(pWalReader, true);
5,639,480✔
1547
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,613,588✔
1548
      ST_TASK_DLOG("%s scan wal error:%s", __func__, tstrerror(code));
554,545✔
1549
      code = TSDB_CODE_SUCCESS;
558,952✔
1550
      goto end;
558,952✔
1551
    }
1552
    STREAM_CHECK_RET_GOTO(code);
5,059,043!
1553
    resultRsp->ver = pWalReader->curVersion;
5,059,043✔
1554
    SWalCont* wCont = &pWalReader->pHead->head;
5,062,169✔
1555
    resultRsp->verTime = wCont->ingestTs;
5,069,499✔
1556
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
5,059,364✔
1557
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
5,071,160✔
1558
    int64_t ver = wCont->version;
5,072,250✔
1559
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d", __func__,
5,071,503✔
1560
      ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1561
    if (wCont->msgType == TDMT_VND_SUBMIT) {
5,072,618✔
1562
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,910,718✔
1563
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,920,640✔
1564
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp));
4,923,385!
1565
    } else if (wCont->msgType == TDMT_VND_ALTER_TABLE && resultRsp->totalRows > 0) {
151,613!
1566
      resultRsp->ver--;
×
1567
      break;
×
1568
    } else {
1569
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
151,613!
1570
    }
1571

1572
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
5,077,775✔
1573
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
5,078,859!
1574
      break;
×
1575
    }
1576
  }
1577
  
1578
end:
3,489,526✔
1579
  STREAM_PRINT_LOG_END(code, lino);
3,489,526!
1580
  return code;
3,490,075✔
1581
}
1582

1583
static int32_t prepareIndexData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, 
4,077,156✔
1584
  SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp){
1585
  int32_t      code = 0;
4,077,156✔
1586
  int32_t      lino = 0;
4,077,156✔
1587

1588
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
11,083,497✔
1589
    int64_t *ver = taosArrayGet(versions, i);
7,005,886✔
1590
    if (ver == NULL) continue;
7,006,796!
1591

1592
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
7,006,796!
1593
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
7,004,882!
1594
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1595
      continue;
×
1596
    }
1597
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
7,005,337!
1598

1599
    SWalCont* wCont = &pWalReader->pHead->head;
7,006,251✔
1600
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
7,005,230✔
1601
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
7,005,796✔
1602

1603
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp));
7,005,230!
1604
  }
1605
  
1606
end:
4,076,066✔
1607
  return code;
4,076,066✔
1608
}
1609

1610
static int32_t filterData(SSTriggerWalNewRsp* resultRsp, SStreamTriggerReaderInfo* sStreamReaderInfo) {
689,750✔
1611
  int32_t      code = 0;
689,750✔
1612
  int32_t       lino = 0;
689,750✔
1613
  SColumnInfoData* pRet = NULL;
689,750✔
1614
  int64_t totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
689,750✔
1615
  STREAM_CHECK_RET_GOTO(qStreamFilter(((SSDataBlock*)resultRsp->dataBlock), sStreamReaderInfo->pFilterInfo, &pRet));
689,750!
1616
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
689,750✔
1617
    filterIndexHash(sStreamReaderInfo->indexHash, pRet);
17,787✔
1618
  }
1619

1620
end:
689,750✔
1621
  colDataDestroy(pRet);
689,750✔
1622
  taosMemoryFree(pRet);
689,750!
1623
  return code;
689,199✔
1624
}
1625

1626
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,493,930✔
1627
                                    SSTriggerWalNewRsp* resultRsp) {
1628
  int32_t      code = 0;
3,493,930✔
1629
  int32_t      lino = 0;
3,493,930✔
1630
  void* pTask = sStreamReaderInfo->pTask;
3,493,930✔
1631
                                        
1632
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,495,575✔
1633
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,491,717!
1634
  resetIndexHash(sStreamReaderInfo->indexHash);
3,491,717✔
1635
  blockDataEmpty(resultRsp->dataBlock);
3,493,930✔
1636
  blockDataEmpty(resultRsp->metaBlock);
3,492,266✔
1637
  int64_t lastVer = resultRsp->ver;                                      
3,484,584✔
1638
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,484,035!
1639
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,490,629✔
1640

1641
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
159,785✔
1642
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
159,785!
1643
  while(lastVer < resultRsp->ver) {
3,907,564✔
1644
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
3,753,828!
1645
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
3,741,211✔
1646
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
107,692!
1647
      continue;
107,692✔
1648
    }
1649
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
3,628,556!
1650
    SWalCont* wCont = &pWalReader->pHead->head;
3,640,647✔
1651
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
3,637,882✔
1652
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
3,641,750✔
1653

1654
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
3,640,647!
1655
  }
1656

1657
  int32_t metaRows = resultRsp->totalRows - ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
159,785✔
1658
  STREAM_CHECK_RET_GOTO(filterData(resultRsp, sStreamReaderInfo));
159,785!
1659
  resultRsp->totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows + metaRows;
159,785✔
1660

1661
end:
3,490,080✔
1662
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
3,490,080✔
1663
          resultRsp->totalRows, resultRsp->ver, walGetAppliedVer(pWalReader->pWal));
1664
  walCloseReader(pWalReader);
3,490,080✔
1665
  return code;
3,490,624✔
1666
}
1667

1668
static int32_t processWalVerDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
4,078,156✔
1669
                                    SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
1670
  int32_t      code = 0;
4,078,156✔
1671
  int32_t      lino = 0;
4,078,156✔
1672

1673
  void* pTask = sStreamReaderInfo->pTask;
4,078,156✔
1674
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
4,077,611✔
1675
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
4,077,066!
1676
  
1677
  if (taosArrayGetSize(versions) > 0) {
4,077,066✔
1678
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
529,965✔
1679
  }
1680
  
1681
  resetIndexHash(sStreamReaderInfo->indexHash);
4,077,066✔
1682
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
4,077,701!
1683
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
4,075,521✔
1684

1685
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
529,965✔
1686

1687
  blockDataEmpty(rsp->dataBlock);
529,965✔
1688
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
529,965!
1689

1690
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
7,535,118✔
1691
    int64_t *ver = taosArrayGet(versions, i);
7,005,697✔
1692
    if (ver == NULL) continue;
7,005,242!
1693

1694
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
7,005,242!
1695
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
7,006,796!
1696
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1697
      continue;
×
1698
    }
1699
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
7,005,157!
1700
    SWalCont* wCont = &pWalReader->pHead->head;
7,002,969✔
1701
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
7,005,698✔
1702
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
7,005,153✔
1703

1704
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
7,004,604!
1705
  }
1706
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
1707
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
529,961!
1708
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
529,414✔
1709

1710
end:
4,076,611✔
1711
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
4,076,611✔
1712
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
1713
  walCloseReader(pWalReader);
4,077,066✔
1714
  return code;
4,076,521✔
1715
}
1716

1717
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas) {
276,209✔
1718
  int32_t code = 0;
276,209✔
1719
  int32_t lino = 0;
276,209✔
1720
  SMetaReader metaReader = {0};
276,209✔
1721
  SStorageAPI api = {0};
276,209✔
1722
  initStorageAPI(&api);
276,209✔
1723
  *schemas = taosArrayInit(8, sizeof(SSchema));
276,209✔
1724
  STREAM_CHECK_NULL_GOTO(*schemas, terrno);
276,209!
1725
  
1726
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
276,209✔
1727
  STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, uid));
276,209✔
1728

1729
  SSchemaWrapper* sSchemaWrapper = NULL;
275,299✔
1730
  if (metaReader.me.type == TD_CHILD_TABLE) {
275,299!
1731
    int64_t suid = metaReader.me.ctbEntry.suid;
275,299✔
1732
    tDecoderClear(&metaReader.coder);
275,299✔
1733
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
275,299!
1734
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
275,299✔
1735
  } else if (metaReader.me.type == TD_NORMAL_TABLE) {
×
1736
    sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
×
1737
  } else {
1738
    qError("invalid table type:%d", metaReader.me.type);
×
1739
  }
1740

1741
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
1,458,079✔
1742
    SSchema* s = sSchemaWrapper->pSchema + j;
1,182,780✔
1743
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
2,365,560!
1744
  }
1745

1746
end:
276,209✔
1747
  api.metaReaderFn.clearReader(&metaReader);
276,209✔
1748
  STREAM_PRINT_LOG_END(code, lino);
276,209!
1749
  if (code != 0)  {
276,209✔
1750
    taosArrayDestroy(*schemas);
910✔
1751
    *schemas = NULL;
910✔
1752
  }
1753
  return code;
276,209✔
1754
}
1755

1756
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
275,299✔
1757
  int32_t code = 0;
275,299✔
1758
  int32_t lino = 0;
275,299✔
1759
  size_t  schemaLen = taosArrayGetSize(schemas);
275,299✔
1760
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
275,299!
1761
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
1,026,579✔
1762
    col_id_t* id = taosArrayGet(cols, i);
751,280✔
1763
    STREAM_CHECK_NULL_GOTO(id, terrno);
751,280!
1764
    for (size_t i = 0; i < schemaLen; i++) {
1,866,535!
1765
      SSchema* s = taosArrayGet(schemas, i);
1,866,535✔
1766
      STREAM_CHECK_NULL_GOTO(s, terrno);
1,866,535!
1767
      if (*id == s->colId) {
1,866,535✔
1768
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
751,280!
1769
        break;
751,280✔
1770
      }
1771
    }
1772
  }
1773
  taosArrayPopFrontBatch(schemas, schemaLen);
275,299✔
1774

1775
end:
275,299✔
1776
  return code;
275,299✔
1777
}
1778

1779
static int32_t processWalVerDataVTable(SVnode* pVnode, SArray *cids, int64_t ver,
×
1780
  int64_t uid, STimeWindow* window, SSDataBlock** pBlock) {
1781
  int32_t      code = 0;
×
1782
  int32_t      lino = 0;
×
1783
  SArray*      schemas = NULL;
×
1784

1785
  SSDataBlock* pBlock2 = NULL;
×
1786

1787
  STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, uid, &schemas));
×
1788
  STREAM_CHECK_RET_GOTO(shrinkScheams(cids, schemas));
×
1789
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlock2));
×
1790

1791
  pBlock2->info.id.uid = uid;
×
1792

1793
  // STREAM_CHECK_RET_GOTO(scanWalOneVer(pVnode, pBlock2, ver, uid, window));
1794
  //printDataBlock(pBlock2, __func__, "");
1795

1796
  *pBlock = pBlock2;
×
1797
  pBlock2 = NULL;
×
1798

1799
end:
×
1800
  STREAM_PRINT_LOG_END(code, lino);
×
1801
  blockDataDestroy(pBlock2);
×
1802
  taosArrayDestroy(schemas);
×
1803
  return code;
×
1804
}
1805

1806
static int32_t createTSAndCondition(int64_t start, int64_t end, SLogicConditionNode** pCond,
×
1807
                                    STargetNode* pTargetNodeTs) {
1808
  int32_t code = 0;
×
1809
  int32_t lino = 0;
×
1810

1811
  SColumnNode*         pCol = NULL;
×
1812
  SColumnNode*         pCol1 = NULL;
×
1813
  SValueNode*          pVal = NULL;
×
1814
  SValueNode*          pVal1 = NULL;
×
1815
  SOperatorNode*       op = NULL;
×
1816
  SOperatorNode*       op1 = NULL;
×
1817
  SLogicConditionNode* cond = NULL;
×
1818

1819
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol));
×
1820
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
×
1821
  pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
×
1822
  pCol->node.resType.bytes = LONG_BYTES;
×
1823
  pCol->slotId = pTargetNodeTs->slotId;
×
1824
  pCol->dataBlockId = pTargetNodeTs->dataBlockId;
×
1825

1826
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pCol, (SNode**)&pCol1));
×
1827

1828
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal));
×
1829
  pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
×
1830
  pVal->node.resType.bytes = LONG_BYTES;
×
1831
  pVal->datum.i = start;
×
1832
  pVal->typeData = start;
×
1833

1834
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
×
1835
  pVal1->datum.i = end;
×
1836
  pVal1->typeData = end;
×
1837

1838
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op));
×
1839
  op->opType = OP_TYPE_GREATER_EQUAL;
×
1840
  op->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
1841
  op->node.resType.bytes = CHAR_BYTES;
×
1842
  op->pLeft = (SNode*)pCol;
×
1843
  op->pRight = (SNode*)pVal;
×
1844
  pCol = NULL;
×
1845
  pVal = NULL;
×
1846

1847
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op1));
×
1848
  op1->opType = OP_TYPE_LOWER_EQUAL;
×
1849
  op1->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
1850
  op1->node.resType.bytes = CHAR_BYTES;
×
1851
  op1->pLeft = (SNode*)pCol1;
×
1852
  op1->pRight = (SNode*)pVal1;
×
1853
  pCol1 = NULL;
×
1854
  pVal1 = NULL;
×
1855

1856
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
×
1857
  cond->condType = LOGIC_COND_TYPE_AND;
×
1858
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
1859
  cond->node.resType.bytes = CHAR_BYTES;
×
1860
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
×
1861
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op));
×
1862
  op = NULL;
×
1863
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op1));
×
1864
  op1 = NULL;
×
1865

1866
  *pCond = cond;
×
1867

1868
end:
×
1869
  if (code != 0) {
×
1870
    nodesDestroyNode((SNode*)pCol);
×
1871
    nodesDestroyNode((SNode*)pCol1);
×
1872
    nodesDestroyNode((SNode*)pVal);
×
1873
    nodesDestroyNode((SNode*)pVal1);
×
1874
    nodesDestroyNode((SNode*)op);
×
1875
    nodesDestroyNode((SNode*)op1);
×
1876
    nodesDestroyNode((SNode*)cond);
×
1877
  }
1878
  STREAM_PRINT_LOG_END(code, lino);
×
1879

1880
  return code;
×
1881
}
1882

1883
/*
1884
static int32_t createExternalConditions(SStreamRuntimeFuncInfo* data, SLogicConditionNode** pCond, STargetNode* pTargetNodeTs, STimeRangeNode* node) {
1885
  int32_t              code = 0;
1886
  int32_t              lino = 0;
1887
  SLogicConditionNode* pAndCondition = NULL;
1888
  SLogicConditionNode* cond = NULL;
1889

1890
  if (pTargetNodeTs == NULL) {
1891
    vError("stream reader %s no ts column", __func__);
1892
    return TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN;
1893
  }
1894
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
1895
  cond->condType = LOGIC_COND_TYPE_OR;
1896
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
1897
  cond->node.resType.bytes = CHAR_BYTES;
1898
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
1899

1900
  for (int i = 0; i < taosArrayGetSize(data->pStreamPesudoFuncVals); ++i) {
1901
    data->curIdx = i;
1902

1903
    SReadHandle handle = {0};
1904
    calcTimeRange(node, data, &handle.winRange, &handle.winRangeValid);
1905
    if (!handle.winRangeValid) {
1906
      stError("stream reader %s invalid time range, skey:%" PRId64 ", ekey:%" PRId64, __func__, handle.winRange.skey,
1907
              handle.winRange.ekey);
1908
      continue;
1909
    }
1910
    STREAM_CHECK_RET_GOTO(createTSAndCondition(handle.winRange.skey, handle.winRange.ekey, &pAndCondition, pTargetNodeTs));
1911
    stDebug("%s create condition skey:%" PRId64 ", eksy:%" PRId64, __func__, handle.winRange.skey, handle.winRange.ekey);
1912
    STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)pAndCondition));
1913
    pAndCondition = NULL;
1914
  }
1915

1916
  *pCond = cond;
1917

1918
end:
1919
  if (code != 0) {
1920
    nodesDestroyNode((SNode*)pAndCondition);
1921
    nodesDestroyNode((SNode*)cond);
1922
  }
1923
  STREAM_PRINT_LOG_END(code, lino);
1924

1925
  return code;
1926
}
1927
*/
1928

1929
static int32_t processCalaTimeRange(SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo, SResFetchReq* req,
403,216✔
1930
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
1931
  int32_t code = 0;
403,216✔
1932
  int32_t lino = 0;
403,216✔
1933
  void* pTask = sStreamReaderCalcInfo->pTask;
403,216✔
1934
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
403,216!
1935
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
403,216!
1936
  
1937
  if (req->pStRtFuncInfo->withExternalWindow) {
403,216✔
1938
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
176,456✔
1939
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
176,456✔
1940
    
1941
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
176,456✔
1942
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
176,456✔
1943
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
176,456!
1944
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
176,456!
1945

1946
    if (!node->needCalc) {
176,456✔
1947
      pWin->skey = pFirst->wstart;
118,326✔
1948
      pWin->ekey = pLast->wend;
118,326✔
1949
      *pValid = true;
118,326✔
1950
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
118,326✔
1951
        pWin->ekey--;
64,405✔
1952
      }
1953
    } else {
1954
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
58,130✔
1955
      memcpy(pTmp, pFirst, sizeof(*pTmp));
58,130!
1956

1957
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
58,130!
1958
      if (*pValid) {
58,130!
1959
        int64_t skey = pWin->skey;
58,130✔
1960

1961
        memcpy(pTmp, pLast, sizeof(*pTmp));
58,130!
1962
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
58,130!
1963

1964
        if (*pValid) {
58,130!
1965
          pWin->skey = skey;
58,130✔
1966
        }
1967
      }
1968
      pWin->ekey--;
58,130✔
1969
    }
1970
  } else {
1971
    if (!node->needCalc) {
226,760!
1972
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
8,360✔
1973
      pWin->skey = pCurr->wstart;
8,360✔
1974
      pWin->ekey = pCurr->wend;
8,360✔
1975
      *pValid = true;
8,360✔
1976
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
8,360✔
1977
        pWin->ekey--;
5,852✔
1978
      }
1979
    } else {
1980
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
218,400!
1981
      pWin->ekey--;
218,400✔
1982
    }
1983
  }
1984

1985
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
403,216!
1986
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
1987

1988
end:
19,225✔
1989

1990
  if (code) {
403,216!
1991
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1992
  }
1993
  
1994
  return code;
403,216✔
1995
}
1996

1997
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
557,754✔
1998
                                  SStreamReaderTaskInner* pTaskInner) {
1999
  int32_t code = 0;
557,754✔
2000
  int32_t lino = 0;
557,754✔
2001

2002
  void* pTask = sStreamReaderInfo->pTask;
557,754✔
2003
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTaskInner->pTableList), sizeof(STsInfo));
557,754✔
2004
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
556,656!
2005
  while (true) {
1,444,383✔
2006
    bool hasNext = false;
2,001,039✔
2007
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
2,002,137!
2008
    if (hasNext) {
1,999,204!
2009
      pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
570,679✔
2010
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
571,777✔
2011
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
572,535!
2012
      if (pTaskInner->options.order == TSDB_ORDER_ASC) {
572,535✔
2013
        tsInfo->ts = pTaskInner->pResBlock->info.window.skey;
362,092✔
2014
      } else {
2015
        tsInfo->ts = pTaskInner->pResBlock->info.window.ekey;
209,685✔
2016
      }
2017
      tsInfo->gId = (sStreamReaderInfo->groupByTbname || sStreamReaderInfo->tableType != TSDB_SUPER_TABLE) ? 
1,211,757!
2018
                    pTaskInner->pResBlock->info.id.uid : qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
638,882✔
2019
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
571,986✔
2020
              tsInfo->gId, tsRsp->ver);
2021
    }
2022
    
2023
    pTaskInner->currentGroupIndex++;
2,000,720✔
2024
    if (pTaskInner->currentGroupIndex >= qStreamGetTableListGroupNum(pTaskInner->pTableList) || pTaskInner->options.gid != 0) {
2,001,588✔
2025
      break;
2026
    }
2027
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTaskInner));
1,443,841!
2028
  }
2029

2030
end:
555,603✔
2031
  STREAM_PRINT_LOG_END_WITHID(code, lino);
555,603!
2032
  return code;
557,205✔
2033
}
2034

2035
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
108,273✔
2036
  int32_t code = 0;
108,273✔
2037
  int32_t lino = 0;
108,273✔
2038
  void*   buf = NULL;
108,273✔
2039
  size_t  size = 0;
108,273✔
2040
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
108,273!
2041
  void* pTask = sStreamReaderInfo->pTask;
108,273✔
2042

2043
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d", TD_VID(pVnode), __func__,
108,273✔
2044
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc));
2045

2046
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
108,273✔
2047
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
108,273✔
2048
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
108,273!
2049
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
108,273!
2050

2051
  sStreamReaderInfo->isVtableStream = true;
108,273✔
2052
  sStreamReaderInfo->groupByTbname = true;
108,273✔
2053
end:
108,273✔
2054
  STREAM_PRINT_LOG_END_WITHID(code, lino);
108,273!
2055
  SRpcMsg rsp = {
108,273✔
2056
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2057
  tmsgSendRsp(&rsp);
108,273✔
2058
  return code;
108,273✔
2059
}
2060

2061
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
297,001✔
2062
  int32_t                 code = 0;
297,001✔
2063
  int32_t                 lino = 0;
297,001✔
2064
  SStreamReaderTaskInner* pTaskInner = NULL;
297,001✔
2065
  SStreamTsResponse       lastTsRsp = {0};
298,600✔
2066
  void*                   buf = NULL;
298,600✔
2067
  size_t                  size = 0;
298,600✔
2068

2069
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
297,000!
2070
  void* pTask = sStreamReaderInfo->pTask;
297,000✔
2071

2072
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
298,600✔
2073

2074
  BUILD_OPTION(options, sStreamReaderInfo, -1, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, sStreamReaderInfo->tsSchemas, true,
298,600✔
2075
               STREAM_SCAN_GROUP_ONE_BY_ONE, 0, true, sStreamReaderInfo->uidHashTrigger);
2076
  SStorageAPI api = {0};
298,600✔
2077
  initStorageAPI(&api);
298,600✔
2078
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
298,600!
2079

2080
  lastTsRsp.ver = pVnode->state.applied + 1;
298,051✔
2081

2082
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner));
298,051!
2083
  ST_TASK_DLOG("vgId:%d %s get result, ver:%" PRId64, TD_VID(pVnode), __func__, lastTsRsp.ver);
298,600✔
2084
  STREAM_CHECK_RET_GOTO(buildTsRsp(&lastTsRsp, &buf, &size))
298,600!
2085
  if (stDebugFlag & DEBUG_DEBUG) {
298,600✔
2086
    int32_t nInfo = taosArrayGetSize(lastTsRsp.tsInfo);
233,738✔
2087
    for (int32_t i = 0; i < nInfo; i++) {
421,652✔
2088
      STsInfo* tsInfo = TARRAY_GET_ELEM(lastTsRsp.tsInfo, i);
187,914✔
2089
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
187,914!
2090
    }
2091
  }
2092

2093
end:
298,600✔
2094
  STREAM_PRINT_LOG_END_WITHID(code, lino);
298,600!
2095
  SRpcMsg rsp = {
298,600✔
2096
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2097
  tmsgSendRsp(&rsp);
297,500✔
2098
  taosArrayDestroy(lastTsRsp.tsInfo);
298,600✔
2099
  releaseStreamTask(&pTaskInner);
298,600✔
2100
  return code;
298,600✔
2101
}
2102

2103
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
261,148✔
2104
  int32_t                 code = 0;
261,148✔
2105
  int32_t                 lino = 0;
261,148✔
2106
  SStreamReaderTaskInner* pTaskInner = NULL;
261,148✔
2107
  SStreamTsResponse       firstTsRsp = {0};
261,148✔
2108
  void*                   buf = NULL;
261,148✔
2109
  size_t                  size = 0;
261,148✔
2110

2111
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
261,148!
2112
  void* pTask = sStreamReaderInfo->pTask;
261,148✔
2113
  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);
261,148✔
2114
  BUILD_OPTION(options, sStreamReaderInfo, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, sStreamReaderInfo->tsSchemas, true,
261,148✔
2115
               STREAM_SCAN_GROUP_ONE_BY_ONE, req->firstTsReq.gid, true, sStreamReaderInfo->uidHashTrigger);
2116
  SStorageAPI api = {0};
261,697✔
2117
  initStorageAPI(&api);
261,697✔
2118
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
261,148✔
2119
  
2120
  firstTsRsp.ver = pVnode->state.applied;
259,154✔
2121
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &firstTsRsp, sStreamReaderInfo, pTaskInner));
259,154!
2122

2123
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(firstTsRsp.tsInfo), firstTsRsp.ver);
259,154✔
2124
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
259,154!
2125
  if (stDebugFlag & DEBUG_DEBUG) {
258,605✔
2126
    int32_t nInfo = taosArrayGetSize(firstTsRsp.tsInfo);
189,937✔
2127
    for (int32_t i = 0; i < nInfo; i++) {
464,099✔
2128
      STsInfo* tsInfo = TARRAY_GET_ELEM(firstTsRsp.tsInfo, i);
274,162✔
2129
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
274,162!
2130
    }
2131
  }
2132

2133
end:
260,599✔
2134
  STREAM_PRINT_LOG_END_WITHID(code, lino);
261,697!
2135
  SRpcMsg rsp = {
261,697✔
2136
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2137
  tmsgSendRsp(&rsp);
261,148✔
2138
  taosArrayDestroy(firstTsRsp.tsInfo);
261,697✔
2139
  releaseStreamTask(&pTaskInner);
261,148✔
2140
  return code;
260,050✔
2141
}
2142

2143
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
559,407✔
2144
  int32_t code = 0;
559,407✔
2145
  int32_t lino = 0;
559,407✔
2146
  void*   buf = NULL;
559,407✔
2147
  size_t  size = 0;
559,407✔
2148

2149
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
559,407!
2150
  void* pTask = sStreamReaderInfo->pTask;
559,407✔
2151
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
559,407✔
2152

2153
  SStreamReaderTaskInner* pTaskInner = NULL;
559,407✔
2154
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
559,407✔
2155

2156
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
559,407!
2157
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, sStreamReaderInfo->tsSchemas, true, 
559,407✔
2158
      (req->tsdbMetaReq.gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), req->tsdbMetaReq.gid, true, sStreamReaderInfo->uidHashTrigger);
2159
    SStorageAPI api = {0};
559,407✔
2160
    initStorageAPI(&api);
559,407✔
2161
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
559,407✔
2162
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
557,413!
2163
    
2164
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
557,413!
2165
  } else {
2166
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2167
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2168
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2169
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2170
  }
2171

2172
  blockDataCleanup(pTaskInner->pResBlockDst);
557,413✔
2173
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
557,413!
2174
  bool hasNext = true;
557,413✔
2175
  while (true) {
252,776✔
2176
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
810,189!
2177
    if (!hasNext) {
810,189!
2178
      break;
557,413✔
2179
    }
2180
    pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
252,776✔
2181
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
252,776✔
2182

2183
    int32_t index = 0;
252,776✔
2184
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
252,776!
2185
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
252,776!
2186
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
252,776!
2187
    if (!sStreamReaderInfo->isVtableStream) {
252,776!
2188
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
32,769!
2189
    }
2190
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
252,776!
2191

2192
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
252,776✔
2193
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2194
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2195
            pTaskInner->pResBlockDst->info.rows++;
252,776✔
2196
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
252,776!
2197
      break;
×
2198
    }
2199
  }
2200

2201
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
557,413✔
2202
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
557,413!
2203
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
557,413✔
2204
  if (!hasNext) {
557,413!
2205
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
557,413!
2206
  }
2207

2208
end:
559,407✔
2209
  STREAM_PRINT_LOG_END_WITHID(code, lino);
559,407!
2210
  SRpcMsg rsp = {
559,407✔
2211
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2212
  tmsgSendRsp(&rsp);
559,407✔
2213
  return code;
559,407✔
2214
}
2215

2216
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
15,826✔
2217
  int32_t                 code = 0;
15,826✔
2218
  int32_t                 lino = 0;
15,826✔
2219
  SStreamReaderTaskInner* pTaskInner = NULL;
15,826✔
2220
  void*                   buf = NULL;
15,826✔
2221
  size_t                  size = 0;
15,826✔
2222
  SSDataBlock*            pBlockRes = NULL;
15,826✔
2223

2224
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
15,826!
2225
  void* pTask = sStreamReaderInfo->pTask;
15,826✔
2226
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
15,826!
2227
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2228
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2229

2230
  BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
15,826✔
2231
               sStreamReaderInfo->triggerCols, false, STREAM_SCAN_ALL, 0, true, NULL);
2232
  options.uid = req->tsdbTsDataReq.uid;
15,826✔
2233
  SStorageAPI api = {0};
15,826✔
2234
  initStorageAPI(&api);
15,826✔
2235
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
15,826!
2236
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
15,826!
2237
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
15,826!
2238

2239
  while (1) {
15,826✔
2240
    bool hasNext = false;
31,652✔
2241
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
31,652!
2242
    if (!hasNext) {
31,652!
2243
      break;
15,826✔
2244
    }
2245
    if (!sStreamReaderInfo->isVtableStream){
15,826!
2246
      pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
15,826✔
2247
    }
2248

2249
    SSDataBlock* pBlock = NULL;
15,826✔
2250
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
15,826!
2251
    if (pBlock != NULL && pBlock->info.rows > 0) {
15,826!
2252
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, false, &api, pBlock->info.id.uid, pBlock,
15,826!
2253
          0, pBlock->info.rows, 1));
2254
    }
2255
    
2256
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
15,826!
2257
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
15,826!
2258
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
15,826!
2259
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2260
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2261
  }
2262

2263
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
15,826✔
2264

2265
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
15,826!
2266
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
15,826!
2267

2268
end:
15,826✔
2269
  STREAM_PRINT_LOG_END_WITHID(code, lino);
15,826!
2270
  SRpcMsg rsp = {
15,826✔
2271
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2272
  tmsgSendRsp(&rsp);
15,826✔
2273
  blockDataDestroy(pBlockRes);
15,826✔
2274

2275
  releaseStreamTask(&pTaskInner);
15,826✔
2276
  return code;
15,826✔
2277
}
2278

2279
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
910✔
2280
  int32_t                 code = 0;
910✔
2281
  int32_t                 lino = 0;
910✔
2282
  SStreamReaderTaskInner* pTaskInner = NULL;
910✔
2283
  void*                   buf = NULL;
910✔
2284
  size_t                  size = 0;
910✔
2285
  SSDataBlock*            pBlockRes = NULL;
910✔
2286

2287
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
910!
2288
  void* pTask = sStreamReaderInfo->pTask;
910✔
2289
  ST_TASK_ELOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
910!
2290
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2291
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2292

2293
  BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
910✔
2294
               sStreamReaderInfo->tsSchemas, true, STREAM_SCAN_ALL, 0, true, NULL);
2295
  options.suid = req->tsdbTsDataReq.suid;
910✔
2296
  options.uid = req->tsdbTsDataReq.uid;
910✔
2297
  SStorageAPI api = {0};
910✔
2298
  initStorageAPI(&api);
910✔
2299
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &api));
910!
2300
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
910!
2301

2302
  while (1) {
910✔
2303
    bool hasNext = false;
1,820✔
2304
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,820!
2305
    if (!hasNext) {
1,820!
2306
      break;
910✔
2307
    }
2308

2309
    SSDataBlock* pBlock = NULL;
910✔
2310
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
910!
2311
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
910!
2312
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
910!
2313
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
2314
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
2315
  }
2316

2317
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
910!
2318
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
910!
2319

2320
end:
910✔
2321
  STREAM_PRINT_LOG_END_WITHID(code, lino);
910!
2322
  SRpcMsg rsp = {
910✔
2323
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2324
  tmsgSendRsp(&rsp);
910✔
2325
  blockDataDestroy(pBlockRes);
910✔
2326

2327
  releaseStreamTask(&pTaskInner);
910✔
2328
  return code;
910✔
2329
}
2330

2331
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
160,919✔
2332
  int32_t code = 0;
160,919✔
2333
  int32_t lino = 0;
160,919✔
2334
  void*   buf = NULL;
160,919✔
2335
  size_t  size = 0;
160,919✔
2336

2337
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
160,919!
2338
  SStreamReaderTaskInner* pTaskInner = NULL;
160,919✔
2339
  void* pTask = sStreamReaderInfo->pTask;
160,919✔
2340
  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);
160,919✔
2341
  
2342
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
160,919✔
2343

2344
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
160,919✔
2345
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
77,432✔
2346
                 sStreamReaderInfo->triggerCols, false, (req->tsdbTriggerDataReq.gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), 
2347
                 req->tsdbTriggerDataReq.gid, true, NULL);
2348
    SStorageAPI api = {0};
77,432✔
2349
    initStorageAPI(&api);
77,432✔
2350
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
77,432!
2351

2352
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
77,432!
2353
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
77,432!
2354
  } else {
2355
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
83,487✔
2356
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
83,487!
2357
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
83,487✔
2358
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
83,487!
2359
  }
2360

2361
  blockDataCleanup(pTaskInner->pResBlockDst);
160,919✔
2362
  bool hasNext = true;
160,919✔
2363
  while (1) {
×
2364
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
160,919!
2365
    if (!hasNext) {
160,919!
2366
      break;
77,432✔
2367
    }
2368
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
83,487✔
2369
    pTaskInner->pResBlockDst->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
83,487✔
2370

2371
    SSDataBlock* pBlock = NULL;
83,487✔
2372
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
83,487!
2373
    if (pBlock != NULL && pBlock->info.rows > 0) {
83,487!
2374
      STREAM_CHECK_RET_GOTO(
83,487!
2375
        processTag(pVnode, sStreamReaderInfo, false, &pTaskInner->api, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
2376
    }
2377
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
83,487!
2378
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
83,487!
2379
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
83,487✔
2380
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2381
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2382
    if (pTaskInner->pResBlockDst->info.rows >= 0) { //todo
83,487!
2383
      break;
83,487✔
2384
    }
2385
  }
2386

2387
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
160,919!
2388
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
160,919✔
2389
  if (!hasNext) {
160,919!
2390
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
77,432!
2391
  }
2392

2393
end:
160,919✔
2394
  STREAM_PRINT_LOG_END_WITHID(code, lino);
160,370!
2395
  SRpcMsg rsp = {
160,370✔
2396
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2397
  tmsgSendRsp(&rsp);
160,370✔
2398

2399
  return code;
160,919✔
2400
}
2401

2402
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
15,364,241✔
2403
  int32_t code = 0;
15,364,241✔
2404
  int32_t lino = 0;
15,364,241✔
2405
  void*   buf = NULL;
15,364,241✔
2406
  size_t  size = 0;
15,364,780✔
2407
  SSDataBlock*            pBlockRes = NULL;
15,364,780✔
2408

2409
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
15,365,319!
2410
  void* pTask = sStreamReaderInfo->pTask;
15,365,319✔
2411
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64, TD_VID(pVnode), __func__, 
15,365,319✔
2412
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid);
2413

2414
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
15,368,014!
2415

2416
  SStreamReaderTaskInner* pTaskInner = NULL;
15,366,936✔
2417
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
15,366,936✔
2418

2419
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
15,366,936!
2420
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
15,366,936✔
2421
                 sStreamReaderInfo->triggerCols, false, STREAM_SCAN_GROUP_ONE_BY_ONE, req->tsdbCalcDataReq.gid, true, NULL);
2422
    SStorageAPI api = {0};
15,366,936✔
2423
    initStorageAPI(&api);
15,366,936✔
2424
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
15,365,858✔
2425

2426
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
15,241,459!
2427
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
15,241,459!
2428
  } else {
2429
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2430
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2431
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2432
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2433
  }
2434

2435
  blockDataCleanup(pTaskInner->pResBlockDst);
15,238,764✔
2436
  bool hasNext = true;
15,239,842✔
2437
  while (1) {
1,347,889✔
2438
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
16,586,653!
2439
    if (!hasNext) {
16,585,036!
2440
      break;
15,237,686✔
2441
    }
2442
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
1,347,350✔
2443

2444
    SSDataBlock* pBlock = NULL;
1,349,428✔
2445
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
1,349,428!
2446
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
1,348,402!
2447
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
1,349,428!
2448
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
1,348,402!
2449
      break;
×
2450
    }
2451
  }
2452

2453
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
15,238,225!
2454
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
15,241,998!
2455
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
15,239,303✔
2456
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
15,238,790!
2457
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
15,238,764✔
2458
  if (!hasNext) {
15,242,537!
2459
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
15,242,537!
2460
  }
2461

2462
end:
15,360,981✔
2463
  STREAM_PRINT_LOG_END_WITHID(code, lino);
15,359,390!
2464
  SRpcMsg rsp = {
15,366,397✔
2465
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2466
  tmsgSendRsp(&rsp);
15,366,936✔
2467
  blockDataDestroy(pBlockRes);
15,366,397✔
2468
  return code;
15,366,936✔
2469
}
2470

2471
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
276,209✔
2472
  int32_t code = 0;
276,209✔
2473
  int32_t lino = 0;
276,209✔
2474
  void*   buf = NULL;
276,209✔
2475
  size_t  size = 0;
276,209✔
2476
  int32_t* slotIdList = NULL;
276,209✔
2477
  SArray* sortedCid = NULL;
276,209✔
2478
  SArray* schemas = NULL;
276,209✔
2479
  
2480
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
276,209!
2481
  void* pTask = sStreamReaderInfo->pTask;
276,209✔
2482
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
276,209✔
2483

2484
  SStreamReaderTaskInner* pTaskInner = NULL;
276,209✔
2485
  int64_t key = req->tsdbDataReq.uid;
276,209✔
2486

2487
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
276,209!
2488
    // sort cid and build slotIdList
2489
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
276,209!
2490
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
276,209!
2491
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
276,209✔
2492
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
276,209!
2493
    taosArraySort(sortedCid, sortCid);
276,209✔
2494
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
1,030,219✔
2495
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
754,010✔
2496
      STREAM_CHECK_NULL_GOTO(cid, terrno);
754,010!
2497
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
1,434,313!
2498
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
1,434,313✔
2499
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
1,434,313!
2500
        if (*cid == *cidSorted) {
1,434,313✔
2501
          slotIdList[j] = i;
754,010✔
2502
          break;
754,010✔
2503
        }
2504
      }
2505
    }
2506

2507
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas));
276,209✔
2508
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
275,299!
2509
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
275,299✔
2510
                    req->tsdbDataReq.ekey, schemas, true, STREAM_SCAN_ALL, 0, false, NULL);
2511

2512
    options.suid = req->tsdbDataReq.suid;
275,299✔
2513
    options.uid = req->tsdbDataReq.uid;
275,299✔
2514

2515
    SStorageAPI api = {0};
275,299✔
2516
    initStorageAPI(&api);
275,299✔
2517
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
275,299!
2518
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
275,299!
2519

2520
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid};
275,299✔
2521
    cleanupQueryTableDataCond(&pTaskInner->cond);
275,299✔
2522
    taosArraySort(pTaskInner->options.schemas, sortSSchema);
275,299✔
2523

2524
    STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTaskInner->cond, pTaskInner->options.order, pTaskInner->options.schemas,
275,299!
2525
                                                        pTaskInner->options.isSchema, pTaskInner->options.twindows,
2526
                                                        pTaskInner->options.suid, pTaskInner->options.ver, &slotIdList));
2527
    STREAM_CHECK_RET_GOTO(pTaskInner->api.tsdReader.tsdReaderOpen(pVnode, &pTaskInner->cond, &keyInfo, 1, pTaskInner->pResBlock,
275,299!
2528
                                                             (void**)&pTaskInner->pReader, pTaskInner->idStr, NULL));
2529
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pTaskInner->pResBlock, false, &pTaskInner->pResBlockDst));
275,299!
2530
  } else {
2531
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2532
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2533
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2534
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2535
  }
2536

2537
  blockDataCleanup(pTaskInner->pResBlockDst);
275,299✔
2538
  bool hasNext = true;
275,299✔
2539
  while (1) {
275,299✔
2540
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
550,598!
2541
    if (!hasNext) {
550,598!
2542
      break;
275,299✔
2543
    }
2544

2545
    SSDataBlock* pBlock = NULL;
275,299✔
2546
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
275,299!
2547
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
275,299!
2548
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
275,299!
2549
      break;
×
2550
    }
2551
  }
2552
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
275,299!
2553
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
275,299✔
2554
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
275,299✔
2555
  if (!hasNext) {
275,299!
2556
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
275,299!
2557
  }
2558

2559
end:
276,209✔
2560
  STREAM_PRINT_LOG_END_WITHID(code, lino);
276,209!
2561
  SRpcMsg rsp = {
276,209✔
2562
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2563
  tmsgSendRsp(&rsp);
276,209✔
2564
  taosMemFree(slotIdList);
276,209✔
2565
  taosArrayDestroy(sortedCid);
276,209✔
2566
  taosArrayDestroy(schemas);
276,209✔
2567
  return code;
276,209✔
2568
}
2569

2570
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
7,258,542✔
2571
  int32_t      code = 0;
7,258,542✔
2572
  int32_t      lino = 0;
7,258,542✔
2573
  void*        buf = NULL;
7,258,542✔
2574
  size_t       size = 0;
7,258,542✔
2575
  int64_t      lastVer = 0;
7,258,542✔
2576
  SSTriggerWalNewRsp resultRsp = {0};
7,258,542✔
2577

2578
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
7,260,674✔
2579
  void* pTask = sStreamReaderInfo->pTask;
7,229,625✔
2580
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
7,229,080✔
2581

2582
  if (sStreamReaderInfo->metaBlock == NULL) {
7,228,625✔
2583
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
211,453!
2584
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
211,453!
2585
  }
2586
  blockDataEmpty(sStreamReaderInfo->metaBlock);
7,230,170✔
2587
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
7,222,974✔
2588
  resultRsp.ver = req->walMetaNewReq.lastVer;
7,223,519✔
2589
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
7,224,609!
2590

2591
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
7,221,714✔
2592
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
7,225,259✔
2593
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, NULL);
286,747✔
2594
  buf = rpcMallocCont(size);
286,747✔
2595
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, NULL);
286,747✔
2596
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
286,747✔
2597

2598
end:
7,256,308✔
2599
  if (resultRsp.totalRows == 0) {
7,255,801✔
2600
    code = TSDB_CODE_STREAM_NO_DATA;
6,968,509✔
2601
    buf = rpcMallocCont(sizeof(int64_t));
6,968,509✔
2602
    *(int64_t *)buf = resultRsp.ver;
6,957,603✔
2603
    size = sizeof(int64_t);
6,960,296✔
2604
  }
2605
  SRpcMsg rsp = {
7,247,588✔
2606
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2607
  tmsgSendRsp(&rsp);
7,250,345✔
2608
  if (code == TSDB_CODE_STREAM_NO_DATA){
7,263,948✔
2609
    code = 0;
6,976,111✔
2610
  }
2611
  STREAM_PRINT_LOG_END_WITHID(code, lino);
7,263,948!
2612
  blockDataDestroy(resultRsp.deleteBlock);
7,266,046✔
2613
  blockDataDestroy(resultRsp.dropBlock);
7,263,399✔
2614

2615
  return code;
7,261,764✔
2616
}
2617
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,493,390✔
2618
  int32_t      code = 0;
3,493,390✔
2619
  int32_t      lino = 0;
3,493,390✔
2620
  void*        buf = NULL;
3,493,390✔
2621
  size_t       size = 0;
3,493,390✔
2622
  SSTriggerWalNewRsp resultRsp = {0};
3,493,390✔
2623
  
2624
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
3,495,584!
2625
  void* pTask = sStreamReaderInfo->pTask;
3,495,584✔
2626
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,489,511✔
2627

2628
  if (sStreamReaderInfo->metaBlock == NULL) {
3,490,051✔
2629
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
92,554!
2630
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
92,554!
2631
  }
2632
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,493,923✔
2633
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
3,494,472✔
2634
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,495,570✔
2635
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,496,119!
2636

2637
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,491,178✔
2638
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
158,677✔
2639
  buf = rpcMallocCont(size);
158,677✔
2640
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
158,677✔
2641
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
158,677✔
2642
  printDataBlock(sStreamReaderInfo->triggerBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
158,677✔
2643
  printDataBlock(resultRsp.dropBlock, __func__, "drop", ((SStreamTask*)pTask)->streamId);
158,677✔
2644
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
158,135✔
2645
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
158,135✔
2646

2647
end:
3,491,178✔
2648
  if (resultRsp.totalRows == 0) {
3,491,727✔
2649
    buf = rpcMallocCont(sizeof(int64_t));
3,336,898✔
2650
    *(int64_t *)buf = resultRsp.ver;
3,324,246✔
2651
    size = sizeof(int64_t);
3,325,893✔
2652
    code = TSDB_CODE_STREAM_NO_DATA;
3,325,893✔
2653
  }
2654
  SRpcMsg rsp = {
3,480,722✔
2655
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2656
  tmsgSendRsp(&rsp);
3,487,869✔
2657
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,495,575✔
2658
    code = 0;
3,336,898✔
2659
  }
2660
  blockDataDestroy(resultRsp.deleteBlock);
3,495,575✔
2661
  blockDataDestroy(resultRsp.dropBlock);
3,495,575✔
2662

2663
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,495,009!
2664

2665
  return code;
3,495,218✔
2666
}
2667

2668
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,426,146✔
2669
  int32_t      code = 0;
3,426,146✔
2670
  int32_t      lino = 0;
3,426,146✔
2671
  void*        buf = NULL;
3,426,146✔
2672
  size_t       size = 0;
3,426,146✔
2673
  SSTriggerWalNewRsp resultRsp = {0};
3,426,146✔
2674

2675
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
3,426,691!
2676
  void* pTask = sStreamReaderInfo->pTask;
3,426,691✔
2677
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
3,425,056✔
2678

2679
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
3,425,056✔
2680
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
3,426,146!
2681
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
3,425,062✔
2682

2683
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,425,056✔
2684

2685
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
171,534✔
2686
  buf = rpcMallocCont(size);
171,534✔
2687
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
171,534✔
2688
  printDataBlock(sStreamReaderInfo->triggerBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
171,534✔
2689
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
171,534✔
2690

2691
end:
3,425,056✔
2692
  if (resultRsp.totalRows == 0) {
3,425,056✔
2693
    buf = rpcMallocCont(sizeof(int64_t));
3,255,157✔
2694
    *(int64_t *)buf = resultRsp.ver;
3,252,432✔
2695
    size = sizeof(int64_t);
3,251,342✔
2696
    code = TSDB_CODE_STREAM_NO_DATA;
3,251,342✔
2697
  }
2698
  SRpcMsg rsp = {
3,421,241✔
2699
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2700
  tmsgSendRsp(&rsp);
3,425,056✔
2701
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,425,236✔
2702
    code = 0;
3,254,157✔
2703
  }
2704

2705
  blockDataDestroy(resultRsp.deleteBlock);
3,425,236✔
2706
  blockDataDestroy(resultRsp.dropBlock);
3,424,146✔
2707
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,423,140!
2708

2709
  return code;
3,424,050✔
2710
}
2711

2712
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
651,447✔
2713
  int32_t      code = 0;
651,447✔
2714
  int32_t      lino = 0;
651,447✔
2715
  void*        buf = NULL;
651,447✔
2716
  size_t       size = 0;
651,447✔
2717
  SSTriggerWalNewRsp resultRsp = {0};
651,447✔
2718
  SSDataBlock* pBlock1 = NULL;
652,010✔
2719
  SSDataBlock* pBlock2 = NULL;
652,010✔
2720
  
2721
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
652,010!
2722
  void* pTask = sStreamReaderInfo->pTask;
652,010✔
2723
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
652,010✔
2724

2725
  resultRsp.dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
652,010!
2726
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
652,010!
2727
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
652,010!
2728
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
652,010✔
2729

2730
  if (!sStreamReaderInfo->isVtableStream){
358,431!
2731
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, true, &pBlock1));
259,944!
2732
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
259,944!
2733
  
2734
    blockDataTransform(pBlock2, pBlock1);
259,944✔
2735
    resultRsp.dataBlock = pBlock2;
259,944✔
2736
  }
2737

2738
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
358,431✔
2739
  buf = rpcMallocCont(size);
358,431✔
2740
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
358,431✔
2741
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
358,431✔
2742
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
358,431✔
2743

2744
end:
652,010✔
2745
  if (resultRsp.totalRows == 0) {
652,010✔
2746
    buf = rpcMallocCont(sizeof(int64_t));
293,579✔
2747
    *(int64_t *)buf = resultRsp.ver;
293,579✔
2748
    size = sizeof(int64_t);
293,579✔
2749
    code = TSDB_CODE_STREAM_NO_DATA;
293,579✔
2750
  }
2751
  SRpcMsg rsp = {
652,010✔
2752
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2753
  tmsgSendRsp(&rsp);
652,010✔
2754
  if (code == TSDB_CODE_STREAM_NO_DATA){
652,010✔
2755
    code = 0;
293,579✔
2756
  }
2757

2758
  blockDataDestroy(pBlock1);
652,010✔
2759
  blockDataDestroy(pBlock2);
652,010✔
2760
  blockDataDestroy(resultRsp.deleteBlock);
652,010✔
2761
  blockDataDestroy(resultRsp.dropBlock);
652,010✔
2762
  STREAM_PRINT_LOG_END_WITHID(code, lino);
652,010!
2763

2764
  return code;
652,010✔
2765
}
2766

2767
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
395,110✔
2768
  int32_t code = 0;
395,110✔
2769
  int32_t lino = 0;
395,110✔
2770
  void*   buf = NULL;
395,110✔
2771
  size_t  size = 0;
395,110✔
2772

2773
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
395,110!
2774
  void* pTask = sStreamReaderInfo->pTask;
395,110✔
2775
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
395,110✔
2776

2777
  SArray** gInfo = taosHashGet(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
395,110✔
2778
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
395,110!
2779
  SStreamGroupInfo pGroupInfo = {0};
395,110✔
2780
  pGroupInfo.gInfo = *gInfo;
395,110✔
2781

2782
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
395,110✔
2783
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
2784
  buf = rpcMallocCont(size);
394,565✔
2785
  STREAM_CHECK_NULL_GOTO(buf, terrno);
394,565!
2786
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
394,565✔
2787
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
2788
end:
395,110✔
2789
  if (code != 0) {
395,110!
2790
    rpcFreeCont(buf);
×
2791
    buf = NULL;
×
2792
    size = 0;
×
2793
  }
2794
  STREAM_PRINT_LOG_END_WITHID(code, lino);
395,110!
2795
  SRpcMsg rsp = {
395,110✔
2796
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2797
  tmsgSendRsp(&rsp);
395,110✔
2798

2799
  return code;
395,110✔
2800
}
2801

2802
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
308,196✔
2803
  int32_t              code = 0;
308,196✔
2804
  int32_t              lino = 0;
308,196✔
2805
  void*                buf = NULL;
308,196✔
2806
  size_t               size = 0;
308,741✔
2807
  SStreamMsgVTableInfo vTableInfo = {0};
308,741✔
2808
  SMetaReader          metaReader = {0};
308,741✔
2809
  SStorageAPI api = {0};
308,741✔
2810
  initStorageAPI(&api);
308,741✔
2811

2812
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
308,741!
2813
  void* pTask = sStreamReaderInfo->pTask;
308,741✔
2814
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
308,741✔
2815

2816
  SArray* cids = req->virTableInfoReq.cids;
308,741✔
2817
  STREAM_CHECK_NULL_GOTO(cids, terrno);
308,741!
2818

2819
  SArray* pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo->tableList);
308,741✔
2820
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
308,196!
2821

2822
  vTableInfo.infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
308,196✔
2823
  STREAM_CHECK_NULL_GOTO(vTableInfo.infos, terrno);
308,741!
2824
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
308,741✔
2825

2826
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
1,044,780✔
2827
    STableKeyInfo* pKeyInfo = taosArrayGet(pTableListArray, i);
736,039✔
2828
    if (pKeyInfo == NULL) {
736,039!
2829
      continue;
×
2830
    }
2831
    VTableInfo* vTable = taosArrayReserve(vTableInfo.infos, 1);
736,039✔
2832
    STREAM_CHECK_NULL_GOTO(vTable, terrno);
736,039!
2833
    vTable->uid = pKeyInfo->uid;
736,039✔
2834
    vTable->gId = pKeyInfo->groupId;
736,039✔
2835

2836
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
736,039✔
2837
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
736,039!
2838
      vTable->cols.nCols = metaReader.me.colRef.nCols;
35,490✔
2839
      vTable->cols.version = metaReader.me.colRef.version;
35,490✔
2840
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
35,490!
2841
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
212,940✔
2842
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
177,450!
2843
      }
2844
    } else {
2845
      vTable->cols.nCols = taosArrayGetSize(cids);
700,549✔
2846
      vTable->cols.version = metaReader.me.colRef.version;
700,549✔
2847
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
700,549!
2848
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
2,606,436✔
2849
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
8,004,020✔
2850
          if (metaReader.me.colRef.pColRef[j].hasRef &&
7,304,016!
2851
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
5,366,345✔
2852
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
1,205,254!
2853
            break;
1,205,883✔
2854
          }
2855
        }
2856
      }
2857
    }
2858
    tDecoderClear(&metaReader.coder);
735,129✔
2859
  }
2860
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
308,741✔
2861
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
308,741!
2862

2863
end:
308,741✔
2864
  tDestroySStreamMsgVTableInfo(&vTableInfo);
308,741✔
2865
  api.metaReaderFn.clearReader(&metaReader);
308,741✔
2866
  STREAM_PRINT_LOG_END_WITHID(code, lino);
308,741!
2867
  SRpcMsg rsp = {
308,741✔
2868
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2869
  tmsgSendRsp(&rsp);
308,741✔
2870
  return code;
308,741✔
2871
}
2872

2873
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req) {
108,273✔
2874
  int32_t                   code = 0;
108,273✔
2875
  int32_t                   lino = 0;
108,273✔
2876
  void*                     buf = NULL;
108,273✔
2877
  size_t                    size = 0;
108,273✔
2878
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
108,273✔
2879
  SMetaReader               metaReader = {0};
108,273✔
2880
  int64_t streamId = req->base.streamId;
108,273✔
2881
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
108,273✔
2882

2883
  SStorageAPI api = {0};
108,273✔
2884
  initStorageAPI(&api);
108,273✔
2885

2886
  SArray* cols = req->origTableInfoReq.cols;
108,273✔
2887
  STREAM_CHECK_NULL_GOTO(cols, terrno);
108,273!
2888

2889
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
108,273✔
2890

2891
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
108,273!
2892

2893
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
108,273✔
2894
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
371,339✔
2895
    OTableInfo*    oInfo = taosArrayGet(cols, i);
262,515✔
2896
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
262,515✔
2897
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
262,515!
2898
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
262,515!
2899
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByName(&metaReader, oInfo->refTableName));
262,515!
2900
    vTableInfo->uid = metaReader.me.uid;
262,515✔
2901
    stsDebug("vgId:%d %s uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
262,515✔
2902

2903
    SSchemaWrapper* sSchemaWrapper = NULL;
263,066✔
2904
    if (metaReader.me.type == TD_CHILD_TABLE) {
263,066✔
2905
      int64_t suid = metaReader.me.ctbEntry.suid;
260,886✔
2906
      vTableInfo->suid = suid;
260,886✔
2907
      tDecoderClear(&metaReader.coder);
260,335✔
2908
      STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
260,335!
2909
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
260,335✔
2910
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
2,180!
2911
      vTableInfo->suid = 0;
2,180✔
2912
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
2,180✔
2913
    } else {
2914
      stError("invalid table type:%d", metaReader.me.type);
×
2915
    }
2916

2917
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
889,465!
2918
      SSchema* s = sSchemaWrapper->pSchema + j;
890,016✔
2919
      if (strcmp(s->name, oInfo->refColName) == 0) {
890,567!
2920
        vTableInfo->cid = s->colId;
263,066✔
2921
        break;
262,515✔
2922
      }
2923
    }
2924
    if (vTableInfo->cid == 0) {
261,964!
2925
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
2926
              oInfo->refTableName);
2927
    }
2928
    tDecoderClear(&metaReader.coder);
261,964✔
2929
  }
2930

2931
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
108,285!
2932

2933
end:
108,273✔
2934
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
108,273✔
2935
  api.metaReaderFn.clearReader(&metaReader);
108,273✔
2936
  STREAM_PRINT_LOG_END(code, lino);
108,273!
2937
  SRpcMsg rsp = {
108,273✔
2938
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2939
  tmsgSendRsp(&rsp);
108,273✔
2940
  return code;
108,273✔
2941
}
2942

2943
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req) {
618,898✔
2944
  int32_t                   code = 0;
618,898✔
2945
  int32_t                   lino = 0;
618,898✔
2946
  void*                     buf = NULL;
618,898✔
2947
  size_t                    size = 0;
618,898✔
2948
  SSDataBlock* pBlock = NULL;
618,898✔
2949

2950
  SMetaReader               metaReader = {0};
618,898✔
2951
  SMetaReader               metaReaderStable = {0};
618,898✔
2952
  int64_t streamId = req->base.streamId;
618,898✔
2953
  stsDebug("vgId:%d %s start", TD_VID(pVnode), __func__);
618,898✔
2954

2955
  SStorageAPI api = {0};
618,898✔
2956
  initStorageAPI(&api);
618,898✔
2957

2958
  SArray* cols = req->virTablePseudoColReq.cids;
618,898✔
2959
  STREAM_CHECK_NULL_GOTO(cols, terrno);
618,898!
2960

2961
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
618,898✔
2962
  STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, req->virTablePseudoColReq.uid));
618,898!
2963

2964
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
618,898!
2965

2966
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
618,898!
2967
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
618,898✔
2968
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
3,815!
2969
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
3,815✔
2970
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
3,815!
2971
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
3,815!
2972
    pBlock->info.rows = 1;
3,815✔
2973
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
3,815✔
2974
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
3,815!
2975
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
3,815!
2976
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
615,083!
2977
    int64_t suid = metaReader.me.ctbEntry.suid;
615,083✔
2978
    api.metaReaderFn.readerReleaseLock(&metaReader);
615,083✔
2979
    api.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &api.metaFn);
615,083✔
2980

2981
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
615,083!
2982
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
615,083✔
2983
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
1,560,395✔
2984
      col_id_t* id = taosArrayGet(cols, i);
945,312✔
2985
      STREAM_CHECK_NULL_GOTO(id, terrno);
945,312!
2986
      if (*id == -1) {
945,312✔
2987
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
612,353✔
2988
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
612,353!
2989
        continue;
612,353✔
2990
      }
2991
      size_t j = 0;
332,959✔
2992
      for (; j < sSchemaWrapper->nCols; j++) {
576,314!
2993
        SSchema* s = sSchemaWrapper->pSchema + j;
576,314✔
2994
        if (s->colId == *id) {
576,314✔
2995
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
332,959✔
2996
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
332,959!
2997
          break;
332,959✔
2998
        }
2999
      }
3000
      if (j == sSchemaWrapper->nCols) {
332,959!
3001
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3002
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3003
      }
3004
    }
3005
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
615,083!
3006
    pBlock->info.rows = 1;
615,083✔
3007
    
3008
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
1,560,395✔
3009
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
945,312✔
3010
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
945,312!
3011

3012
      if (pDst->info.colId == -1) {
945,312✔
3013
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
612,353!
3014
        continue;
612,353✔
3015
      }
3016
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
332,959!
3017
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3018
        continue;
×
3019
      }
3020

3021
      STagVal val = {0};
332,959✔
3022
      val.cid = pDst->info.colId;
332,959✔
3023
      const char* p = api.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
332,959✔
3024

3025
      char* data = NULL;
332,959✔
3026
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
332,959!
3027
        data = tTagValToData((const STagVal*)p, false);
332,959✔
3028
      } else {
3029
        data = (char*)p;
×
3030
      }
3031

3032
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
332,959!
3033
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3034

3035
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
332,959!
3036
          (data != NULL)) {
3037
        taosMemoryFree(data);
229,880!
3038
      }
3039
    }
3040
  } else {
3041
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3042
    code = TSDB_CODE_INVALID_PARA;
×
3043
    goto end;
×
3044
  }
3045
  
3046
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
618,898✔
3047
  printDataBlock(pBlock, __func__, "", streamId);
618,898✔
3048
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
618,898!
3049

3050
end:
618,898✔
3051
  if(size == 0){
618,898!
3052
    code = TSDB_CODE_STREAM_NO_DATA;
×
3053
  }
3054
  api.metaReaderFn.clearReader(&metaReaderStable);
618,898✔
3055
  api.metaReaderFn.clearReader(&metaReader);
618,898✔
3056
  STREAM_PRINT_LOG_END(code, lino);
618,898!
3057
  SRpcMsg rsp = {
618,898✔
3058
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3059
  tmsgSendRsp(&rsp);
618,898✔
3060
  blockDataDestroy(pBlock);
618,898✔
3061
  return code;
618,443✔
3062
}
3063

3064
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg) {
8,695,136✔
3065
  int32_t            code = 0;
8,695,136✔
3066
  int32_t            lino = 0;
8,695,136✔
3067
  void*              buf = NULL;
8,695,136✔
3068
  size_t             size = 0;
8,695,136✔
3069
  void*              taskAddr = NULL;
8,695,136✔
3070
  SArray*            pResList = NULL;
8,695,136✔
3071

3072
  SResFetchReq req = {0};
8,695,136✔
3073
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
8,695,136!
3074
                              TSDB_CODE_QRY_INVALID_INPUT);
3075
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
8,695,136✔
3076
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
8,694,569!
3077

3078
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
8,695,136!
3079
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
8,695,136✔
3080
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
8,694,609!
3081
  void* pTask = sStreamReaderCalcInfo->pTask;
8,694,609✔
3082
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
8,695,136!
3083
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
3084

3085
  if (req.reset || sStreamReaderCalcInfo->pTaskInfo == NULL) {
8,695,136!
3086
  // if (req.reset) {
3087
    qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
8,627,482✔
3088
    int64_t uid = 0;
8,626,901✔
3089
    if (req.dynTbname) {
8,626,901!
3090
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
33,527✔
3091
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
33,527!
3092
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
33,527✔
3093
        if (pValue != NULL && pValue->isTbname) {
33,527!
3094
          uid = pValue->uid;
33,527✔
3095
          break;
33,527✔
3096
        }
3097
      }
3098
    }
3099
    
3100
    SReadHandle handle = {0};
8,626,901✔
3101
    handle.vnode = pVnode;
8,626,901✔
3102
    handle.uid = uid;
8,626,901✔
3103

3104
    initStorageAPI(&handle.api);
8,626,901✔
3105
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
8,626,342✔
3106
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
8,080,823✔
3107
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
7,468,418✔
3108
      if (node != NULL) {
7,468,758✔
3109
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
403,216!
3110
      } else {
3111
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
7,065,542✔
3112
      }
3113

3114
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
7,471,233✔
3115
      if (node != NULL) {
7,469,552!
3116
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
×
3117
      } else {
3118
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
7,469,552✔
3119
      }      
3120
    }
3121

3122
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
8,626,901!
3123
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
8,627,482✔
3124

3125
    // if (sStreamReaderCalcInfo->pTaskInfo == NULL) {
3126
    STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
8,627,482✔
3127
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
3128
                                                    req.taskId));
3129
    // } else {
3130
    // STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, handle.winRange));
3131
    // }
3132

3133
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
8,622,550!
3134
  }
3135

3136
  if (req.pOpParam != NULL) {
8,690,204✔
3137
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, req.pOpParam);
389,025✔
3138
  }
3139
  
3140
  pResList = taosArrayInit(4, POINTER_BYTES);
8,690,204✔
3141
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
8,690,204!
3142
  uint64_t ts = 0;
8,690,204✔
3143
  bool     hasNext = false;
8,690,204✔
3144
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
8,690,204✔
3145

3146
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
19,140,770✔
3147
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
10,457,687✔
3148
    if (pBlock == NULL) continue;
10,457,687!
3149
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
10,457,687✔
3150
/*    
3151
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
3152
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
3153
      printDataBlock(pBlock, __func__, "fetch filter");
3154
    }
3155
*/    
3156
  }
3157

3158
  ST_TASK_DLOG("vgId:%d %s start to build rsp", TD_VID(pVnode), __func__);
8,683,083✔
3159
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
8,683,641!
3160
  ST_TASK_DLOG("vgId:%d %s end:", TD_VID(pVnode), __func__);
8,683,083✔
3161

3162
end:
8,692,750✔
3163
  taosArrayDestroy(pResList);
8,695,136✔
3164
  streamReleaseTask(taskAddr);
8,695,136✔
3165

3166
  STREAM_PRINT_LOG_END(code, lino);
8,694,609!
3167
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
8,695,136✔
3168
  tmsgSendRsp(&rsp);
8,695,136✔
3169
  tDestroySResFetchReq(&req);
8,694,594✔
3170
  return code;
8,694,006✔
3171
}
3172

3173
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
42,052,739✔
3174
  int32_t                   code = 0;
42,052,739✔
3175
  int32_t                   lino = 0;
42,052,739✔
3176
  SSTriggerPullRequestUnion req = {0};
42,052,739✔
3177
  void*                     taskAddr = NULL;
42,053,281✔
3178

3179
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
42,044,395✔
3180
  if (!syncIsReadyForRead(pVnode->sync)) {
42,046,148✔
3181
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
42,301✔
3182
    return 0;
42,301✔
3183
  }
3184

3185
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
42,010,414✔
3186
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
8,695,136✔
3187
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
33,314,194!
3188
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
33,318,564✔
3189
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
33,319,109✔
3190
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
33,315,816!
3191
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
33,306,971✔
3192
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId);
3193
    SStreamTriggerReaderInfo* sStreamReaderInfo = (STRIGGER_PULL_OTABLE_INFO == req.base.type) ? NULL : qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
33,315,288✔
3194
    if (sStreamReaderInfo != NULL) {  
33,308,270✔
3195
      (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
33,170,487✔
3196
      if (sStreamReaderInfo->tableList == NULL) {
33,175,958✔
3197
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, false));  
304,007!
3198
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, true));
303,458!
3199
        STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamReaderInfo->pConditions, &sStreamReaderInfo->pFilterInfo, 0, NULL));
304,007!
3200
      }
3201
      (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
33,175,949✔
3202
      sStreamReaderInfo->pVnode = pVnode;
33,173,234✔
3203
    }
3204
    switch (req.base.type) {
33,311,566!
3205
      case STRIGGER_PULL_SET_TABLE:
108,273✔
3206
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
108,273!
3207
        break;
108,273✔
3208
      case STRIGGER_PULL_LAST_TS:
298,600✔
3209
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
298,600!
3210
        break;
298,074✔
3211
      case STRIGGER_PULL_FIRST_TS:
261,697✔
3212
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
261,697✔
3213
        break;
258,605✔
3214
      case STRIGGER_PULL_TSDB_META:
559,407✔
3215
      case STRIGGER_PULL_TSDB_META_NEXT:
3216
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
559,407✔
3217
        break;
557,413✔
3218
      case STRIGGER_PULL_TSDB_TS_DATA:
16,736✔
3219
        if (sStreamReaderInfo->isVtableStream) {
16,736!
3220
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
910!
3221
        } else {
3222
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
15,826!
3223
        }
3224
        break;
16,736✔
3225
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
160,919✔
3226
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
3227
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
160,919!
3228
        break;
160,919✔
3229
      case STRIGGER_PULL_TSDB_CALC_DATA:
15,366,397✔
3230
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
3231
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
15,366,397✔
3232
        break;
15,238,225✔
3233
      case STRIGGER_PULL_TSDB_DATA:
276,209✔
3234
      case STRIGGER_PULL_TSDB_DATA_NEXT:
3235
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
276,209✔
3236
        break;
275,299✔
3237
      case STRIGGER_PULL_GROUP_COL_VALUE:
395,110✔
3238
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
395,110!
3239
        break;
395,110✔
3240
      case STRIGGER_PULL_VTABLE_INFO:
308,741✔
3241
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
308,741!
3242
        break;
308,741✔
3243
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
618,898✔
3244
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req));
618,898!
3245
        break;
618,443✔
3246
      case STRIGGER_PULL_OTABLE_INFO:
108,273✔
3247
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req));
108,273!
3248
        break;
108,273✔
3249
      case STRIGGER_PULL_WAL_META_NEW:
7,260,117✔
3250
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
7,260,117!
3251
        break;
7,262,309✔
3252
      case STRIGGER_PULL_WAL_DATA_NEW:
3,425,691✔
3253
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,425,691!
3254
        break;
3,422,870✔
3255
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,494,488✔
3256
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,494,488!
3257
        break;
3,495,026✔
3258
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
652,010✔
3259
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
652,010!
3260
        break;
652,010✔
3261
      default:
×
3262
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
3263
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3264
        break;
×
3265
    }
3266
  } else {
UNCOV
3267
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
3268
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3269
  }
3270
end:
33,288,552✔
3271

3272
  streamReleaseTask(taskAddr);
33,308,874✔
3273

3274
  tDestroySTriggerPullRequest(&req);
33,313,185✔
3275
  STREAM_PRINT_LOG_END(code, lino);
33,294,773!
3276
  return code;
33,305,448✔
3277
}
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