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

taosdata / TDengine / #4836

31 Oct 2025 03:37AM UTC coverage: 58.728% (+0.2%) from 58.506%
#4836

push

travis-ci

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

# Conflicts:
#	test/ci/run.sh

149727 of 324176 branches covered (46.19%)

Branch coverage included in aggregate %.

198923 of 269498 relevant lines covered (73.81%)

238054213.11 hits per line

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

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

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

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

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

60
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
37,302,668✔
61

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

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

68
  if (*c1 < *c2) {
442,765✔
69
    return -1;
437,785✔
70
  } else if (*c1 > *c2) {
4,980!
71
    return 1;
4,980✔
72
  }
73

74
  return 0;
×
75
}
76

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

81
  if (c1->colId < c2->colId) {
442,765✔
82
    return -1;
437,785✔
83
  } else if (c1->colId > c2->colId) {
4,980!
84
    return 1;
4,980✔
85
  }
86

87
  return 0;
×
88
}
89

90
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
32,543,804✔
91
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
32,543,804✔
92
  if (pSrc == NULL) {
32,556,895!
93
    return terrno;
×
94
  }
95

96
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
32,556,895!
97
  return 0;
32,541,219✔
98
}
99

100
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
42,740,151✔
101
  int32_t code = pTask->api.tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
42,740,151✔
102
  if (code != TSDB_CODE_SUCCESS) {
42,723,780!
103
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
104
  }
105

106
  return code;
42,727,598✔
107
}
108

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

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

131
static bool needRefreshTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
3,588,952✔
132
  if (sStreamReaderInfo->isVtableStream) {
3,588,952!
133
    int64_t id[2] = {suid, uid};
1,480,110✔
134
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id)) == NULL) {
1,478,822!
135
      return true;
1,471,179✔
136
    }
137
  } else {
138
    if (tableType != TD_CHILD_TABLE) {
2,110,129✔
139
      return false;
737,309✔
140
    }
141
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
1,372,820✔
142
        suid == sStreamReaderInfo->suid && 
829,543✔
143
        qStreamGetGroupId(sStreamReaderInfo->tableList, uid) == -1) {
29,427✔
144
      return true;
11,481✔
145
    }
146
  }
147
  return false;
1,371,542✔
148
}
149

150
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc){
47,269,324✔
151
  if (sStreamReaderInfo->isVtableStream) {
47,269,324!
152
    int64_t tmp[2] = {suid, uid};
17,046,337✔
153
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) == NULL) {
17,048,896✔
154
      return false;
6,249,642✔
155
    }
156
    *id = uid;
10,796,643✔
157
  } else {
158
    if (sStreamReaderInfo->tableList == NULL) return false;
30,237,021!
159

160
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
30,253,730✔
161
      if (suid != sStreamReaderInfo->suid) return false;
19,168,985✔
162
      if (sStreamReaderInfo->pTagCond == NULL) {
14,326,434✔
163
        if (sStreamReaderInfo->partitionCols == NULL){
12,189,684✔
164
          *id = 0;
52,106✔
165
        } else if (sStreamReaderInfo->groupByTbname){
12,137,578!
166
          *id= uid;
11,263,268✔
167
        } else {
168
          *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
874,310✔
169
          if (*id == -1) return false;
874,310!
170
        }
171
      } else {
172
        //*id= uid;
173
        *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
2,138,030✔
174
        if (*id == -1) return false;
2,138,030✔
175
      }
176
    } else {
177
      *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
11,094,994✔
178
      if(*id == -1) *id = uid;
11,091,002✔
179
      return uid == sStreamReaderInfo->uid;
11,091,002✔
180
    }
181
  }
182
  return true;
24,246,052✔
183
}
184

185
static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, bool isHistory) {
4,244,560✔
186
  int32_t                   code = 0;
4,244,560✔
187
  int32_t                   lino = 0;
4,244,560✔
188
  SNodeList* groupNew = NULL;                                      
4,244,560✔
189
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
4,250,984!
190

191
  SStorageAPI api = {0};
4,249,714✔
192
  initStorageAPI(&api);
4,250,959✔
193
  code = qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
4,252,073✔
194
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, 
195
                                         isHistory ? &sStreamReaderInfo->historyTableList : &sStreamReaderInfo->tableList,
196
                                         isHistory ? NULL : sStreamReaderInfo->groupIdMap);
197
  end:
4,250,984✔
198
  nodesDestroyList(groupNew);
4,250,984✔
199
  STREAM_PRINT_LOG_END(code, lino);
4,253,508!
200
  return code;
4,253,508✔
201
}
202

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

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

239

240
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
37,771,944✔
241
  int32_t code = 0;
37,771,944✔
242
  int32_t lino = 0;
37,771,944✔
243
  void*   buf = NULL;
37,771,944✔
244
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
37,771,944!
245
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
2,331,935✔
246
  buf = rpcMallocCont(dataEncodeSize);
2,331,935✔
247
  STREAM_CHECK_NULL_GOTO(buf, terrno);
2,329,400!
248
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
2,329,400✔
249
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
2,329,400!
250
  *data = buf;
2,329,400✔
251
  *size = dataEncodeSize;
2,329,400✔
252
  buf = NULL;
2,331,935✔
253
end:
37,776,999✔
254
  rpcFreeCont(buf);
37,776,999✔
255
  return code;
37,771,914✔
256
}
257

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

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

276
end:
694,382✔
277
  STREAM_PRINT_LOG_END(code, lino);
694,382!
278
  return code;
695,628✔
279
}
280

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

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

301
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
7,860,074✔
302
  int32_t code = 0;
7,860,074✔
303
  int32_t lino = 0;
7,860,074✔
304
  int32_t index = 0;
7,860,074✔
305
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
7,860,074!
306
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
7,857,508!
307
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
7,856,230!
308
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
7,857,503!
309

310
end:
7,860,069✔
311
  return code;
7,860,069✔
312
}
313

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

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

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

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

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

358
end:
131,744✔
359
  taosArrayDestroy(req.uidList);
131,744✔
360
  tDecoderClear(&decoder);
133,024✔
361
  return code;
133,024✔
362
}
363

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

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

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

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

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

395
static int32_t reloadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo){
1,509,571✔
396
  (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
1,509,571✔
397
  qStreamDestroyTableList(sStreamReaderInfo->tableList);
1,509,571✔
398
  sStreamReaderInfo->tableList = NULL;
1,509,571✔
399
  int32_t code = generateTablistForStreamReader(sStreamReaderInfo->pVnode, sStreamReaderInfo, false);
1,509,571✔
400
  if (code == 0){
1,508,292✔
401
    qStreamDestroyTableList(sStreamReaderInfo->historyTableList);
1,507,013✔
402
    sStreamReaderInfo->historyTableList = NULL;
1,508,311✔
403
    code = generateTablistForStreamReader(sStreamReaderInfo->pVnode, sStreamReaderInfo, true);
1,509,571✔
404
  }
405
  (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
1,510,850✔
406
  return code;
1,509,571✔
407
}
408

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

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

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

430
    found = true;
62,006✔
431
    break;
62,006✔
432
  }
433
  STREAM_CHECK_CONDITION_GOTO(!found, TDB_CODE_SUCCESS);
129,426✔
434

435
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
62,006!
436
end:
129,426✔
437
  tDeleteSVCreateTbBatchReq(&req);
129,426✔
438
  tDecoderClear(&decoder);
129,426✔
439
  return code;
129,426✔
440
}
441

442
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq) {
3,459,525✔
443
  int32_t  code = 0;
3,459,525✔
444
  int32_t  lino = 0;
3,459,525✔
445
  void*    pTask = sStreamReaderInfo->pTask;
3,459,525✔
446
  if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
3,459,525✔
447
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
2,038,871✔
448
    goto end;
2,041,438✔
449
  }
450
  ST_TASK_ILOG("stream reader scan auto create table %s", pCreateReq->name);
1,419,374!
451

452
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
1,419,374!
453
end:
1,419,375✔
454
  return code;
3,460,813✔
455
}
456

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

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

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

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

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

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

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

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

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

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

527
static int32_t scanSubmitTbDataForMeta(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* gidHash) {
11,206,609✔
528
  int32_t code = 0;
11,206,609✔
529
  int32_t lino = 0;
11,206,609✔
530
  WalMetaResult walMeta = {0};
11,206,609✔
531
  SSubmitTbData submitTbData = {0};
11,207,888✔
532
  
533
  if (tStartDecode(pCoder) < 0) {
11,206,609!
534
    code = TSDB_CODE_INVALID_MSG;
×
535
    TSDB_CHECK_CODE(code, lino, end);
×
536
  }
537

538
  uint8_t       version = 0;
11,213,029✔
539
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
11,209,258!
540
    code = TSDB_CODE_INVALID_MSG;
×
541
    TSDB_CHECK_CODE(code, lino, end);
×
542
  }
