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

taosdata / TDengine / #4807

17 Oct 2025 06:47AM UTC coverage: 61.121% (+0.03%) from 61.094%
#4807

push

travis-ci

web-flow
Merge pull request #33289 from taosdata/3.0

enh: Code Optimization (#33283)

155421 of 324369 branches covered (47.91%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2727 existing lines in 120 files now uncovered.

207582 of 269535 relevant lines covered (77.01%)

127069383.69 hits per line

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

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

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

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

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

59
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
15,483,763✔
60

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

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

67
  if (*c1 < *c2) {
167,136!
68
    return -1;
167,136✔
UNCOV
69
  } else if (*c1 > *c2) {
×
UNCOV
70
    return 1;
×
71
  }
72

73
  return 0;
×
74
}
75

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

80
  if (c1->colId < c2->colId) {
167,136!
81
    return -1;
167,136✔
UNCOV
82
  } else if (c1->colId > c2->colId) {
×
UNCOV
83
    return 1;
×
84
  }
85

86
  return 0;
×
87
}
88

89
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
12,080,938✔
90
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
12,080,938✔
91
  if (pSrc == NULL) {
12,097,406!
92
    return terrno;
×
93
  }
94

95
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
12,097,406!
96
  return 0;
12,090,238✔
97
}
98

99
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
17,753,509✔
100
  int32_t code = pTask->api.tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
17,753,509✔
101
  if (code != TSDB_CODE_SUCCESS) {
17,754,021!
102
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
103
  }
104

105
  return code;
17,755,183✔
106
}
107

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

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

130
static bool needRefreshTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
954,241✔
131
  if (sStreamReaderInfo->isVtableStream) {
954,241!
132
    int64_t id[2] = {suid, uid};
315,787✔
133
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id)) == NULL) {
316,877!
134
      return true;
313,044✔
135
    }
136
  } else {
137
    if (tableType != TD_CHILD_TABLE) {
638,462✔
138
      return false;
213,858✔
139
    }
140
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
424,604✔
141
        suid == sStreamReaderInfo->suid && 
260,553✔
142
        qStreamGetGroupId(sStreamReaderInfo->tableList, uid) == -1) {
11,046✔
143
      return true;
3,365✔
144
    }
145
  }
146
  return false;
425,072✔
147
}
148

149
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc){
17,159,055✔
150
  if (sStreamReaderInfo->isVtableStream) {
17,159,055!
151
    int64_t tmp[2] = {suid, uid};
5,891,150✔
152
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) == NULL) {
5,891,150✔
153
      return false;
2,030,894✔
154
    }
155
    *id = uid;
3,866,791✔
156
  } else {
157
    if (sStreamReaderInfo->tableList == NULL) return false;
11,275,627!
158

159
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
11,282,848✔
160
      if (suid != sStreamReaderInfo->suid) return false;
7,272,344✔
161
      if (sStreamReaderInfo->pTagCond == NULL) {
5,351,398✔
162
        if (sStreamReaderInfo->partitionCols == NULL){
4,436,967✔
163
          *id = 0;
22,730✔
164
        } else if (sStreamReaderInfo->groupByTbname){
4,413,696!
165
          *id= uid;
4,405,072✔
166
        } else {
167
          *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
8,624✔
168
          if (*id == -1) return false;
8,624!
169
        }
170
      } else {
171
        //*id= uid;
172
        *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
916,076✔
173
        if (*id == -1) return false;
916,630✔
174
      }
175
    } else {
176
      *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
4,019,312✔
177
      if(*id == -1) *id = uid;
4,017,704✔
178
      return uid == sStreamReaderInfo->uid;
4,016,596✔
179
    }
180
  }
181
  return true;
8,835,494✔
182
}
183

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

190
  SStorageAPI api = {0};
1,116,105✔
191
  initStorageAPI(&api);
1,116,105✔
192
  code = qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
1,116,105✔
193
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, 
194
                                         isHistory ? &sStreamReaderInfo->historyTableList : &sStreamReaderInfo->tableList,
195
                                         isHistory ? NULL : sStreamReaderInfo->groupIdMap);
196
  end:
1,116,069✔
197
  nodesDestroyList(groupNew);
1,116,069✔
198
  STREAM_PRINT_LOG_END(code, lino);
1,116,618!
199
  return code;
1,116,618✔
200
}
201

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

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

238

239
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
15,693,093✔
240
  int32_t code = 0;
15,693,093✔
241
  int32_t lino = 0;
15,693,093✔
242
  void*   buf = NULL;
15,693,093✔
243
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
15,693,093!
244
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
931,833✔
245
  buf = rpcMallocCont(dataEncodeSize);
931,316✔
246
  STREAM_CHECK_NULL_GOTO(buf, terrno);
931,316!
247
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
931,316✔
248
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
931,316!
249
  *data = buf;
931,316✔
250
  *size = dataEncodeSize;
931,316✔
251
  buf = NULL;
931,316✔
252
end:
15,693,093✔
253
  rpcFreeCont(buf);
15,693,093✔
254
  return code;
15,691,494✔
255
}
256

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

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

275
end:
308,426✔
276
  STREAM_PRINT_LOG_END(code, lino);
308,426!
277
  return code;
308,426✔
278
}
279

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

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

300
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
2,905,957✔
301
  int32_t code = 0;
2,905,957✔
302
  int32_t lino = 0;
2,905,957✔
303
  int32_t index = 0;
2,905,957✔
304
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
2,905,957!
305
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
2,905,403!
306
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
2,905,939!
307
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
2,905,959!
308

309
end:
2,906,493✔
310
  return code;
2,906,493✔
311
}
312

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

441
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq) {
917,512✔
442
  int32_t  code = 0;
917,512✔
443
  int32_t  lino = 0;
917,512✔
444
  void*    pTask = sStreamReaderInfo->pTask;
917,512✔
445
  if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
917,512✔
446
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
616,400✔
447
    goto end;
616,496✔
448
  }
449
  ST_TASK_ILOG("stream reader scan auto create table %s", pCreateReq->name);
301,565!
450

451
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
301,565!
452
end:
301,565✔
453
  return code;
918,061✔
454
}
455

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

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

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

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

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

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

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

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

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

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

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

537
  uint8_t       version = 0;
4,017,070✔
538
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
4,018,767!
539
    code = TSDB_CODE_INVALID_MSG;
×
540
    TSDB_CHECK_CODE(code, lino, end);
×
541
  }
542
  version = (submitTbData.flags >> 8) & 0xff;
4,018,767✔
543
  submitTbData.flags = submitTbData.flags & 0xff;
4,018,767✔
544

545
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
546
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
4,018,767✔
547
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
453,765!
548
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
453,765!
549
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
453,765!
550
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
453,765!
551
  }
552

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

563
  if (!uidInTableList(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
4,014,920✔
564
    goto end;
2,759,823✔
565
  }
566
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
1,257,270!
567
    code = TSDB_CODE_INVALID_MSG;
×
568
    TSDB_CHECK_CODE(code, lino, end);
×
569
  }
570

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

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

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

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

606
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
4,901,305✔
607
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
3,640,202✔
608
      pCoder->pos += pRow->len;
3,642,398✔
609
      if (iRow == 0){
3,641,849✔
610
#ifndef NO_UNALIGNED_ACCESS
611
        walMeta.skey = pRow->ts;
1,258,907✔
612
#else
613
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
614
#endif
615
      }
616
      if (iRow == nRow - 1) {
3,641,849✔
617
#ifndef NO_UNALIGNED_ACCESS
618
        walMeta.ekey = pRow->ts;
1,258,907✔
619
#else
620
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
621
#endif
622
      }
