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

taosdata / TDengine / #4820

20 Oct 2025 09:08AM UTC coverage: 61.353% (-0.04%) from 61.392%
#4820

push

travis-ci

happyguoxy
add alarm result print

156500 of 324369 branches covered (48.25%)

Branch coverage included in aggregate %.

207878 of 269535 relevant lines covered (77.12%)

242602011.17 hits per line

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

66.64
/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)); }
38,840,770✔
60

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

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

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

73
  return 0;
×
74
}
75

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

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

86
  return 0;
×
87
}
88

89
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
29,872,371✔
90
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
29,872,371✔
91
  if (pSrc == NULL) {
29,888,443!
92
    return terrno;
×
93
  }
94

95
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
29,888,443!
96
  return 0;
29,875,074✔
97
}
98

99
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
44,469,889✔
100
  int32_t code = pTask->api.tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
44,469,889✔
101
  if (code != TSDB_CODE_SUCCESS) {
44,472,714!
102
    pTask->api.tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
103
  }
104

105
  return code;
44,466,019✔
106
}
107

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

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

130
static bool needRefreshTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
2,370,300✔
131
  if (sStreamReaderInfo->isVtableStream) {
2,370,300!
132
    int64_t id[2] = {suid, uid};
799,670✔
133
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id)) == NULL) {
799,670!
134
      return true;
790,306✔
135
    }
136
  } else {
137
    if (tableType != TD_CHILD_TABLE) {
1,573,299✔
138
      return false;
491,738✔
139
    }
140
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
1,081,561✔
141
        suid == sStreamReaderInfo->suid && 
655,509✔
142
        qStreamGetGroupId(sStreamReaderInfo->tableList, uid) == -1) {
26,864✔
143
      return true;
8,097✔
144
    }
145
  }
146
  return false;
1,081,490✔
147
}
148

149
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc){
41,696,726✔
150
  if (sStreamReaderInfo->isVtableStream) {
41,696,726!
151
    int64_t tmp[2] = {suid, uid};
13,954,213✔
152
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) == NULL) {
13,952,872✔
153
      return false;
4,716,259✔
154
    }
155
    *id = uid;
9,256,661✔
156
  } else {
157
    if (sStreamReaderInfo->tableList == NULL) return false;
27,761,250!
158

159
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
27,766,598✔
160
      if (suid != sStreamReaderInfo->suid) return false;
17,744,292✔
161
      if (sStreamReaderInfo->pTagCond == NULL) {
13,299,039✔
162
        if (sStreamReaderInfo->partitionCols == NULL){
11,046,563✔
163
          *id = 0;
54,806✔
164
        } else if (sStreamReaderInfo->groupByTbname){
10,993,095!
165
          *id= uid;
10,971,799✔
166
        } else {
167
          *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
21,296✔
168
          if (*id == -1) return false;
21,296!
169
        }
170
      } else {
171
        //*id= uid;
172
        *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
2,252,482✔
173
        if (*id == -1) return false;
2,251,132✔
174
      }
175
    } else {
176
      *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
10,039,819✔
177
      if(*id == -1) *id = uid;
10,039,833✔
178
      return uid == sStreamReaderInfo->uid;
10,039,833✔
179
    }
180
  }
181
  return true;
21,602,733✔
182
}
183

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

190
  SStorageAPI api = {0};
2,814,999✔
191
  initStorageAPI(&api);
2,814,999✔
192
  code = qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
2,812,325✔
193
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, 
194
                                         isHistory ? &sStreamReaderInfo->historyTableList : &sStreamReaderInfo->tableList,
195
                                         isHistory ? NULL : sStreamReaderInfo->groupIdMap);
196
  end:
2,815,094✔
197
  nodesDestroyList(groupNew);
2,815,094✔
198
  STREAM_PRINT_LOG_END(code, lino);
2,813,762!
199
  return code;
2,813,762✔
200
}
201

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

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

238

239
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
39,297,482✔
240
  int32_t code = 0;
39,297,482✔
241
  int32_t lino = 0;
39,297,482✔
242
  void*   buf = NULL;
39,297,482✔
243
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
39,297,482!
244
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
2,292,070✔
245
  buf = rpcMallocCont(dataEncodeSize);
2,289,458✔
246
  STREAM_CHECK_NULL_GOTO(buf, terrno);
2,289,422!
247
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
2,289,422✔
248
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
2,290,762!
249
  *data = buf;
2,290,762✔
250
  *size = dataEncodeSize;
2,289,458✔
251
  buf = NULL;
2,289,458✔
252
end:
39,302,794✔
253
  rpcFreeCont(buf);
39,302,794✔
254
  return code;
39,300,114✔
255
}
256

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

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

275
end:
760,712✔
276
  STREAM_PRINT_LOG_END(code, lino);
760,712!
277
  return code;
763,372✔
278
}
279

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

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

300
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
7,196,930✔
301
  int32_t code = 0;
7,196,930✔
302
  int32_t lino = 0;
7,196,930✔
303
  int32_t index = 0;
7,196,930✔
304
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
7,196,930!
305
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
7,194,252!
306
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
7,196,932!
307
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
7,192,934!
308

309
end:
7,195,592✔
310
  return code;
7,195,592✔
311
}
312

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

320
end:
1,359✔
321
  return code;
1,359✔
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,
139,152✔
333
                              int64_t ver) {
334
  int32_t    code = 0;
139,152✔
335
  int32_t    lino = 0;
139,152✔
336
  SDecoder   decoder = {0};
139,152✔
337
  SDeleteRes req = {0};
139,152✔
338
  void* pTask = sStreamReaderInfo->pTask;
139,152✔
339

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

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

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

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

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

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

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

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

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

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

419
  bool found = false;
91,035✔
420
  SVCreateTbReq* pCreateReq = NULL;
91,035✔
421
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
145,913✔
422
    pCreateReq = req.pReqs + iReq;
91,035✔
423
    if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
91,035✔
424
      ST_TASK_ILOG("stream reader scan create table jump, %s", pCreateReq->name);
54,878!
425
      continue;
54,878✔
426
    }
427
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
36,157!
428

429
    found = true;
36,157✔
430
    break;
36,157✔
431
  }
432
  STREAM_CHECK_CONDITION_GOTO(!found, TDB_CODE_SUCCESS);
91,035✔
433

434
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
36,157!
435
end:
91,035✔
436
  tDeleteSVCreateTbBatchReq(&req);
91,035✔
437
  tDecoderClear(&decoder);
91,035✔
438
  return code;
89,703✔
439
}
440

441
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq) {
2,277,927✔
442
  int32_t  code = 0;
2,277,927✔
443
  int32_t  lino = 0;
2,277,927✔
444
  void*    pTask = sStreamReaderInfo->pTask;
2,277,927✔
445
  if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
2,277,927✔
446
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
1,516,997✔
447
    goto end;
1,518,350✔
448
  }
449
  ST_TASK_ILOG("stream reader scan auto create table %s", pCreateReq->name);
762,246!
450

451
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
762,246!
452
end:
762,246✔
453
  return code;
2,280,596✔
454
}
455

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

462
  SVAlterTbReq req = {0};
143,052✔
463
  tDecoderInit(&decoder, data, len);
144,384✔
464
  
465
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
144,384!
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);
144,384!
467

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

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

477
end:
144,384✔
478
  taosArrayDestroy(req.pMultiTag);
144,384✔
479
  tDecoderClear(&decoder);
143,052✔
480
  return code;
143,052✔
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) {
9,477,441✔
527
  int32_t code = 0;
9,477,441✔
528
  int32_t lino = 0;
9,477,441✔
529
  WalMetaResult walMeta = {0};
9,477,441✔
530
  SSubmitTbData submitTbData = {0};
9,485,419✔
531
  
532
  if (tStartDecode(pCoder) < 0) {
9,482,766!
533
    code = TSDB_CODE_INVALID_MSG;
×
534
    TSDB_CHECK_CODE(code, lino, end);
×
535
  }
536

537
  uint8_t       version = 0;
9,490,766✔
538
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
9,484,226!
539
    code = TSDB_CODE_INVALID_MSG;
×
540
    TSDB_CHECK_CODE(code, lino, end);
×
541
  }
542
  version = (submitTbData.flags >> 8) & 0xff;
9,484,226✔
543
  submitTbData.flags = submitTbData.flags & 0xff;
9,484,226✔
544

545
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
546
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
9,484,226✔
547
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,104,227!
548
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,101,549!
549
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,101,549!
550
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
1,101,566!
551
  }
552

553
  // submit data
554
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
9,484,138!
555
    code = TSDB_CODE_INVALID_MSG;
×
556
    TSDB_CHECK_CODE(code, lino, end);
×
557
  }
558
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
9,482,795!
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)){
9,482,795✔
564
    goto end;
6,444,109✔
565
  }
566
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,052,011!
567
    code = TSDB_CODE_INVALID_MSG;
×
568
    TSDB_CHECK_CODE(code, lino, end);
×
569
  }
570

571
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
3,052,011!
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;
3,052,011✔
601
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,054,675!
602
      code = TSDB_CODE_INVALID_MSG;
×
603
      TSDB_CHECK_CODE(code, lino, end);
×
604
    }
605

606
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
12,923,126✔
607
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,863,124✔
608
      pCoder->pos += pRow->len;
9,867,119✔
609
      if (iRow == 0){
9,864,456✔
610
#ifndef NO_UNALIGNED_ACCESS
611
        walMeta.skey = pRow->ts;
3,053,344✔
612
#else
613
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
614
#endif
615
      }
616
      if (iRow == nRow - 1) {
9,863,124✔
617
#ifndef NO_UNALIGNED_ACCESS
618
        walMeta.ekey = pRow->ts;
3,054,675✔
619
#else
620
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
621
#endif
622
      }
623
    }
624
  }
625

626
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
3,054,675✔
627
  if (data != NULL) {
3,052,015!
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)));
3,052,015!
632
  }
633

634
end:
9,471,409✔
635
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
9,492,107✔
636
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
9,496,112!
637
  tEndDecode(pCoder);
9,496,112✔
638
  return code;
9,480,115✔
639
}
640

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

648
  tDecoderInit(&decoder, data, len);
9,482,792✔
649
  if (tStartDecode(&decoder) < 0) {
9,481,464!
650
    code = TSDB_CODE_INVALID_MSG;
×
651
    TSDB_CHECK_CODE(code, lino, end);
×
652
  }
653

654
  uint64_t nSubmitTbData = 0;
9,484,113✔
655
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
9,484,184!
656
    code = TSDB_CODE_INVALID_MSG;
×
657
    TSDB_CHECK_CODE(code, lino, end);
×
658
  }
659

660
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
9,484,184✔
661
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
9,480,128!
662

663
  for (int32_t i = 0; i < nSubmitTbData; i++) {
18,966,915✔
664
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash));
9,476,110!
665
  }
666
  tEndDecode(&decoder);
9,490,805✔
667

668
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
9,484,112!
669
  int32_t iter = 0;
9,482,783✔
670
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
9,484,115✔
671
  while (px != NULL) {
12,534,784✔
672
    WalMetaResult* pMeta = (WalMetaResult*)px;
3,047,999✔
673
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
3,047,999!
674
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
3,054,675✔
675
    rsp->totalRows++;
3,054,675✔
676
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
3,053,343✔
677
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
678
    px = tSimpleHashIterate(gidHash, px, &iter);
3,053,343✔
679
  }
680
end:
9,486,785✔
681
  tDecoderClear(&decoder);
9,482,808✔
682
  tSimpleHashCleanup( gidHash);
9,494,780✔
683
  return code;
9,492,104✔
684
}
685

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

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

701
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
940,573!
702

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

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

713
  schemas = taosArrayInit(8, sizeof(SSchema));
629,030✔
714
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
632,968!
715

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

722
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
632,968!
723

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

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

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

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

741
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
1,359!
742

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

748
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int32_t ver) {
654,617✔
749
  int32_t code = 0;
654,617✔
750
  int32_t lino = 0;
654,617✔
751
  SDecoder dcoder = {0};
654,617✔
752
  tDecoderInit(&dcoder, data, len);
654,617✔
753
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
651,953✔
754
    if (rsp->deleteBlock == NULL) {
139,152✔
755
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
48,046!
756
    }
757
      
758
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
139,152!
759
  } else if (msgType == TDMT_VND_DROP_TABLE && sStreamReaderInfo->deleteOutTbl != 0) {
512,801✔
760
    if (rsp->dropBlock == NULL) {
1,359!
761
      STREAM_CHECK_RET_GOTO(createBlockForDropTable((SSDataBlock**)&rsp->dropBlock));
1,359!
762
    }
763
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
1,359!
764
  } else if (msgType == TDMT_VND_DROP_STB) {
511,442!
765
    STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
×
766
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
511,442✔
767
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, data, len));
91,035!
768
  } else if (msgType == TDMT_VND_ALTER_STB) {
420,407✔
769
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
770
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
362,789✔
771
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, data, len));
143,052!
772
  }
773

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

784
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
10,968,624✔
785
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
10,959,292!
786
  code = walReaderSeekVer(pWalReader, rsp->ver);
10,959,292✔
787
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
10,952,747✔
788
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
9,978,392!
789
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
790
    }
791
    ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
9,987,685✔
792
    code = TSDB_CODE_SUCCESS;
9,982,357✔
793
    goto end;
9,982,357✔
794
  }
795
  STREAM_CHECK_RET_GOTO(code);
974,355!
796

797
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
974,355!
798
  while (1) {
9,772,112✔
799
    code = walNextValidMsg(pWalReader, true);
10,743,719✔
800
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){\
10,731,850✔
801
      ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
972,959✔
802
      code = TSDB_CODE_SUCCESS;
975,611✔
803
      goto end;
975,611✔
804
    }
805
    STREAM_CHECK_RET_GOTO(code);
9,758,891!
806
    rsp->ver = pWalReader->curVersion;
9,758,891✔
807
    SWalCont* wCont = &pWalReader->pHead->head;
9,772,603✔
808
    rsp->verTime = wCont->ingestTs;
9,776,245✔
809
    if (wCont->ingestTs / 1000 > ctime) break;
9,771,000!
810
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
9,762,890✔
811
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
9,772,502✔
812
    int64_t ver = wCont->version;
9,778,802✔
813

814
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
9,773,637✔
815
      TD_VID(pVnode), ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
816
    if (wCont->msgType == TDMT_VND_SUBMIT) {
9,786,884✔
817
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
9,484,116✔
818
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
9,496,120✔
819
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
9,493,456!
820
    } else {
821
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
289,356!
822
    }
823

824
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
9,770,775!
825
      break;
×
826
    }
827
  }
828

829
end:
10,957,968✔
830
  walCloseReader(pWalReader);
10,957,968✔
831
  return code;
10,951,292✔
832
}
833

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

841
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
8,118,960!
842
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
8,114,944!
843
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
8,120,300!
844
  if (numOfExpr == 0) {
8,118,960!
845
    return TSDB_CODE_SUCCESS;
×
846
  }
847

848
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
8,118,960✔
849
  if (uidData == NULL) {
8,124,304✔
850
    api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
380,811✔
851
    code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
379,811✔
852
    api->metaReaderFn.readerReleaseLock(&mr);
380,811✔
853
    STREAM_CHECK_RET_GOTO(code);
380,811!
854

855
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
380,811✔
856
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
380,811!
857
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
380,811!
858
      taosArrayDestroyP(tagCache, taosMemFree);
×
859
      code = terrno;
×
860
      goto end;
×
861
    }
862
  } else {
863
    tagCache = *(SArray**)uidData;
7,743,493✔
864
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
7,739,489!
865
  }
866
  
867
  for (int32_t j = 0; j < numOfExpr; ++j) {
22,150,191✔
868
    const SExprInfo* pExpr1 = &pExprInfo[j];
14,030,222✔
869
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
14,031,556✔
870

871
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
14,032,894✔
872
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
14,028,530!
873
    int32_t functionId = pExpr1->pExpr->_function.functionId;
14,028,530✔
874

875
    // this is to handle the tbname
876
    if (fmIsScanPseudoColumnFunc(functionId)) {
14,028,868✔
877
      int32_t fType = pExpr1->pExpr->_function.functionType;
8,117,606✔
878
      if (fType == FUNCTION_TYPE_TBNAME) {
8,117,606!
879
        char   buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
8,118,944✔
880
        if (uidData == NULL) {
8,118,946✔
881
          STR_TO_VARSTR(buf, mr.me.name)
380,811!
882
          char* tbname = taosStrdup(mr.me.name);
380,811!
883
          STREAM_CHECK_NULL_GOTO(tbname, terrno);
379,811!
884
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno);
759,622!
885
        } else {
886
          char* tbname = taosArrayGetP(tagCache, j);
7,738,135✔
887
          STR_TO_VARSTR(buf, tbname)
7,736,791!
888
        }
889
        for (uint32_t i = 0; i < numOfRows; i++){
24,868,596✔
890
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
16,750,654!
891
        }
892
        code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false);
8,117,942✔
893
        pColInfoData->info.colId = -1;
8,117,613✔
894
      }
895
    } else {  // these are tags
896
      char* data = NULL;
5,912,278✔
897
      const char* p = NULL;
5,912,278✔
898
      STagVal tagVal = {0};
5,912,278✔
899
      if (uidData == NULL) {
5,912,278✔
900
        tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
314,688✔
901
        p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
314,688✔
902

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

909
        if (data == NULL) {
314,688!
910
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
×
911
        } else {
912
          int32_t len = pColInfoData->info.bytes;
314,688✔
913
          if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
314,688!
914
            len = calcStrBytesByType(pColInfoData->info.type, (char*)data);
94,930✔
915
          }
916
          char* pData = taosMemoryCalloc(1, len);
314,688!
917
          STREAM_CHECK_NULL_GOTO(pData, terrno);
314,688!
918
          (void)memcpy(pData, data, len);
314,688!
919
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno);
629,376!
920
        }
921
      } else {
922
        data = taosArrayGetP(tagCache, j);
5,597,590✔
923
      }
924

925
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
5,910,938!
926
      if (isNullVal) {
5,910,938!
927
        colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
928
      } else {
929
        for (uint32_t i = 0; i < numOfRows; i++){
46,579,142✔
930
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
40,666,864!
931
        }
932
        code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false);
5,912,278✔
933
        if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
5,913,622!
934
          taosMemoryFree(data);
94,930!
935
        }
936
        STREAM_CHECK_RET_GOTO(code);
5,912,284!
937
      }
938
    }
939
  }
940

941
end:
8,118,631✔
942
  api->metaReaderFn.clearReader(&mr);
8,118,951✔
943
  return code;
8,116,273✔
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, 
14,612,379✔
992
  STSchema** schemas, SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
993
  int32_t code = 0;
14,612,379✔
994
  int32_t lino = 0;
14,612,379✔
995
  uint64_t id = 0;
14,612,379✔
996
  WalMetaResult walMeta = {0};
14,615,059✔
997
  void* pTask = sStreamReaderInfo->pTask;
14,624,439✔
998
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
14,628,463✔
999

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

1005
  SSubmitTbData submitTbData = {0};
14,627,125✔
1006
  uint8_t       version = 0;
14,627,125✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
14,609,713!
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
14,609,713✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
14,609,713✔
1013
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1014
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
14,609,713✔
1015
    if (tStartDecode(pCoder) < 0) {
36,921!
1016
      code = TSDB_CODE_INVALID_MSG;
×
1017
      TSDB_CHECK_CODE(code, lino, end);
×
1018
    }
1019
    tEndDecode(pCoder);
36,921✔
1020
  }
1021

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

1034
  walMeta.id = id;
11,366,963✔
1035
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
11,366,963✔
1036

1037
  if (ranges != NULL){
11,373,667✔
1038
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
7,317,094✔
1039
    if (timerange == NULL) goto end;;
7,321,110!
1040
    int64_t* pRange = (int64_t*)timerange;
7,321,110✔
1041
    window.skey = pRange[0];
7,321,110✔
1042
    window.ekey = pRange[1];
7,321,110✔
1043
  }
1044
  
1045
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
11,375,005!
1046
    code = TSDB_CODE_INVALID_MSG;
×
1047
    TSDB_CHECK_CODE(code, lino, end);
×
1048
  }
1049

1050
  if (*schemas == NULL) {
11,375,005✔
1051
    *schemas = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
11,365,625✔
1052
    STREAM_CHECK_NULL_GOTO(*schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
11,364,320!
1053
  }
1054

1055
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &submitTbData.uid, LONG_BYTES);
11,384,411✔
1056
  STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
11,369,649!
1057
  int32_t blockStart = pSlice->currentRowIdx;
11,369,649✔
1058

1059
  int32_t numOfRows = 0;
11,369,649✔
1060
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
11,355,278!
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;
11,355,278✔
1148
    if (tDecodeU64v(pCoder, &nRow) < 0) {
11,368,651!
1149
      code = TSDB_CODE_INVALID_MSG;
×
1150
      TSDB_CHECK_CODE(code, lino, end);
×
1151
    }
1152
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
29,441,139✔
1153
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
18,051,452✔
1154
      pCoder->pos += pRow->len;
18,068,821✔
1155

1156
      if (iRow == 0){
18,075,185✔
1157
#ifndef NO_UNALIGNED_ACCESS
1158
        walMeta.skey = pRow->ts;
11,374,009✔
1159
#else
1160
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1161
#endif
1162
      }
1163
      if (iRow == nRow - 1) {
18,065,828✔
1164
#ifndef NO_UNALIGNED_ACCESS
1165
        walMeta.ekey = pRow->ts;
11,369,999✔
1166
#else
1167
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1168
#endif
1169
      }
1170

1171
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
18,055,094!
1172
        continue;
40,160✔
1173
      }
1174
     
1175
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
131,886,145✔
1176
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
113,849,645✔
1177
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
113,844,075!
1178
        if (pColData->info.colId <= -1) {
113,844,075✔
1179
          pColData->hasNull = true;
34,450,757✔
1180
          continue;
34,450,757✔
1181
        }
1182
        int16_t colId = 0;
79,393,683✔
1183
        if (sStreamReaderInfo->isVtableStream){
79,393,683!
1184
          int64_t id[2] = {submitTbData.suid, submitTbData.uid};
9,344,640✔
1185
          void* px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
9,348,649!
1186
          STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
9,363,327!
1187
          SSHashObj* uInfo = *(SSHashObj**)px;
9,363,327✔
1188
          STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
9,359,307!
1189
          int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
9,359,307✔
1190
          if (tmp != NULL) {
9,356,662✔
1191
            colId = *tmp;
7,764,290✔
1192
          } else {
1193
            colId = -1;
1,592,372✔
1194
          }
1195
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
9,360,658!
1196
        } else {
1197
          colId = pColData->info.colId;
70,059,427✔
1198
        }
1199
        
1200
        SColVal colVal = {0};
79,407,057✔
1201
        int32_t sourceIdx = 0;
79,405,728✔
1202
        while (1) {
1203
          if (sourceIdx >= (*schemas)->numOfCols) {
199,799,633✔
1204
            break;
40,380,272✔
1205
          }
1206
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, *schemas, sourceIdx, &colVal));
159,387,006!
1207
          if (colVal.cid == colId) {
159,445,873✔
1208
            break;
39,051,968✔
1209
          }
1210
          sourceIdx++;
120,393,905✔
1211
        }
1212
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
79,432,240✔
1213
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
38,474,967!
1214
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
116,182!
1215
          } else {
1216
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
38,358,785!
1217
          }
1218
        } else {
1219
          colDataSetNULL(pColData, blockStart + numOfRows);
40,957,273!
1220
        }
1221
      }
1222
      
1223
      numOfRows++;
18,032,328✔
1224
    }
1225
  }
1226

1227
  if (numOfRows > 0) {
11,372,314!
1228
    if (!sStreamReaderInfo->isVtableStream) {
11,372,314✔
1229
      SStorageAPI  api = {0};
7,883,745✔
1230
      initStorageAPI(&api);
7,879,729✔
1231
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
7,877,408!
1232
    }
1233
    
1234
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
11,368,307✔
1235
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
11,359,289!
1236
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
11,359,289!
1237
  }
1238

1239
  ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
11,365,615✔
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;
11,370,970✔
1243
  pBlock->info.rows += numOfRows;
11,370,983✔
1244
  
1245
  if (gidHash == NULL) goto end;
11,373,663✔
1246

1247
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
4,056,571✔
1248
  if (data != NULL) {
4,055,227!
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)));
4,055,227!
1253
  }
1254

1255
end:
14,614,306✔
1256
  if (code != 0) {                                                             \
14,620,415!
1257
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1258
  }
1259
  tEndDecode(pCoder);
14,620,415✔
1260
  return code;
14,613,717✔
1261
}
1262
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
14,616,405✔
1263
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1264
  int32_t  code = 0;
14,616,405✔
1265
  int32_t  lino = 0;
14,616,405✔
1266
  STSchema* schemas = NULL;
14,616,405✔
1267
  SDecoder decoder = {0};
14,619,085✔
1268
  SSHashObj* gidHash = NULL;
14,625,783✔
1269
  void* pTask = sStreamReaderInfo->pTask;
14,625,783✔
1270

1271
  tDecoderInit(&decoder, data, len);
14,625,783✔
1272
  if (tStartDecode(&decoder) < 0) {
14,617,747!
1273
    code = TSDB_CODE_INVALID_MSG;
×
1274
    TSDB_CHECK_CODE(code, lino, end);
×
1275
  }
1276

1277
  uint64_t nSubmitTbData = 0;
14,627,128✔
1278
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
14,621,757!
1279
    code = TSDB_CODE_INVALID_MSG;
×
1280
    TSDB_CHECK_CODE(code, lino, end);
×
1281
  }
1282

1283
  if (rsp->metaBlock != NULL){
14,621,757✔
1284
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,303,325✔
1285
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
7,309,934!
1286
  }
1287

1288
  for (int32_t i = 0; i < nSubmitTbData; i++) {
29,240,747✔
1289
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, &schemas, ranges, gidHash, rsp, ver));
14,614,966!
1290
  }
1291

1292
  tEndDecode(&decoder);
14,625,781✔
1293

1294
  if (rsp->metaBlock != NULL){
14,615,059✔
1295
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
7,306,003!
1296
    int32_t iter = 0;
7,297,961✔
1297
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
7,299,299✔
1298
    while (px != NULL) {
11,362,582✔
1299
      WalMetaResult* pMeta = (WalMetaResult*)px;
4,055,233✔
1300
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
4,055,233!
1301
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
4,052,553✔
1302
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
4,055,231✔
1303
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1304
      px = tSimpleHashIterate(gidHash, px, &iter);
4,055,231✔
1305
    }
1306
  }
1307
  
1308

1309
end:
14,610,889✔
1310
  taosMemoryFree(schemas);
14,628,463!
1311
  tSimpleHashCleanup(gidHash);
14,617,737✔
1312
  tDecoderClear(&decoder);
14,615,063✔
1313
  return code;
14,625,775✔
1314
}
1315

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

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

1327
  SSubmitTbData submitTbData = {0};
17,511,869✔
1328
  uint8_t       version = 0;
17,511,869✔
1329
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
17,518,607!
1330
    code = TSDB_CODE_INVALID_MSG;
×
1331
    TSDB_CHECK_CODE(code, lino, end);
×
1332
  }
1333
  version = (submitTbData.flags >> 8) & 0xff;
17,518,607✔
1334
  submitTbData.flags = submitTbData.flags & 0xff;
17,518,607✔
1335

1336
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1337
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
17,518,607✔
1338
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,175,029!
1339
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,169,667!
1340
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,169,667!
1341
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
1,175,033!
1342
  }
1343

1344
  // submit data
1345
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
17,514,575!
1346
    code = TSDB_CODE_INVALID_MSG;
×
1347
    TSDB_CHECK_CODE(code, lino, end);
×
1348
  }
1349
  if (tDecodeI64(pCoder, uid) < 0) {
17,503,833!
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);
17,503,833✔
1355

1356
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
11,370,999✔
1357

1358
  if (ranges != NULL){
11,370,999✔
1359
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
7,318,444✔
1360
    if (timerange == NULL) goto end;;
7,322,454!
1361
    int64_t* pRange = (int64_t*)timerange;
7,322,454✔
1362
    window.skey = pRange[0];
7,322,454✔
1363
    window.ekey = pRange[1];
7,322,454✔
1364
  }
1365
  
1366
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
11,375,007!
1367
    code = TSDB_CODE_INVALID_MSG;
×
1368
    TSDB_CHECK_CODE(code, lino, end);
×
1369
  }
1370

1371
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
11,375,007!
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;
11,375,007✔
1398
    if (tDecodeU64v(pCoder, &nRow) < 0) {
11,373,686!
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) { 
11,373,686!
1404
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
21,284,482✔
1405
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
13,964,687✔
1406
        pCoder->pos += pRow->len;
13,964,687✔
1407
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
13,962,007!
1408
          continue;
40,160✔
1409
        }
1410
        (*numOfRows)++;
13,924,527✔
1411
      }
1412
    } else {
1413
      (*numOfRows) = nRow;
4,055,231✔
1414
    }
1415
  }
1416
  
1417
end:
17,522,624✔
1418
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
17,517,248✔
1419
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
17,517,161!
1420
  tEndDecode(pCoder);
17,515,823✔
1421
  return code;
17,506,530✔
1422
}
1423

1424
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
17,521,291✔
1425
  int32_t  code = 0;
17,521,291✔
1426
  int32_t  lino = 0;
17,521,291✔
1427
  SDecoder decoder = {0};
17,521,291✔
1428
  void* pTask = sStreamReaderInfo->pTask;
17,525,309✔
1429

1430
  tDecoderInit(&decoder, data, len);
17,519,949✔
1431
  if (tStartDecode(&decoder) < 0) {
17,483,697!
1432
    code = TSDB_CODE_INVALID_MSG;
×
1433
    TSDB_CHECK_CODE(code, lino, end);
×
1434
  }
1435

1436
  uint64_t nSubmitTbData = 0;
17,515,893✔
1437
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
17,515,911!
1438
    code = TSDB_CODE_INVALID_MSG;
×
1439
    TSDB_CHECK_CODE(code, lino, end);
×
1440
  }
1441

1442
  for (int32_t i = 0; i < nSubmitTbData; i++) {
35,022,436✔
1443
    uint64_t gid = -1;
17,513,233✔
1444
    int64_t  uid = 0;
17,509,201✔
1445
    int32_t numOfRows = 0;
17,511,881✔
1446
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp->isCalc));
17,511,881!
1447
    if (numOfRows <= 0) {
17,518,606✔
1448
      continue;
6,148,950✔
1449
    }
1450
    rsp->totalRows += numOfRows;
11,369,656✔
1451

1452
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &uid, LONG_BYTES);
11,379,025✔
1453
    if (pSlice != NULL) {
11,372,337✔
1454
      pSlice->numRows += numOfRows;
10,858,008✔
1455
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d", __func__, uid, gid, pSlice->numRows);
10,860,684✔
1456
      pSlice->gId = gid;
10,860,684✔
1457
    } else {
1458
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
514,329✔
1459
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d", __func__, uid, gid, tmp.numRows);
514,329✔
1460
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(sStreamReaderInfo->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
514,329!
1461
    } 
1462
  }
1463

1464
  tEndDecode(&decoder);
17,509,203✔
1465

1466
end:
17,506,539✔
1467
  tDecoderClear(&decoder);
17,513,245✔
1468
  return code;
17,514,563✔
1469
}
1470

1471
static void resetIndexHash(SSHashObj* indexHash){
12,497,887✔
1472
  void*   pe = NULL;
12,497,887✔
1473
  int32_t iter = 0;
12,497,887✔
1474
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
30,967,060✔
1475
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
18,478,518✔
1476
    pInfo->startRowIdx = 0;
18,478,518✔
1477
    pInfo->currentRowIdx = 0;
18,481,200✔
1478
    pInfo->numRows = 0;
18,426,326✔
1479
    pInfo->gId = -1;
18,441,058✔
1480
  }
1481
}
12,507,254✔
1482

1483
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
1,251,515✔
1484
  void*   pe = NULL;
1,251,515✔
1485
  int32_t iter = 0;
1,251,515✔
1486
  int32_t index = 0;
1,251,515✔
1487
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
4,442,853✔
1488
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
3,191,338✔
1489
    pInfo->startRowIdx = index;
3,191,338✔
1490
    pInfo->currentRowIdx = index;
3,191,338✔
1491
    index += pInfo->numRows;
3,191,338✔
1492
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
3,876,366!
1493
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1494
  }
1495
}
1,251,515✔
1496

1497
static void printIndexHash(SSHashObj* indexHash, void* pTask){
1,248,827✔
1498
  void*   pe = NULL;
1,248,827✔
1499
  int32_t iter = 0;
1,248,827✔
1500
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
4,436,133✔
1501
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
3,187,306✔
1502
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
3,872,334!
1503
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1504
  }
1505
}
1,248,827✔
1506

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

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

1534
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
8,397,286✔
1535
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
8,406,779✔
1536
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
7,094,939!
1537
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
1538
    }
1539
    ST_TASK_DLOG("%s scan wal error:%s",  __func__, tstrerror(code));
7,094,941✔
1540
    code = TSDB_CODE_SUCCESS;
7,085,557✔
1541
    goto end;
7,085,557✔
1542
  }
1543
  STREAM_CHECK_RET_GOTO(code);
1,311,840!
1544

1545
  while (1) {
10,564,084✔
1546
    code = walNextValidMsg(pWalReader, true);
11,875,924✔
1547
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
11,869,190✔
1548
      ST_TASK_DLOG("%s scan wal error:%s", __func__, tstrerror(code));
1,315,832✔
1549
      code = TSDB_CODE_SUCCESS;
1,317,184✔
1550
      goto end;
1,317,184✔
1551
    }
1552
    STREAM_CHECK_RET_GOTO(code);
10,553,358!
1553
    resultRsp->ver = pWalReader->curVersion;
10,553,358✔
1554
    SWalCont* wCont = &pWalReader->pHead->head;
10,553,358✔
1555
    resultRsp->verTime = wCont->ingestTs;
10,549,142✔
1556
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
10,556,046✔
1557
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
10,552,030✔
1558
    int64_t ver = wCont->version;
10,554,702✔
1559
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d", __func__,
10,546,565✔
1560
      ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1561
    if (wCont->msgType == TDMT_VND_SUBMIT) {
10,552,115✔
1562
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
10,198,825✔
1563
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
10,196,131✔
1564
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp));
10,193,451!
1565
    } else if (wCont->msgType == TDMT_VND_ALTER_TABLE && resultRsp->totalRows > 0) {
363,929!
1566
      resultRsp->ver--;
×
1567
      break;
10✔
1568
    } else {
1569
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
363,929!
1570
    }
1571

1572
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
10,563,609✔
1573
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
10,563,609!
1574
      break;
×
1575
    }
1576
  }
1577
  
1578
end:
8,400,075✔
1579
  STREAM_PRINT_LOG_END(code, lino);
8,400,075!
1580
  return code;
8,404,091✔
1581
}
1582

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

1588
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
11,425,613✔
1589
    int64_t *ver = taosArrayGet(versions, i);
7,315,750✔
1590
    if (ver == NULL) continue;
7,321,114!
1591

1592
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
7,321,114!
1593
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
7,319,774!
1594
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1595
      continue;
×
1596
    }
1597
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
7,319,774!
1598

1599
    SWalCont* wCont = &pWalReader->pHead->head;
7,318,442✔
1600
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
7,319,782✔
1601
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
7,319,782✔
1602

1603
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp));
7,321,122!
1604
  }
1605
  
1606
end:
4,103,171✔
1607
  return code;
4,103,171✔
1608
}
1609

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

1620
end:
1,251,515✔
1621
  colDataDestroy(pRet);
1,251,515✔
1622
  taosMemoryFree(pRet);
1,251,515!
1623
  return code;
1,251,515✔
1624
}
1625

1626
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
8,401,415✔
1627
                                    SSTriggerWalNewRsp* resultRsp) {
1628
  int32_t      code = 0;
8,401,415✔
1629
  int32_t      lino = 0;
8,401,415✔
1630
  void* pTask = sStreamReaderInfo->pTask;
8,401,415✔
1631
                                        
1632
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
8,402,765✔
1633
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
8,402,755!
1634
  resetIndexHash(sStreamReaderInfo->indexHash);
8,402,755✔
1635
  blockDataEmpty(resultRsp->dataBlock);
8,404,083✔
1636
  blockDataEmpty(resultRsp->metaBlock);
8,401,320✔
1637
  int64_t lastVer = resultRsp->ver;                                      
8,383,904✔
1638
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
8,383,904!
1639
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
8,401,409✔
1640

1641
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
382,087✔
1642
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
382,087!
1643
  while(lastVer < resultRsp->ver) {
7,952,944✔
1644
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
7,570,857!
1645
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
7,570,859✔
1646
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
263,510!
1647
      continue;
264,848✔
1648
    }
1649
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
7,307,349!
1650
    SWalCont* wCont = &pWalReader->pHead->head;
7,306,009✔
1651
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
7,306,009✔
1652
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
7,306,009✔
1653

1654
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
7,306,009!
1655
  }
1656

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

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

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

1673
  void* pTask = sStreamReaderInfo->pTask;
4,099,159✔
1674
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
4,101,823✔
1675
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
4,101,831!
1676
  
1677
  if (taosArrayGetSize(versions) > 0) {
4,101,831✔
1678
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
869,428✔
1679
  }
1680
  
1681
  resetIndexHash(sStreamReaderInfo->indexHash);
4,101,831✔
1682
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
4,104,503!
1683
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
4,103,171✔
1684

1685
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
869,428✔
1686

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

1690
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
8,174,464✔
1691
    int64_t *ver = taosArrayGet(versions, i);
7,315,754✔
1692
    if (ver == NULL) continue;
7,309,046!
1693

1694
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
7,309,046!
1695
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
7,318,432!
1696
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1697
      continue;
×
1698
    }
1699
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
7,307,712!
1700
    SWalCont* wCont = &pWalReader->pHead->head;
7,315,764✔
1701
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
7,319,782✔
1702
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
7,321,122✔
1703

1704
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
7,318,444!
1705
  }
1706
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
1707
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
870,768!
1708
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
869,428✔
1709

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

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

1729
  SSchemaWrapper* sSchemaWrapper = NULL;
190,483✔
1730
  if (metaReader.me.type == TD_CHILD_TABLE) {
190,483!
1731
    int64_t suid = metaReader.me.ctbEntry.suid;
190,483✔
1732
    tDecoderClear(&metaReader.coder);
190,483✔
1733
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
190,483!
1734
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
190,483✔
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++) {
637,987✔
1742
    SSchema* s = sSchemaWrapper->pSchema + j;
447,504✔
1743
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
895,008!
1744
  }
1745

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

1756
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
190,483✔
1757
  int32_t code = 0;
190,483✔
1758
  int32_t lino = 0;
190,483✔
1759
  size_t  schemaLen = taosArrayGetSize(schemas);
190,483✔
1760
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
190,483!
1761
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
580,796✔
1762
    col_id_t* id = taosArrayGet(cols, i);
390,313✔
1763
    STREAM_CHECK_NULL_GOTO(id, terrno);
390,313!
1764
    for (size_t i = 0; i < schemaLen; i++) {
647,334!
1765
      SSchema* s = taosArrayGet(schemas, i);
647,334✔
1766
      STREAM_CHECK_NULL_GOTO(s, terrno);
647,334!
1767
      if (*id == s->colId) {
647,334✔
1768
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
390,313!
1769
        break;
390,313✔
1770
      }
1771
    }
1772
  }
1773
  taosArrayPopFrontBatch(schemas, schemaLen);
190,483✔
1774

1775
end:
190,483✔
1776
  return code;
190,483✔
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,
447,155✔
1930
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
1931
  int32_t code = 0;
447,155✔
1932
  int32_t lino = 0;
447,155✔
1933
  void* pTask = sStreamReaderCalcInfo->pTask;
447,155✔
1934
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
447,155!
1935
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
447,155!
1936
  
1937
  if (req->pStRtFuncInfo->withExternalWindow) {
447,155✔
1938
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
259,365✔
1939
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
259,365✔
1940
    
1941
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
259,365✔
1942
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
259,365✔
1943
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
259,365!
1944
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
259,365!
1945

1946
    if (!node->needCalc) {
259,365✔
1947
      pWin->skey = pFirst->wstart;
190,400✔
1948
      pWin->ekey = pLast->wend;
190,400✔
1949
      *pValid = true;
190,400✔
1950
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
190,400✔
1951
        pWin->ekey--;
126,674✔
1952
      }
1953
    } else {
1954
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
68,965✔
1955
      memcpy(pTmp, pFirst, sizeof(*pTmp));
68,965!
1956

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

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

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

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

1988
end:
46,836✔
1989

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

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

2002
  void* pTask = sStreamReaderInfo->pTask;
1,035,094✔
2003
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTaskInner->pTableList), sizeof(STsInfo));
1,039,068✔
2004
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
1,040,408!
2005
  while (true) {
762,041✔
2006
    bool hasNext = false;
1,802,449✔
2007
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,801,109!
2008
    if (hasNext) {
1,788,128!
2009
      pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
755,659✔
2010
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
755,659✔
2011
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
755,319!
2012
      if (pTaskInner->options.order == TSDB_ORDER_ASC) {
755,319✔
2013
        tsInfo->ts = pTaskInner->pResBlock->info.window.skey;
483,666✔
2014
      } else {
2015
        tsInfo->ts = pTaskInner->pResBlock->info.window.ekey;
270,349✔
2016
      }
2017
      tsInfo->gId = (sStreamReaderInfo->groupByTbname || sStreamReaderInfo->tableType != TSDB_SUPER_TABLE) ? 
1,676,744!
2018
                    pTaskInner->pResBlock->info.id.uid : qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
916,067✔
2019
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
759,337✔
2020
              tsInfo->gId, tsRsp->ver);
2021
    }
2022
    
2023
    pTaskInner->currentGroupIndex++;
1,791,806✔
2024
    if (pTaskInner->currentGroupIndex >= qStreamGetTableListGroupNum(pTaskInner->pTableList) || pTaskInner->options.gid != 0) {
1,794,480✔
2025
      break;
2026
    }
2027
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTaskInner));
762,041!
2028
  }
2029

2030
end:
1,036,411✔
2031
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,036,411!
2032
  return code;
1,039,070✔
2033
}
2034

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

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

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

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

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

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

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

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

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

2082
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &lastTsRsp, sStreamReaderInfo, pTaskInner));
573,555!
2083
  ST_TASK_DLOG("vgId:%d %s get result, ver:%" PRId64, TD_VID(pVnode), __func__, lastTsRsp.ver);
574,895✔
2084
  STREAM_CHECK_RET_GOTO(buildTsRsp(&lastTsRsp, &buf, &size))
574,895!
2085
  if (stDebugFlag & DEBUG_DEBUG) {
574,895✔
2086
    int32_t nInfo = taosArrayGetSize(lastTsRsp.tsInfo);
416,887✔
2087
    for (int32_t i = 0; i < nInfo; i++) {
634,989✔
2088
      STsInfo* tsInfo = TARRAY_GET_ELEM(lastTsRsp.tsInfo, i);
219,433✔
2089
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
218,433!
2090
    }
2091
  }
2092

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

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

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

2123
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(firstTsRsp.tsInfo), firstTsRsp.ver);
465,513✔
2124
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
465,513!
2125
  if (stDebugFlag & DEBUG_DEBUG) {
465,513✔
2126
    int32_t nInfo = taosArrayGetSize(firstTsRsp.tsInfo);
295,481✔
2127
    for (int32_t i = 0; i < nInfo; i++) {
566,249✔
2128
      STsInfo* tsInfo = TARRAY_GET_ELEM(firstTsRsp.tsInfo, i);
270,768✔
2129
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
270,768!
2130
    }
2131
  }
2132

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

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

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

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

2156
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
943,235!
2157
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, sStreamReaderInfo->tsSchemas, true, 
943,235✔
2158
      (req->tsdbMetaReq.gid != 0 ? STREAM_SCAN_GROUP_ONE_BY_ONE : STREAM_SCAN_ALL), req->tsdbMetaReq.gid, true, sStreamReaderInfo->uidHashTrigger);
2159
    SStorageAPI api = {0};
943,235✔
2160
    initStorageAPI(&api);
943,235✔
2161
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, &api));
943,235✔
2162
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
940,573!
2163
    
2164
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
940,573!
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);
940,573✔
2173
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
940,573!
2174
  bool hasNext = true;
940,573✔
2175
  while (true) {
266,522✔
2176
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
1,207,095!
2177
    if (!hasNext) {
1,207,095!
2178
      break;
940,573✔
2179
    }
2180
    pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
266,522✔
2181
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
266,522✔
2182

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

2192
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
266,522✔
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++;
266,522✔
2196
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
266,522!
2197
      break;
×
2198
    }
2199
  }
2200

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

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

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

2224
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
31,700!
2225
  void* pTask = sStreamReaderInfo->pTask;
31,700✔
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, 
31,700!
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,
31,700✔
2231
               sStreamReaderInfo->triggerCols, false, STREAM_SCAN_ALL, 0, true, NULL);
2232
  options.uid = req->tsdbTsDataReq.uid;
31,700✔
2233
  SStorageAPI api = {0};
31,700✔
2234
  initStorageAPI(&api);
31,700✔
2235
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
31,700!
2236
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
31,700!
2237
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
31,700!
2238

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

2249
    SSDataBlock* pBlock = NULL;
31,700✔
2250
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
31,700!
2251
    if (pBlock != NULL && pBlock->info.rows > 0) {
31,700!
2252
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, false, &api, pBlock->info.id.uid, pBlock,
31,700!
2253
          0, pBlock->info.rows, 1));
2254
    }
2255
    
2256
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
31,700!
2257
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
31,700!
2258
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
31,700!
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);
31,700✔
2264

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

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

2275
  releaseStreamTask(&pTaskInner);
31,700✔
2276
  return code;
31,700✔
2277
}
2278

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

2287
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
×
2288
  void* pTask = sStreamReaderInfo->pTask;
×
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

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);
2295
  options.suid = req->tsdbTsDataReq.suid;
×
2296
  options.uid = req->tsdbTsDataReq.uid;
×
2297
  SStorageAPI api = {0};
×
2298
  initStorageAPI(&api);
×
2299
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &api));
×
2300
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
×
2301

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

2309
    SSDataBlock* pBlock = NULL;
×
2310
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
×
2311
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
×
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

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

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

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

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

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

2344
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
392,234✔
2345
    BUILD_OPTION(options, sStreamReaderInfo, req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
188,746✔
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};
188,746✔
2349
    initStorageAPI(&api);
188,746✔
2350
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &api));
188,746!
2351

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

2361
  blockDataCleanup(pTaskInner->pResBlockDst);
392,234✔
2362
  bool hasNext = true;
392,234✔
2363
  while (1) {
×
2364
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
392,234!
2365
    if (!hasNext) {
392,234!
2366
      break;
188,746✔
2367
    }
2368
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
203,488✔
2369
    pTaskInner->pResBlockDst->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
203,488✔
2370

2371
    SSDataBlock* pBlock = NULL;
203,488✔
2372
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
203,488!
2373
    if (pBlock != NULL && pBlock->info.rows > 0) {
203,488!
2374
      STREAM_CHECK_RET_GOTO(
203,488!
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));
203,488!
2378
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
202,142!
2379
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
203,488✔
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
203,488!
2383
      break;
203,488✔
2384
    }
2385
  }
2386

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

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

2399
  return code;
392,234✔
2400
}
2401

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

2409
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
37,502,645!
2410
  void* pTask = sStreamReaderInfo->pTask;
37,502,645✔
2411
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64, TD_VID(pVnode), __func__, 
37,503,973✔
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);
37,505,301!
2415

2416
  SStreamReaderTaskInner* pTaskInner = NULL;
37,505,301✔
2417
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
37,505,301✔
2418

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

2426
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
37,396,991!
2427
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
37,398,319!
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);
37,391,703✔
2436
  bool hasNext = true;
37,394,359✔
2437
  while (1) {
3,242,630✔
2438
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
40,636,989!
2439
    if (!hasNext) {
40,635,613!
2440
      break;
37,394,359✔
2441
    }
2442
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
3,241,254✔
2443

2444
    SSDataBlock* pBlock = NULL;
3,245,242✔
2445
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
3,245,242!
2446
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, pTaskInner->pFilterInfo, NULL));
3,243,934!
2447
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3,243,938!
2448
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
3,242,630!
2449
      break;
×
2450
    }
2451
  }
2452

2453
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
37,390,375!
2454
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
37,395,707!
2455
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
37,394,355✔
2456
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
37,393,027!
2457
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
37,395,663✔
2458
  if (!hasNext) {
37,396,991!
2459
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
37,396,991!
2460
  }
2461

2462
end:
37,501,269✔
2463
  STREAM_PRINT_LOG_END_WITHID(code, lino);
37,489,385!
2464
  SRpcMsg rsp = {
37,507,937✔
2465
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2466
  tmsgSendRsp(&rsp);
37,505,301✔
2467
  blockDataDestroy(pBlockRes);
37,498,661✔
2468
  return code;
37,501,317✔
2469
}
2470

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

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

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

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

2512
    options.suid = req->tsdbDataReq.suid;
190,483✔
2513
    options.uid = req->tsdbDataReq.uid;
190,483✔
2514

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

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

2524
    STREAM_CHECK_RET_GOTO(qStreamInitQueryTableDataCond(&pTaskInner->cond, pTaskInner->options.order, pTaskInner->options.schemas,
190,483!
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,
190,483!
2528
                                                             (void**)&pTaskInner->pReader, pTaskInner->idStr, NULL));
2529
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pTaskInner->pResBlock, false, &pTaskInner->pResBlockDst));
190,483!
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);
190,483✔
2538
  bool hasNext = true;
190,483✔
2539
  while (1) {
190,483✔
2540
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
380,966!
2541
    if (!hasNext) {
380,966!
2542
      break;
190,483✔
2543
    }
2544

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

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

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

2578
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
11,046,576✔
2579
  void* pTask = sStreamReaderInfo->pTask;
10,964,613✔
2580
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
10,964,621✔
2581

2582
  if (sStreamReaderInfo->metaBlock == NULL) {
10,963,304✔
2583
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
364,807!
2584
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
364,807!
2585
  }
2586
  blockDataEmpty(sStreamReaderInfo->metaBlock);
10,968,624✔
2587
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
10,956,621✔
2588
  resultRsp.ver = req->walMetaNewReq.lastVer;
10,956,621✔
2589
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
10,957,953!
2590

2591
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
10,948,628✔
2592
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
10,945,948✔
2593
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, NULL);
271,470✔
2594
  buf = rpcMallocCont(size);
271,470✔
2595
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, NULL);
271,470✔
2596
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
271,470✔
2597

2598
end:
11,027,911✔
2599
  if (resultRsp.totalRows == 0) {
11,029,243✔
2600
    code = TSDB_CODE_STREAM_NO_DATA;
10,755,109✔
2601
    buf = rpcMallocCont(sizeof(int64_t));
10,755,109✔
2602
    *(int64_t *)buf = resultRsp.ver;
10,736,469✔
2603
    size = sizeof(int64_t);
10,741,797✔
2604
  }
2605
  SRpcMsg rsp = {
11,015,931✔
2606
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2607
  tmsgSendRsp(&rsp);
11,026,589✔
2608
  if (code == TSDB_CODE_STREAM_NO_DATA){
11,063,915✔
2609
    code = 0;
10,792,445✔
2610
  }
2611
  STREAM_PRINT_LOG_END_WITHID(code, lino);
11,063,915!
2612
  blockDataDestroy(resultRsp.deleteBlock);
11,065,259✔
2613
  blockDataDestroy(resultRsp.dropBlock);
11,061,251✔
2614

2615
  return code;
11,053,251✔
2616
}
2617
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
8,405,433✔
2618
  int32_t      code = 0;
8,405,433✔
2619
  int32_t      lino = 0;
8,405,433✔
2620
  void*        buf = NULL;
8,405,433✔
2621
  size_t       size = 0;
8,405,433✔
2622
  SSTriggerWalNewRsp resultRsp = {0};
8,405,433✔
2623
  
2624
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
8,408,115!
2625
  void* pTask = sStreamReaderInfo->pTask;
8,408,115✔
2626
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
8,390,707✔
2627

2628
  if (sStreamReaderInfo->metaBlock == NULL) {
8,390,707✔
2629
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
220,115!
2630
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
220,115!
2631
  }
2632
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
8,409,455✔
2633
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
8,410,791✔
2634
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
8,409,449✔
2635
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
8,408,117!
2636

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

2647
end:
8,405,443✔
2648
  if (resultRsp.totalRows == 0) {
8,398,741✔
2649
    buf = rpcMallocCont(sizeof(int64_t));
8,031,400✔
2650
    *(int64_t *)buf = resultRsp.ver;
8,004,586✔
2651
    size = sizeof(int64_t);
8,004,586✔
2652
    code = TSDB_CODE_STREAM_NO_DATA;
8,004,586✔
2653
  }
2654
  SRpcMsg rsp = {
8,371,927✔
2655
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2656
  tmsgSendRsp(&rsp);
8,392,035✔
2657
  if (code == TSDB_CODE_STREAM_NO_DATA){
8,406,746✔
2658
    code = 0;
8,026,009✔
2659
  }
2660
  blockDataDestroy(resultRsp.deleteBlock);
8,406,746✔
2661
  blockDataDestroy(resultRsp.dropBlock);
8,405,408✔
2662

2663
  STREAM_PRINT_LOG_END_WITHID(code, lino);
8,404,066!
2664

2665
  return code;
8,405,419✔
2666
}
2667

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

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

2679
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
3,155,245✔
2680
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
3,159,249!
2681
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
3,156,585✔
2682

2683
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,155,256✔
2684

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

2691
end:
3,155,256✔
2692
  if (resultRsp.totalRows == 0) {
3,157,917✔
2693
    buf = rpcMallocCont(sizeof(int64_t));
3,044,488✔
2694
    *(int64_t *)buf = resultRsp.ver;
3,036,480✔
2695
    size = sizeof(int64_t);
3,036,480✔
2696
    code = TSDB_CODE_STREAM_NO_DATA;
3,036,480✔
2697
  }
2698
  SRpcMsg rsp = {
3,149,909✔
2699
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2700
  tmsgSendRsp(&rsp);
3,155,245✔
2701
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,157,917✔
2702
    code = 0;
3,041,816✔
2703
  }
2704

2705
  blockDataDestroy(resultRsp.deleteBlock);
3,157,917✔
2706
  blockDataDestroy(resultRsp.dropBlock);
3,159,249✔
2707
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,157,917!
2708

2709
  return code;
3,157,917✔
2710
}
2711

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

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

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

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

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

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

2764
  return code;
943,914✔
2765
}
2766

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

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

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

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

2799
  return code;
842,687✔
2800
}
2801

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

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

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

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

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

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

2836
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
523,071✔
2837
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
523,071!
2838
      vTable->cols.nCols = metaReader.me.colRef.nCols;
×
2839
      vTable->cols.version = metaReader.me.colRef.version;
×
2840
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
×
2841
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
×
2842
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
×
2843
      }
2844
    } else {
2845
      vTable->cols.nCols = taosArrayGetSize(cids);
523,071✔
2846
      vTable->cols.version = metaReader.me.colRef.version;
523,071✔
2847
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
523,071!
2848
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
1,669,053✔
2849
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
4,866,650✔
2850
          if (metaReader.me.colRef.pColRef[j].hasRef &&
4,343,579!
2851
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
3,096,374✔
2852
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
622,911!
2853
            break;
622,911✔
2854
          }
2855
        }
2856
      }
2857
    }
2858
    tDecoderClear(&metaReader.coder);
523,071✔
2859
  }
2860
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
306,721✔
2861
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
306,721!
2862

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

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

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

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

2889
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
106,624✔
2890

2891
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
106,624!
2892

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

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

2917
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
664,636!
2918
      SSchema* s = sSchemaWrapper->pSchema + j;
664,636✔
2919
      if (strcmp(s->name, oInfo->refColName) == 0) {
664,636!
2920
        vTableInfo->cid = s->colId;
177,464✔
2921
        break;
176,124✔
2922
      }
2923
    }
2924
    if (vTableInfo->cid == 0) {
176,124!
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);
176,124✔
2929
  }
2930

2931
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
105,284!
2932

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

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

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

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

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

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

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

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

2981
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
342,773!
2982
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
342,773✔
2983
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
967,980✔
2984
      col_id_t* id = taosArrayGet(cols, i);
625,207✔
2985
      STREAM_CHECK_NULL_GOTO(id, terrno);
625,207!
2986
      if (*id == -1) {
625,207✔
2987
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
342,773✔
2988
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
342,773!
2989
        continue;
342,773✔
2990
      }
2991
      size_t j = 0;
282,434✔
2992
      for (; j < sSchemaWrapper->nCols; j++) {
342,239!
2993
        SSchema* s = sSchemaWrapper->pSchema + j;
342,239✔
2994
        if (s->colId == *id) {
342,239✔
2995
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
282,434✔
2996
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
282,434!
2997
          break;
282,434✔
2998
        }
2999
      }
3000
      if (j == sSchemaWrapper->nCols) {
282,434!
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));
342,773!
3006
    pBlock->info.rows = 1;
342,773✔
3007
    
3008
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
967,980✔
3009
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
625,207✔
3010
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
625,207!
3011

3012
      if (pDst->info.colId == -1) {
625,207✔
3013
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
342,773!
3014
        continue;
342,773✔
3015
      }
3016
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
282,434!
3017
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3018
        continue;
×
3019
      }
3020

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

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

3032
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
282,434!
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) &&
282,434!
3036
          (data != NULL)) {
3037
        taosMemoryFree(data);
39,870!
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);
352,097✔
3047
  printDataBlock(pBlock, __func__, "", streamId);
352,097✔
3048
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
352,097!
3049

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

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

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

3078
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
18,125,119!
3079
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
18,125,119✔
3080
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
18,125,119!
3081
  void* pTask = sStreamReaderCalcInfo->pTask;
18,125,119✔
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,
18,125,119!
3083
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
3084

3085
  if (req.reset || sStreamReaderCalcInfo->pTaskInfo == NULL) {
18,125,119!
3086
  // if (req.reset) {
3087
    qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
17,994,771✔
3088
    int64_t uid = 0;
17,989,321✔
3089
    if (req.dynTbname) {
17,989,321!
3090
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
217,202✔
3091
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
217,202!
3092
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
217,202✔
3093
        if (pValue != NULL && pValue->isTbname) {
217,202!
3094
          uid = pValue->uid;
217,202✔
3095
          break;
217,202✔
3096
        }
3097
      }
3098
    }
3099
    
3100
    SReadHandle handle = {0};
17,989,321✔
3101
    handle.vnode = pVnode;
17,992,045✔
3102
    handle.uid = uid;
17,992,045✔
3103

3104
    initStorageAPI(&handle.api);
17,992,045✔
3105
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
17,981,293✔
3106
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
17,243,037✔
3107
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
17,418,304✔
3108
      if (node != NULL) {
17,419,717✔
3109
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
447,155!
3110
      } else {
3111
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
16,972,562✔
3112
      }
3113

3114
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
17,423,800✔
3115
      if (node != NULL) {
17,421,081!
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__);
17,421,081✔
3119
      }      
3120
    }
3121

3122
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
17,994,771!
3123
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
17,994,771✔
3124

3125
    // if (sStreamReaderCalcInfo->pTaskInfo == NULL) {
3126
    STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
17,994,771✔
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));
17,982,747!
3134
  }
3135

3136
  if (req.pOpParam != NULL) {
18,113,095✔
3137
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, req.pOpParam);
247,550✔
3138
  }
3139
  
3140
  pResList = taosArrayInit(4, POINTER_BYTES);
18,113,095✔
3141
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
18,111,733!
3142
  uint64_t ts = 0;
18,111,733✔
3143
  bool     hasNext = false;
18,111,733✔
3144
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
18,113,095✔
3145

3146
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
42,330,765✔
3147
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
24,232,382✔
3148
    if (pBlock == NULL) continue;
24,232,382!
3149
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
24,232,382✔
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__);
18,099,715✔
3159
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
18,099,715!
3160
  ST_TASK_DLOG("vgId:%d %s end:", TD_VID(pVnode), __func__);
18,098,383✔
3161

3162
end:
18,120,676✔
3163
  taosArrayDestroy(pResList);
18,125,119✔
3164
  streamReleaseTask(taskAddr);
18,123,787✔
3165

3166
  STREAM_PRINT_LOG_END(code, lino);
18,123,787!
3167
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
18,123,787✔
3168
  tmsgSendRsp(&rsp);
18,123,787✔
3169
  tDestroySResFetchReq(&req);
18,121,162✔
3170
  return code;
18,125,119✔
3171
}
3172

3173
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
83,754,278✔
3174
  int32_t                   code = 0;
83,754,278✔
3175
  int32_t                   lino = 0;
83,754,278✔
3176
  SSTriggerPullRequestUnion req = {0};
83,754,278✔
3177
  void*                     taskAddr = NULL;
83,760,900✔
3178

3179
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
83,743,448✔
3180
  if (!syncIsReadyForRead(pVnode->sync)) {
83,752,834✔
3181
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
237,149✔
3182
    return 0;
237,149✔
3183
  }
3184

3185
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
83,518,471✔
3186
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
18,125,119✔
3187
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
65,394,684!
3188
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
65,405,335✔
3189
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
65,405,333✔
3190
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
65,399,989!
3191
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
65,375,985✔
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);
65,387,979✔
3194
    if (sStreamReaderInfo != NULL) {  
65,374,616✔
3195
      (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
65,192,692✔
3196
      if (sStreamReaderInfo->tableList == NULL) {
65,210,090✔
3197
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, false));  
584,922!
3198
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, true));
584,922!
3199
        STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamReaderInfo->pConditions, &sStreamReaderInfo->pFilterInfo, 0, NULL));
584,922!
3200
      }
3201
      (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
65,218,096✔
3202
      sStreamReaderInfo->pVnode = pVnode;
65,204,742✔
3203
    }
3204
    switch (req.base.type) {
65,379,966!
3205
      case STRIGGER_PULL_SET_TABLE:
106,624✔
3206
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
106,624!
3207
        break;
106,624✔
3208
      case STRIGGER_PULL_LAST_TS:
574,895✔
3209
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
574,895!
3210
        break;
573,553✔
3211
      case STRIGGER_PULL_FIRST_TS:
468,175✔
3212
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
468,175✔
3213
        break;
461,499✔
3214
      case STRIGGER_PULL_TSDB_META:
943,235✔
3215
      case STRIGGER_PULL_TSDB_META_NEXT:
3216
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
943,235✔
3217
        break;
940,573✔
3218
      case STRIGGER_PULL_TSDB_TS_DATA:
31,700✔
3219
        if (sStreamReaderInfo->isVtableStream) {
31,700!
3220
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
3221
        } else {
3222
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
31,700!
3223
        }
3224
        break;
31,700✔
3225
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
392,234✔
3226
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
3227
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
392,234!
3228
        break;
392,234✔
3229
      case STRIGGER_PULL_TSDB_CALC_DATA:
37,505,301✔
3230
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
3231
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
37,505,301✔
3232
        break;
37,395,663✔
3233
      case STRIGGER_PULL_TSDB_DATA:
190,483✔
3234
      case STRIGGER_PULL_TSDB_DATA_NEXT:
3235
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
190,483!
3236
        break;
190,483✔
3237
      case STRIGGER_PULL_GROUP_COL_VALUE:
842,687✔
3238
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
842,687!
3239
        break;
842,687✔
3240
      case STRIGGER_PULL_VTABLE_INFO:
306,721✔
3241
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
306,721!
3242
        break;
306,721✔
3243
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
352,097✔
3244
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req));
352,097!
3245
        break;
352,097✔
3246
      case STRIGGER_PULL_OTABLE_INFO:
106,624✔
3247
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req));
106,624!
3248
        break;
106,624✔
3249
      case STRIGGER_PULL_WAL_META_NEW:
11,047,916✔
3250
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
11,047,916!
3251
        break;
11,058,587✔
3252
      case STRIGGER_PULL_WAL_DATA_NEW:
3,160,581✔
3253
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,160,581!
3254
        break;
3,160,589✔
3255
      case STRIGGER_PULL_WAL_META_DATA_NEW:
8,406,779✔
3256
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
8,406,779!
3257
        break;
8,404,077✔
3258
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
943,914✔
3259
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
943,914!
3260
        break;
943,914✔
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:
65,357,788✔
3271

3272
  streamReleaseTask(taskAddr);
65,377,298✔
3273

3274
  tDestroySTriggerPullRequest(&req);
65,394,669✔
3275
  STREAM_PRINT_LOG_END(code, lino);
65,342,624!
3276
  return code;
65,361,291✔
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