543
  version = (submitTbData.flags >> 8) & 0xff;
11,209,258✔
544
  submitTbData.flags = submitTbData.flags & 0xff;
11,209,258✔
545

546
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
547
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
11,209,258✔
548
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,746,534!
549
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,745,254!
550
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,745,254!
551
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
1,740,127!
552
  }
553

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

564
  if (!uidInTableList(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
11,211,764✔
565
    goto end;
7,880,592✔
566
  }
567
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,334,957!
568
    code = TSDB_CODE_INVALID_MSG;
×
569
    TSDB_CHECK_CODE(code, lino, end);
×
570
  }
571

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

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

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

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

607
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
13,153,490✔
608
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,821,093✔
609
      pCoder->pos += pRow->len;
9,819,807✔
610
      if (iRow == 0){
9,821,093✔
611
#ifndef NO_UNALIGNED_ACCESS
612
        walMeta.skey = pRow->ts;
3,332,398✔
613
#else
614
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
615
#endif
616
      }
617
      if (iRow == nRow - 1) {
9,819,807✔
618
#ifndef NO_UNALIGNED_ACCESS
619
        walMeta.ekey = pRow->ts;
3,331,112✔
620
#else
621
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
622
#endif
623
      }
624
    }
625
  }
626

627
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
3,331,118✔
628
  if (data != NULL) {
3,329,858!
629
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
630
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
631
  } else {
632
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
3,329,858!
633
  }
634

635
end:
11,195,453✔
636
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
11,211,711✔
637
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
11,206,588!
638
  tEndDecode(pCoder);
11,206,588✔
639
  return code;
11,210,466✔
640
}
641

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

649
  tDecoderInit(&decoder, data, len);
11,214,288✔
650
  if (tStartDecode(&decoder) < 0) {
11,198,919!
651
    code = TSDB_CODE_INVALID_MSG;
×
652
    TSDB_CHECK_CODE(code, lino, end);
×
653
  }
654

655
  uint64_t nSubmitTbData = 0;
11,207,944✔
656
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
11,204,129!
657
    code = TSDB_CODE_INVALID_MSG;
×
658
    TSDB_CHECK_CODE(code, lino, end);
×
659
  }
660

661
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
11,204,129✔
662
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
11,207,870!
663

664
  for (int32_t i = 0; i < nSubmitTbData; i++) {
22,417,057✔
665
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash));
11,209,150!
666
  }
667
  tEndDecode(&decoder);
11,207,907✔
668

669
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
11,209,187!
670
  int32_t iter = 0;
11,199,011✔
671
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
11,200,291✔
672
  while (px != NULL) {
14,542,902✔
673
    WalMetaResult* pMeta = (WalMetaResult*)px;
3,333,678✔
674
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
3,333,678!
675
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
3,333,678✔
676
    rsp->totalRows++;
3,333,678✔
677
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
3,333,678✔
678
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
679
    px = tSimpleHashIterate(gidHash, px, &iter);
3,333,678✔
680
  }
681
end:
11,209,224✔
682
  tDecoderClear(&decoder);
11,211,763✔
683
  tSimpleHashCleanup( gidHash);
11,215,549✔
684
  return code;
11,202,810✔
685
}
686

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

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

702
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
948,142!
703

704
end:
948,142✔
705
  taosArrayDestroy(schemas);
948,142✔
706
  return code;
948,142✔
707
}
708

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

714
  schemas = taosArrayInit(8, sizeof(SSchema));
661,839✔
715
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
663,111!
716

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

723
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
663,111!
724

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

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

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

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

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

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

749
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int32_t ver) {
982,814✔
750
  int32_t code = 0;
982,814✔
751
  int32_t lino = 0;
982,814✔
752
  SDecoder dcoder = {0};
982,814✔
753
  tDecoderInit(&dcoder, data, len);
982,814✔
754
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
982,814✔
755
    if (rsp->deleteBlock == NULL) {
133,024✔
756
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
45,928!
757
    }
758
      
759
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
133,024!
760
  } else if (msgType == TDMT_VND_DROP_TABLE && sStreamReaderInfo->deleteOutTbl != 0) {
849,790✔
761
    if (rsp->dropBlock == NULL) {
1,300!
762
      STREAM_CHECK_RET_GOTO(createBlockForDropTable((SSDataBlock**)&rsp->dropBlock));
1,300!
763
    }
764
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
1,300!
765
  } else if (msgType == TDMT_VND_DROP_STB) {
848,490!
766
    STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
×
767
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
848,490✔
768
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, data, len));
129,426!
769
  } else if (msgType == TDMT_VND_ALTER_STB) {
719,064✔
770
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
771
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
503,218✔
772
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, data, len));
159,493!
773
  }
774

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

785
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
16,728,552✔
786
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
16,720,757!
787
  code = walReaderSeekVer(pWalReader, rsp->ver);
16,720,757✔
788
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
16,707,856✔
789
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
15,347,033!
790
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
791
    }
792
    ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
15,357,415✔
793
    code = TSDB_CODE_SUCCESS;
15,359,955✔
794
    goto end;
15,359,955✔
795
  }
796
  STREAM_CHECK_RET_GOTO(code);
1,360,823!
797

798
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
1,360,823!
799
  while (1) {
11,688,281✔
800
    code = walNextValidMsg(pWalReader, true);
13,049,104✔
801
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){\
13,045,402✔
802
      ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
1,360,986✔
803
      code = TSDB_CODE_SUCCESS;
1,364,745✔
804
      goto end;
1,364,745✔
805
    }
806
    STREAM_CHECK_RET_GOTO(code);
11,684,416!
807
    rsp->ver = pWalReader->curVersion;
11,684,416✔
808
    SWalCont* wCont = &pWalReader->pHead->head;
11,687,017✔
809
    rsp->verTime = wCont->ingestTs;
11,685,813✔
810
    if (wCont->ingestTs / 1000 > ctime) break;
11,686,997!
811
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
11,687,039✔
812
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
11,685,692✔
813
    int64_t ver = wCont->version;
11,693,451✔
814

815
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
11,689,612✔
816
      TD_VID(pVnode), ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
817
    if (wCont->msgType == TDMT_VND_SUBMIT) {
11,695,992✔
818
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
11,211,736✔
819
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
11,214,275✔
820
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
11,213,016!
821
    } else {
822
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
482,927!
823
    }
824

825
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
11,688,296!
826
      break;
×
827
    }
828
  }
829

830
end:
16,724,700✔
831
  walCloseReader(pWalReader);
16,724,700✔
832
  return code;
16,722,161✔
833
}
834

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

842
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
8,791,358!
843
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
8,792,628!
844
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
8,795,204!
845
  if (numOfExpr == 0) {
8,792,634!
846
    return TSDB_CODE_SUCCESS;
×
847
  }
848

849
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
8,792,634✔
850
  if (uidData == NULL) {
8,797,758✔
851
    api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
408,862✔
852
    code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
408,862✔
853
    api->metaReaderFn.readerReleaseLock(&mr);
408,862✔
854
    STREAM_CHECK_RET_GOTO(code);
408,862!
855

856
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
408,862✔
857
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
408,862!
858
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
408,862!
859
      taosArrayDestroyP(tagCache, taosMemFree);
×
860
      code = terrno;
×
861
      goto end;
×
862
    }
863
  } else {
864
    tagCache = *(SArray**)uidData;
8,388,896✔
865
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
8,387,622!
866
  }
867
  
868
  for (int32_t j = 0; j < numOfExpr; ++j) {
23,761,975✔
869
    const SExprInfo* pExpr1 = &pExprInfo[j];
14,961,608✔
870
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
14,962,888✔
871

872
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
14,965,448✔
873
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
14,962,876!
874
    int32_t functionId = pExpr1->pExpr->_function.functionId;
14,962,876✔
875

876
    // this is to handle the tbname
877
    if (fmIsScanPseudoColumnFunc(functionId)) {
14,962,870✔
878
      int32_t fType = pExpr1->pExpr->_function.functionType;
8,797,746✔
879
      if (fType == FUNCTION_TYPE_TBNAME) {
8,797,746!
880
        char   buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
8,797,746✔
881
        if (uidData == NULL) {
8,796,472✔
882
          STR_TO_VARSTR(buf, mr.me.name)
407,590!
883
          char* tbname = taosStrdup(mr.me.name);
407,590!
884
          STREAM_CHECK_NULL_GOTO(tbname, terrno);
408,862!
885
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno);
817,724!
886
        } else {
887
          char* tbname = taosArrayGetP(tagCache, j);
8,388,882✔
888
          STR_TO_VARSTR(buf, tbname)
8,392,742!
889
        }
890
        code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false);
8,795,198✔
891
        // stInfo("set pseudo column tbname:%s currentRow:%d, numOfRows:%d, dstSlotId:%d, totalRows:%"PRId64" for uid:%" PRIu64 ", %p,%p", buf + VARSTR_HEADER_SIZE, 
892
        //   currentRow, numOfRows, dstSlotId, pBlock->info.rows, uid, pColInfoData, pColInfoData->pData);
893
        pColInfoData->info.colId = -1;
8,799,052✔
894
      }