623
    }
624
  }
625

626
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,258,907✔
627
  if (data != NULL) {
1,257,809!
628
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
629
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
630
  } else {
631
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
1,257,809!
632
  }
633

634
end:
4,000,927✔
635
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
4,013,804✔
636
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
4,013,804!
637
  tEndDecode(pCoder);
4,013,250✔
638
  return code;
4,012,177✔
639
}
640

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

648
  tDecoderInit(&decoder, data, len);
4,018,714✔
649
  if (tStartDecode(&decoder) < 0) {
4,014,322!
650
    code = TSDB_CODE_INVALID_MSG;
×
651
    TSDB_CHECK_CODE(code, lino, end);
×
652
  }
653

654
  uint64_t nSubmitTbData = 0;
4,014,902✔
655
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
4,016,022!
656
    code = TSDB_CODE_INVALID_MSG;
×
657
    TSDB_CHECK_CODE(code, lino, end);
×
658
  }
659

660
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
4,016,022✔
661
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
4,011,102!
662

663
  for (int32_t i = 0; i < nSubmitTbData; i++) {
8,020,491✔
664
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash));
4,010,553!
665
  }
666
  tEndDecode(&decoder);
4,009,938✔
667

668
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
4,013,791!
669
  int32_t iter = 0;
4,017,072✔
670
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
4,017,072✔
671
  while (px != NULL) {
5,264,580✔
672
    WalMetaResult* pMeta = (WalMetaResult*)px;
1,255,646✔
673
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,255,646!
674
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,259,456✔
675
    rsp->totalRows++;
1,258,907✔
676
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,258,912✔
677
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
678
    px = tSimpleHashIterate(gidHash, px, &iter);
1,258,912✔
679
  }
680
end:
4,008,934✔
681
  tDecoderClear(&decoder);
4,009,470✔
682
  tSimpleHashCleanup( gidHash);
4,014,381✔
683
  return code;
4,015,464✔
684
}
685

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

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

701
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
397,976!
702

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

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

713
  schemas = taosArrayInit(8, sizeof(SSchema));
250,384✔
714
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
250,384!
715

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

722
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
250,384!
723

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

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

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

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

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

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

748
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int32_t ver) {
301,353✔
749
  int32_t code = 0;
301,353✔
750
  int32_t lino = 0;
301,353✔
751
  SDecoder dcoder = {0};
301,353✔
752
  tDecoderInit(&dcoder, data, len);
301,353✔
753
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
301,353✔
754
    if (rsp->deleteBlock == NULL) {
56,840✔
755
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
18,490!
756
    }
757
      
758
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
56,840!
759
  } else if (msgType == TDMT_VND_DROP_TABLE && sStreamReaderInfo->deleteOutTbl != 0) {
244,513✔
760
    if (rsp->dropBlock == NULL) {
571!
761
      STREAM_CHECK_RET_GOTO(createBlockForDropTable((SSDataBlock**)&rsp->dropBlock));
571!
762
    }
763
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
571!
764
  } else if (msgType == TDMT_VND_DROP_STB) {
243,942!
765
    STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
×
766
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
243,942✔
767
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, data, len));
37,278!
768
  } else if (msgType == TDMT_VND_ALTER_STB) {
206,664✔
769
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
770
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
172,642✔
771
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, data, len));
68,965!
772
  }
773

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

784
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
5,371,292✔
785
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
5,371,873!
786
  code = walReaderSeekVer(pWalReader, rsp->ver);
5,371,873✔
787
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,362,077✔
788
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
4,959,880!
789
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
790
    }
791
    ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
4,968,027✔
792
    code = TSDB_CODE_SUCCESS;
4,969,649✔
793
    goto end;
4,969,649✔
794
  }
795
  STREAM_CHECK_RET_GOTO(code);
402,197!
796

797
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
402,197!
798
  while (1) {
4,178,204✔
799
    code = walNextValidMsg(pWalReader, true);
4,579,100✔
800
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){\
4,577,053✔
801
      ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
402,197✔
802
      code = TSDB_CODE_SUCCESS;
403,275✔
803
      goto end;
403,275✔
804
    }
805
    STREAM_CHECK_RET_GOTO(code);
4,174,856!
806
    rsp->ver = pWalReader->curVersion;
4,174,856✔
807
    SWalCont* wCont = &pWalReader->pHead->head;
4,176,434✔
808
    rsp->verTime = wCont->ingestTs;
4,176,510✔
809
    if (wCont->ingestTs / 1000 > ctime) break;
4,176,411!
810
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
4,174,861✔
811
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
4,175,259✔
812
    int64_t ver = wCont->version;
4,177,157✔
813

814
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
4,174,802✔
815
      TD_VID(pVnode), ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
816
    if (wCont->msgType == TDMT_VND_SUBMIT) {
4,179,141✔
817
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,018,707✔
818
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,018,158✔
819
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
4,017,609!
820
    } else {
821
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
162,199!
822
    }
823

824
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
4,177,660!
825
      break;
×
826
    }
827
  }
828

829
end:
5,372,924✔
830
  walCloseReader(pWalReader);
5,372,924✔
831
  return code;
5,368,604✔
832
}
833

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

841
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
3,258,755!
842
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
3,256,527!
843
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
3,257,620!
844
  if (numOfExpr == 0) {
3,258,180!
845
    return TSDB_CODE_SUCCESS;
×
846
  }
847

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

855
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
152,373✔
856
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
152,373!
857
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
152,373!
858
      taosArrayDestroyP(tagCache, taosMemFree);
×
859
      code = terrno;
×
860
      goto end;
×
861
    }
862
  } else {
863
    tagCache = *(SArray**)uidData;
3,108,026✔
864
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
3,105,247!
865
  }
866
  
867
  for (int32_t j = 0; j < numOfExpr; ++j) {
8,915,529✔
868
    const SExprInfo* pExpr1 = &pExprInfo[j];
5,657,244✔
869
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
5,657,252✔
870

871
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
5,658,360✔
872
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
5,659,461!
873
    int32_t functionId = pExpr1->pExpr->_function.functionId;
5,659,461✔
874

875
    // this is to handle the tbname
876
    if (fmIsScanPseudoColumnFunc(functionId)) {
5,659,461✔
877
      int32_t fType = pExpr1->pExpr->_function.functionType;
3,258,194✔
878
      if (fType == FUNCTION_TYPE_TBNAME) {
3,258,755!
879
        char   buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
3,258,760✔
880
        if (uidData == NULL) {
3,259,850✔
881
          STR_TO_VARSTR(buf, mr.me.name)
152,373!
882
          char* tbname = taosStrdup(mr.me.name);
152,373!
883
          STREAM_CHECK_NULL_GOTO(tbname, terrno);
152,373!
884
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno);
304,746!
885
        } else {
886
          char* tbname = taosArrayGetP(tagCache, j);
3,107,477✔
887
          STR_TO_VARSTR(buf, tbname)
3,105,280!
888
        }
889
        for (uint32_t i = 0; i < numOfRows; i++){
9,633,345✔
890
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
6,374,036!
891
        }
892
        code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false);
3,259,309✔
893
        pColInfoData->info.colId = -1;
3,258,231✔
894
      }
895
    } else {  // these are tags
896
      char* data = NULL;
2,399,088✔
897
      const char* p = NULL;
2,399,629✔
898
      STagVal tagVal = {0};
2,399,629✔
899
      if (uidData == NULL) {
2,399,629✔
900
        tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
126,817✔
901
        p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
127,366✔
902

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

909
        if (data == NULL) {
127,366!
910
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
×
911
        } else {
912
          int32_t len = pColInfoData->info.bytes;
127,366✔
913
          if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
127,366!
914
            len = calcStrBytesByType(pColInfoData->info.type, (char*)data);
37,980✔
915
          }
916
          char* pData = taosMemoryCalloc(1, len);
127,366!
917
          STREAM_CHECK_NULL_GOTO(pData, terrno);
126,817!
918
          (void)memcpy(pData, data, len);
126,817!
919
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno);
254,183!
920
        }
921
      } else {
922
        data = taosArrayGetP(tagCache, j);
2,272,812✔
923
      }
924

925
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
2,399,629!
926
      if (isNullVal) {
2,399,629!
927
        colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
928
      } else {
929
        for (uint32_t i = 0; i < numOfRows; i++){
16,987,642✔
930
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
14,587,464!
931
        }
932
        code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false);
2,400,178✔
933
        if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
2,400,178!
934
          taosMemoryFree(data);
37,431!
935
        }
936
        STREAM_CHECK_RET_GOTO(code);
2,400,178!
937
      }
938
    }
939
  }
940

941
end:
3,261,546✔
942
  api->metaReaderFn.clearReader(&mr);
3,260,948✔
943
  return code;
3,258,778✔
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, 
6,059,951✔
992
  STSchema** schemas, SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
993
  int32_t code = 0;
6,059,951✔
994
  int32_t lino = 0;
6,059,951✔
995
  uint64_t id = 0;
6,059,951✔
996
  WalMetaResult walMeta = {0};
6,060,508✔
997
  void* pTask = sStreamReaderInfo->pTask;
6,062,714✔
998
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
6,066,003✔
999

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

1005
  SSubmitTbData submitTbData = {0};
6,063,230✔
1006
  uint8_t       version = 0;
6,064,328✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
6,063,246!
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
6,063,246✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
6,063,246✔
1013
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1014
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
6,063,246✔
1015
    if (tStartDecode(pCoder) < 0) {
25,048!
1016
      code = TSDB_CODE_INVALID_MSG;
×
1017
      TSDB_CHECK_CODE(code, lino, end);
×
1018
    }
1019
    tEndDecode(pCoder);
25,048✔
1020
  }
1021

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

1034
  walMeta.id = id;
4,605,865✔
1035
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
4,605,865✔
1036

1037
  if (ranges != NULL){
4,608,620✔
1038
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
2,996,589✔
1039
    if (timerange == NULL) goto end;;
3,000,407!
1040
    int64_t* pRange = (int64_t*)timerange;
3,000,407✔
1041
    window.skey = pRange[0];
3,000,407✔
1042
    window.ekey = pRange[1];
3,000,407✔
1043
  }
1044
  
1045
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
4,611,365!
1046
    code = TSDB_CODE_INVALID_MSG;
×
1047
    TSDB_CHECK_CODE(code, lino, end);
×
1048
  }
1049

1050
  if (*schemas == NULL) {
4,611,365✔
1051
    *schemas = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
4,608,071✔
1052
    STREAM_CHECK_NULL_GOTO(*schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
4,609,718!
1053
  }
1054

1055
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &submitTbData.uid, LONG_BYTES);
4,611,945✔
1056
  STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
4,610,265!
1057
  int32_t blockStart = pSlice->currentRowIdx;
4,610,265✔
1058

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

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

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

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

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

1100
      pCoder->pos = pos;
×
1101

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

1156
      if (iRow == 0){
6,946,886✔
1157
#ifndef NO_UNALIGNED_ACCESS
1158
        walMeta.skey = pRow->ts;
4,609,723✔
1159
#else
1160
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1161
#endif
1162
      }
1163
      if (iRow == nRow - 1) {
6,946,327✔
1164
#ifndef NO_UNALIGNED_ACCESS
1165
        walMeta.ekey = pRow->ts;
4,610,254✔
1166
#else
1167
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1168
#endif
1169
      }
1170

1171
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
6,944,177!
1172
        continue;
15,841✔
1173
      }
1174
     
1175
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
49,715,107✔
1176
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
42,789,436✔
1177
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
42,784,488!
1178
        if (pColData->info.colId <= -1) {
42,784,488✔
1179
          pColData->hasNull = true;
13,214,605✔
1180
          continue;
13,214,605✔
1181
        }
1182
        int16_t colId = 0;
29,577,548✔
1183
        if (sStreamReaderInfo->isVtableStream){
29,577,548!
1184
          int64_t id[2] = {submitTbData.suid, submitTbData.uid};
3,893,510✔
1185
          void* px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
3,893,510!
1186
          STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
3,895,663!
1187
          SSHashObj* uInfo = *(SSHashObj**)px;
3,895,663✔
1188
          STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
3,895,663!
1189
          int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
3,895,663✔
1190
          if (tmp != NULL) {
3,893,467✔
1191
            colId = *tmp;
3,213,426✔
1192
          } else {
1193
            colId = -1;
680,041✔
1194
          }
1195
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
3,895,658!
1196
        } else {
1197
          colId = pColData->info.colId;
25,685,126✔
1198
        }
1199
        
1200
        SColVal colVal = {0};
29,578,051✔
1201
        int32_t sourceIdx = 0;
29,578,600✔
1202
        while (1) {
1203
          if (sourceIdx >= (*schemas)->numOfCols) {
74,199,915✔
1204
            break;
14,501,805✔
1205
          }
1206
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, *schemas, sourceIdx, &colVal));
59,684,584!
1207
          if (colVal.cid == colId) {
59,702,640✔
1208
            break;
15,081,325✔
1209
          }
1210
          sourceIdx++;
44,621,315✔
1211
        }
1212
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
29,583,130✔
1213
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
14,864,822!
1214
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
33,327!
1215
          } else {
1216
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
14,831,501!
1217
          }
1218
        } else {
1219
          colDataSetNULL(pColData, blockStart + numOfRows);
14,718,308!
1220
        }
1221
      }
1222
      
1223
      numOfRows++;
6,930,546✔
1224
    }
1225
  }
1226

1227
  if (numOfRows > 0) {
4,610,298!
1228
    if (!sStreamReaderInfo->isVtableStream) {
4,610,298✔
1229
      SStorageAPI  api = {0};
3,160,120✔
1230
      initStorageAPI(&api);
3,161,767✔
1231
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
3,157,351!
1232
    }
1233
    
1234
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
4,609,769✔
1235
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
4,609,774!
1236
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
4,609,774!
1237
  }
1238

1239
  ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
4,610,839✔
1240
    ", uid:%" PRId64 ", ver:%d, row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1241
    id, submitTbData.uid, submitTbData.sver, pSlice->currentRowIdx, numOfRows);
1242
  pSlice->currentRowIdx += numOfRows;
4,612,443✔
1243
  pBlock->info.rows += numOfRows;
4,613,002✔
1244
  
1245
  if (gidHash == NULL) goto end;
4,613,002✔
1246

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

1255
end:
6,060,468✔
1256
  if (code != 0) {                                                             \
6,062,139!
1257
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1258
  }
1259
  tEndDecode(pCoder);
6,062,139✔
1260
  return code;
6,064,867✔
1261
}
1262
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
6,064,318✔
1263
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1264
  int32_t  code = 0;
6,064,318✔
1265
  int32_t  lino = 0;
6,064,318✔
1266
  STSchema* schemas = NULL;
6,064,318✔
1267
  SDecoder decoder = {0};
6,065,426✔
1268
  SSHashObj* gidHash = NULL;
6,067,078✔
1269
  void* pTask = sStreamReaderInfo->pTask;
6,067,078✔
1270

1271
  tDecoderInit(&decoder, data, len);
6,069,274✔
1272
  if (tStartDecode(&decoder) < 0) {
6,059,377!
1273
    code = TSDB_CODE_INVALID_MSG;
×
1274
    TSDB_CHECK_CODE(code, lino, end);
×
1275
  }
1276

1277
  uint64_t nSubmitTbData = 0;
6,060,505✔
1278
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
6,061,080!
1279
    code = TSDB_CODE_INVALID_MSG;
×
1280
    TSDB_CHECK_CODE(code, lino, end);
×
1281
  }
1282

1283
  if (rsp->metaBlock != NULL){
6,061,080✔
1284
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,064,496✔
1285
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
3,065,032!
1286
  }
1287

1288
  for (int32_t i = 0; i < nSubmitTbData; i++) {
12,123,179✔
1289
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, &schemas, ranges, gidHash, rsp, ver));
6,058,292!
1290
  }
1291

1292
  tEndDecode(&decoder);
6,064,887✔
1293

1294
  if (rsp->metaBlock != NULL){
6,066,534✔
1295
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
3,068,867!
1296
    int32_t iter = 0;
3,062,825✔
1297
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
3,062,825✔
1298
    while (px != NULL) {
4,679,800✔
1299
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,611,482✔
1300
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,611,482!
1301
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,609,830✔
1302
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,610,938✔
1303
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1304
      px = tSimpleHashIterate(gidHash, px, &iter);
1,610,938✔
1305
    }
1306
  }
1307
  
1308

1309
end:
6,058,395✔
1310
  taosMemoryFree(schemas);
6,065,995!
1311
  tSimpleHashCleanup(gidHash);
6,065,454✔
1312
  tDecoderClear(&decoder);
6,056,639✔
1313
  return code;
6,065,990✔
1314
}
1315

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

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

1327
  SSubmitTbData submitTbData = {0};
7,045,371✔
1328
  uint8_t       version = 0;
7,046,479✔
1329
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
7,049,254!
1330
    code = TSDB_CODE_INVALID_MSG;
×
1331
    TSDB_CHECK_CODE(code, lino, end);
×
1332
  }
1333
  version = (submitTbData.flags >> 8) & 0xff;
7,049,254✔
1334
  submitTbData.flags = submitTbData.flags & 0xff;
7,049,254✔
1335

1336
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1337
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
7,049,254✔
1338
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
463,747!
1339
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
462,111!
1340
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
462,111!
1341
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
462,644!
1342
  }
1343

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

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

1356
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
4,610,819✔
1357

1358
  if (ranges != NULL){
4,611,361✔
1359
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
2,999,866✔
1360
    if (timerange == NULL) goto end;;
3,000,407!
1361
    int64_t* pRange = (int64_t*)timerange;
3,000,407✔
1362
    window.skey = pRange[0];
3,000,407✔
1363
    window.ekey = pRange[1];
3,000,407✔
1364
  }
1365
  
1366
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
4,611,901!
1367
    code = TSDB_CODE_INVALID_MSG;
×
1368
    TSDB_CHECK_CODE(code, lino, end);
×
1369
  }
1370

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

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

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

1403
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
4,611,363✔
1404
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
8,316,590✔
1405
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
5,315,069✔
1406
        pCoder->pos += pRow->len;
5,315,069✔
1407
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
5,315,069!
1408
          continue;
16,390✔
1409
        }
1410
        (*numOfRows)++;
5,298,679✔
1411
      }
1412
    } else {
1413
      (*numOfRows) = nRow;
1,609,842✔
1414
    }
1415
  }
1416
  
1417
end:
7,060,865✔
1418
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
7,050,354✔
1419
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
7,052,013!
1420
  tEndDecode(pCoder);
7,051,472✔
1421
  return code;
7,043,266✔
1422
}
1423

1424
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
7,042,570✔
1425
  int32_t  code = 0;
7,042,570✔
1426
  int32_t  lino = 0;
7,042,570✔
1427
  SDecoder decoder = {0};
7,042,570✔
1428
  void* pTask = sStreamReaderInfo->pTask;
7,045,330✔
1429

1430
  tDecoderInit(&decoder, data, len);
7,048,105✔
1431
  if (tStartDecode(&decoder) < 0) {
7,017,861!
1432
    code = TSDB_CODE_INVALID_MSG;
×
1433
    TSDB_CHECK_CODE(code, lino, end);
×
1434
  }
1435

1436
  uint64_t nSubmitTbData = 0;
7,043,164✔
1437
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
7,052,592!
1438
    code = TSDB_CODE_INVALID_MSG;
×
1439
    TSDB_CHECK_CODE(code, lino, end);
×
1440
  }
1441

1442
  for (int32_t i = 0; i < nSubmitTbData; i++) {
14,101,934✔
1443
    uint64_t gid = -1;
7,046,496✔
1444
    int64_t  uid = 0;
7,045,947✔
1445
    int32_t numOfRows = 0;
7,048,163✔
1446
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp->isCalc));
7,048,163!
1447
    if (numOfRows <= 0) {
7,045,970✔
1448
      continue;
2,447,301✔
1449
    }
1450
    rsp->totalRows += numOfRows;
4,598,669✔
1451

1452
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &uid, LONG_BYTES);
4,609,177✔
1453
    if (pSlice != NULL) {
4,610,227✔
1454
      pSlice->numRows += numOfRows;
4,401,544✔
1455
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d", __func__, uid, gid, pSlice->numRows);
4,401,015✔
1456
      pSlice->gId = gid;
4,401,015✔
1457
    } else {
1458
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
208,683✔
1459
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d", __func__, uid, gid, tmp.numRows);
209,237✔
1460
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(sStreamReaderInfo->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
209,237!
1461
    } 
1462
  }
1463

1464
  tEndDecode(&decoder);
7,055,438✔
1465

1466
end:
7,049,869✔
1467
  tDecoderClear(&decoder);
7,050,990✔
1468
  return code;
7,048,200✔
1469
}
1470

1471
static void resetIndexHash(SSHashObj* indexHash){
6,040,490✔
1472
  void*   pe = NULL;
6,040,490✔
1473
  int32_t iter = 0;
6,040,490✔
1474
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
13,668,674✔
1475
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
7,628,222✔
1476
    pInfo->startRowIdx = 0;
7,628,222✔
1477
    pInfo->currentRowIdx = 0;
7,627,668✔
1478
    pInfo->numRows = 0;
7,616,730✔
1479
    pInfo->gId = -1;
7,621,114✔
1480
  }
1481
}
6,037,749✔
1482

1483
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
497,299✔
1484
  void*   pe = NULL;
497,299✔
1485
  int32_t iter = 0;
497,299✔
1486
  int32_t index = 0;
497,299✔
1487
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
1,758,905✔
1488
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
1,261,606✔
1489
    pInfo->startRowIdx = index;
1,261,606✔
1490
    pInfo->currentRowIdx = index;
1,261,606✔
1491
    index += pInfo->numRows;
1,261,606✔
1492
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
1,521,850!
1493
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1494
  }
1495
}
497,299✔
1496

1497
static void printIndexHash(SSHashObj* indexHash, void* pTask){
494,527✔
1498
  void*   pe = NULL;
494,527✔
1499
  int32_t iter = 0;
494,527✔
1500
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
1,753,942✔
1501
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
1,258,854✔
1502
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
1,517,988!
1503
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1504
  }
1505
}
496,191✔
1506

1507
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
14,099✔
1508
  void*   pe = NULL;
14,099✔
1509
  int32_t iter = 0;
14,099✔
1510
  int32_t index = 0;
14,099✔
1511
  int32_t pIndex = 0;
14,099✔
1512
  int8_t* pIndicator = (int8_t*)pRet->pData;
14,099✔
1513
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
43,442✔
1514
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
29,343✔
1515
    pInfo->startRowIdx = index;
29,343✔
1516
    int32_t size = pInfo->numRows;
29,343✔
1517
    for (int32_t i = 0; i < pInfo->numRows; i++) {
186,050✔
1518
      if (pIndicator && !pIndicator[pIndex++]) {
156,707!
1519
        size--;
57,557✔
1520
      }
1521
    }
1522
    pInfo->numRows = size;
29,343✔
1523
    index += pInfo->numRows;
29,343✔
1524
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
29,343!
1525
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1526
  }
1527
}
14,099✔
1528

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

1534
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,846,010✔
1535
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,849,200✔
1536
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
3,333,421!
1537
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
1538
    }
1539
    ST_TASK_DLOG("%s scan wal error:%s",  __func__, tstrerror(code));
3,336,220✔
1540
    code = TSDB_CODE_SUCCESS;
3,336,766✔
1541
    goto end;
3,336,766✔
1542
  }
1543
  STREAM_CHECK_RET_GOTO(code);
515,779!
1544

1545
  while (1) {
4,191,330✔
1546
    code = walNextValidMsg(pWalReader, true);
4,707,109✔
1547
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
4,696,079✔
1548
      ST_TASK_DLOG("%s scan wal error:%s", __func__, tstrerror(code));
514,151✔
1549
      code = TSDB_CODE_SUCCESS;
516,890✔
1550
      goto end;
516,890✔
1551
    }
1552
    STREAM_CHECK_RET_GOTO(code);
4,181,928!
1553
    resultRsp->ver = pWalReader->curVersion;
4,181,928✔
1554
    SWalCont* wCont = &pWalReader->pHead->head;
4,181,946✔
1555
    resultRsp->verTime = wCont->ingestTs;
4,183,609✔
1556
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
4,185,796✔
1557
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
4,191,871✔
1558
    int64_t ver = wCont->version;
4,192,412✔
1559
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d", __func__,
4,188,014✔
1560
      ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1561
    if (wCont->msgType == TDMT_VND_SUBMIT) {
4,190,748✔
1562
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,052,697✔
1563
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,052,702✔
1564
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp));
4,051,612!
1565
    } else if (wCont->msgType == TDMT_VND_ALTER_TABLE && resultRsp->totalRows > 0) {
139,154!
UNCOV
1566
      resultRsp->ver--;
×
1567
      break;
554✔
1568
    } else {
1569
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
139,154!
1570
    }
1571

1572
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
4,190,212✔
1573
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
4,190,212!
1574
      break;
×
1575
    }
1576
  }
1577
  
1578
end:
3,854,210✔
1579
  STREAM_PRINT_LOG_END(code, lino);
3,854,210!
1580
  return code;
3,855,305✔
1581
}
1582

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

1588
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
5,188,301✔
1589
    int64_t *ver = taosArrayGet(versions, i);
2,998,219✔
1590
    if (ver == NULL) continue;
2,998,768!
1591

1592
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
2,998,768!
1593
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
3,000,407!
1594
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1595
      continue;
×
1596
    }
1597
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
2,999,858!
1598

1599
    SWalCont* wCont = &pWalReader->pHead->head;
2,999,858✔
1600
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
2,998,760✔
1601
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
2,999,309✔
1602

1603
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp));
2,999,309!
1604
  }
1605
  
1606
end:
2,190,082✔
1607
  return code;
2,190,082✔
1608
}
1609

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

1620
end:
496,750✔
1621
  colDataDestroy(pRet);
496,750✔
1622
  taosMemoryFree(pRet);
497,299!
1623
  return code;
496,201✔
1624
}
1625

1626
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,853,635✔
1627
                                    SSTriggerWalNewRsp* resultRsp) {
1628
  int32_t      code = 0;
3,853,635✔
1629
  int32_t      lino = 0;
3,853,635✔
1630
  void* pTask = sStreamReaderInfo->pTask;
3,853,635✔
1631
                                        
1632
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,854,189✔
1633
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,849,262!
1634
  resetIndexHash(sStreamReaderInfo->indexHash);
3,849,262✔
1635
  blockDataEmpty(resultRsp->dataBlock);
3,847,667✔
1636
  blockDataEmpty(resultRsp->metaBlock);
3,848,762✔
1637
  int64_t lastVer = resultRsp->ver;                                      
3,843,820✔
1638
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,844,361!
1639
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,855,305✔
1640

1641
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
145,720✔
1642
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
145,720!
1643
  while(lastVer < resultRsp->ver) {
3,321,790✔
1644
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
3,176,624!
1645
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
3,176,622✔
1646
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
110,512!
1647
      continue;
110,512✔
1648
    }
1649
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
3,065,543!
1650
    SWalCont* wCont = &pWalReader->pHead->head;
3,062,813✔
1651
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
3,063,354✔
1652
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
3,065,560✔
1653

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

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

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

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

1673
  void* pTask = sStreamReaderInfo->pTask;
2,190,659✔
1674
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
2,191,170✔
1675
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
2,191,170!
1676
  
1677
  if (taosArrayGetSize(versions) > 0) {
2,191,170✔
1678
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
351,579✔
1679
  }
1680
  
1681
  resetIndexHash(sStreamReaderInfo->indexHash);
2,191,170✔
1682
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
2,190,082!
1683
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
2,190,082✔
1684

1685
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
351,579✔
1686

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

1690
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
3,347,629✔
1691
    int64_t *ver = taosArrayGet(versions, i);
2,998,231✔
1692
    if (ver == NULL) continue;
2,997,682!
1693

1694
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
2,997,682!
1695
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
2,998,775!
1696
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1697
      continue;
×
1698
    }
1699
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
2,998,775!
1700
    SWalCont* wCont = &pWalReader->pHead->head;
2,997,682✔
1701
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
2,998,775✔
1702
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
2,999,863✔
1703

1704
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
2,998,775!
1705
  }
1706
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
1707
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
351,579!
1708
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
351,030✔
1709

1710
end:
2,189,533✔
1711
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
2,189,533✔
1712
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
1713
  walCloseReader(pWalReader);
2,189,533✔
1714
  return code;
2,188,989✔
1715
}
1716

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

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

1741
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
265,317✔
1742
    SSchema* s = sSchemaWrapper->pSchema + j;
186,072✔
1743
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
372,144!
1744
  }
1745

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

1756
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
79,245✔
1757
  int32_t code = 0;
79,245✔
1758
  int32_t lino = 0;
79,245✔
1759
  size_t  schemaLen = taosArrayGetSize(schemas);
79,245✔
1760
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
79,245!
1761
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
242,058✔
1762
    col_id_t* id = taosArrayGet(cols, i);
162,813✔
1763
    STREAM_CHECK_NULL_GOTO(id, terrno);
162,813!
1764
    for (size_t i = 0; i < schemaLen; i++) {
269,640!
1765
      SSchema* s = taosArrayGet(schemas, i);
269,640✔
1766
      STREAM_CHECK_NULL_GOTO(s, terrno);
269,640!
1767
      if (*id == s->colId) {
269,640✔
1768
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
162,813!
1769
        break;
162,813✔
1770
      }
1771
    }
1772
  }
1773
  taosArrayPopFrontBatch(schemas, schemaLen);
79,245✔
1774

1775
end:
79,245✔
1776
  return code;
79,245✔
1777
}
1778

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

1785
  SSDataBlock* pBlock2 = NULL;
×
1786

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1866
  *pCond = cond;
×
1867

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

1880
  return code;
×
1881
}
1882

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

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

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

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

1916
  *pCond = cond;
1917

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

1925
  return code;
1926
}
1927
*/
1928

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

1946
    if (!node->needCalc) {
105,993✔
1947
      pWin->skey = pFirst->wstart;
77,990✔
1948
      pWin->ekey = pLast->wend;
77,990✔
1949
      *pValid = true;
77,990✔
1950
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
77,990✔
1951
        pWin->ekey--;
53,384✔
1952
      }
1953
    } else {
1954
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
28,003✔
1955
      memcpy(pTmp, pFirst, sizeof(*pTmp));
28,003!
1956

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

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

1964
        if (*pValid) {
28,003!
1965
          pWin->skey = skey;
28,003✔
1966
        }
1967
      }
1968
      pWin->ekey--;
28,003✔
1969
    }
1970
  } else {
1971
    if (!node->needCalc) {
8,815!
1972
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
8,815✔
1973
      pWin->skey = pCurr->wstart;
8,815✔
1974
      pWin->ekey = pCurr->wend;
8,815✔
1975
      *pValid = true;
8,815✔
1976
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
8,815✔
1977
        pWin->ekey--;
6,355✔
1978
      }
1979
    } else {
UNCOV
1980
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
×
UNCOV
1981
      pWin->ekey--;
×
1982
    }
1983
  }
1984

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

1988
end:
19,168✔
1989

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

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

2002
  void* pTask = sStreamReaderInfo->pTask;
411,633✔
2003
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTaskInner->pTableList), sizeof(STsInfo));
412,161✔
2004
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
411,063!
2005
  while (true) {
308,967✔
2006
    bool hasNext = false;
720,579✔
2007
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
721,128!
2008
    if (hasNext) {
718,491!
2009
      pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
300,377✔
2010
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
298,249✔
2011
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
299,864!
2012
      if (pTaskInner->options.order == TSDB_ORDER_ASC) {
299,864✔
2013
        tsInfo->ts = pTaskInner->pResBlock->info.window.skey;
200,447✔
2014
      } else {
2015
        tsInfo->ts = pTaskInner->pResBlock->info.window.ekey;
98,860✔
2016
      }
2017
      tsInfo->gId = (sStreamReaderInfo->groupByTbname || sStreamReaderInfo->tableType != TSDB_SUPER_TABLE) ? 
659,418!
2018
                    pTaskInner->pResBlock->info.id.uid : qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
358,500✔
2019
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
300,890✔
2020
              tsInfo->gId, tsRsp->ver);
2021
    }
2022
    
2023
    pTaskInner->currentGroupIndex++;
719,004✔
2024
    if (pTaskInner->currentGroupIndex >= qStreamGetTableListGroupNum(pTaskInner->pTableList) || pTaskInner->options.gid != 0) {
720,057✔
2025
      break;
2026
    }
2027
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTaskInner));
307,344!
2028
  }
2029

2030
end:
409,051✔
2031
  STREAM_PRINT_LOG_END_WITHID(code, lino);
409,051!
2032
  return code;
412,161✔
2033
}
2034

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

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

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

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

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

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

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

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

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

2082
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner));
223,016!
2083
  ST_TASK_DLOG("vgId:%d %s get result, ver:%" PRId64, TD_VID(pVnode), __func__, lastTsRsp.ver);
223,016✔
2084
  STREAM_CHECK_RET_GOTO(buildTsRsp(&lastTsRsp, &buf, &size))
223,016!
2085
  if (stDebugFlag & DEBUG_DEBUG) {
223,016✔
2086
    int32_t nInfo = taosArrayGetSize(lastTsRsp.tsInfo);
158,396✔
2087
    for (int32_t i = 0; i < nInfo; i++) {
236,959✔
2088
      STsInfo* tsInfo = TARRAY_GET_ELEM(lastTsRsp.tsInfo, i);
78,563✔
2089
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
78,563!
2090
    }
2091
  }
2092

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

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

2111
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
190,229!
2112
  void* pTask = sStreamReaderInfo->pTask;
190,229✔
2113
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64, TD_VID(pVnode), __func__, req->firstTsReq.startTime, req->firstTsReq.ver, req->firstTsReq.gid);
190,229✔
2114
  BUILD_OPTION(options, sStreamReaderInfo, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, sStreamReaderInfo->tsSchemas, true,
190,229✔
2115
               STREAM_SCAN_GROUP_ONE_BY_ONE, req->firstTsReq.gid, true, sStreamReaderInfo->uidHashTrigger);
2116
  SStorageAPI api = {0};
190,229✔
2117
  initStorageAPI(&api);
190,229✔
2118
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
189,688✔
2119
  
2120
  firstTsRsp.ver = pVnode->state.applied;
189,145✔
2121
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &firstTsRsp, sStreamReaderInfo, pTaskInner));
189,145!
2122

2123
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(firstTsRsp.tsInfo), firstTsRsp.ver);
188,604✔
2124
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
188,604!
2125
  if (stDebugFlag & DEBUG_DEBUG) {
188,604✔
2126
    int32_t nInfo = taosArrayGetSize(firstTsRsp.tsInfo);
119,146✔
2127
    for (int32_t i = 0; i < nInfo; i++) {
229,310✔
2128
      STsInfo* tsInfo = TARRAY_GET_ELEM(firstTsRsp.tsInfo, i);
110,164✔
2129
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
110,164!
2130
    }
2131
  }
2132

2133
end:
189,688✔
2134
  STREAM_PRINT_LOG_END_WITHID(code, lino);
189,688!
2135
  SRpcMsg rsp = {
189,688✔
2136
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2137
  tmsgSendRsp(&rsp);
188,598✔
2138
  taosArrayDestroy(firstTsRsp.tsInfo);
190,229✔
2139
  releaseStreamTask(&pTaskInner);
190,229✔
2140
  return code;
189,688✔
2141
}
2142

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2263
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
14,901✔
2264

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

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

2275
  releaseStreamTask(&pTaskInner);
14,901✔
2276
  return code;
14,901✔
2277
}
2278

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

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

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

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

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

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

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

UNCOV
2327
  releaseStreamTask(&pTaskInner);
×
UNCOV
2328
  return code;
×
2329
}
2330

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

2337
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
160,330!
2338
  SStreamReaderTaskInner* pTaskInner = NULL;
160,330✔
2339
  void* pTask = sStreamReaderInfo->pTask;
160,330✔
2340
  ST_TASK_DLOG("vgId:%d %s start. ver:%"PRId64",order:%d,startTs:%"PRId64",gid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, req->tsdbTriggerDataReq.gid);
160,330✔
2341
  
2342
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
160,330✔
2343

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

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

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

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

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

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

2399
  return code;
160,330✔
2400
}
2401

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

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

2414
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
14,925,960!
2415

2416
  SStreamReaderTaskInner* pTaskInner = NULL;
14,924,902✔
2417
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
14,924,902✔
2418

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

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

2435
  blockDataCleanup(pTaskInner->pResBlockDst);
14,894,545✔
2436
  bool hasNext = true;
14,892,958✔
2437
  while (1) {
1,282,332✔
2438
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
16,175,290!
2439
    if (!hasNext) {
16,176,352!
2440
      break;
14,893,503✔
2441
    }
2442
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
1,282,849✔
2443

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

2453
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
14,894,032!
2454
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
14,895,074!
2455
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
14,894,545✔
2456
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
14,894,545!
2457
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
14,892,958✔
2458
  if (!hasNext) {
14,895,603!
2459
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
14,895,603!
2460
  }
2461

2462
end:
14,918,602✔
2463
  STREAM_PRINT_LOG_END_WITHID(code, lino);
14,918,566!
2464
  SRpcMsg rsp = {
14,924,902✔
2465
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2466
  tmsgSendRsp(&rsp);
14,924,902✔
2467
  blockDataDestroy(pBlockRes);
14,924,373✔
2468
  return code;
14,924,373✔
2469
}
2470

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

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

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

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

2512
    options.suid = req->tsdbDataReq.suid;
79,245✔
2513
    options.uid = req->tsdbDataReq.uid;
79,245✔
2514

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

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

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

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

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

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

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

2578
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
5,401,721✔
2579
  void* pTask = sStreamReaderInfo->pTask;
5,371,841✔
2580
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
5,371,315✔
2581

2582
  if (sStreamReaderInfo->metaBlock == NULL) {
5,371,315✔
2583
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
146,192!
2584
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
146,192!
2585
  }
2586
  blockDataEmpty(sStreamReaderInfo->metaBlock);
5,374,012✔
2587
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
5,363,669✔
2588
  resultRsp.ver = req->walMetaNewReq.lastVer;
5,363,669✔
2589
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
5,364,218!
2590

2591
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
5,369,686✔
2592
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
5,371,831✔
2593
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, NULL);
109,053✔
2594
  buf = rpcMallocCont(size);
109,053✔
2595
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, NULL);
109,053✔
2596
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
109,053✔
2597

2598
end:
5,401,185✔
2599
  if (resultRsp.totalRows == 0) {
5,401,190✔
2600
    code = TSDB_CODE_STREAM_NO_DATA;
5,291,570✔
2601
    buf = rpcMallocCont(sizeof(int64_t));
5,291,570✔
2602
    *(int64_t *)buf = resultRsp.ver;
5,283,952✔
2603
    size = sizeof(int64_t);
5,284,496✔
2604
  }
2605
  SRpcMsg rsp = {
5,394,116✔
2606
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2607
  tmsgSendRsp(&rsp);
5,395,735✔
2608
  if (code == TSDB_CODE_STREAM_NO_DATA){
5,403,361✔
2609
    code = 0;
5,294,308✔
2610
  }
2611
  STREAM_PRINT_LOG_END_WITHID(code, lino);
5,403,361!
2612
  blockDataDestroy(resultRsp.deleteBlock);
5,404,518✔
2613
  blockDataDestroy(resultRsp.dropBlock);
5,401,157✔
2614

2615
  return code;
5,402,245✔
2616
}
2617
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,855,292✔
2618
  int32_t      code = 0;
3,855,292✔
2619
  int32_t      lino = 0;
3,855,292✔
2620
  void*        buf = NULL;
3,855,292✔
2621
  size_t       size = 0;
3,855,292✔
2622
  SSTriggerWalNewRsp resultRsp = {0};
3,855,292✔
2623
  
2624
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
3,855,828!
2625
  void* pTask = sStreamReaderInfo->pTask;
3,855,828✔
2626
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,851,447✔
2627

2628
  if (sStreamReaderInfo->metaBlock == NULL) {
3,851,447✔
2629
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
85,702!
2630
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
85,702!
2631
  }
2632
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,856,931✔
2633
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
3,854,205✔
2634
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,854,197✔
2635
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,855,854!
2636

2637
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,853,669✔
2638
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, sStreamReaderInfo->indexHash);
144,612✔
2639
  buf = rpcMallocCont(size);
144,051✔
2640
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, sStreamReaderInfo->indexHash);
144,612✔
2641
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
144,051✔
2642
  printDataBlock(sStreamReaderInfo->triggerBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
143,497✔
2643
  printDataBlock(resultRsp.dropBlock, __func__, "drop", ((SStreamTask*)pTask)->streamId);
143,517✔
2644
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
143,517✔
2645
  printIndexHash(sStreamReaderInfo->indexHash, pTask);
144,071✔
2646

2647
end:
3,853,669✔
2648
  if (resultRsp.totalRows == 0) {
3,853,107✔
2649
    buf = rpcMallocCont(sizeof(int64_t));
3,710,680✔
2650
    *(int64_t *)buf = resultRsp.ver;
3,699,017✔
2651
    size = sizeof(int64_t);
3,699,558✔
2652
    code = TSDB_CODE_STREAM_NO_DATA;
3,699,558✔
2653
  }
2654
  SRpcMsg rsp = {
3,841,985✔
2655
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2656
  tmsgSendRsp(&rsp);
3,845,247✔
2657
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,855,297✔
2658
    code = 0;
3,709,589✔
2659
  }
2660
  blockDataDestroy(resultRsp.deleteBlock);
3,855,297✔
2661
  blockDataDestroy(resultRsp.dropBlock);
3,852,337✔
2662

2663
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,851,232!
2664

2665
  return code;
3,852,902✔
2666
}
2667

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

2675
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
1,812,380!
2676
  void* pTask = sStreamReaderInfo->pTask;
1,812,380✔
2677
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
1,811,836✔
2678

2679
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
1,811,836✔
2680
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
1,812,380!
2681
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
1,810,748✔
2682

2683
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
1,811,836✔
2684

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

2691
end:
1,811,836✔
2692
  if (resultRsp.totalRows == 0) {
1,811,836✔
2693
    buf = rpcMallocCont(sizeof(int64_t));
1,764,130✔
2694
    *(int64_t *)buf = resultRsp.ver;
1,762,498✔
2695
    size = sizeof(int64_t);
1,763,042✔
2696
    code = TSDB_CODE_STREAM_NO_DATA;
1,763,042✔
2697
  }
2698
  SRpcMsg rsp = {
1,810,748✔
2699
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2700
  tmsgSendRsp(&rsp);
1,811,292✔
2701
  if (code == TSDB_CODE_STREAM_NO_DATA){
1,812,380✔
2702
    code = 0;
1,764,674✔
2703
  }
2704

2705
  blockDataDestroy(resultRsp.deleteBlock);
1,812,380✔
2706
  blockDataDestroy(resultRsp.dropBlock);
1,811,836✔
2707
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,811,836!
2708

2709
  return code;
1,811,836✔
2710
}
2711

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

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

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

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

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

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

2764
  return code;
378,241✔
2765
}
2766

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

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

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

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

2799
  return code;
345,146✔
2800
}
2801

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

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

2816
  SArray* cids = req->virTableInfoReq.cids;
191,896✔
2817
  STREAM_CHECK_NULL_GOTO(cids, terrno);
192,422!
2818

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

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

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

2836
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
296,019✔
2837
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
295,475!
UNCOV
2838
      vTable->cols.nCols = metaReader.me.colRef.nCols;
×
UNCOV
2839
      vTable->cols.version = metaReader.me.colRef.version;
×
UNCOV
2840
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
×
UNCOV
2841
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
×
UNCOV
2842
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
×
2843
      }
2844
    } else {
2845
      vTable->cols.nCols = taosArrayGetSize(cids);
295,475✔
2846
      vTable->cols.version = metaReader.me.colRef.version;
296,019✔
2847
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
294,931!
2848
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
969,878✔
2849
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
3,555,229✔
2850
          if (metaReader.me.colRef.pColRef[j].hasRef &&
3,259,210!
2851
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
2,549,489✔
2852
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
379,472!
2853
            break;
378,384✔
2854
          }
2855
        }
2856
      }
2857
    }
2858
    tDecoderClear(&metaReader.coder);
295,475✔
2859
  }
2860
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
192,422✔
2861
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
192,422!
2862

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

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

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

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

2889
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
43,937✔
2890

2891
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
43,937!
2892

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

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

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

2931
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
44,486!
2932

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

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

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

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

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

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

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

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

2981
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
142,261!
2982
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
142,261✔
2983
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
400,960✔
2984
      col_id_t* id = taosArrayGet(cols, i);
258,699✔
2985
      STREAM_CHECK_NULL_GOTO(id, terrno);
258,699!
2986
      if (*id == -1) {
258,699✔
2987
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
141,163✔
2988
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
141,712!
2989
        continue;
142,261✔
2990
      }
2991
      size_t j = 0;
116,987✔
2992
      for (; j < sSchemaWrapper->nCols; j++) {
139,079!
2993
        SSchema* s = sSchemaWrapper->pSchema + j;
139,079✔
2994
        if (s->colId == *id) {
138,530✔
2995
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
116,438✔
2996
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
116,987!
2997
          break;
116,438✔
2998
        }
2999
      }
3000
      if (j == sSchemaWrapper->nCols) {
116,438!
3001
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3002
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3003
      }
3004
    }
3005
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
142,261!
3006
    pBlock->info.rows = 1;
142,261✔
3007
    
3008
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
401,509✔
3009
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
258,699✔
3010
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
258,699!
3011

3012
      if (pDst->info.colId == -1) {
258,699✔
3013
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
142,261!
3014
        continue;
141,712✔
3015
      }
3016
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
116,987!
3017
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3018
        continue;
×
3019
      }
3020

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

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

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

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

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

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

3072
  SResFetchReq req = {0};
6,936,495✔
3073
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
6,936,495!
3074
                              TSDB_CODE_QRY_INVALID_INPUT);
3075
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
6,935,928✔
3076
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
6,936,499!
3077

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

3085
  if (req.reset || sStreamReaderCalcInfo->pTaskInfo == NULL) {
6,937,056!
3086
  // if (req.reset) {
3087
    qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
6,884,102✔
3088
    int64_t uid = 0;
6,881,935✔
3089
    if (req.dynTbname) {
6,881,935!
3090
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
25,216✔
3091
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
25,216!
3092
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
25,216✔
3093
        if (pValue != NULL && pValue->isTbname) {
25,216!
3094
          uid = pValue->uid;
25,216✔
3095
          break;
25,216✔
3096
        }
3097
      }
3098
    }
3099
    
3100
    SReadHandle handle = {0};
6,881,935✔
3101
    handle.vnode = pVnode;
6,882,565✔
3102
    handle.uid = uid;
6,882,565✔
3103

3104
    initStorageAPI(&handle.api);
6,882,565✔
3105
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
6,879,802✔
3106
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
6,642,683✔
3107
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
6,648,952✔
3108
      if (node != NULL) {
6,648,385✔
3109
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
114,808!
3110
      } else {
3111
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
6,533,577✔
3112
      }
3113

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

3122
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
6,883,037!
3123
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
6,884,102✔
3124

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

3133
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
6,879,176!
3134
  }
3135

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

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

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

3162
end:
6,934,737✔
3163
  taosArrayDestroy(pResList);
6,937,056✔
3164
  streamReleaseTask(taskAddr);
6,937,056✔
3165

3166
  STREAM_PRINT_LOG_END(code, lino);
6,937,056!
3167
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
6,937,056✔
3168
  tmsgSendRsp(&rsp);
6,937,056✔
3169
  tDestroySResFetchReq(&req);
6,936,489✔
3170
  return code;
6,937,056✔
3171
}
3172

3173
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
35,222,859✔
3174
  int32_t                   code = 0;
35,222,859✔
3175
  int32_t                   lino = 0;
35,222,859✔
3176
  SSTriggerPullRequestUnion req = {0};
35,222,859✔
3177
  void*                     taskAddr = NULL;
35,225,013✔
3178

3179
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
35,217,371✔
3180
  if (!syncIsReadyForRead(pVnode->sync)) {
35,220,128✔
3181
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
71,712✔
3182
    return 0;
71,712✔
3183
  }
3184

3185
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
35,151,135✔
3186
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
6,937,056✔
3187
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
28,212,994!
3188
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
28,213,550✔
3189
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
28,214,633✔
3190
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
28,213,558!
3191
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
28,203,741✔
3192
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId);
3193
    SStreamTriggerReaderInfo* sStreamReaderInfo = (STRIGGER_PULL_OTABLE_INFO == req.base.type) ? NULL : qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
28,208,097✔
3194
    if (sStreamReaderInfo != NULL) {  
28,207,603✔
3195
      (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
28,134,844✔
3196
      if (sStreamReaderInfo->tableList == NULL) {
28,140,069✔
3197
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, false));  
231,894!
3198
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, true));
231,894!
3199
        STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamReaderInfo->pConditions, &sStreamReaderInfo->pFilterInfo, 0, NULL));
231,894!
3200
      }
3201
      (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
28,140,084✔
3202
      sStreamReaderInfo->pVnode = pVnode;
28,138,655✔
3203
    }
3204
    switch (req.base.type) {
28,210,862!
3205
      case STRIGGER_PULL_SET_TABLE:
44,486✔
3206
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
44,486!
3207
        break;
44,486✔
3208
      case STRIGGER_PULL_LAST_TS:
223,016✔
3209
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
223,016!
3210
        break;
222,488✔
3211
      case STRIGGER_PULL_FIRST_TS:
190,229✔
3212
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
190,229✔
3213
        break;
188,604✔
3214
      case STRIGGER_PULL_TSDB_META:
399,060✔
3215
      case STRIGGER_PULL_TSDB_META_NEXT:
3216
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
399,060✔
3217
        break;
397,976✔
3218
      case STRIGGER_PULL_TSDB_TS_DATA:
14,901✔
3219
        if (sStreamReaderInfo->isVtableStream) {
14,901!
UNCOV
3220
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
3221
        } else {
3222
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
14,901!
3223
        }
3224
        break;
14,901✔
3225
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
160,330✔
3226
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
3227
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
160,330!
3228
        break;
160,330✔
3229
      case STRIGGER_PULL_TSDB_CALC_DATA:
14,924,373✔
3230
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
3231
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
14,924,373✔
3232
        break;
14,893,503✔
3233
      case STRIGGER_PULL_TSDB_DATA:
79,245✔
3234
      case STRIGGER_PULL_TSDB_DATA_NEXT:
3235
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
79,245!
3236
        break;
79,245✔
3237
      case STRIGGER_PULL_GROUP_COL_VALUE:
345,146✔
3238
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
345,146!
3239
        break;
345,146✔
3240
      case STRIGGER_PULL_VTABLE_INFO:
192,422✔
3241
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
192,422!
3242
        break;
192,422✔
3243
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
146,613✔
3244
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req));
146,613!
3245
        break;
146,613✔
3246
      case STRIGGER_PULL_OTABLE_INFO:
44,486✔
3247
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req));
44,486!
3248
        break;
44,486✔
3249
      case STRIGGER_PULL_WAL_META_NEW:
5,401,716✔
3250
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
5,401,716!
3251
        break;
5,400,616✔
3252
      case STRIGGER_PULL_WAL_DATA_NEW:
1,812,380✔
3253
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
1,812,380!
3254
        break;
1,811,836✔
3255
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,853,669✔
3256
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,853,669!
3257
        break;
3,854,207✔
3258
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
378,790✔
3259
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
378,790!
3260
        break;
378,241✔
3261
      default:
×
3262
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
3263
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3264
        break;
×
3265
    }
3266
  } else {
3267
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
3268
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3269
  }
3270
end:
28,189,644✔
3271

3272
  streamReleaseTask(taskAddr);
28,208,723✔
3273

3274
  tDestroySTriggerPullRequest(&req);
28,214,179✔
3275
  STREAM_PRINT_LOG_END(code, lino);
28,201,191!
3276
  return code;
28,204,298✔
3277
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc