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

taosdata / TDengine / #4806

17 Oct 2025 09:36AM UTC coverage: 61.094% (-0.2%) from 61.259%
#4806

push

travis-ci

web-flow
Merge da5cd734f into 21184b20f

155401 of 324487 branches covered (47.89%)

Branch coverage included in aggregate %.

72 of 84 new or added lines in 6 files covered. (85.71%)

778 existing lines in 110 files now uncovered.

207559 of 269610 relevant lines covered (76.98%)

127253104.64 hits per line

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

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

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

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

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

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

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

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

67
  if (*c1 < *c2) {
1,680,488✔
68
    return -1;
1,672,016✔
69
  } else if (*c1 > *c2) {
8,472!
70
    return 1;
8,472✔
71
  }
72

73
  return 0;
×
74
}
75

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

80
  if (c1->colId < c2->colId) {
1,676,152✔
81
    return -1;
1,667,680✔
82
  } else if (c1->colId > c2->colId) {
8,472!
83
    return 1;
8,472✔
84
  }
85

86
  return 0;
×
87
}
88

89
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
36,483,196✔
90
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
36,483,196✔
91
  if (pSrc == NULL) {
36,504,975!
92
    return terrno;
×
93
  }
94

95
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
36,504,975!
96
  return 0;
36,487,328✔
97
}
98

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

105
  return code;
20,973,473✔
106
}
107

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

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

130
static bool needRefreshTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
4,075,096✔
131
  if (sStreamReaderInfo->isVtableStream) {
4,075,096!
132
    int64_t id[2] = {suid, uid};
3,233,269✔
133
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id)) == NULL) {
3,231,047!
134
      return true;
3,227,772✔
135
    }
136
  } else {
137
    if (tableType != TD_CHILD_TABLE) {
842,369✔
138
      return false;
282,590✔
139
    }
140
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
559,779✔
141
        suid == sStreamReaderInfo->suid && 
338,437✔
142
        qStreamGetGroupId(sStreamReaderInfo->tableList, uid) == -1) {
12,734✔
143
      return true;
4,897✔
144
    }
145
  }
146
  return false;
558,546✔
147
}
148

149
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc){
50,916,550✔
150
  if (sStreamReaderInfo->isVtableStream) {
50,916,550!
151
    int64_t tmp[2] = {suid, uid};
36,265,197✔
152
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) == NULL) {
36,265,187✔
153
      return false;
17,936,026✔
154
    }
155
    *id = uid;
18,329,204✔
156
  } else {
157
    if (sStreamReaderInfo->tableList == NULL) return false;
14,730,229!
158

159
    if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
14,737,946✔
160
      if (suid != sStreamReaderInfo->suid) return false;
9,227,348✔
161
      if (sStreamReaderInfo->pTagCond == NULL) {
7,184,932✔
162
        if (sStreamReaderInfo->partitionCols == NULL){
6,241,703✔
163
          *id = 0;
23,076✔
164
        } else if (sStreamReaderInfo->groupByTbname){
6,218,627!
165
          *id= uid;
5,871,395✔
166
        } else {
167
          *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
347,232✔
168
          if (*id == -1) return false;
347,232!
169
        }
170
      } else {
171
        //*id= uid;
172
        *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
944,343✔
173
        if (*id == -1) return false;
942,642✔
174
      }
175
    } else {
176
      *id = qStreamGetGroupId(sStreamReaderInfo->tableList, uid);
5,519,058✔
177
      if(*id == -1) *id = uid;
5,519,584✔
178
      return uid == sStreamReaderInfo->uid;
5,519,024✔
179
    }
180
  }
181
  return true;
25,118,618✔
182
}
183

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

190
  SStorageAPI api = {0};
7,157,092✔
191
  initStorageAPI(&api);
7,157,634✔
192
  code = qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
7,156,593✔
193
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &api, 
194
                                         isHistory ? &sStreamReaderInfo->historyTableList : &sStreamReaderInfo->tableList,
195
                                         isHistory ? NULL : sStreamReaderInfo->groupIdMap);
196
  end:
7,158,176✔
197
  nodesDestroyList(groupNew);
7,158,176✔
198
  STREAM_PRINT_LOG_END(code, lino);
7,158,176!
199
  return code;
7,157,634✔
200
}
201

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

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

238

239
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
17,490,549✔
240
  int32_t code = 0;
17,490,549✔
241
  int32_t lino = 0;
17,490,549✔
242
  void*   buf = NULL;
17,490,549✔
243
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
17,490,549!
244
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
2,196,886✔
245
  buf = rpcMallocCont(dataEncodeSize);
2,196,886✔
246
  STREAM_CHECK_NULL_GOTO(buf, terrno);
2,196,344!
247
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
2,196,344✔
248
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
2,196,886!
249
  *data = buf;
2,196,886✔
250
  *size = dataEncodeSize;
2,196,886✔
251
  buf = NULL;
2,196,886✔
252
end:
17,494,364✔
253
  rpcFreeCont(buf);
17,494,364✔
254
  return code;
17,492,184✔
255
}
256

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

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

275
end:
1,549,663✔
276
  STREAM_PRINT_LOG_END(code, lino);
1,549,663!
277
  return code;
1,549,663✔
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) {
8,862,151✔
301
  int32_t code = 0;
8,862,151✔
302
  int32_t lino = 0;
8,862,151✔
303
  int32_t index = 0;
8,862,151✔
304
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
8,862,151!
305
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
8,862,176!
306
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
8,862,162!
307
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
8,861,592!
308

309
end:
8,862,722✔
310
  return code;
8,862,722✔
311
}
312

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

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

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

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

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

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

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

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

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

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

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

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

419
  bool found = false;
53,646✔
420
  SVCreateTbReq* pCreateReq = NULL;
53,646✔
421
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
81,408✔
422
    pCreateReq = req.pReqs + iReq;
53,646✔
423
    if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
53,646✔
424
      ST_TASK_ILOG("stream reader scan create table jump, %s", pCreateReq->name);
27,762!
425
      continue;
27,762✔
426
    }
427
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
25,884!
428

429
    found = true;
25,884✔
430
    break;
25,884✔
431
  }
432
  STREAM_CHECK_CONDITION_GOTO(!found, TDB_CODE_SUCCESS);
53,646✔
433

434
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
25,884!
435
end:
53,646✔
436
  tDeleteSVCreateTbBatchReq(&req);
53,646✔
437
  tDecoderClear(&decoder);
53,646✔
438
  return code;
53,646✔
439
}
440

441
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq) {
4,019,264✔
442
  int32_t  code = 0;
4,019,264✔
443
  int32_t  lino = 0;
4,019,264✔
444
  void*    pTask = sStreamReaderInfo->pTask;
4,019,264✔
445
  if (!needRefreshTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
4,020,920✔
446
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
812,116✔
447
    goto end;
814,651✔
448
  }
449
  ST_TASK_ILOG("stream reader scan auto create table %s", pCreateReq->name);
3,206,243✔
450

451
  STREAM_CHECK_RET_GOTO(reloadTableList(sStreamReaderInfo));
3,206,861!
452
end:
3,206,785✔
453
  return code;
4,021,436✔
454
}
455

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

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

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

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

477
end:
67,983✔
478
  taosArrayDestroy(req.pMultiTag);
67,983✔
479
  tDecoderClear(&decoder);
67,983✔
480
  return code;
67,983✔
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) {
25,236,232✔
527
  int32_t code = 0;
25,236,232✔
528
  int32_t lino = 0;
25,236,232✔
529
  WalMetaResult walMeta = {0};
25,236,232✔
530
  SSubmitTbData submitTbData = {0};
25,236,226✔
531
  
532
  if (tStartDecode(pCoder) < 0) {
25,236,174!
533
    code = TSDB_CODE_INVALID_MSG;
×
534
    TSDB_CHECK_CODE(code, lino, end);
×
535
  }
536

537
  uint8_t       version = 0;
25,246,068✔
538
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
25,244,971!
539
    code = TSDB_CODE_INVALID_MSG;
×
540
    TSDB_CHECK_CODE(code, lino, end);
×
541
  }
542
  version = (submitTbData.flags >> 8) & 0xff;
25,244,971✔
543
  submitTbData.flags = submitTbData.flags & 0xff;
25,244,971✔
544

545
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
546
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
25,244,971✔
547
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
3,363,754!
548
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
3,362,664!
549
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
3,362,664!
550
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
3,363,196!
551
  }
552

553
  // submit data
554
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
25,243,375!
555
    code = TSDB_CODE_INVALID_MSG;
×
556
    TSDB_CHECK_CODE(code, lino, end);
×
557
  }
558
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
25,243,910!
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)){
25,243,910✔
564
    goto end;
18,658,659✔
565
  }
566
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
6,590,130!
567
    code = TSDB_CODE_INVALID_MSG;
×
568
    TSDB_CHECK_CODE(code, lino, end);
×
569
  }
570

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

606
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
15,967,878✔
607
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,378,263✔
608
      pCoder->pos += pRow->len;
9,379,364✔
609
      if (iRow == 0){
9,378,822✔
610
#ifndef NO_UNALIGNED_ACCESS
611
        walMeta.skey = pRow->ts;
6,590,147✔
612
#else
613
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
614
#endif
615
      }
616
      if (iRow == nRow - 1) {
9,377,731✔
617
#ifndef NO_UNALIGNED_ACCESS
618
        walMeta.ekey = pRow->ts;
6,589,605✔
619
#else
620
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
621
#endif
622
      }
623
    }
624
  }
625

626
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
6,590,147✔
627
  if (data != NULL) {
6,588,507!
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)));
6,588,507!
632
  }
633

634
end:
25,230,394✔
635
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
25,244,422✔
636
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
25,241,142!
637
  tEndDecode(pCoder);
25,241,142✔
638
  return code;
25,244,978✔
639
}
640

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

648
  tDecoderInit(&decoder, data, len);
25,244,435✔
649
  if (tStartDecode(&decoder) < 0) {
25,246,095!
650
    code = TSDB_CODE_INVALID_MSG;
×
651
    TSDB_CHECK_CODE(code, lino, end);
×
652
  }
653

654
  uint64_t nSubmitTbData = 0;
25,242,816✔
655
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
25,242,274!
656
    code = TSDB_CODE_INVALID_MSG;
×
657
    TSDB_CHECK_CODE(code, lino, end);
×
658
  }
659

660
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
25,242,274✔
661
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
25,236,294!
662

663
  for (int32_t i = 0; i < nSubmitTbData; i++) {
50,479,615✔
664
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash));
25,236,294!
665
  }
666
  tEndDecode(&decoder);
25,243,321✔
667

668
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
25,244,385!
669
  int32_t iter = 0;
25,241,679✔
670
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
25,242,221✔
671
  while (px != NULL) {
31,830,797✔
672
    WalMetaResult* pMeta = (WalMetaResult*)px;
6,588,494✔
673
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
6,588,494!
674
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
6,589,049✔
675
    rsp->totalRows++;
6,589,598✔
676
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
6,588,507✔
677
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
678
    px = tSimpleHashIterate(gidHash, px, &iter);
6,589,049✔
679
  }
680
end:
25,242,303✔
681
  tDecoderClear(&decoder);
25,242,841✔
682
  tSimpleHashCleanup( gidHash);
25,244,971✔
683
  return code;
25,240,084✔
684
}
685

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

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

701
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
530,130!
702

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

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

713
  schemas = taosArrayInit(8, sizeof(SSchema));
358,068✔
714
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
358,613!
715

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

722
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
358,613!
723

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

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

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

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

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

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

748
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int32_t ver) {
556,426✔
749
  int32_t code = 0;
556,426✔
750
  int32_t lino = 0;
556,426✔
751
  SDecoder dcoder = {0};
556,426✔
752
  tDecoderInit(&dcoder, data, len);
556,426✔
753
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
556,426✔
754
    if (rsp->deleteBlock == NULL) {
65,220✔
755
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
23,906!
756
    }
757
      
758
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
65,220!
759
  } else if (msgType == TDMT_VND_DROP_TABLE && sStreamReaderInfo->deleteOutTbl != 0) {
491,206✔
760
    if (rsp->dropBlock == NULL) {
582!
761
      STREAM_CHECK_RET_GOTO(createBlockForDropTable((SSDataBlock**)&rsp->dropBlock));
582!
762
    }
763
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
582!
764
  } else if (msgType == TDMT_VND_DROP_STB) {
490,057!
765
    STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
×
766
  } else if (msgType == TDMT_VND_CREATE_TABLE) {
490,057✔
767
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, data, len));
53,646!
768
  } else if (msgType == TDMT_VND_ALTER_STB) {
436,411✔
769
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
770
  } else if (msgType == TDMT_VND_ALTER_TABLE) {
351,316✔
771
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, data, len));
67,983!
772
  }
773

774
  end:
555,859✔
775
  tDecoderClear(&dcoder);
555,859✔
776
  return code;
556,426✔
777
}
778
static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
8,145,479✔
779
                       int64_t ctime) {
780
  int32_t code = 0;
8,145,479✔
781
  int32_t lino = 0;
8,145,479✔
782
  void* pTask = sStreamReaderInfo->pTask;
8,145,479✔
783

784
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
8,146,028✔
785
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
8,141,653!
786
  code = walReaderSeekVer(pWalReader, rsp->ver);
8,141,653✔
787
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
8,138,304✔
788
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
6,086,058!
789
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
790
    }
791
    ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
6,088,296✔
792
    code = TSDB_CODE_SUCCESS;
6,091,586✔
793
    goto end;
6,091,586✔
794
  }
795
  STREAM_CHECK_RET_GOTO(code);
2,052,246!
796

797
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
2,052,246!
798
  while (1) {
25,593,005✔
799
    code = walNextValidMsg(pWalReader, true);
27,644,147✔
800
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){\
27,651,190✔
801
      ST_TASK_DLOG("vgId:%d %s scan wal error:%s", TD_VID(pVnode), __func__, tstrerror(code));
2,051,128✔
802
      code = TSDB_CODE_SUCCESS;
2,052,246✔
803
      goto end;
2,052,246✔
804
    }
805
    STREAM_CHECK_RET_GOTO(code);
25,600,062!
806
    rsp->ver = pWalReader->curVersion;
25,600,062✔
807
    SWalCont* wCont = &pWalReader->pHead->head;
25,598,955✔
808
    rsp->verTime = wCont->ingestTs;
25,598,411✔
809
    if (wCont->ingestTs / 1000 > ctime) break;
25,599,510!
810
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
25,598,420✔
811
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
25,598,944✔
812
    int64_t ver = wCont->version;
25,599,509✔
813

814
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d",
25,596,705✔
815
      TD_VID(pVnode), ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
816
    if (wCont->msgType == TDMT_VND_SUBMIT) {
25,594,062✔
817
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
25,246,081✔
818
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
25,247,728✔
819
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
25,247,161!
820
    } else {
821
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
354,549!
822
    }
823

824
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
25,594,640!
825
      break;
×
826
    }
827
  }
828

829
end:
8,143,832✔
830
  walCloseReader(pWalReader);
8,143,832✔
831
  return code;
8,142,196✔
832
}
833

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

841
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
4,334,945!
842
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
4,332,393!
843
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
4,330,493!
844
  if (numOfExpr == 0) {
4,332,723!
845
    return TSDB_CODE_SUCCESS;
×
846
  }
847

848
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
4,332,723✔
849
  if (uidData == NULL) {
4,337,405✔
850
    api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
177,988✔
851
    code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
177,440✔
852
    api->metaReaderFn.readerReleaseLock(&mr);
177,988✔
853
    STREAM_CHECK_RET_GOTO(code);
177,988!
854

855
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
177,988✔
856
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
177,988!
857
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
177,988!
858
      taosArrayDestroyP(tagCache, taosMemFree);
×
859
      code = terrno;
×
860
      goto end;
×
861
    }
862
  } else {
863
    tagCache = *(SArray**)uidData;
4,159,417✔
864
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
4,153,835!
865
  }
866
  
867
  for (int32_t j = 0; j < numOfExpr; ++j) {
11,860,800✔
868
    const SExprInfo* pExpr1 = &pExprInfo[j];
7,523,942✔
869
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
7,525,548✔
870

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

875
    // this is to handle the tbname
876
    if (fmIsScanPseudoColumnFunc(functionId)) {
7,530,009✔
877
      int32_t fType = pExpr1->pExpr->_function.functionType;
4,335,172✔
878
      if (fType == FUNCTION_TYPE_TBNAME) {
4,335,500✔
879
        char   buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
4,335,160✔
880
        if (uidData == NULL) {
4,334,396✔
881
          STR_TO_VARSTR(buf, mr.me.name)
177,440!
882
          char* tbname = taosStrdup(mr.me.name);
177,988!
883
          STREAM_CHECK_NULL_GOTO(tbname, terrno);
177,440!
884
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &tbname), terrno);
354,874!
885
        } else {
886
          char* tbname = taosArrayGetP(tagCache, j);
4,156,956✔
887
          STR_TO_VARSTR(buf, tbname)
4,156,069!
888
        }
889
        for (uint32_t i = 0; i < numOfRows; i++){
12,495,208✔
890
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
8,159,127!
891
        }
892
        code = colDataSetNItems(pColInfoData, currentRow, buf, numOfRows, numOfBlocks, false);
4,336,081✔
893
        pColInfoData->info.colId = -1;
4,335,188✔
894
      }
895
    } else {  // these are tags
896
      char* data = NULL;
3,193,730✔
897
      const char* p = NULL;
3,191,490✔
898
      STagVal tagVal = {0};
3,191,490✔
899
      if (uidData == NULL) {
3,191,490✔
900
        tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
143,427✔
901
        p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal);
143,427✔
902

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

909
        if (data == NULL) {
143,427!
910
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
×
911
        } else {
912
          int32_t len = pColInfoData->info.bytes;
143,427✔
913
          if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
143,427!
914
            len = calcStrBytesByType(pColInfoData->info.type, (char*)data);
44,766✔
915
          }
916
          char* pData = taosMemoryCalloc(1, len);
143,427!
917
          STREAM_CHECK_NULL_GOTO(pData, terrno);
143,427!
918
          (void)memcpy(pData, data, len);
143,427!
919
          STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &pData), terrno);
286,854!
920
        }
921
      } else {
922
        data = taosArrayGetP(tagCache, j);
3,048,063✔
923
      }
924

925
      bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
3,191,490!
926
      if (isNullVal) {
3,193,156!
927
        colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
928
      } else {
929
        for (uint32_t i = 0; i < numOfRows; i++){
20,842,655✔
930
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
17,648,939!
931
        }
932
        code = colDataSetNItems(pColInfoData, currentRow, data, numOfRows, numOfBlocks, false);
3,193,716✔
933
        if (uidData == NULL && pColInfoData->info.type != TSDB_DATA_TYPE_JSON && IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) {
3,192,603!
934
          taosMemoryFree(data);
44,766!
935
        }
936
        STREAM_CHECK_RET_GOTO(code);
3,192,603!
937
      }
938
    }
939
  }
940

941
end:
4,340,497✔
942
  api->metaReaderFn.clearReader(&mr);
4,336,293✔
943
  return code;
4,336,625✔
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, 
12,022,006✔
992
  STSchema** schemas, SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
993
  int32_t code = 0;
12,022,006✔
994
  int32_t lino = 0;
12,022,006✔
995
  uint64_t id = 0;
12,022,006✔
996
  WalMetaResult walMeta = {0};
12,023,122✔
997
  void* pTask = sStreamReaderInfo->pTask;
12,024,224✔
998
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
12,027,568✔
999

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

1005
  SSubmitTbData submitTbData = {0};
12,030,944✔
1006
  uint8_t       version = 0;
12,030,944✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
12,028,744!
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
12,028,744✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
12,028,744✔
1013
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1014
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
12,028,744✔
1015
    if (tStartDecode(pCoder) < 0) {
34,352!
1016
      code = TSDB_CODE_INVALID_MSG;
×
1017
      TSDB_CHECK_CODE(code, lino, end);
×
1018
    }
1019
    tEndDecode(pCoder);
34,352✔
1020
  }
1021

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

1034
  walMeta.id = id;
10,242,541✔
1035
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,242,541✔
1036

1037
  if (ranges != NULL){
10,245,343✔
1038
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
8,015,337✔
1039
    if (timerange == NULL) goto end;;
8,015,865!
1040
    int64_t* pRange = (int64_t*)timerange;
8,015,865✔
1041
    window.skey = pRange[0];
8,015,865✔
1042
    window.ekey = pRange[1];
8,015,865✔
1043
  }
1044
  
1045
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,246,997!
1046
    code = TSDB_CODE_INVALID_MSG;
×
1047
    TSDB_CHECK_CODE(code, lino, end);
×
1048
  }
1049

1050
  if (*schemas == NULL) {
10,246,997!
1051
    *schemas = metaGetTbTSchema(pVnode->pMeta, submitTbData.suid != 0 ? submitTbData.suid : submitTbData.uid, submitTbData.sver, 1);
10,248,676✔
1052
    STREAM_CHECK_NULL_GOTO(*schemas, TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND);
10,243,103!
1053
  }
1054

1055
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &submitTbData.uid, LONG_BYTES);
10,246,993✔
1056
  STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
10,245,878!
1057
  int32_t blockStart = pSlice->currentRowIdx;
10,245,878✔
1058

1059
  int32_t numOfRows = 0;
10,246,434✔
1060
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,239,579!
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;
10,239,579✔
1148
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,244,372!
1149
      code = TSDB_CODE_INVALID_MSG;
×
1150
      TSDB_CHECK_CODE(code, lino, end);
×
1151
    }
1152
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
23,282,142✔
1153
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
13,027,285✔
1154
      pCoder->pos += pRow->len;
13,036,079✔
1155

1156
      if (iRow == 0){
13,036,623✔
1157
#ifndef NO_UNALIGNED_ACCESS
1158
        walMeta.skey = pRow->ts;
10,245,900✔
1159
#else
1160
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1161
#endif
1162
      }
1163
      if (iRow == nRow - 1) {
13,034,195✔
1164
#ifndef NO_UNALIGNED_ACCESS
1165
        walMeta.ekey = pRow->ts;
10,245,898✔
1166
#else
1167
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1168
#endif
1169
      }
1170

1171
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
13,032,500✔
1172
        continue;
18,908✔
1173
      }
1174
     
1175
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
86,973,392✔
1176
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
73,950,795✔
1177
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
73,944,622!
1178
        if (pColData->info.colId <= -1) {
73,944,622✔
1179
          pColData->hasNull = true;
23,850,582✔
1180
          continue;
23,851,673✔
1181
        }
1182
        int16_t colId = 0;
50,116,201✔
1183
        if (sStreamReaderInfo->isVtableStream){
50,116,201!
1184
          int64_t id[2] = {submitTbData.suid, submitTbData.uid};
17,898,818✔
1185
          void* px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
17,898,276!
1186
          STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
17,897,805!
1187
          SSHashObj* uInfo = *(SSHashObj**)px;
17,897,805✔
1188
          STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
17,897,805!
1189
          int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
17,897,805✔
1190
          if (tmp != NULL) {
17,898,882✔
1191
            colId = *tmp;
16,320,439✔
1192
          } else {
1193
            colId = -1;
1,578,443✔
1194
          }
1195
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
17,899,986!
1196
        } else {
1197
          colId = pColData->info.colId;
32,221,987✔
1198
        }
1199
        
1200
        SColVal colVal = {0};
50,111,168✔
1201
        int32_t sourceIdx = 0;
50,111,142✔
1202
        while (1) {
1203
          if (sourceIdx >= (*schemas)->numOfCols) {
136,647,204✔
1204
            break;
18,212,634✔
1205
          }
1206
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, *schemas, sourceIdx, &colVal));
118,415,211!
1207
          if (colVal.cid == colId) {
118,450,994✔
1208
            break;
31,914,932✔
1209
          }
1210
          sourceIdx++;
86,536,062✔
1211
        }
1212
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
50,127,566✔
1213
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
30,108,196!
1214
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
41,015!
1215
          } else {
1216
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
30,067,192!
1217
          }
1218
        } else {
1219
          colDataSetNULL(pColData, blockStart + numOfRows);
20,019,370!
1220
        }
1221
      }
1222
      
1223
      numOfRows++;
13,018,862✔
1224
    }
1225
  }
1226

1227
  if (numOfRows > 0) {
10,247,607!
1228
    if (!sStreamReaderInfo->isVtableStream) {
10,247,607✔
1229
      SStorageAPI  api = {0};
4,225,447✔
1230
      initStorageAPI(&api);
4,226,020✔
1231
      STREAM_CHECK_RET_GOTO(processTag(pVnode, sStreamReaderInfo, rsp->isCalc, &api, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
4,225,809!
1232
    }
1233
    
1234
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
10,248,750✔
1235
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
10,243,026!
1236
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
10,243,026!
1237
  }
1238

1239
  ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
10,244,320✔
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;
10,249,190✔
1243
  pBlock->info.rows += numOfRows;
10,245,864✔
1244
  
1245
  if (gidHash == NULL) goto end;
10,247,533✔
1246

1247
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
2,231,685✔
1248
  if (data != NULL) {
2,229,453!
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)));
2,229,453!
1253
  }
1254

1255
end:
12,020,379✔
1256
  if (code != 0) {                                                             \
12,028,719!
1257
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1258
  }
1259
  tEndDecode(pCoder);
12,028,719✔
1260
  return code;
12,027,594✔
1261
}
1262
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
12,023,193✔
1263
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1264
  int32_t  code = 0;
12,023,193✔
1265
  int32_t  lino = 0;
12,023,193✔
1266
  STSchema* schemas = NULL;
12,023,193✔
1267
  SDecoder decoder = {0};
12,025,429✔
1268
  SSHashObj* gidHash = NULL;
12,028,225✔
1269
  void* pTask = sStreamReaderInfo->pTask;
12,028,225✔
1270

1271
  tDecoderInit(&decoder, data, len);
12,029,341✔
1272
  if (tStartDecode(&decoder) < 0) {
12,027,085!
1273
    code = TSDB_CODE_INVALID_MSG;
×
1274
    TSDB_CHECK_CODE(code, lino, end);
×
1275
  }
1276

1277
  uint64_t nSubmitTbData = 0;
12,028,134✔
1278
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
12,025,383!
1279
    code = TSDB_CODE_INVALID_MSG;
×
1280
    TSDB_CHECK_CODE(code, lino, end);
×
1281
  }
1282

1283
  if (rsp->metaBlock != NULL){
12,025,383✔
1284
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
4,011,187✔
1285
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
4,013,401!
1286
  }
1287

1288
  for (int32_t i = 0; i < nSubmitTbData; i++) {
24,047,432✔
1289
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, &schemas, ranges, gidHash, rsp, ver));
12,024,270!
1290
  }
1291

1292
  tEndDecode(&decoder);
12,023,162✔
1293

1294
  if (rsp->metaBlock != NULL){
12,023,678✔
1295
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
4,012,296!
1296
    int32_t iter = 0;
4,007,270✔
1297
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
4,007,826✔
1298
    while (px != NULL) {
6,240,616✔
1299
      WalMetaResult* pMeta = (WalMetaResult*)px;
2,231,692✔
1300
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
2,231,692!
1301
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
2,230,005✔
1302
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
2,230,569✔
1303
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1304
      px = tSimpleHashIterate(gidHash, px, &iter);
2,230,569✔
1305
    }
1306
  }
1307
  
1308

1309
end:
12,015,609✔
1310
  taosMemoryFree(schemas);
12,025,359!
1311
  tSimpleHashCleanup(gidHash);
12,026,461✔
1312
  tDecoderClear(&decoder);
12,025,388✔
1313
  return code;
12,028,705✔
1314
}
1315

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

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

1327
  SSubmitTbData submitTbData = {0};
13,674,033✔
1328
  uint8_t       version = 0;
13,676,824✔
1329
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
13,673,030!
1330
    code = TSDB_CODE_INVALID_MSG;
×
1331
    TSDB_CHECK_CODE(code, lino, end);
×
1332
  }
1333
  version = (submitTbData.flags >> 8) & 0xff;
13,673,030✔
1334
  submitTbData.flags = submitTbData.flags & 0xff;
13,673,030✔
1335

1336
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1337
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
13,673,030✔
1338
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
658,234!
1339
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
654,323!
1340
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
654,323!
1341
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq));
657,720!
1342
  }
1343

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

1356
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,246,399✔
1357

1358
  if (ranges != NULL){
10,246,399✔
1359
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
8,015,832✔
1360
    if (timerange == NULL) goto end;;
8,016,398!
1361
    int64_t* pRange = (int64_t*)timerange;
8,016,398✔
1362
    window.skey = pRange[0];
8,016,398✔
1363
    window.ekey = pRange[1];
8,016,398✔
1364
  }
1365
  
1366
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,247,558!
1367
    code = TSDB_CODE_INVALID_MSG;
×
1368
    TSDB_CHECK_CODE(code, lino, end);
×
1369
  }
1370

1371
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,247,558!
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;
10,247,558✔
1398
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,247,552!
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) { 
10,247,552✔
1404
      for (int32_t iRow = 0; iRow < nRow; ++iRow) {
18,769,837✔
1405
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
10,751,199✔
1406
        pCoder->pos += pRow->len;
10,751,741✔
1407
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
10,751,741!
1408
          continue;
18,908✔
1409
        }
1410
        (*numOfRows)++;
10,732,291✔
1411
      }
1412
    } else {
1413
      (*numOfRows) = nRow;
2,229,456✔
1414
    }
1415
  }
1416
  
1417
end:
13,681,339✔
1418
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
13,673,991✔
1419
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
13,672,922!
1420
  tEndDecode(pCoder);
13,671,799✔
1421
  return code;
13,673,560✔
1422
}
1423

1424
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
13,670,805✔
1425
  int32_t  code = 0;
13,670,805✔
1426
  int32_t  lino = 0;
13,670,805✔
1427
  SDecoder decoder = {0};
13,670,805✔
1428
  void* pTask = sStreamReaderInfo->pTask;
13,674,145✔
1429

1430
  tDecoderInit(&decoder, data, len);
13,678,591✔
1431
  if (tStartDecode(&decoder) < 0) {
13,676,276!
1432
    code = TSDB_CODE_INVALID_MSG;
×
1433
    TSDB_CHECK_CODE(code, lino, end);
×
1434
  }
1435

1436
  uint64_t nSubmitTbData = 0;
13,679,081✔
1437
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
13,673,473!
1438
    code = TSDB_CODE_INVALID_MSG;
×
1439
    TSDB_CHECK_CODE(code, lino, end);
×
1440
  }
1441

1442
  for (int32_t i = 0; i < nSubmitTbData; i++) {
27,351,424✔
1443
    uint64_t gid = -1;
13,663,998✔
1444
    int64_t  uid = 0;
13,664,546✔
1445
    int32_t numOfRows = 0;
13,667,326✔
1446
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp->isCalc));
13,671,785!
1447
    if (numOfRows <= 0) {
13,670,735✔
1448
      continue;
3,433,254✔
1449
    }
1450
    rsp->totalRows += numOfRows;
10,237,481✔
1451

1452
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(sStreamReaderInfo->indexHash, &uid, LONG_BYTES);
10,246,957✔
1453
    if (pSlice != NULL) {
10,246,975✔
1454
      pSlice->numRows += numOfRows;
9,927,601✔
1455
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d", __func__, uid, gid, pSlice->numRows);
9,927,601✔
1456
      pSlice->gId = gid;
9,928,697✔
1457
    } else {
1458
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
319,374✔
1459
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d", __func__, uid, gid, tmp.numRows);
319,374✔
1460
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(sStreamReaderInfo->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
319,374!
1461
    } 
1462
  }
1463

1464
  tEndDecode(&decoder);
13,687,426✔
1465

1466
end:
13,681,335✔
1467
  tDecoderClear(&decoder);
13,682,447✔
1468
  return code;
13,675,103✔
1469
}
1470

1471
static void resetIndexHash(SSHashObj* indexHash){
8,928,223✔
1472
  void*   pe = NULL;
8,928,223✔
1473
  int32_t iter = 0;
8,928,223✔
1474
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
20,662,570✔
1475
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
11,741,057✔
1476
    pInfo->startRowIdx = 0;
11,741,057✔
1477
    pInfo->currentRowIdx = 0;
11,741,057✔
1478
    pInfo->numRows = 0;
11,729,331✔
1479
    pInfo->gId = -1;
11,731,014✔
1480
  }
1481
}
8,929,919✔
1482

1483
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
837,280✔
1484
  void*   pe = NULL;
837,280✔
1485
  int32_t iter = 0;
837,280✔
1486
  int32_t index = 0;
837,280✔
1487
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
3,043,846✔
1488
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
2,206,566✔
1489
    pInfo->startRowIdx = index;
2,206,566✔
1490
    pInfo->currentRowIdx = index;
2,206,566✔
1491
    index += pInfo->numRows;
2,206,566✔
1492
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
3,413,778!
1493
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1494
  }
1495
}
837,280✔
1496

1497
static void printIndexHash(SSHashObj* indexHash, void* pTask){
834,506✔
1498
  void*   pe = NULL;
834,506✔
1499
  int32_t iter = 0;
834,506✔
1500
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
3,038,843✔
1501
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
2,203,781✔
1502
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
3,409,909!
1503
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1504
  }
1505
}
835,062✔
1506

1507
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
19,814✔
1508
  void*   pe = NULL;
19,814✔
1509
  int32_t iter = 0;
19,814✔
1510
  int32_t index = 0;
19,814✔
1511
  int32_t pIndex = 0;
19,814✔
1512
  int8_t* pIndicator = (int8_t*)pRet->pData;
19,814✔
1513
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
55,185✔
1514
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
35,371✔
1515
    pInfo->startRowIdx = index;
35,371✔
1516
    int32_t size = pInfo->numRows;
35,371✔
1517
    for (int32_t i = 0; i < pInfo->numRows; i++) {
277,687✔
1518
      if (pIndicator && !pIndicator[pIndex++]) {
242,316!
1519
        size--;
86,952✔
1520
      }
1521
    }
1522
    pInfo->numRows = size;
35,371✔
1523
    index += pInfo->numRows;
35,371✔
1524
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
35,371!
1525
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
1526
  }
1527
}
19,814✔
1528

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

1534
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,956,099✔
1535
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,952,203✔
1536
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
3,309,712!
1537
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
1538
    }
1539
    ST_TASK_DLOG("%s scan wal error:%s",  __func__, tstrerror(code));
3,309,162✔
1540
    code = TSDB_CODE_SUCCESS;
3,310,258✔
1541
    goto end;
3,310,258✔
1542
  }
1543
  STREAM_CHECK_RET_GOTO(code);
642,491!
1544

1545
  while (1) {
5,858,362✔
1546
    code = walNextValidMsg(pWalReader, true);
6,500,853✔
1547
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
6,501,988✔
1548
      ST_TASK_DLOG("%s scan wal error:%s", __func__, tstrerror(code));
643,312✔
1549
      code = TSDB_CODE_SUCCESS;
642,741✔
1550
      goto end;
642,741✔
1551
    }
1552
    STREAM_CHECK_RET_GOTO(code);
5,858,676!
1553
    resultRsp->ver = pWalReader->curVersion;
5,858,676✔
1554
    SWalCont* wCont = &pWalReader->pHead->head;
5,864,258✔
1555
    resultRsp->verTime = wCont->ingestTs;
5,864,260✔
1556
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
5,865,380✔
1557
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
5,866,288✔
1558
    int64_t ver = wCont->version;
5,867,377✔
1559
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%d, deleteData:%d, deleteTb:%d", __func__,
5,864,843✔
1560
      ver, wCont->msgType, sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1561
    if (wCont->msgType == TDMT_VND_SUBMIT) {
5,867,900✔
1562
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
5,663,259✔
1563
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
5,664,375✔
1564
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp));
5,665,491!
1565
    } else if (wCont->msgType == TDMT_VND_ALTER_TABLE && resultRsp->totalRows > 0) {
203,845✔
1566
      resultRsp->ver--;
1,968✔
1567
      break;
1,498✔
1568
    } else {
1569
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
201,877!
1570
    }
1571

1572
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
5,859,430✔
1573
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
5,861,244!
1574
      break;
×
1575
    }
1576
  }
1577
  
1578
end:
3,954,433✔
1579
  STREAM_PRINT_LOG_END(code, lino);
3,954,433!
1580
  return code;
3,955,534✔
1581
}
1582

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

1588
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
12,989,673✔
1589
    int64_t *ver = taosArrayGet(versions, i);
8,015,857✔
1590
    if (ver == NULL) continue;
8,016,424!
1591

1592
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,016,424!
1593
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,016,407!
1594
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1595
      continue;
×
1596
    }
1597
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,016,407!
1598

1599
    SWalCont* wCont = &pWalReader->pHead->head;
8,016,966✔
1600
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,015,865✔
1601
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,016,407✔
1602

1603
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp));
8,016,407!
1604
  }
1605
  
1606
end:
4,972,700✔
1607
  return code;
4,972,700✔
1608
}
1609

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

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

1626
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,953,877✔
1627
                                    SSTriggerWalNewRsp* resultRsp) {
1628
  int32_t      code = 0;
3,953,877✔
1629
  int32_t      lino = 0;
3,953,877✔
1630
  void* pTask = sStreamReaderInfo->pTask;
3,953,877✔
1631
                                        
1632
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,954,989✔
1633
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,949,948!
1634
  resetIndexHash(sStreamReaderInfo->indexHash);
3,949,948✔
1635
  blockDataEmpty(resultRsp->dataBlock);
3,957,219✔
1636
  blockDataEmpty(resultRsp->metaBlock);
3,952,774✔
1637
  int64_t lastVer = resultRsp->ver;                                      
3,952,709✔
1638
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,953,276!
1639
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,956,094✔
1640

1641
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
181,276✔
1642
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
181,276!
1643
  while(lastVer < resultRsp->ver) {
4,338,977✔
1644
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
4,159,381!
1645
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
4,156,545✔
1646
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
149,884!
1647
      continue;
149,884✔
1648
    }
1649
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
4,007,221!
1650
    SWalCont* wCont = &pWalReader->pHead->head;
4,010,065✔
1651
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,010,621✔
1652
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,011,729✔
1653

1654
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
4,011,181!
1655
  }
1656

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

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

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

1673
  void* pTask = sStreamReaderInfo->pTask;
4,974,347✔
1674
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
4,974,347✔
1675
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
4,973,249!
1676
  
1677
  if (taosArrayGetSize(versions) > 0) {
4,973,249✔
1678
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
656,004✔
1679
  }
1680
  
1681
  resetIndexHash(sStreamReaderInfo->indexHash);
4,973,798✔
1682
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
4,973,249!
1683
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
4,972,151✔
1684

1685
  buildIndexHash(sStreamReaderInfo->indexHash, pTask);
656,004✔
1686

1687
  blockDataEmpty(rsp->dataBlock);
656,004✔
1688
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
655,444!
1689

1690
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
8,670,766✔
1691
    int64_t *ver = taosArrayGet(versions, i);
8,016,406✔
1692
    if (ver == NULL) continue;
8,015,846!
1693

1694
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,015,846!
1695
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,015,868!
1696
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
1697
      continue;
×
1698
    }
1699
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,015,308!
1700
    SWalCont* wCont = &pWalReader->pHead->head;
8,016,407✔
1701
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,016,407✔
1702
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,016,407✔
1703

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

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

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

1729
  SSchemaWrapper* sSchemaWrapper = NULL;
458,294✔
1730
  if (metaReader.me.type == TD_CHILD_TABLE) {
458,294!
1731
    int64_t suid = metaReader.me.ctbEntry.suid;
458,294✔
1732
    tDecoderClear(&metaReader.coder);
458,294✔
1733
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReader, suid));
458,294!
1734
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
458,294✔
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++) {
2,657,668✔
1742
    SSchema* s = sSchemaWrapper->pSchema + j;
2,199,374✔
1743
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
4,398,748!
1744
  }
1745

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

1756
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
458,294✔
1757
  int32_t code = 0;
458,294✔
1758
  int32_t lino = 0;
458,294✔
1759
  size_t  schemaLen = taosArrayGetSize(schemas);
458,294✔
1760
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
458,294!
1761
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
1,750,774✔
1762
    col_id_t* id = taosArrayGet(cols, i);
1,292,480✔
1763
    STREAM_CHECK_NULL_GOTO(id, terrno);
1,292,480!
1764
    for (size_t i = 0; i < schemaLen; i++) {
3,315,078!
1765
      SSchema* s = taosArrayGet(schemas, i);
3,315,078✔
1766
      STREAM_CHECK_NULL_GOTO(s, terrno);
3,315,078!
1767
      if (*id == s->colId) {
3,315,078✔
1768
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
1,292,480!
1769
        break;
1,292,480✔
1770
      }
1771
    }
1772
  }
1773
  taosArrayPopFrontBatch(schemas, schemaLen);
458,294✔
1774

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

1946
    if (!node->needCalc) {
188,176✔
1947
      pWin->skey = pFirst->wstart;
127,393✔
1948
      pWin->ekey = pLast->wend;
127,393✔
1949
      *pValid = true;
127,393✔
1950
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
127,393✔
1951
        pWin->ekey--;
69,193✔
1952
      }
1953
    } else {
1954
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
60,783✔
1955
      memcpy(pTmp, pFirst, sizeof(*pTmp));
60,783!
1956

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

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

1964
        if (*pValid) {
60,783!
1965
          pWin->skey = skey;
60,783✔
1966
        }
1967
      }
1968
      pWin->ekey--;
60,783✔
1969
    }
1970
  } else {
1971
    if (!node->needCalc) {
307,080!
1972
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
46,920✔
1973
      pWin->skey = pCurr->wstart;
46,920✔
1974
      pWin->ekey = pCurr->wend;
46,920✔
1975
      *pValid = true;
46,920✔
1976
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
46,920✔
1977
        pWin->ekey--;
44,328✔
1978
      }
1979
    } else {
1980
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
260,160!
1981
      pWin->ekey--;
260,160✔
1982
    }
1983
  }
1984

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

1988
end:
17,856✔
1989

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

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

2002
  void* pTask = sStreamReaderInfo->pTask;
608,704✔
2003
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(pTaskInner->pTableList), sizeof(STsInfo));
608,704✔
2004
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
607,096!
2005
  while (true) {
1,549,663✔
2006
    bool hasNext = false;
2,156,759✔
2007
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
2,157,875!
2008
    if (hasNext) {
2,155,612!
2009
      pTaskInner->api.tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
600,196✔
2010
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
598,865✔
2011
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
599,637!
2012
      if (pTaskInner->options.order == TSDB_ORDER_ASC) {
599,637✔
2013
        tsInfo->ts = pTaskInner->pResBlock->info.window.skey;
366,742✔
2014
      } else {
2015
        tsInfo->ts = pTaskInner->pResBlock->info.window.ekey;
233,454✔
2016
      }
2017
      tsInfo->gId = (sStreamReaderInfo->groupByTbname || sStreamReaderInfo->tableType != TSDB_SUPER_TABLE) ? 
1,273,943!
2018
                    pTaskInner->pResBlock->info.id.uid : qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
674,306✔
2019
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, TD_VID(pVnode), __func__, tsInfo->ts,
599,637✔
2020
              tsInfo->gId, tsRsp->ver);
2021
    }
2022
    
2023
    pTaskInner->currentGroupIndex++;
2,155,269✔
2024
    if (pTaskInner->currentGroupIndex >= qStreamGetTableListGroupNum(pTaskInner->pTableList) || pTaskInner->options.gid != 0) {
2,156,721✔
2025
      break;
2026
    }
2027
    STREAM_CHECK_RET_GOTO(resetTsdbReader(pTaskInner));
1,549,115!
2028
  }
2029

2030
end:
606,530✔
2031
  STREAM_PRINT_LOG_END_WITHID(code, lino);
606,530!
2032
  return code;
608,704✔
2033
}
2034

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

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

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

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

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

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

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

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

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

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

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

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

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

2123
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(firstTsRsp.tsInfo), firstTsRsp.ver);
280,801✔
2124
  STREAM_CHECK_RET_GOTO(buildTsRsp(&firstTsRsp, &buf, &size));
280,801!
2125
  if (stDebugFlag & DEBUG_DEBUG) {
280,245✔
2126
    int32_t nInfo = taosArrayGetSize(firstTsRsp.tsInfo);
209,435✔
2127
    for (int32_t i = 0; i < nInfo; i++) {
484,151✔
2128
      STsInfo* tsInfo = TARRAY_GET_ELEM(firstTsRsp.tsInfo, i);
274,716✔
2129
      ST_TASK_DLOG("vgId:%d %s get ts:%" PRId64 ", gId:%" PRIu64, TD_VID(pVnode), __func__, tsInfo->ts, tsInfo->gId);
274,716!
2130
    }
2131
  }
2132

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2275
  releaseStreamTask(&pTaskInner);
22,152✔
2276
  return code;
22,152✔
2277
}
2278

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

2287
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
1,626!
2288
  void* pTask = sStreamReaderInfo->pTask;
1,626✔
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, 
1,626!
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,
1,626✔
2294
               sStreamReaderInfo->tsSchemas, true, STREAM_SCAN_ALL, 0, true, NULL);
2295
  options.suid = req->tsdbTsDataReq.suid;
1,626✔
2296
  options.uid = req->tsdbTsDataReq.uid;
1,626✔
2297
  SStorageAPI api = {0};
1,626✔
2298
  initStorageAPI(&api);
1,626✔
2299
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &api));
1,626!
2300
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
1,626!
2301

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

2309
    SSDataBlock* pBlock = NULL;
1,626✔
2310
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
1,626!
2311
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
1,626!
2312
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
1,626!
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);
1,626!
2318
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
1,626!
2319

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

2327
  releaseStreamTask(&pTaskInner);
1,626✔
2328
  return code;
1,626✔
2329
}
2330

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

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

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

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

2361
  blockDataCleanup(pTaskInner->pResBlockDst);
163,390✔
2362
  bool hasNext = true;
163,390✔
2363
  while (1) {
×
2364
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
163,390!
2365
    if (!hasNext) {
163,390!
2366
      break;
78,617✔
2367
    }
2368
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
84,773✔
2369
    pTaskInner->pResBlockDst->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
84,773✔
2370

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

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

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

2399
  return code;
163,390✔
2400
}
2401

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

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

2414
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
15,667,333!
2415

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

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

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

2435
  blockDataCleanup(pTaskInner->pResBlockDst);
15,475,787✔
2436
  bool hasNext = true;
15,477,967✔
2437
  while (1) {
1,429,008✔
2438
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
16,904,795!
2439
    if (!hasNext) {
16,904,250!
2440
      break;
15,475,787✔
2441
    }
2442
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupId(pTaskInner->pTableList, pTaskInner->pResBlock->info.id.uid);
1,428,463✔
2443

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

2453
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
15,474,152!
2454
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
15,474,718!
2455
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
15,473,062✔
2456
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
15,475,242!
2457
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
15,475,242✔
2458
  if (!hasNext) {
15,477,967!
2459
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
15,477,967!
2460
  }
2461

2462
end:
15,667,850✔
2463
  STREAM_PRINT_LOG_END_WITHID(code, lino);
15,666,243!
2464
  SRpcMsg rsp = {
15,669,513✔
2465
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2466
  tmsgSendRsp(&rsp);
15,668,423✔
2467
  blockDataDestroy(pBlockRes);
15,667,878✔
2468
  return code;
15,667,333✔
2469
}
2470

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

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

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

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

2512
    options.suid = req->tsdbDataReq.suid;
458,294✔
2513
    options.uid = req->tsdbDataReq.uid;
458,294✔
2514

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

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

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

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

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

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

2578
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
8,154,755✔
2579
  void* pTask = sStreamReaderInfo->pTask;
8,145,479✔
2580
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
8,145,479✔
2581

2582
  if (sStreamReaderInfo->metaBlock == NULL) {
8,145,479✔
2583
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
235,802!
2584
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
235,802!
2585
  }
2586
  blockDataEmpty(sStreamReaderInfo->metaBlock);
8,145,479✔
2587
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
8,143,835✔
2588
  resultRsp.ver = req->walMetaNewReq.lastVer;
8,144,930✔
2589
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
8,144,381!
2590

2591
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
8,142,745✔
2592
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
8,143,832✔
2593
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp, NULL);
390,679✔
2594
  buf = rpcMallocCont(size);
390,679✔
2595
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp, NULL);
390,679✔
2596
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
390,679✔
2597

2598
end:
8,153,108✔
2599
  if (resultRsp.totalRows == 0) {
8,152,559✔
2600
    code = TSDB_CODE_STREAM_NO_DATA;
7,761,331✔
2601
    buf = rpcMallocCont(sizeof(int64_t));
7,761,331✔
2602
    *(int64_t *)buf = resultRsp.ver;
7,757,478✔
2603
    size = sizeof(int64_t);
7,757,478✔
2604
  }
2605
  SRpcMsg rsp = {
8,148,706✔
2606
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2607
  tmsgSendRsp(&rsp);
8,149,832✔
2608
  if (code == TSDB_CODE_STREAM_NO_DATA){
8,154,755✔
2609
    code = 0;
7,763,058✔
2610
  }
2611
  STREAM_PRINT_LOG_END_WITHID(code, lino);
8,154,755!
2612
  blockDataDestroy(resultRsp.deleteBlock);
8,155,278✔
2613
  blockDataDestroy(resultRsp.dropBlock);
8,154,214✔
2614

2615
  return code;
8,153,120✔
2616
}
2617
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,955,556✔
2618
  int32_t      code = 0;
3,955,556✔
2619
  int32_t      lino = 0;
3,955,556✔
2620
  void*        buf = NULL;
3,955,556✔
2621
  size_t       size = 0;
3,955,556✔
2622
  SSTriggerWalNewRsp resultRsp = {0};
3,955,556✔
2623
  
2624
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
3,956,101!
2625
  void* pTask = sStreamReaderInfo->pTask;
3,956,101✔
2626
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,950,537✔
2627

2628
  if (sStreamReaderInfo->metaBlock == NULL) {
3,950,537✔
2629
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
98,905!
2630
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
98,905!
2631
  }
2632
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,955,549✔
2633
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
3,951,075✔
2634
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,952,765✔
2635
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,951,089!
2636

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

2647
end:
3,953,309✔
2648
  if (resultRsp.totalRows == 0) {
3,953,320✔
2649
    buf = rpcMallocCont(sizeof(int64_t));
3,777,602✔
2650
    *(int64_t *)buf = resultRsp.ver;
3,767,590✔
2651
    size = sizeof(int64_t);
3,767,438✔
2652
    code = TSDB_CODE_STREAM_NO_DATA;
3,767,438✔
2653
  }
2654
  SRpcMsg rsp = {
3,943,156✔
2655
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2656
  tmsgSendRsp(&rsp);
3,950,521✔
2657
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,954,448✔
2658
    code = 0;
3,774,823✔
2659
  }
2660
  blockDataDestroy(resultRsp.deleteBlock);
3,954,448✔
2661
  blockDataDestroy(resultRsp.dropBlock);
3,953,319✔
2662

2663
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,949,963!
2664

2665
  return code;
3,950,508✔
2666
}
2667

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

2675
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
4,271,029✔
2676
  void* pTask = sStreamReaderInfo->pTask;
4,269,403✔
2677
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
4,268,861✔
2678

2679
  resultRsp.dataBlock = sStreamReaderInfo->triggerBlock;
4,268,861✔
2680
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
4,269,403!
2681
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
4,268,312✔
2682

2683
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
4,268,854✔
2684

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

2691
end:
4,270,480✔
2692
  if (resultRsp.totalRows == 0) {
4,270,480✔
2693
    buf = rpcMallocCont(sizeof(int64_t));
3,997,339✔
2694
    *(int64_t *)buf = resultRsp.ver;
3,994,594✔
2695
    size = sizeof(int64_t);
3,995,143✔
2696
    code = TSDB_CODE_STREAM_NO_DATA;
3,995,143✔
2697
  }
2698
  SRpcMsg rsp = {
4,268,284✔
2699
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2700
  tmsgSendRsp(&rsp);
4,267,735✔
2701
  if (code == TSDB_CODE_STREAM_NO_DATA){
4,271,029✔
2702
    code = 0;
3,997,888✔
2703
  }
2704

2705
  blockDataDestroy(resultRsp.deleteBlock);
4,271,029✔
2706
  blockDataDestroy(resultRsp.dropBlock);
4,271,029✔
2707
  STREAM_PRINT_LOG_END_WITHID(code, lino);
4,271,029!
2708

2709
  return code;
4,271,029✔
2710
}
2711

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

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

2730
  if (!sStreamReaderInfo->isVtableStream){
382,863!
2731
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, true, &pBlock1));
266,903!
2732
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
266,903!
2733
  
2734
    blockDataTransform(pBlock2, pBlock1);
266,903✔
2735
    resultRsp.dataBlock = pBlock2;
266,347✔
2736
  }
2737

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

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

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

2764
  return code;
704,944✔
2765
}
2766

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

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

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

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

2799
  return code;
428,600✔
2800
}
2801

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

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

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

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

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

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

2836
    code = api.metaReaderFn.getTableEntryByUid(&metaReader, pKeyInfo->uid);
885,552✔
2837
    if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
885,003!
2838
      vTable->cols.nCols = metaReader.me.colRef.nCols;
52,308✔
2839
      vTable->cols.version = metaReader.me.colRef.version;
52,308✔
2840
      vTable->cols.pColRef = taosMemoryCalloc(metaReader.me.colRef.nCols, sizeof(SColRef));
52,308!
2841
      for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
313,848✔
2842
        memcpy(vTable->cols.pColRef + j, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
261,540!
2843
      }
2844
    } else {
2845
      vTable->cols.nCols = taosArrayGetSize(cids);
832,695✔
2846
      vTable->cols.version = metaReader.me.colRef.version;
832,752✔
2847
      vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
832,203!
2848
      for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
3,085,763✔
2849
        for (size_t j = 0; j < metaReader.me.colRef.nCols; j++) {
9,478,455✔
2850
          if (metaReader.me.colRef.pColRef[j].hasRef &&
8,643,582!
2851
              metaReader.me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
6,356,445✔
2852
            memcpy(vTable->cols.pColRef + i, &metaReader.me.colRef.pColRef[j], sizeof(SColRef));
1,418,733!
2853
            break;
1,417,646✔
2854
          }
2855
        }
2856
      }
2857
    }
2858
    tDecoderClear(&metaReader.coder);
885,552✔
2859
  }
2860
  ST_TASK_DLOG("vgId:%d %s end", TD_VID(pVnode), __func__);
398,287✔
2861
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
398,287!
2862

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

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

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

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

2889
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
130,156✔
2890

2891
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
129,611!
2892

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

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

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

2931
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
130,156!
2932

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

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

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

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

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

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

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

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

2981
    STREAM_CHECK_RET_GOTO(api.metaReaderFn.getTableEntryByUid(&metaReaderStable, suid));
838,052!
2982
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
838,052✔
2983
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
2,186,554✔
2984
      col_id_t* id = taosArrayGet(cols, i);
1,348,502✔
2985
      STREAM_CHECK_NULL_GOTO(id, terrno);
1,348,502!
2986
      if (*id == -1) {
1,348,502✔
2987
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
836,968✔
2988
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
836,968!
2989
        continue;
836,968✔
2990
      }
2991
      size_t j = 0;
511,534✔
2992
      for (; j < sSchemaWrapper->nCols; j++) {
923,074!
2993
        SSchema* s = sSchemaWrapper->pSchema + j;
923,074✔
2994
        if (s->colId == *id) {
923,074✔
2995
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
511,534✔
2996
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
511,534!
2997
          break;
511,534✔
2998
        }
2999
      }
3000
      if (j == sSchemaWrapper->nCols) {
511,534!
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));
838,052!
3006
    pBlock->info.rows = 1;
838,052✔
3007
    
3008
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
2,185,470✔
3009
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
1,347,960✔
3010
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
1,347,960!
3011

3012
      if (pDst->info.colId == -1) {
1,347,960✔
3013
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
836,968!
3014
        continue;
836,426✔
3015
      }
3016
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
510,992!
3017
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3018
        continue;
×
3019
      }
3020

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

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

3032
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
510,992!
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) &&
510,992!
3036
          (data != NULL)) {
3037
        taosMemoryFree(data);
401,188!
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);
840,811✔
3047
  printDataBlock(pBlock, __func__, "", streamId);
841,895✔
3048
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
841,895!
3049

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

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

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

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

3085
  if (req.reset || sStreamReaderCalcInfo->pTaskInfo == NULL) {
9,945,535!
3086
  // if (req.reset) {
3087
    qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
9,882,105✔
3088
    int64_t uid = 0;
9,880,920✔
3089
    if (req.dynTbname) {
9,880,920!
3090
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
49,896✔
3091
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
49,896!
3092
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
49,896✔
3093
        if (pValue != NULL && pValue->isTbname) {
49,896!
3094
          uid = pValue->uid;
49,896✔
3095
          break;
49,896✔
3096
        }
3097
      }
3098
    }
3099
    
3100
    SReadHandle handle = {0};
9,880,920✔
3101
    handle.vnode = pVnode;
9,880,993✔
3102
    handle.uid = uid;
9,880,993✔
3103

3104
    initStorageAPI(&handle.api);
9,880,993✔
3105
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
9,875,842✔
3106
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
9,244,661✔
3107
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
8,563,887✔
3108
      if (node != NULL) {
8,562,370✔
3109
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
495,256!
3110
      } else {
3111
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
8,067,114✔
3112
      }
3113

3114
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
8,562,949✔
3115
      if (node != NULL) {
8,564,617!
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__);
8,564,617✔
3119
      }      
3120
    }
3121

3122
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
9,882,596!
3123
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
9,882,665✔
3124

3125
    // if (sStreamReaderCalcInfo->pTaskInfo == NULL) {
3126
    STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
9,882,665✔
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));
9,879,317!
3134
  }
3135

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

3146
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
21,178,098✔
3147
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
11,240,386✔
3148
    if (pBlock == NULL) continue;
11,240,931!
3149
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
11,240,931✔
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__);
9,936,622✔
3159
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
9,936,622!
3160
  ST_TASK_DLOG("vgId:%d %s end:", TD_VID(pVnode), __func__);
9,937,167✔
3161

3162
end:
9,943,739✔
3163
  taosArrayDestroy(pResList);
9,946,095✔
3164
  streamReleaseTask(taskAddr);
9,946,095✔
3165

3166
  STREAM_PRINT_LOG_END(code, lino);
9,946,095!
3167
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
9,946,095✔
3168
  tmsgSendRsp(&rsp);
9,946,095✔
3169
  tDestroySResFetchReq(&req);
9,946,095✔
3170
  return code;
9,944,925✔
3171
}
3172

3173
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg) {
46,437,849✔
3174
  int32_t                   code = 0;
46,437,849✔
3175
  int32_t                   lino = 0;
46,437,849✔
3176
  SSTriggerPullRequestUnion req = {0};
46,437,849✔
3177
  void*                     taskAddr = NULL;
46,441,026✔
3178

3179
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
46,435,502✔
3180
  if (!syncIsReadyForRead(pVnode->sync)) {
46,438,731✔
3181
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
16,175✔
3182
    return 0;
16,175✔
3183
  }
3184

3185
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
46,428,203✔
3186
    return vnodeProcessStreamFetchMsg(pVnode, pMsg);
9,946,095✔
3187
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
36,481,548!
3188
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
36,483,751✔
3189
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
36,482,090✔
3190
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
36,480,415!
3191
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64,
36,473,187✔
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);
36,475,960✔
3194
    if (sStreamReaderInfo != NULL) {  
36,474,302✔
3195
      (void)taosThreadMutexLock(&sStreamReaderInfo->mutex);
36,338,230✔
3196
      if (sStreamReaderInfo->tableList == NULL) {
36,338,238✔
3197
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, false));  
334,707!
3198
        STREAM_CHECK_RET_GOTO(generateTablistForStreamReader(pVnode, sStreamReaderInfo, true));
334,707!
3199
        STREAM_CHECK_RET_GOTO(filterInitFromNode(sStreamReaderInfo->pConditions, &sStreamReaderInfo->pFilterInfo, 0, NULL));
334,707!
3200
      }
3201
      (void)taosThreadMutexUnlock(&sStreamReaderInfo->mutex);
36,339,906✔
3202
      sStreamReaderInfo->pVnode = pVnode;
36,338,247✔
3203
    }
3204
    switch (req.base.type) {
36,474,883!
3205
      case STRIGGER_PULL_SET_TABLE:
130,156✔
3206
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
130,156!
3207
        break;
130,156✔
3208
      case STRIGGER_PULL_LAST_TS:
327,903✔
3209
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
327,903!
3210
        break;
327,364✔
3211
      case STRIGGER_PULL_FIRST_TS:
286,425✔
3212
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
286,425✔
3213
        break;
280,801✔
3214
      case STRIGGER_PULL_TSDB_META:
535,754✔
3215
      case STRIGGER_PULL_TSDB_META_NEXT:
3216
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
535,754✔
3217
        break;
530,130✔
3218
      case STRIGGER_PULL_TSDB_TS_DATA:
23,778✔
3219
        if (sStreamReaderInfo->isVtableStream) {
23,778!
3220
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
1,626!
3221
        } else {
3222
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
22,152!
3223
        }
3224
        break;
23,778✔
3225
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
163,390✔
3226
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
3227
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
163,390!
3228
        break;
163,390✔
3229
      case STRIGGER_PULL_TSDB_CALC_DATA:
15,667,878✔
3230
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
3231
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
15,667,878✔
3232
        break;
15,475,815✔
3233
      case STRIGGER_PULL_TSDB_DATA:
459,378✔
3234
      case STRIGGER_PULL_TSDB_DATA_NEXT:
3235
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
459,378✔
3236
        break;
458,294✔
3237
      case STRIGGER_PULL_GROUP_COL_VALUE:
428,600✔
3238
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
428,600!
3239
        break;
428,600✔
3240
      case STRIGGER_PULL_VTABLE_INFO:
398,287✔
3241
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
398,287!
3242
        break;
398,287✔
3243
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
841,895✔
3244
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req));
841,895!
3245
        break;
841,895✔
3246
      case STRIGGER_PULL_OTABLE_INFO:
130,156✔
3247
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req));
130,156!
3248
        break;
130,156✔
3249
      case STRIGGER_PULL_WAL_META_NEW:
8,150,892✔
3250
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
8,150,892!
3251
        break;
8,154,759✔
3252
      case STRIGGER_PULL_WAL_DATA_NEW:
4,271,029✔
3253
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
4,271,029!
3254
        break;
4,271,029✔
3255
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,954,418✔
3256
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,954,418!
3257
        break;
3,953,873✔
3258
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
704,944✔
3259
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
704,944!
3260
        break;
704,944✔
3261
      default:
×
3262
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
3263
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3264
        break;
×
3265
    }
3266
  } else {
UNCOV
3267
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
3268
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
3269
  }
3270
end:
36,460,033✔
3271

3272
  streamReleaseTask(taskAddr);
36,474,915✔
3273

3274
  tDestroySTriggerPullRequest(&req);
36,480,448✔
3275
  STREAM_PRINT_LOG_END(code, lino);
36,461,723!
3276
  return code;
36,470,453✔
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