895
    } else {  // these are tags
896
      char* data = NULL;
6,163,838✔
897
      const char* p = NULL;
6,162,558✔
898
      STagVal tagVal = {0};
6,162,558✔
899
      if (uidData == NULL) {
6,162,558✔
900
        tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
318,481✔
901
        p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
318,481✔
902

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

909
        if (data == NULL) {
318,481!
910
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
×
911
        } else {
912
          int32_t len = pColInfoData->info.bytes;
318,481✔
913
          if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
318,481!
914
            len = calcStrBytesByType(pColInfoData->info.type, (char*)data);
90,879✔
915
          }
916
          char* pData = taosMemoryCalloc(1, len);
318,481!
917
          STREAM_CHECK_NULL_GOTO(pData, terrno);
318,481!
918
          (void)memcpy(pData, data, len);
318,481!
919
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno);
636,962!
920
        }
921
      } else {
922
        data = taosArrayGetP(tagCache, j);
5,844,077✔
923
      }
924

925
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
6,162,558!
926
      if (isNullVal) {
6,162,558!
927
        colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
928
      } else {
929
        for (uint32_t i = 0; i < numOfRows && !IS_VAR_DATA_TYPE(pColInfoData->info.type); i++){
13,191,147!
930
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
7,028,589!
931
        }
932
        code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false);
6,165,124✔
933
        if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
6,166,404!
934
          taosMemoryFree(data);
90,879!
935
        }
936
        STREAM_CHECK_RET_GOTO(code);
6,166,404!
937
      }
938
    }
939
  }
940

941
end:
8,804,172✔
942
  api->metaReaderFn.clearReader(&mr);
8,799,052✔
943
  return code;
8,797,772✔
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, 
16,237,565✔
992
  STSchema** schemas, SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
993
  int32_t code = 0;
16,237,565✔
994
  int32_t lino = 0;
16,237,565✔
995
  uint64_t id = 0;
16,237,565✔
996
  WalMetaResult walMeta = {0};
16,243,965✔
997
  void* pTask = sStreamReaderInfo->pTask;
16,245,245✔
998
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
16,247,805✔
999

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

1005
  SSubmitTbData submitTbData = {0};
16,255,617✔
1006
  uint8_t       version = 0;
16,255,617✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
16,254,337!
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
16,254,337✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
16,254,337✔
1013
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1014
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
16,254,337✔
1015
    if (tStartDecode(pCoder) < 0) {
127,504!
1016
      code = TSDB_CODE_INVALID_MSG;
×
1017
      TSDB_CHECK_CODE(code, lino, end);
×
1018
    }
1019
    tEndDecode(pCoder);
127,504✔
1020
  }
1021

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

1034
  walMeta.id = id;
12,661,577✔
1035
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
12,661,577✔
1036

1037
  if (ranges != NULL){
12,666,715✔
1038
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
8,224,782✔
1039
    if (timerange == NULL) goto end;;
8,224,782!
1040
    int64_t* pRange = (int64_t*)timerange;
8,224,782✔
1041
    window.skey = pRange[0];
8,224,782✔
1042
    window.ekey = pRange[1];
8,224,782✔
1043
  }
1044
  
1045
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
12,660,315!
1046
    code = TSDB_CODE_INVALID_MSG;
×
1047
    TSDB_CHECK_CODE(code, lino, end);
×
1048
  }
1049

1050
  STSchema*    schema = NULL;
12,660,315✔
1051
  if (sStreamReaderInfo->isVtableStream) {
12,660,315!
1052
    if (*schemas == NULL) {
4,102,214!
1053
      *schemas = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
4,102,214✔
1054
      STREAM_CHECK_NULL_GOTO(*schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
4,102,214!
1055
    }
1056
    schema = *schemas;
4,102,214✔
1057
  } else {
1058
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != submitTbData.sver) {
8,560,661✔
1059
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
265,386!
1060
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
265,386✔
1061
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
265,386!
1062
    }
1063
    schema = sStreamReaderInfo->triggerTableSchema;
8,555,541✔
1064
  }
1065
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &submitTbData.uid, LONG_BYTES);
12,661,630✔
1066
  STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
12,661,644!
1067
  int32_t blockStart = pSlice->currentRowIdx;
12,661,644✔
1068

1069
  int32_t numOfRows = 0;
12,661,644✔
1070
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
12,655,279!
1071
    uint64_t nColData = 0;
×
1072
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1073
      code = TSDB_CODE_INVALID_MSG;
×
1074
      TSDB_CHECK_CODE(code, lino, end);
×
1075
    }
1076

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

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

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

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

1110
      pCoder->pos = pos;
×
1111

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

1166
      if (iRow == 0){
19,243,878✔
1167
#ifndef NO_UNALIGNED_ACCESS
1168
        walMeta.skey = pRow->ts;
12,660,406✔
1169
#else
1170
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1171
#endif
1172
      }
1173
      if (iRow == nRow - 1) {
19,241,318✔
1174
#ifndef NO_UNALIGNED_ACCESS
1175
        walMeta.ekey = pRow->ts;
12,659,126✔
1176
#else
1177
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1178
#endif
1179
      }
1180

1181
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
19,237,443!
1182
        continue;
45,659✔
1183
      }
1184
     
1185
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
135,871,630✔
1186
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
116,659,461✔
1187
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
116,665,858!
1188
        if (pColData->info.colId <= -1) {
116,665,858✔
1189
          pColData->hasNull = true;
36,471,321✔
1190
          continue;
36,472,602✔
1191
        }
1192
        int16_t colId = 0;
80,235,398✔
1193
        if (sStreamReaderInfo->isVtableStream){
80,235,398!
1194
          int64_t id[2] = {submitTbData.suid, submitTbData.uid};
10,531,580✔
1195
          void* px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
10,531,580!
1196
          STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
10,530,301!
1197
          SSHashObj* uInfo = *(SSHashObj**)px;
10,530,301✔
1198
          STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
10,527,761!
1199
          int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
10,527,761✔
1200
          if (tmp != NULL) {
10,530,261✔
1201
            colId = *tmp;
9,079,569✔
1202
          } else {
1203
            colId = -1;
1,450,692✔
1204
          }
1205
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
10,532,821!
1206
        } else {
1207
          colId = pColData->info.colId;
69,705,098✔
1208
        }
1209
        
1210
        SColVal colVal = {0};
80,230,233✔
1211
        int32_t sourceIdx = 0;
80,231,513✔
1212
        while (1) {
1213
          if (sourceIdx >= schema->numOfCols) {
214,556,795✔
1214
            break;
38,904,213✔
1215
          }
1216
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
175,616,757!
1217
          if (colVal.cid == colId) {
175,669,264✔
1218
            break;
41,343,982✔
1219
          }
1220
          sourceIdx++;
134,325,282✔
1221
        }
1222
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
80,248,195✔
1223
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
40,782,588!
1224
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
135,877!
1225
            // ST_TASK_ILOG("%s vtable colId:%d, i:%d, colData:%p, data:%s, len:%d, rowIndex:%d, offset:%d, uid:%" PRId64, __func__, colId, i, pColData, 
1226
            //   (const char*)colVal.value.pData, colVal.value.nData, blockStart+ numOfRows, pColData->varmeta.offset[blockStart+ numOfRows], submitTbData.uid);
1227
          } else {
1228
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
40,646,725!
1229
          }
1230
        } else {
1231
          colDataSetNULL(pColData, blockStart + numOfRows);
39,465,607!
1232
        }
1233
      }
1234
      
1235
      numOfRows++;
19,205,808✔
1236
    }
1237
  }
1238

1239
  if (numOfRows > 0) {
12,666,715!
1240
    if (!sStreamReaderInfo->isVtableStream) {
12,666,715✔
1241
      SStorageAPI  api = {0};
8,559,381✔
1242
      initStorageAPI(&api);
8,555,541✔
1243
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
8,551,720!
1244
    }
1245
    
1246
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
12,665,443✔
1247
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
12,656,483!
1248
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
12,656,483!
1249
  }
1250

1251
  ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
12,664,163✔
1252
    ", uid:%" PRId64 ", ver:%d, row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1253
    id, submitTbData.uid, submitTbData.sver, pSlice->currentRowIdx, numOfRows);
1254
  pSlice->currentRowIdx += numOfRows;
12,665,435✔
1255
  pBlock->info.rows += numOfRows;
12,666,715✔
1256
  
1257
  if (gidHash == NULL) goto end;
12,664,155✔
1258

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

1267
end:
16,244,544✔
1268
  if (code != 0) {                                                             \
16,250,491!
1269
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1270
  }
1271
  tEndDecode(pCoder);
16,250,491✔
1272
  return code;
16,253,060✔
1273
}
1274
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
16,244,123✔
1275
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1276
  int32_t  code = 0;
16,244,123✔
1277
  int32_t  lino = 0;
16,244,123✔
1278
  STSchema* schemas = NULL;
16,244,123✔
1279
  SDecoder decoder = {0};
16,245,368✔
1280
  SSHashObj* gidHash = NULL;
16,253,048✔
1281
  void* pTask = sStreamReaderInfo->pTask;
16,253,048✔
1282

1283
  tDecoderInit(&decoder, data, len);
16,255,608✔
1284
  if (tStartDecode(&decoder) < 0) {
16,249,208!
1285
    code = TSDB_CODE_INVALID_MSG;
×
1286
    TSDB_CHECK_CODE(code, lino, end);
×
1287
  }
1288

1289
  uint64_t nSubmitTbData = 0;
16,251,777✔
1290
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
16,244,082!
1291
    code = TSDB_CODE_INVALID_MSG;
×
1292
    TSDB_CHECK_CODE(code, lino, end);
×
1293
  }
1294

1295
  if (rsp->metaBlock != NULL){
16,244,082✔
1296
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
8,025,700✔
1297
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
8,026,857!
1298
  }
1299

1300
  for (int32_t i = 0; i < nSubmitTbData; i++) {
32,494,475✔
1301
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, &schemas, ranges, gidHash, rsp, ver));
16,243,959!
1302
  }
1303

1304
  tEndDecode(&decoder);
16,250,516✔
1305

1306
  if (rsp->metaBlock != NULL){
16,250,516✔
1307
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
8,030,854!
1308
    int32_t iter = 0;
8,024,458✔
1309
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
8,023,178✔
1310
    while (px != NULL) {
12,468,922✔
1311
      WalMetaResult* pMeta = (WalMetaResult*)px;
4,441,933✔
1312
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
4,441,933!
1313
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
4,441,927✔
1314
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
4,441,927✔
1315
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1316
      px = tSimpleHashIterate(gidHash, px, &iter);
4,441,927✔
1317
    }
1318
  }
1319
  
1320

1321
end:
16,238,706✔
1322
  taosMemoryFree(schemas);
16,254,331!
1323
  tSimpleHashCleanup(gidHash);
16,256,765✔
1324
  tDecoderClear(&decoder);
16,250,488✔
1325
  return code;
16,259,448✔
1326
}
1327

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

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

1339
  SSubmitTbData submitTbData = {0};
19,733,885✔
1340
  uint8_t       version = 0;
19,733,885✔
1341
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
19,727,478!
1342
    code = TSDB_CODE_INVALID_MSG;
×
1343
    TSDB_CHECK_CODE(code, lino, end);
×
1344
  }
1345
  version = (submitTbData.flags >> 8) & 0xff;
19,727,478✔
1346
  submitTbData.flags = submitTbData.flags & 0xff;
19,727,478✔
1347

1348
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1349
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
19,727,478✔
1350
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,718,118!
1351
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,711,747!
1352
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,711,747!
1353
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
1,715,558!
1354
  }
1355

1356
  // submit data
1357
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
19,721,048!
1358
    code = TSDB_CODE_INVALID_MSG;
×
1359
    TSDB_CHECK_CODE(code, lino, end);
×
1360
  }
1361
  if (tDecodeI64(pCoder, uid) < 0) {
19,731,618!
1362
    code = TSDB_CODE_INVALID_MSG;
×
1363
    TSDB_CHECK_CODE(code, lino, end);
×
1364
  }
1365

1366
  STREAM_CHECK_CONDITION_GOTO(!uidInTableList(sStreamReaderInfo, submitTbData.suid, *uid, gid, isCalc), TDB_CODE_SUCCESS);
19,731,618✔
1367

1368
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
12,664,149✔
1369

1370
  if (ranges != NULL){
12,662,869✔
1371
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
8,222,222✔
1372
    if (timerange == NULL) goto end;;
8,224,782!
1373
    int64_t* pRange = (int64_t*)timerange;
8,224,782✔
1374
    window.skey = pRange[0];
8,224,782✔
1375
    window.ekey = pRange[1];
8,224,782✔
1376
  }
1377
  
1378
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
12,666,735!
1379
    code = TSDB_CODE_INVALID_MSG;
×
1380
    TSDB_CHECK_CODE(code, lino, end);
×
1381
  }
1382

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

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

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

1415
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
12,660,547✔
1416
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
22,831,160✔
1417
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
14,608,599✔
1418
        pCoder->pos += pRow->len;
14,609,844✔
1419
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
14,609,844!
1420
          continue;
45,659✔
1421
        }
1422
        (*numOfRows)++;
14,564,185✔
1423
      }
1424
    } else {
1425
      (*numOfRows) = nRow;
4,436,706✔
1426
    }
1427
  }
1428
  
1429
end:
19,715,873✔
1430
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
19,714,672✔
1431
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
19,722,372!
1432
  tEndDecode(pCoder);
19,721,086✔
1433
  return code;
19,713,690✔
1434
}
1435

1436
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
19,713,315✔
1437
  int32_t  code = 0;
19,713,315✔
1438
  int32_t  lino = 0;
19,713,315✔
1439
  SDecoder decoder = {0};
19,713,315✔
1440
  void* pTask = sStreamReaderInfo->pTask;
19,730,033✔
1441

1442
  tDecoderInit(&decoder, data, len);
19,728,747✔
1443
  if (tStartDecode(&decoder) < 0) {
19,721,049!
1444
    code = TSDB_CODE_INVALID_MSG;
×
1445
    TSDB_CHECK_CODE(code, lino, end);
×
1446
  }
1447

1448
  uint64_t nSubmitTbData = 0;
19,718,511✔
1449
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
19,726,233!
1450
    code = TSDB_CODE_INVALID_MSG;
×
1451
    TSDB_CHECK_CODE(code, lino, end);
×
1452
  }
1453

1454
  for (int32_t i = 0; i < nSubmitTbData; i++) {
39,448,573✔
1455
    uint64_t gid = -1;
19,715,951✔
1456
    int64_t  uid = 0;
19,715,925✔
1457
    int32_t numOfRows = 0;
19,721,069✔
1458
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp->isCalc));
19,721,069!
1459
    if (numOfRows <= 0) {
19,704,729✔
1460
      continue;
7,056,893✔
1461
    }
1462
    rsp->totalRows += numOfRows;
12,647,836✔
1463

1464
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &uid, LONG_BYTES);
12,658,038✔
1465
    if (pSlice != NULL) {
12,662,765✔
1466
      pSlice->numRows += numOfRows;
12,102,778✔
1467
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d", __func__, uid, gid, pSlice->numRows);
12,102,778✔
1468
      pSlice->gId = gid;
12,102,778✔
1469
    } else {
1470
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
559,987✔
1471
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d", __func__, uid, gid, tmp.numRows);
559,080✔
1472
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(sStreamReaderInfo->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
560,352!
1473
    } 
1474
  }
1475

1476
  tEndDecode(&decoder);
19,732,622✔
1477

1478
end:
19,721,049✔
1479
  tDecoderClear(&decoder);
19,724,901✔
1480
  return code;
19,712,098✔
1481
}
1482

1483
static void resetIndexHash(SSHashObj* indexHash){
18,467,454✔
1484
  void*   pe = NULL;
18,467,454✔
1485
  int32_t iter = 0;
18,467,454✔
1486
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
44,379,984✔
1487
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
25,925,357✔
1488
    pInfo->startRowIdx = 0;
25,925,357✔
1489
    pInfo->currentRowIdx = 0;
25,925,357✔
1490
    pInfo->numRows = 0;
25,900,941✔
1491
    pInfo->gId = -1;
25,907,318✔
1492
  }
1493
}
18,473,699✔
1494

1495
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
1,368,890✔
1496
  void*   pe = NULL;
1,368,890✔
1497
  int32_t iter = 0;
1,368,890✔
1498
  int32_t index = 0;
1,368,890✔
1499
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
4,903,924✔
1500
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
3,535,034✔
1501
    pInfo->startRowIdx = index;
3,535,034✔
1502
    pInfo->currentRowIdx = index;
3,535,034✔
1503
    index += pInfo->numRows;
3,535,034✔
1504
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
4,536,567!
1505
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1506
  }
1507
}
1,368,890✔
1508

1509
static void printIndexHash(SSHashObj* indexHash, void* pTask){
1,366,318✔
1510
  void*   pe = NULL;
1,366,318✔
1511
  int32_t iter = 0;
1,366,318✔
1512
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
4,896,214✔
1513
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
3,529,896✔
1514
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
4,531,429!
1515
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1516
  }
1517
}
1,366,318✔
1518

1519
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
33,167✔
1520
  void*   pe = NULL;
33,167✔
1521
  int32_t iter = 0;
33,167✔
1522
  int32_t index = 0;
33,167✔
1523
  int32_t pIndex = 0;
33,167✔
1524
  int8_t* pIndicator = (int8_t*)pRet->pData;
33,167✔
1525
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
102,117✔
1526
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
68,950✔
1527
    pInfo->startRowIdx = index;
68,950✔
1528
    int32_t size = pInfo->numRows;
68,950✔
1529
    for (int32_t i = 0; i < pInfo->numRows; i++) {
434,349✔
1530
      if (pIndicator && !pIndicator[pIndex++]) {
365,399!
1531
        size--;
135,291✔
1532
      }
1533
    }
1534
    pInfo->numRows = size;
68,950✔
1535
    index += pInfo->numRows;
68,950✔
1536
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
68,950!
1537
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1538
  }
1539
}
33,167✔
1540

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

1546
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
10,564,070✔
1547
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
10,570,505✔
1548
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
9,230,877!
1549
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
1550
    }
1551
    ST_TASK_DLOG("%s scan wal error:%s",  __func__, tstrerror(code));
9,222,119✔
1552
    code = TSDB_CODE_SUCCESS;
9,224,678✔
1553
    goto end;
9,224,678✔
1554
  }
1555
  STREAM_CHECK_RET_GOTO(code);
1,339,628!
1556

1557
  while (1) {
11,998,731✔
1558
    code = walNextValidMsg(pWalReader, true);
13,338,359✔
1559
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
13,331,952✔
1560
      ST_TASK_DLOG("%s scan wal error:%s", __func__, tstrerror(code));
1,335,918✔
1561
      code = TSDB_CODE_SUCCESS;
1,338,498✔
1562
      goto end;
1,338,498✔
1563
    }
1564
    STREAM_CHECK_RET_GOTO(code);
11,996,034!
1565
    resultRsp->ver = pWalReader->curVersion;
11,996,034✔
1566
    SWalCont* wCont = &pWalReader->pHead->head;
12,001,178✔
1567
    resultRsp->verTime = wCont->ingestTs;
12,003,698✔
1568
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
11,997,314✔
1569
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
12,006,242✔
1570
    int64_t ver = wCont->version;
12,009,150✔
1571
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d", __func__,
12,005,093✔
1572
      ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1573
    if (wCont->msgType == TDMT_VND_SUBMIT) {
12,011,468✔
1574
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
11,500,118✔
1575
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
11,505,256✔
1576
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp));
11,509,114!
1577
    } else if (wCont->msgType == TDMT_VND_ALTER_TABLE && resultRsp->totalRows > 0) {
506,112✔
1578
      resultRsp->ver--;
6,225✔
1579
      break;
3,735✔
1580
    } else {
1581
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
499,887!
1582
    }
1583

1584
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
11,991,015✔
1585
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
11,993,558!
1586
      break;
×
1587
    }
1588
  }
1589
  
1590
end:
10,566,835✔
1591
  STREAM_PRINT_LOG_END(code, lino);
10,566,835!
1592
  return code;
10,566,849✔
1593
}
1594

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

1600
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
16,126,674✔
1601
    int64_t *ver = taosArrayGet(versions, i);
8,220,963✔
1602
    if (ver == NULL) continue;
8,222,243!
1603

1604
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,222,243!
1605
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,222,242!
1606
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1607
      continue;
×
1608
    }
1609
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,222,242!
1610

1611
    SWalCont* wCont = &pWalReader->pHead->head;
8,223,503✔
1612
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,223,503✔
1613
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,223,503✔
1614

1615
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp));
8,223,503!
1616
  }
1617
  
1618
end:
7,903,171✔
1619
  return code;
7,903,171✔
1620
}
1621

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

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

1630
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
1,368,890✔
1631
    filterIndexHash(sStreamReaderInfo->indexHash, pRet);
33,167✔
1632
  }
1633

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

1640
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
10,571,943✔
1641
                                    SSTriggerWalNewRsp* resultRsp) {
1642
  int32_t      code = 0;
10,571,943✔
1643
  int32_t      lino = 0;
10,571,943✔
1644
  void* pTask = sStreamReaderInfo->pTask;
10,571,943✔
1645
                                        
1646
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
10,575,789✔
1647
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
10,569,395!
1648
  resetIndexHash(sStreamReaderInfo->indexHash);
10,569,395✔
1649
  blockDataEmpty(resultRsp->dataBlock);
10,573,054✔
1650
  blockDataEmpty(resultRsp->metaBlock);
10,569,314✔
1651
  int64_t lastVer = resultRsp->ver;                                      
10,552,829✔
1652
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
10,552,829!
1653
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
10,565,569✔
1654

1655
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
400,344✔
1656
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
400,344!
1657
  while(lastVer < resultRsp->ver) {
8,774,049✔
1658
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
8,374,985!
1659
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,363,465✔
1660
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
340,319!
1661
      continue;
340,319✔
1662
    }
1663
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,025,706!
1664
    SWalCont* wCont = &pWalReader->pHead->head;
8,024,420✔
1665
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,026,980✔
1666
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,026,980✔
1667

1668
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
8,026,986!
1669
  }
1670

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

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

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

1687
  void* pTask = sStreamReaderInfo->pTask;
7,904,450✔
1688
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
7,904,450✔
1689
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
7,903,170!
1690
  
1691
  if (taosArrayGetSize(versions) > 0) {
7,903,170✔
1692
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
968,546✔
1693
  }
1694
  
1695
  resetIndexHash(sStreamReaderInfo->indexHash);
7,903,171✔
1696
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
7,903,171!
1697
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
7,903,171✔
1698

1699
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
968,546✔
1700

1701
  blockDataEmpty(rsp->dataBlock);
968,546✔
1702
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
968,546!
1703

1704
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
9,188,209✔
1705
    int64_t *ver = taosArrayGet(versions, i);
8,220,943✔
1706
    if (ver == NULL) continue;
8,218,384!
1707

1708
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,218,384!
1709
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,222,222!
1710
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1711
      continue;
×
1712
    }
1713
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,220,942!
1714
    SWalCont* wCont = &pWalReader->pHead->head;
8,222,222✔
1715
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,218,382✔
1716
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,220,942✔
1717

1718
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
8,222,222!
1719
  }
1720
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
1721
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
969,826!
1722
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
968,546✔
1723

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

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

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

1755
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
963,835✔
1756
    SSchema* s = sSchemaWrapper->pSchema + j;
763,150✔
1757
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
1,526,300!
1758
  }
1759

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

1770
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
200,685✔
1771
  int32_t code = 0;
200,685✔
1772
  int32_t lino = 0;
200,685✔
1773
  size_t  schemaLen = taosArrayGetSize(schemas);
200,685✔
1774
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
200,685!
1775
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
618,395✔
1776
    col_id_t* id = taosArrayGet(cols, i);
417,710✔
1777
    STREAM_CHECK_NULL_GOTO(id, terrno);
417,710!
1778
    for (size_t i = 0; i < schemaLen; i++) {
815,715!
1779
      SSchema* s = taosArrayGet(schemas, i);
815,715✔
1780
      STREAM_CHECK_NULL_GOTO(s, terrno);
815,715!
1781
      if (*id == s->colId) {
815,715✔
1782
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
417,710!
1783
        break;
417,710✔
1784
      }
1785
    }
1786
  }
1787
  taosArrayPopFrontBatch(schemas, schemaLen);
200,685✔
1788

1789
end:
200,685✔
1790
  return code;
200,685✔
1791
}
1792

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

1799
  SSDataBlock* pBlock2 = NULL;
×
1800

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1880
  *pCond = cond;
×
1881

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

1894
  return code;
×
1895
}
1896

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

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

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

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

1930
  *pCond = cond;
1931

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

1939
  return code;
1940
}
1941
*/
1942

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

1960
    if (!node->needCalc) {
260,614✔
1961
      pWin->skey = pFirst->wstart;
196,110✔
1962
      pWin->ekey = pLast->wend;
196,110✔
1963
      *pValid = true;
196,110✔
1964
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
196,110✔
1965
        pWin->ekey--;
135,753✔
1966
      }
1967
    } else {
1968
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
65,859✔
1969
      memcpy(pTmp, pFirst, sizeof(*pTmp));
65,859!
1970

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

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

1978
        if (*pValid) {
65,859!
1979
          pWin->skey = skey;
65,859✔
1980
        }
1981
      }
1982
      pWin->ekey--;
65,859✔
1983
    }
1984
  } else {
1985
    if (!node->needCalc) {
162,332!
1986
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
162,332✔
1987
      pWin->skey = pCurr->wstart;
162,332✔
1988
      pWin->ekey = pCurr->wend;
162,332✔
1989
      *pValid = true;
162,332✔
1990
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
162,332✔
1991
        pWin->ekey--;
145,820✔
1992
      }
1993
    } else {
1994
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
×
1995
      pWin->ekey--;
×
1996
    }
1997
  }
1998

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

2002
end:
40,990✔
2003

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

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

2016
  void* pTask = sStreamReaderInfo->pTask;
1,059,659✔
2017
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTaskInner->pTableList), sizeof(STsInfo));
1,065,997✔
2018
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
1,059,597!
2019
  while (true) {
694,348✔
2020
    bool hasNext = false;
1,753,945✔
2021
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,757,785!
2022
    if (hasNext) {
1,757,872!
2023
      pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
754,968✔
2024
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
749,908✔
2025
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
751,399!
2026
      if (pTaskInner->options.order == TSDB_ORDER_ASC) {
751,399✔
2027
        tsInfo->ts = pTaskInner->pResBlock->info.window.skey;
466,864✔
2028
      } else {
2029
        tsInfo->ts = pTaskInner->pResBlock->info.window.ekey;
288,070✔
2030
      }
2031
      tsInfo->gId = (sStreamReaderInfo->groupByTbname || sStreamReaderInfo->tableType != TSDB_SUPER_TABLE) ? 
1,680,539!
2032
                    pTaskInner->pResBlock->info.id.uid : qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
923,009✔
2033
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
755,215✔
2034
              tsInfo->gId, tsRsp->ver);
2035
    }
2036
    
2037
    pTaskInner->currentGroupIndex++;
1,760,610✔
2038
    if (pTaskInner->currentGroupIndex >= qStreamGetTableListGroupNum(pTaskInner->pTableList) || pTaskInner->options.gid != 0) {
1,756,555✔
2039
      break;
2040
    }
2041
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTaskInner));
694,356!
2042
  }
2043

2044
end:
1,062,209✔
2045
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,062,209!
2046
  return code;
1,065,997✔
2047
}
2048

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

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

2060
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
127,630✔
2061
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
127,630✔
2062
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
126,385!
2063
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
126,385!
2064

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

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

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

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

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

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

2096
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner));
602,668!
2097
  ST_TASK_DLOG("vgId:%d %s get result, ver:%" PRId64, TD_VID(pVnode), __func__, lastTsRsp.ver);
601,388✔
2098
  STREAM_CHECK_RET_GOTO(buildTsRsp(&lastTsRsp, &buf, &size))
601,388!
2099
  if (stDebugFlag & DEBUG_DEBUG) {
601,388✔
2100
    int32_t nInfo = taosArrayGetSize(lastTsRsp.tsInfo);
451,542✔
2101
    for (int32_t i = 0; i < nInfo; i++) {
687,126✔
2102
      STsInfo* tsInfo = TARRAY_GET_ELEM(lastTsRsp.tsInfo, i);
238,115✔
2103
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
238,115!
2104
    }
2105
  }
2106

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

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

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

2137
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(firstTsRsp.tsInfo), firstTsRsp.ver);
464,609✔
2138
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
464,609!
2139
  if (stDebugFlag & DEBUG_DEBUG) {
464,609✔
2140
    int32_t nInfo = taosArrayGetSize(firstTsRsp.tsInfo);
302,031✔
2141
    for (int32_t i = 0; i < nInfo; i++) {
564,083✔
2142
      STsInfo* tsInfo = TARRAY_GET_ELEM(firstTsRsp.tsInfo, i);
262,052✔
2143
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
262,052!
2144
    }
2145
  }
2146

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2277
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
45,304✔
2278

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

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

2289
  releaseStreamTask(&pTaskInner);
45,304✔
2290
  return code;
45,304✔
2291
}
2292

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

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

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

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

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

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

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

2341
  releaseStreamTask(&pTaskInner);
×
2342
  return code;
×
2343
}
2344

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

2351
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
377,174!
2352
  SStreamReaderTaskInner* pTaskInner = NULL;
377,174✔
2353
  void* pTask = sStreamReaderInfo->pTask;
377,174✔
2354
  ST_TASK_DLOG("vgId:%d %s start. ver:%"PRId64",order:%d,startTs:%"PRId64",gid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, req->tsdbTriggerDataReq.gid);
377,174✔
2355
  
2356
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
377,174✔
2357

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

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

2375
  blockDataCleanup(pTaskInner->pResBlockDst);
375,894✔
2376
  bool hasNext = true;
377,174✔
2377
  while (1) {
×
2378
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
377,174!
2379
    if (!hasNext) {
375,894!
2380
      break;
181,535✔
2381
    }
2382
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
194,359✔
2383
    pTaskInner->pResBlockDst->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
195,639✔
2384

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

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

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

2413
  return code;
377,174✔
2414
}
2415

2416
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
35,968,558✔
2417
  int32_t code = 0;
35,968,558✔
2418
  int32_t lino = 0;
35,968,558✔
2419
  void*   buf = NULL;
35,968,558✔
2420
  size_t  size = 0;
35,969,828✔
2421
  SSDataBlock*            pBlockRes = NULL;
35,969,828✔
2422

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

2428
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
35,971,098!
2429

2430
  SStreamReaderTaskInner* pTaskInner = NULL;
35,971,098✔
2431
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
35,971,098✔
2432

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

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

2449
  blockDataCleanup(pTaskInner->pResBlockDst);
35,797,914✔
2450
  bool hasNext = true;
35,801,724✔
2451
  while (1) {
3,107,629✔
2452
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
38,909,353!
2453
    if (!hasNext) {
38,892,992!
2454
      break;
35,791,569✔
2455
    }
2456
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
3,101,423✔
2457

2458
    SSDataBlock* pBlock = NULL;
3,111,409✔
2459
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
3,112,654!
2460
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
3,100,159!
2461
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3,103,939!
2462
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
3,103,894!
2463
      break;
×
2464
    }
2465
  }
2466

2467
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
35,791,569!
2468
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
35,795,424!
2469
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
35,791,589✔
2470
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
35,795,374!
2471
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
35,795,354✔
2472
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
35,801,724✔
2473
  if (!hasNext) {
35,797,914!
2474
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
35,797,914!
2475
  }
2476

2477
end:
35,959,718✔
2478
  STREAM_PRINT_LOG_END_WITHID(code, lino);
35,954,588!
2479
  SRpcMsg rsp = {
35,966,043✔
2480
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2481
  tmsgSendRsp(&rsp);
35,969,853✔
2482
  blockDataDestroy(pBlockRes);
35,963,478✔
2483
  return code;
35,964,748✔
2484
}
2485

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

2503
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
200,685!
2504
    // sort cid and build slotIdList
2505
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
200,685!
2506
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
200,685!
2507
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
200,685✔
2508
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
200,685!
2509
    taosArraySort(sortedCid, sortCid);
200,685✔
2510
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
618,395✔
2511
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
417,710✔
2512
      STREAM_CHECK_NULL_GOTO(cid, terrno);
417,710!
2513
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
659,790!
2514
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
659,790✔
2515
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
659,790!
2516
        if (*cid == *cidSorted) {
659,790✔
2517
          slotIdList[j] = i;
417,710✔
2518
          break;
417,710✔
2519
        }
2520
      }
2521
    }
2522

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

2528
    options.suid = req->tsdbDataReq.suid;
200,685✔
2529
    options.uid = req->tsdbDataReq.uid;
200,685✔
2530

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

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

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

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

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

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

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

2594
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
16,804,197✔
2595
  void* pTask = sStreamReaderInfo->pTask;
16,731,096✔
2596
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
16,715,771✔
2597

2598
  if (sStreamReaderInfo->metaBlock == NULL) {
16,714,512✔
2599
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
374,540!
2600
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
374,540!
2601
  }
2602
  blockDataEmpty(sStreamReaderInfo->metaBlock);
16,729,837✔
2603
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
16,713,256✔
2604
  resultRsp.ver = req->walMetaNewReq.lastVer;
16,714,520✔
2605
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
16,714,521!
2606

2607
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
16,723,440✔
2608
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
16,725,995✔
2609
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, NULL);
312,896✔
2610
  buf = rpcMallocCont(size);
312,896✔
2611
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, NULL);
312,896✔
2612
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
312,896✔
2613

2614
end:
16,799,096✔
2615
  if (resultRsp.totalRows == 0) {
16,797,836✔
2616
    code = TSDB_CODE_STREAM_NO_DATA;
16,488,779✔
2617
    buf = rpcMallocCont(sizeof(int64_t));
16,488,779✔
2618
    *(int64_t *)buf = resultRsp.ver;
16,460,604✔
2619
    size = sizeof(int64_t);
16,461,883✔
2620
  }
2621
  SRpcMsg rsp = {
16,770,940✔
2622
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2623
  tmsgSendRsp(&rsp);
16,792,684✔
2624
  if (code == TSDB_CODE_STREAM_NO_DATA){
16,805,380✔
2625
    code = 0;
16,492,484✔
2626
  }
2627
  STREAM_PRINT_LOG_END_WITHID(code, lino);
16,805,380!
2628
  blockDataDestroy(resultRsp.deleteBlock);
16,806,721✔
2629
  blockDataDestroy(resultRsp.dropBlock);
16,802,937✔
2630

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

2644
  if (sStreamReaderInfo->metaBlock == NULL) {
10,574,503✔
2645
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
242,643!
2646
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
242,643!
2647
  }
2648
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
10,578,355✔
2649
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
10,577,069✔
2650
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
10,574,509✔
2651
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
10,573,229!
2652

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

2663
end:
10,570,675✔
2664
  if (resultRsp.totalRows == 0) {
10,570,675✔
2665
    buf = rpcMallocCont(sizeof(int64_t));
10,178,023✔
2666
    *(int64_t *)buf = resultRsp.ver;
10,153,726✔
2667
    size = sizeof(int64_t);
10,155,006✔
2668
    code = TSDB_CODE_STREAM_NO_DATA;
10,155,006✔
2669
  }
2670
  SRpcMsg rsp = {
10,547,658✔
2671
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2672
  tmsgSendRsp(&rsp);
10,559,171✔
2673
  if (code == TSDB_CODE_STREAM_NO_DATA){
10,580,908✔
2674
    code = 0;
10,184,435✔
2675
  }
2676
  blockDataDestroy(resultRsp.deleteBlock);
10,580,908✔
2677
  blockDataDestroy(resultRsp.dropBlock);
10,574,415✔
2678

2679
  STREAM_PRINT_LOG_END_WITHID(code, lino);
10,570,591!
2680

2681
  return code;
10,571,955✔
2682
}
2683

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

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

2695
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
6,859,429✔
2696
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
6,860,708!
2697
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
6,859,448✔
2698

2699
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
6,859,429✔
2700

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

2707
end:
6,859,429✔
2708
  if (resultRsp.totalRows == 0) {
6,859,429✔
2709
    buf = rpcMallocCont(sizeof(int64_t));
6,703,149✔
2710
    *(int64_t *)buf = resultRsp.ver;
6,700,625✔
2711
    size = sizeof(int64_t);
6,701,904✔
2712
    code = TSDB_CODE_STREAM_NO_DATA;
6,701,904✔
2713
  }
2714
  SRpcMsg rsp = {
6,858,184✔
2715
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2716
  tmsgSendRsp(&rsp);
6,859,463✔
2717
  if (code == TSDB_CODE_STREAM_NO_DATA){
6,858,150✔
2718
    code = 0;
6,703,149✔
2719
  }
2720

2721
  blockDataDestroy(resultRsp.deleteBlock);
6,858,150✔
2722
  blockDataDestroy(resultRsp.dropBlock);
6,858,184✔
2723
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,858,184!
2724

2725
  return code;
6,856,902✔
2726
}
2727

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

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

2746
  if (!sStreamReaderInfo->isVtableStream){
810,987!
2747
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, true, &pBlock1));
654,960!
2748
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
654,960!
2749
  
2750
    blockDataTransform(pBlock2, pBlock1);
654,960✔
2751
    resultRsp.dataBlock = pBlock2;
654,960✔
2752
  }
2753

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

2760
end:
1,043,742✔
2761
  if (resultRsp.totalRows == 0) {
1,043,742✔
2762
    buf = rpcMallocCont(sizeof(int64_t));
232,755✔
2763
    *(int64_t *)buf = resultRsp.ver;
232,755✔
2764
    size = sizeof(int64_t);
232,755✔
2765
    code = TSDB_CODE_STREAM_NO_DATA;
232,755✔
2766
  }
2767
  SRpcMsg rsp = {
1,043,742✔
2768
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2769
  tmsgSendRsp(&rsp);
1,043,742✔
2770
  if (code == TSDB_CODE_STREAM_NO_DATA){
1,043,742✔
2771
    code = 0;
232,755✔
2772
  }
2773

2774
  blockDataDestroy(pBlock1);
1,043,742✔
2775
  blockDataDestroy(pBlock2);
1,043,742✔
2776
  blockDataDestroy(resultRsp.deleteBlock);
1,042,462✔
2777
  blockDataDestroy(resultRsp.dropBlock);
1,043,742✔
2778
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,043,742!
2779

2780
  return code;
1,043,742✔
2781
}
2782

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

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

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

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

2815
  return code;
881,026✔
2816
}
2817

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

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

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

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

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

2842
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
1,914,661✔
2843
    STableKeyInfo* pKeyInfo = taosArrayGet(pTableListArray, i);
1,141,439✔
2844
    if (pKeyInfo == NULL) {
1,142,718!
2845
      continue;
×
2846
    }
2847
    VTableInfo* vTable = taosArrayReserve(vTableInfo.infos, 1);
1,142,718✔
2848
    STREAM_CHECK_NULL_GOTO(vTable, terrno);
1,142,718!
2849
    vTable->uid = pKeyInfo->uid;
1,142,718✔
2850
    vTable->gId = pKeyInfo->groupId;
1,142,718✔
2851

2852
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
1,142,718✔
2853
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
1,142,718!
2854
      vTable->cols.nCols = metaReader.me.colRef.nCols;
54,780✔
2855
      vTable->cols.version = metaReader.me.colRef.version;
54,780✔
2856
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
54,780!
2857
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
328,680✔
2858
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
273,900!
2859
      }
2860
    } else {
2861
      vTable->cols.nCols = taosArrayGetSize(cids);
1,087,938✔
2862
      vTable->cols.version = metaReader.me.colRef.version;
1,087,938✔
2863
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
1,087,938!
2864
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
3,640,077✔
2865
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
12,798,265✔
2866
          if (metaReader.me.colRef.pColRef[j].hasRef &&
11,715,424!
2867
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
9,044,399✔
2868
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
1,469,298!
2869
            break;
1,471,856✔
2870
          }
2871
        }
2872
      }
2873
    }
2874
    tDecoderClear(&metaReader.coder);
1,141,439✔
2875
  }
2876
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
773,222✔
2877
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
773,222!
2878

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

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

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

2902
  SArray* cols = req->origTableInfoReq.cols;
127,630✔
2903
  STREAM_CHECK_NULL_GOTO(cols, terrno);
127,630!
2904

2905
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
127,630✔
2906

2907
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
127,630!
2908

2909
  api.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api.metaFn);
127,630✔
2910
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
340,276✔
2911
    OTableInfo*    oInfo = taosArrayGet(cols, i);
212,646✔
2912
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
212,646✔
2913
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
212,646!
2914
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
212,646!
2915
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByName(&metaReader, oInfo->refTableName));
212,646!
2916
    vTableInfo->uid = metaReader.me.uid;
211,366✔
2917
    stsDebug("vgId:%d %s uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
212,646✔
2918

2919
    SSchemaWrapper* sSchemaWrapper = NULL;
211,366✔
2920
    if (metaReader.me.type == TD_CHILD_TABLE) {
211,366✔
2921
      int64_t suid = metaReader.me.ctbEntry.suid;
206,250✔
2922
      vTableInfo->suid = suid;
206,250✔
2923
      tDecoderClear(&metaReader.coder);
207,530✔
2924
      STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
206,250!
2925
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
206,250✔
2926
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
5,116!
2927
      vTableInfo->suid = 0;
5,116✔
2928
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
5,116✔
2929
    } else {
2930
      stError("invalid table type:%d", metaReader.me.type);
×
2931
    }
2932

2933
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
961,846!
2934
      SSchema* s = sSchemaWrapper->pSchema + j;
960,566✔
2935
      if (strcmp(s->name, oInfo->refColName) == 0) {
959,286!
2936
        vTableInfo->cid = s->colId;
212,646✔
2937
        break;
212,646✔
2938
      }
2939
    }
2940
    if (vTableInfo->cid == 0) {
212,646!
2941
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
2942
              oInfo->refTableName);
2943
    }
2944
    tDecoderClear(&metaReader.coder);
212,646✔
2945
  }
2946

2947
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
127,630!
2948

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

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

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

2971
  SStorageAPI api = {0};
409,060✔
2972
  initStorageAPI(&api);
409,060✔
2973

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

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

2980
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
409,060!
2981

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

2997
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
400,107!
2998
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
400,107✔
2999
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
1,074,019✔
3000
      col_id_t* id = taosArrayGet(cols, i);
673,912✔
3001
      STREAM_CHECK_NULL_GOTO(id, terrno);
673,912!
3002
      if (*id == -1) {
673,912✔
3003
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
400,107✔
3004
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
400,107!
3005
        continue;
400,107✔
3006
      }
3007
      size_t j = 0;
273,805✔
3008
      for (; j < sSchemaWrapper->nCols; j++) {
315,385!
3009
        SSchema* s = sSchemaWrapper->pSchema + j;
315,385✔
3010
        if (s->colId == *id) {
315,385✔
3011
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
273,805✔
3012
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
273,805!
3013
          break;
273,805✔
3014
        }
3015
      }
3016
      if (j == sSchemaWrapper->nCols) {
273,805!
3017
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3018
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3019
      }
3020
    }
3021
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
400,107!
3022
    pBlock->info.rows = 1;
400,107✔
3023
    
3024
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
1,074,019✔
3025
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
673,912✔
3026
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
673,912!
3027

3028
      if (pDst->info.colId == -1) {
673,912✔
3029
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
400,107!
3030
        continue;
400,107✔
3031
      }
3032
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
273,805!
3033
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3034
        continue;
×
3035
      }
3036

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

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

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

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

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

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

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

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

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

3119
    initStorageAPI(&handle.api);
18,356,831✔
3120
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
18,356,831✔
3121
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
17,564,369✔
3122
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
17,769,063✔
3123
      if (node != NULL) {
17,769,063✔
3124
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
424,301!
3125
      } else {
3126
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
17,344,762✔
3127
      }
3128

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

3137
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
18,356,831!
3138
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
18,356,831✔
3139

3140
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
18,356,831✔
3141
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
631,818✔
3142
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
631,818!
3143
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
3144
                                                    req.taskId));
3145
    } else {
3146
      handle.version = pVnode->state.applied;
17,725,013✔
3147
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
17,725,013!
3148
    }
3149

3150
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
18,356,831!
3151
  }
3152

3153
  if (req.pOpParam != NULL) {
18,504,015✔
3154
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, req.pOpParam);
251,860✔
3155
  }
3156
  
3157
  pResList = taosArrayInit(4, POINTER_BYTES);
18,504,015✔
3158
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
18,502,755!
3159
  uint64_t ts = 0;
18,502,755✔
3160
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
18,502,755✔
3161

3162
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
42,052,862✔
3163
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
23,552,588✔
3164
    if (pBlock == NULL) continue;
23,552,588!
3165
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
23,552,588✔
3166
/*    
3167
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
3168
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
3169
      printDataBlock(pBlock, __func__, "fetch filter");
3170
    }
3171
*/    
3172
  }
3173

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

3179
  taosArrayDestroy(pResList);
18,504,110✔
3180
  streamReleaseTask(taskAddr);
18,502,808✔
3181

3182
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
18,504,110!
3183
    code = TDB_CODE_SUCCESS;
×
3184
  }
3185
  STREAM_PRINT_LOG_END(code, lino);
18,504,110!
3186
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
18,504,110✔
3187
  tmsgSendRsp(&rsp);
18,504,110✔
3188
  tDestroySResFetchReq(&req);
18,502,801✔
3189
  return code;
18,501,499✔
3190
}
3191

3192
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
94,893,246✔
3193
  int32_t                   code = 0;
94,893,246✔
3194
  int32_t                   lino = 0;
94,893,246✔
3195
  SSTriggerPullRequestUnion req = {0};
94,893,246✔
3196
  void*                     taskAddr = NULL;
94,897,060✔
3197

3198
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
94,877,985✔
3199
  if (!syncIsReadyForRead(pVnode->sync)) {
94,890,514✔
3200
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
170,048✔
3201
    return 0;
170,048✔
3202
  }
3203

3204
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
94,731,786✔
3205
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
18,504,110✔
3206
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
76,229,048✔
3207
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
76,230,328✔
3208
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
76,234,148✔
3209
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
76,231,584!
3210
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
76,208,512✔
3211
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId);
3212
    SStreamTriggerReaderInfo* sStreamReaderInfo = (STRIGGER_PULL_OTABLE_INFO == req.base.type) ? NULL : qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
76,217,549✔
3213
    if (sStreamReaderInfo != NULL) {  
76,231,708✔
3214
      (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
76,018,082✔
3215
      if (sStreamReaderInfo->tableList == NULL) {
76,027,032✔
3216
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, false));  
617,183!
3217
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, true));
617,183!
3218
        STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamReaderInfo->pConditions, &sStreamReaderInfo->pFilterInfo, 0, NULL));
617,183!
3219
      }
3220
      (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
76,020,628✔
3221
      sStreamReaderInfo->pVnode = pVnode;
76,024,452✔
3222
    }
3223
    switch (req.base.type) {
76,215,049!
3224
      case STRIGGER_PULL_SET_TABLE:
127,630✔
3225
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
127,630!
3226
        break;
127,630✔
3227
      case STRIGGER_PULL_LAST_TS:
602,668✔
3228
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
602,668!
3229
        break;
600,118✔
3230
      case STRIGGER_PULL_FIRST_TS:
470,853✔
3231
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
470,853✔
3232
        break;
462,039✔
3233
      case STRIGGER_PULL_TSDB_META:
955,666✔
3234
      case STRIGGER_PULL_TSDB_META_NEXT:
3235
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
955,666✔
3236
        break;
948,142✔
3237
      case STRIGGER_PULL_TSDB_TS_DATA:
45,304✔
3238
        if (sStreamReaderInfo->isVtableStream) {
45,304!
3239
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
3240
        } else {
3241
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
45,304!
3242
        }
3243
        break;
45,304✔
3244
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
377,174✔
3245
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
3246
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
377,174!
3247
        break;
377,174✔
3248
      case STRIGGER_PULL_TSDB_CALC_DATA:
35,971,098✔
3249
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
3250
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
35,971,098✔
3251
        break;
35,787,754✔
3252
      case STRIGGER_PULL_TSDB_DATA:
200,685✔
3253
      case STRIGGER_PULL_TSDB_DATA_NEXT:
3254
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
200,685!
3255
        break;
200,685✔
3256
      case STRIGGER_PULL_GROUP_COL_VALUE:
881,026✔
3257
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
881,026!
3258
        break;
881,026✔
3259
      case STRIGGER_PULL_VTABLE_INFO:
773,222✔
3260
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
773,222!
3261
        break;
773,222✔
3262
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
409,060✔
3263
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req));
409,060!
3264
        break;
409,060✔
3265
      case STRIGGER_PULL_OTABLE_INFO:
127,630✔
3266
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req));
127,630!
3267
        break;
127,630✔
3268
      case STRIGGER_PULL_WAL_META_NEW:
16,799,179✔
3269
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
16,799,179!
3270
        break;
16,801,638✔
3271
      case STRIGGER_PULL_WAL_DATA_NEW:
6,860,708✔
3272
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
6,860,708!
3273
        break;
6,858,150✔
3274
      case STRIGGER_PULL_WAL_META_DATA_NEW:
10,569,404✔
3275
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
10,569,404!
3276
        break;
10,571,955✔
3277
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
1,043,742✔
3278
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,043,742!
3279
        break;
1,043,742✔
3280
      default:
×
3281
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
3282
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3283
        break;
×
3284
    }
3285
  } else {
3286
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
2,560!
3287
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3288
  }
3289
end:
76,180,911✔
3290

3291
  streamReleaseTask(taskAddr);
76,206,122✔
3292

3293
  tDestroySTriggerPullRequest(&req);
76,212,503✔
3294
  STREAM_PRINT_LOG_END(code, lino);
76,174,459!
3295
  return code;
76,207,292✔
3296
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc