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

taosdata / TDengine / #5013

03 Apr 2026 03:59PM UTC coverage: 72.317% (+0.01%) from 72.305%
#5013

push

travis-ci

web-flow
merge: from main to 3.0 branch #35067

4053 of 5985 new or added lines in 68 files covered. (67.72%)

13131 existing lines in 160 files now uncovered.

257489 of 356056 relevant lines covered (72.32%)

129893134.08 hits per line

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

85.03
/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 <taos.h>
19
#include <tdef.h>
20
#include "executor.h"
21
#include "nodes.h"
22
#include "osMemPool.h"
23
#include "osMemory.h"
24
#include "scalar.h"
25
#include "stream.h"
26
#include "streamReader.h"
27
#include "taosdef.h"
28
#include "taoserror.h"
29
#include "tarray.h"
30
#include "tcommon.h"
31
#include "tdatablock.h"
32
#include "tdb.h"
33
#include "tdef.h"
34
#include "tencode.h"
35
#include "tglobal.h"
36
#include "thash.h"
37
#include "tlist.h"
38
#include "tlockfree.h"
39
#include "tmsg.h"
40
#include "tsimplehash.h"
41
#include "ttypes.h"
42
#include "vnd.h"
43
#include "vnode.h"
44
#include "vnodeInt.h"
45
#include "executor.h"
46

47
int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid, col_id_t colId, SRWLatch* lock);
48

49
#define BUILD_OPTION(options, _suid, _ver, _order, startTime, endTime, _schemas, _isSchema, _pSlotList)      \
50
  SStreamOptions                       options = {.suid = _suid,                                                   \
51
                                                  .ver = _ver,                                                     \
52
                                                  .order = _order,                                                 \
53
                                                  .twindows = {.skey = startTime, .ekey = endTime},                \
54
                                                  .schemas = _schemas,                                             \
55
                                                  .isSchema = _isSchema,                                           \
56
                                                  .pSlotList = _pSlotList};
57

58
typedef struct WalMetaResult {
59
  uint64_t    id;
60
  int64_t     skey;
61
  int64_t     ekey;
62
} WalMetaResult;
63

64
static int64_t getSuid(SStreamTriggerReaderInfo* sStreamReaderInfo, STableKeyInfo* pList) {
7,151,846✔
65
  int64_t suid = 0;
7,151,846✔
66
  if (!sStreamReaderInfo->isVtableStream) {
7,151,846✔
67
    suid = sStreamReaderInfo->suid;
6,718,133✔
68
    goto end;
6,718,581✔
69
  }
70

71
  if (pList == NULL) {
433,265✔
72
    goto end;
×
73
  }
74

75
  taosRLockLatch(&sStreamReaderInfo->lock);
433,265✔
76
  SStreamTableMapElement* element = taosHashGet(sStreamReaderInfo->vSetTableList.uIdMap, &pList->uid, LONG_BYTES);  
433,265✔
77
  if (element != 0) {
433,265✔
78
    suid = element->table->groupId;
247,400✔
79
    taosRUnLockLatch(&sStreamReaderInfo->lock);
247,400✔
80
    goto end;
247,400✔
81
  }
82
  taosRUnLockLatch(&sStreamReaderInfo->lock);
185,865✔
83

84
end:
7,151,846✔
85
  return suid;
7,151,846✔
86
}
87

88
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
7,073,068✔
89

90
int32_t sortCid(const void *lp, const void *rp) {
1,687,212✔
91
  int16_t* c1 = (int16_t*)lp;
1,687,212✔
92
  int16_t* c2 = (int16_t*)rp;
1,687,212✔
93

94
  if (*c1 < *c2) {
1,687,212✔
95
    return -1;
1,670,968✔
96
  } else if (*c1 > *c2) {
16,244✔
97
    return 1;
16,244✔
98
  }
99

100
  return 0;
×
101
}
102

103
int32_t sortSSchema(const void *lp, const void *rp) {
1,671,772✔
104
  SSchema* c1 = (SSchema*)lp;
1,671,772✔
105
  SSchema* c2 = (SSchema*)rp;
1,671,772✔
106

107
  if (c1->colId < c2->colId) {
1,671,772✔
108
    return -1;
1,655,528✔
109
  } else if (c1->colId > c2->colId) {
16,244✔
110
    return 1;
16,244✔
111
  }
112

113
  return 0;
×
114
}
115

116
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
41,660,670✔
117
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
41,660,670✔
118
  if (pSrc == NULL) {
41,669,676✔
119
    return terrno;
×
120
  }
121

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
41,669,676✔
123
  return 0;
41,663,191✔
124
}
125

126
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
9,362,864✔
127
  int32_t code = pTask->storageApi->tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
9,362,864✔
128
  if (code != TSDB_CODE_SUCCESS) {
9,363,452✔
129
    pTask->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
130
  }
131

132
  return code;
9,362,828✔
133
}
134

135
static int32_t getTableData(SStreamReaderTaskInner* pTask, SSDataBlock** ppRes) {
1,401,059✔
136
  return pTask->storageApi->tsdReader.tsdReaderRetrieveDataBlock(pTask->pReader, ppRes);
1,401,059✔
137
}
138

139
static int32_t buildOTableInfoRsp(const SSTriggerOrigTableInfoRsp* rsp, void** data, size_t* size) {
134,454✔
140
  int32_t code = 0;
134,454✔
141
  int32_t lino = 0;
134,454✔
142
  void*   buf = NULL;
134,454✔
143
  int32_t len = tSerializeSTriggerOrigTableInfoRsp(NULL, 0, rsp);
134,454✔
144
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
134,454✔
145
  buf = rpcMallocCont(len);
134,454✔
146
  STREAM_CHECK_NULL_GOTO(buf, terrno);
134,454✔
147
  int32_t actLen = tSerializeSTriggerOrigTableInfoRsp(buf, len, rsp);
134,454✔
148
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
134,454✔
149
  *data = buf;
134,454✔
150
  *size = len;
134,454✔
151
  buf = NULL;
134,454✔
152
end:
134,454✔
153
  rpcFreeCont(buf);
134,454✔
154
  return code;
134,454✔
155
}
156

157
static bool ignoreMetaChange(int64_t tableListVer, int64_t ver) {
168,976✔
158
  stDebug("%s tableListVer:%" PRId64 " ver:%" PRId64, __func__, tableListVer, ver);
168,976✔
159
  return tableListVer >= ver;
168,976✔
160
}
161

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
7,150,332✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
7,150,332✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
2,468,304✔
165
      suid == sStreamReaderInfo->suid) {
871,269✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
10,600✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
10,600✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
10,600✔
169
    if (gid == (uint64_t)-1) return true;
10,600✔
170
  }
171
  return false;
7,139,804✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
18,226,813✔
175
  int32_t  ret = false;
18,226,813✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
18,226,813✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
8,751,261✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
3,515,089✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
12,989,331✔
181
  if (*id == -1) goto end;
12,989,970✔
182
  ret = true;
5,543,269✔
183

184
end:
18,231,691✔
185
  stTrace("%s ret:%d %p %p check suid:%" PRId64 " uid:%" PRId64 " gid:%"PRIu64, __func__, ret, sStreamReaderInfo, sStreamReaderInfo->tableList.gIdMap, suid, uid, *id);
18,231,691✔
186
  return ret;
18,229,176✔
187
}
188

189
static bool uidInTableListOrigin(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id) {
31,864✔
190
  return uidInTableList(sStreamReaderInfo, suid, uid, id);
31,864✔
191
}
192

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
61,186,942✔
194
  bool ret = false;
61,186,942✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
61,186,942✔
196
  if (sStreamReaderInfo->isVtableStream) {
61,190,322✔
197
    int64_t tmp[2] = {suid, uid};
42,994,499✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
42,994,298✔
199
      *id = uid;
14,965,157✔
200
      ret = true;
14,965,157✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
18,196,594✔
204
  }
205

206
end:
61,190,916✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
61,190,916✔
208
  return ret;
61,197,833✔
209
}
210

211
static int32_t  qTransformStreamTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, void* pTableListInfo, StreamTableListInfo* tableInfo){
301,621✔
212
  SArray* pList = qStreamGetTableListArray(pTableListInfo);
301,621✔
213
  int32_t totalSize = taosArrayGetSize(pList);
301,621✔
214
  int32_t code = 0;
301,621✔
215
  void* pTask = sStreamReaderInfo->pTask;
301,621✔
216
  for (int32_t i = 0; i < totalSize; ++i) {
809,923✔
217
    STableKeyInfo* info = taosArrayGet(pList, i);
508,302✔
218
    if (info == NULL) {
508,302✔
219
      continue;
×
220
    }
221
    code = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
508,302✔
222
    if (code != 0){
507,729✔
223
      ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, code);
×
224
      continue;
×
225
    }
226
    code = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
507,729✔
227
    if (code != 0){
508,125✔
228
      ST_TASK_WLOG("%s cacheTag calc failed for uid:%" PRId64",code:%d", __func__, info->uid, code);
×
229
      continue;
×
230
    }
231
    code = qStreamSetTableList(tableInfo, info->uid, info->groupId);
508,125✔
232
    if (code != 0){
508,302✔
233
      return code;
×
234
    }
235
  }
236
  return 0;
301,621✔
237
}
238

239
static int32_t generateTablistForStreamReader(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo) {
301,198✔
240
  int32_t                   code = 0;
301,198✔
241
  int32_t                   lino = 0;
301,198✔
242
  SNodeList* groupNew = NULL;   
301,198✔
243
  void* pTableListInfo = NULL;
301,621✔
244

245
  
246
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));
301,621✔
247

248
  STREAM_CHECK_RET_GOTO(qStreamCreateTableListForReader(pVnode, sStreamReaderInfo->suid, sStreamReaderInfo->uid, sStreamReaderInfo->tableType, groupNew,
301,621✔
249
                                         true, sStreamReaderInfo->pTagCond, sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi, 
250
                                         &pTableListInfo, sStreamReaderInfo->groupIdMap));
251
  
252
  STREAM_CHECK_RET_GOTO(qTransformStreamTableList(sStreamReaderInfo, pTableListInfo, &sStreamReaderInfo->tableList));
301,621✔
253
  
254
  void* pTask = sStreamReaderInfo->pTask;
301,621✔
255
  ST_TASK_DLOG("vgId:%d %s tablelist size:%" PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList));
301,621✔
256
end:
301,175✔
257
  nodesDestroyList(groupNew);
301,621✔
258
  qStreamDestroyTableList(pTableListInfo);
301,621✔
259
  STREAM_PRINT_LOG_END(code, lino);
301,621✔
260
  return code;
301,621✔
261
}
262

263
static int32_t buildVTableInfoRsp(const SStreamMsgVTableInfo* rsp, void** data, size_t* size) {
75,656✔
264
  int32_t code = 0;
75,656✔
265
  int32_t lino = 0;
75,656✔
266
  void*   buf = NULL;
75,656✔
267
  int32_t len = tSerializeSStreamMsgVTableInfo(NULL, 0, rsp);
75,656✔
268
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
75,656✔
269
  buf = rpcMallocCont(len);
75,656✔
270
  STREAM_CHECK_NULL_GOTO(buf, terrno);
75,656✔
271
  int32_t actLen = tSerializeSStreamMsgVTableInfo(buf, len, rsp);
75,656✔
272
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
75,656✔
273
  *data = buf;
75,656✔
274
  *size = len;
75,656✔
275
  buf = NULL;
75,656✔
276
end:
75,656✔
277
  rpcFreeCont(buf);
75,656✔
278
  return code;
75,656✔
279
}
280

281
static int32_t buildTsRsp(const SStreamTsResponse* tsRsp, void** data, size_t* size) {
564,905✔
282
  int32_t code = 0;
564,905✔
283
  int32_t lino = 0;
564,905✔
284
  void*   buf = NULL;
564,905✔
285
  int32_t len = tSerializeSStreamTsResponse(NULL, 0, tsRsp);
564,905✔
286
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
564,436✔
287
  buf = rpcMallocCont(len);
564,436✔
288
  STREAM_CHECK_NULL_GOTO(buf, terrno);
564,313✔
289
  int32_t actLen = tSerializeSStreamTsResponse(buf, len, tsRsp);
564,313✔
290
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
564,453✔
291
  *data = buf;
564,453✔
292
  *size = len;
564,219✔
293
  buf = NULL;
563,862✔
294
end:
563,862✔
295
  rpcFreeCont(buf);
563,862✔
296
  return code;
563,861✔
297
}
298

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
8,393,029✔
301
  int32_t code = 0;
8,393,029✔
302
  int32_t lino = 0;
8,393,029✔
303
  void*   buf = NULL;
8,393,029✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
8,393,029✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
2,035,793✔
306
  buf = rpcMallocCont(dataEncodeSize);
2,035,793✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
2,035,844✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
2,035,844✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
2,035,793✔
310
  *data = buf;
2,035,793✔
311
  *size = dataEncodeSize;
2,035,844✔
312
  buf = NULL;
2,035,793✔
313
end:
8,396,830✔
314
  rpcFreeCont(buf);
8,396,830✔
315
  return code;
8,394,690✔
316
}
317

318
static int32_t buildArrayRsp(SArray* pBlockList, void** data, size_t* size) {
56,650✔
319
  int32_t code = 0;
56,650✔
320
  int32_t lino = 0;
56,650✔
321

322
  void*   buf = NULL;
56,650✔
323

324
  int32_t blockNum = 0;
56,650✔
325
  size_t  dataEncodeBufSize = 0;
56,650✔
326
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
118,560✔
327
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
61,910✔
328
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
61,910✔
329
    int32_t blockSize = blockGetEncodeSize(pBlock);
61,910✔
330
    dataEncodeBufSize += blockSize;
61,910✔
331
    blockNum++;
61,910✔
332
  }
333
  buf = rpcMallocCont(INT_BYTES + dataEncodeBufSize);
56,650✔
334
  STREAM_CHECK_NULL_GOTO(buf, terrno);
56,650✔
335

336
  char* dataBuf = (char*)buf;
56,650✔
337
  *((int32_t*)(dataBuf)) = blockNum;
56,650✔
338
  dataBuf += INT_BYTES;
56,650✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
118,560✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
61,910✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
61,910✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
61,910✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
61,910✔
344
    dataBuf += actualLen;
61,910✔
345
  }
346
  *data = buf;
56,416✔
347
  *size = INT_BYTES + dataEncodeBufSize;
56,650✔
348
  buf = NULL;
56,650✔
349
end:
56,650✔
350
  rpcFreeCont(buf);
56,650✔
351
  return code;
56,650✔
352
}
353

354
static int32_t buildWalMetaBlock(SSDataBlock* pBlock, int8_t type, int64_t id, bool isVTable, int64_t uid,
×
355
                                 int64_t skey, int64_t ekey, int64_t ver, int64_t rows) {
356
  int32_t code = 0;
×
357
  int32_t lino = 0;
×
358
  int32_t index = 0;
×
359
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &type));
×
360
  if (!isVTable) {
×
361
    STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
×
362
  }
363
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &uid));
×
364
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
×
365
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
×
366
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
×
367
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &rows));
×
368

369
end:
×
370
  // STREAM_PRINT_LOG_END(code, lino)
371
  return code;
×
372
}
373

374
static int32_t buildWalMetaBlockNew(SSDataBlock* pBlock, int64_t id, int64_t skey, int64_t ekey, int64_t ver) {
10,001,888✔
375
  int32_t code = 0;
10,001,888✔
376
  int32_t lino = 0;
10,001,888✔
377
  int32_t index = 0;
10,001,888✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
10,001,888✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
10,001,060✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
10,002,417✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
10,003,330✔
382

383
end:
10,001,617✔
384
  return code;
10,001,617✔
385
}
386

387
static int32_t buildTableBlock(SSDataBlock* pBlock, int64_t id, int64_t ver, ETableBlockType type) {
3,418✔
388
  int32_t code = 0;
3,418✔
389
  int32_t lino = 0;
3,418✔
390
  int32_t index = 0;
3,418✔
391
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
3,418✔
392
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
3,418✔
393
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &type));
3,418✔
394

395
end:
3,418✔
396
  return code;
3,418✔
397
}
398

399
static void buildTSchema(STSchema* pTSchema, int32_t ver, col_id_t colId, int8_t type, int32_t bytes) {
×
400
  pTSchema->numOfCols = 1;
×
401
  pTSchema->version = ver;
×
402
  pTSchema->columns[0].colId = colId;
×
403
  pTSchema->columns[0].type = type;
×
404
  pTSchema->columns[0].bytes = bytes;
×
405
}
×
406

407
static int32_t scanDeleteDataNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
30,392✔
408
                              int64_t ver) {
409
  int32_t    code = 0;
30,392✔
410
  int32_t    lino = 0;
30,392✔
411
  SDecoder   decoder = {0};
30,392✔
412
  SDeleteRes req = {0};
30,392✔
413
  void* pTask = sStreamReaderInfo->pTask;
30,392✔
414

415
  req.uidList = taosArrayInit(0, sizeof(tb_uid_t));
30,392✔
416
  tDecoderInit(&decoder, data, len);
30,392✔
417
  STREAM_CHECK_RET_GOTO(tDecodeDeleteRes(&decoder, &req));
30,392✔
418
  STREAM_CHECK_CONDITION_GOTO((sStreamReaderInfo->tableType == TSDB_SUPER_TABLE && !sStreamReaderInfo->isVtableStream && req.suid != sStreamReaderInfo->suid), TDB_CODE_SUCCESS);
30,392✔
419
  
420
  for (int32_t i = 0; i < taosArrayGetSize(req.uidList); i++) {
47,145✔
421
    uint64_t* uid = taosArrayGet(req.uidList, i);
27,059✔
422
    STREAM_CHECK_NULL_GOTO(uid, terrno);
27,059✔
423
    uint64_t   id = 0;
27,059✔
424
    ST_TASK_DLOG("stream reader scan delete start data:uid %" PRIu64 ", skey %" PRIu64 ", ekey %" PRIu64, *uid, req.skey, req.ekey);
27,059✔
425
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, req.suid, *uid, &id, false), TDB_CODE_SUCCESS);
27,059✔
426
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->deleteBlock, ((SSDataBlock*)rsp->deleteBlock)->info.rows + 1));
20,086✔
427
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->deleteBlock, id, req.skey, req.ekey, ver));
20,086✔
428
    ((SSDataBlock*)rsp->deleteBlock)->info.rows++;
20,086✔
429
    rsp->totalRows++;
20,086✔
430
  }
431

432
end:
30,392✔
433
  taosArrayDestroy(req.uidList);
30,392✔
434
  tDecoderClear(&decoder);
30,392✔
435
  return code;
30,158✔
436
}
437

438
static int32_t createBlockForProcessMeta(SSDataBlock** pBlock) {
2,948✔
439
  int32_t code = 0;
2,948✔
440
  int32_t lino = 0;
2,948✔
441
  SArray* schemas = NULL;
2,948✔
442

443
  schemas = taosArrayInit(8, sizeof(SSchema));
2,948✔
444
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
2,948✔
445

446
  int32_t index = 0;
2,948✔
447
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid non vtable/uid vtable
2,948✔
448
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
2,948✔
449
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TINYINT, CHAR_BYTES, index++))  // type
2,948✔
450

451
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
2,948✔
452

453
end:
2,948✔
454
  taosArrayDestroy(schemas);
2,948✔
455
  return code;
2,948✔
456
}
457

458
static int32_t addOneRow(void** tmp, int64_t id, int64_t ver, ETableBlockType type) {
3,418✔
459
  int32_t  code = 0;
3,418✔
460
  int32_t  lino = 0;
3,418✔
461
  if (*tmp == NULL) {
3,418✔
462
    STREAM_CHECK_RET_GOTO(createBlockForProcessMeta((SSDataBlock**)tmp));
2,948✔
463
  }
464
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(*tmp, ((SSDataBlock*)(*tmp))->info.rows + 1));
3,418✔
465
  STREAM_CHECK_RET_GOTO(buildTableBlock(*tmp, id, ver, type));
3,418✔
466
  ((SSDataBlock*)(*tmp))->info.rows++;
3,418✔
467
  
468
end:
3,418✔
469
  return code;
3,418✔
470
}
471

472
static int32_t addUidListToBlock(SArray* uidListAdd, void** block, int64_t ver, int32_t* totalRows, ETableBlockType type) {
71,170✔
473
  for (int32_t i = 0; i < taosArrayGetSize(uidListAdd); ++i) {
74,588✔
474
    uint64_t* uid = taosArrayGet(uidListAdd, i);
3,418✔
475
    if (uid == NULL) {
3,418✔
476
      continue;
×
477
    }
478
    int32_t code = addOneRow(block, *uid, ver, type);
3,418✔
479
    if (code != 0) {
3,418✔
480
      return code;
×
481
    }
482
    (*totalRows)++;
3,418✔
483
  }
484
  return 0;
71,170✔
485
}
486

487
static int32_t qStreamGetAddTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* uidListAdd) {
46,514✔
488
  int32_t      code = 0;
46,514✔
489
  int32_t      lino = 0;
46,514✔
490
  if (uidListAdd == NULL) {
46,514✔
491
    return 0;
40,011✔
492
  }
493
  void* pTask = sStreamReaderInfo->pTask;
6,503✔
494
  
495
  taosRLockLatch(&sStreamReaderInfo->lock);
6,503✔
496
  int32_t totalSize = taosArrayGetSize(tableListAdd);
6,503✔
497
  for (int32_t i = 0; i < totalSize; ++i) {
8,581✔
498
    STableKeyInfo* info = taosArrayGet(tableListAdd, i);
2,078✔
499
    if (info == NULL) {
2,078✔
500
      continue;
×
501
    }
502
    if (taosHashGet(sStreamReaderInfo->tableList.uIdMap, &info->uid, LONG_BYTES) != NULL) {
2,078✔
503
      continue;
×
504
    }
505
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListAdd, &info->uid), terrno);
4,156✔
506
    ST_TASK_WLOG("%s real add table to list for uid:%" PRId64, __func__, info->uid);
2,078✔
507
  }
508

509
end:
6,503✔
510
  taosRUnLockLatch(&sStreamReaderInfo->lock);
6,503✔
511
  return code;
6,503✔
512
}
513

514
static int32_t qStreamGetDelTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListDel, SArray* uidListDel) {
51,709✔
515
  int32_t      code = 0;
51,709✔
516
  int32_t      lino = 0;
51,709✔
517
  if (uidListDel == NULL) {
51,709✔
518
    return 0;
×
519
  }
520
  void* pTask = sStreamReaderInfo->pTask;
51,709✔
521
  
522
  taosRLockLatch(&sStreamReaderInfo->lock);
51,709✔
523
  int32_t totalSize = taosArrayGetSize(tableListDel);
51,709✔
524
  for (int32_t i = 0; i < totalSize; ++i) {
52,581✔
525
    int64_t* uid = taosArrayGet(tableListDel, i);
872✔
526
    if (uid == NULL) {
872✔
527
      continue;
×
528
    }
529
    if (taosHashGet(sStreamReaderInfo->tableList.uIdMap, uid, LONG_BYTES) == NULL) {
872✔
530
      continue;
×
531
    }
532
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListDel, uid), terrno);
872✔
533
    ST_TASK_WLOG("%s real del table from list for uid:%" PRId64, __func__, *uid);
872✔
534
  }
535

536
end:
51,709✔
537
  taosRUnLockLatch(&sStreamReaderInfo->lock);
51,709✔
538
  return code;
51,709✔
539
}
540

541
static int32_t scanDropTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
31,396✔
542
                             int64_t ver) {
543
  int32_t  code = 0;
31,396✔
544
  int32_t  lino = 0;
31,396✔
545
  SDecoder decoder = {0};
31,396✔
546
  void* pTask = sStreamReaderInfo->pTask;
31,396✔
547
  SArray* uidList = NULL;
31,396✔
548
  SArray* uidListDel = NULL;
31,396✔
549
  SArray* uidListDelOutTbl = NULL;
31,396✔
550
  SVDropTbBatchReq req = {0};
31,396✔
551
  tDecoderInit(&decoder, data, len);
31,396✔
552
  STREAM_CHECK_RET_GOTO(tDecodeSVDropTbBatchReq(&decoder, &req));
31,396✔
553

554
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
62,792✔
555
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
31,396✔
556
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
31,396✔
557
    uint64_t id = 0;
31,396✔
558
    if(!uidInTableListOrigin(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id)) {
31,396✔
559
      continue;
30,524✔
560
    }
561

562
    if (sStreamReaderInfo->deleteOutTbl != 0) {
872✔
563
      if (uidListDelOutTbl == NULL) {
×
564
        uidListDelOutTbl = taosArrayInit(8, sizeof(tb_uid_t));
×
565
        STREAM_CHECK_NULL_GOTO(uidListDelOutTbl, terrno);
×
566
      }
567
      STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListDelOutTbl, &pDropTbReq->uid), terrno);
×
568
    }
569
    if (sStreamReaderInfo->isVtableStream) {
872✔
570
      if (uidList == NULL) {
872✔
571
        uidList = taosArrayInit(8, sizeof(tb_uid_t));
872✔
572
        STREAM_CHECK_NULL_GOTO(uidList, terrno);
872✔
573
      }
574
      STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pDropTbReq->uid), terrno);
1,744✔
575
    }
576
    
577
    ST_TASK_DLOG("stream reader scan drop uid %" PRId64 ", id %" PRIu64, pDropTbReq->uid, id);
872✔
578
  }
579
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDelOutTbl, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_DROP));
31,396✔
580

581
  if (sStreamReaderInfo->isVtableStream) {
31,396✔
582
    uidListDel = taosArrayInit(8, sizeof(tb_uid_t));
31,396✔
583
    STREAM_CHECK_NULL_GOTO(uidListDel, terrno);
31,396✔
584
    STREAM_CHECK_RET_GOTO(qStreamGetDelTable(sStreamReaderInfo, uidList, uidListDel));
31,396✔
585
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
31,396✔
586
  }
587
  
588
end:
31,396✔
589
  taosArrayDestroy(uidList);
31,396✔
590
  taosArrayDestroy(uidListDel);
31,396✔
591
  taosArrayDestroy(uidListDelOutTbl);
31,396✔
592
  tDecoderClear(&decoder);
31,396✔
593
  return code;
31,396✔
594
}
595

596
static int32_t qStreamModifyTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* tableListDel) {
47,951✔
597
  int32_t      code = 0;
47,951✔
598
  int32_t      lino = 0;
47,951✔
599
  void* pTask = sStreamReaderInfo->pTask;
47,951✔
600
  
601
  taosWLockLatch(&sStreamReaderInfo->lock);
47,951✔
602
  int32_t totalSize = taosArrayGetSize(tableListDel);
47,951✔
603
  for (int32_t i = 0; i < totalSize; ++i) {
47,951✔
604
    int64_t* uid = taosArrayGet(tableListDel, i);
×
605
    if (uid == NULL) {
×
606
      continue;
×
607
    }
608
    STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, *uid));
×
609
  }
610

611
  totalSize = taosArrayGetSize(tableListAdd);
47,951✔
612
  for (int32_t i = 0; i < totalSize; ++i) {
77,784✔
613
    STableKeyInfo* info = taosArrayGet(tableListAdd, i);
29,833✔
614
    if (info == NULL) {
29,833✔
615
      continue;
×
616
    }
617
    int ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
29,833✔
618
    if (ret != 0){
29,833✔
619
      ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, ret);
6,303✔
620
      continue;
6,303✔
621
    }
622
    ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
23,530✔
623
    if (ret != 0){
23,530✔
624
      ST_TASK_WLOG("%s cacheTag calc failed for uid:%" PRId64",code:%d", __func__, info->uid, ret);
×
625
      continue;
×
626
    }
627
    STREAM_CHECK_RET_GOTO(qStreamRemoveTableList(&sStreamReaderInfo->tableList, info->uid));
23,530✔
628
    STREAM_CHECK_RET_GOTO(qStreamSetTableList(&sStreamReaderInfo->tableList, info->uid, info->groupId));
23,530✔
629
  }
630

631
end:
47,951✔
632
  taosWUnLockLatch(&sStreamReaderInfo->lock);
47,951✔
633
  return code;
47,951✔
634
}
635

636
static int32_t processTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* uidList, SArray** tableList) {
47,774✔
637
  int32_t code = 0;
47,774✔
638
  int32_t lino = 0;
47,774✔
639
  SNodeList* groupNew = NULL;   
47,774✔
640

641
  if (taosArrayGetSize(uidList) == 0) {
47,951✔
642
    return 0;
18,118✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
29,833✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
29,833✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

649
end:
29,833✔
650
  nodesDestroyList(groupNew);
29,833✔
651
  return code;
29,833✔
652
}
653

654
static int32_t scanCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len,
26,201✔
655
                             int64_t ver) {
656
  int32_t  code = 0;
26,201✔
657
  int32_t  lino = 0;
26,201✔
658
  SDecoder decoder = {0};
26,201✔
659
  SArray*  uidList = NULL;
26,201✔
660
  SArray*  tableList = NULL;
26,201✔
661
  SArray*  uidListAdd = NULL;
26,201✔
662
  void* pTask = sStreamReaderInfo->pTask;
26,201✔
663

664
  SVCreateTbBatchReq req = {0};
26,201✔
665
  tDecoderInit(&decoder, data, len);
26,201✔
666
  
667
  STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbBatchReq(&decoder, &req));
26,201✔
668

669
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
26,201✔
670
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
26,201✔
671

672
  if (sStreamReaderInfo->isVtableStream) {
26,201✔
673
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
5,096✔
674
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
5,096✔
675
  }
676
  
677
  SVCreateTbReq* pCreateReq = NULL;
26,201✔
678
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
52,402✔
679
    pCreateReq = req.pReqs + iReq;
26,201✔
680
    if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
26,201✔
681
      ST_TASK_DLOG("stream reader scan create table jump, %s", pCreateReq->name);
18,118✔
682
      continue;
18,118✔
683
    }
684
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
8,083✔
685
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
16,166✔
686
  }
687
  
688
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
26,201✔
689
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
26,201✔
690
  if (sStreamReaderInfo->isVtableStream) {
26,201✔
691
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
5,096✔
692
  }
693

694
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
26,201✔
695
end:
26,201✔
696
  taosArrayDestroy(uidList);
26,201✔
697
  taosArrayDestroy(uidListAdd);
26,201✔
698
  taosArrayDestroy(tableList);
26,201✔
699
  tDeleteSVCreateTbBatchReq(&req);
26,201✔
700
  tDecoderClear(&decoder);
26,201✔
701
  return code;
26,201✔
702
}
703

704
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq, int64_t ver) {
7,120,803✔
705
  int32_t  code = 0;
7,120,803✔
706
  int32_t  lino = 0;
7,120,803✔
707
  void*    pTask = sStreamReaderInfo->pTask;
7,120,803✔
708
  SArray*  uidList = NULL;
7,122,156✔
709
  SArray*  tableList = NULL;
7,122,156✔
710

711
  ST_TASK_DLOG("%s start, name:%s uid:%"PRId64, __func__, pCreateReq->name, pCreateReq->uid);
7,121,441✔
712
  if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false) ||
7,125,610✔
713
      ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
1,977✔
714
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
7,121,756✔
715
    goto end;
7,122,013✔
716
  }
717
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,437✔
718
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,437✔
719
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
2,874✔
720
  ST_TASK_DLOG("stream reader scan auto create table %s", pCreateReq->name);
1,437✔
721

722
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,437✔
723
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,437✔
724
end:
5,326,895✔
725
  taosArrayDestroy(uidList);
7,123,450✔
726
  taosArrayDestroy(tableList);
7,122,724✔
727
  return code;
7,122,276✔
728
}
729

730
static bool isColIdInList(SNodeList* colList, col_id_t cid){
468✔
731
  int32_t  code = 0;
468✔
732
  int32_t  lino = 0;
468✔
733
  SNode*  nodeItem = NULL;
468✔
734
  FOREACH(nodeItem, colList) {
1,170✔
735
    SNode*           pNode = ((STargetNode*)nodeItem)->pExpr;
1,170✔
736
    if (nodeType(pNode) == QUERY_NODE_COLUMN) {
1,170✔
737
      SColumnNode*     valueNode = (SColumnNode*)(pNode);
1,170✔
738
      if (cid == valueNode->colId) {
1,170✔
739
        return true;
468✔
740
      }
741
    }
742
  }
743
end:
×
744
  return false;
×
745
}
746

747
static bool isAlteredTable(int8_t action, ETableType tbType) {
20,781✔
748
  if (action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL && tbType == TSDB_CHILD_TABLE) {
20,781✔
749
    return true;
20,313✔
750
  } else if (action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL && tbType == TSDB_SUPER_TABLE) {
468✔
751
    return true;
×
752
  } else if ((action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) && 
468✔
753
     (tbType == TSDB_VIRTUAL_CHILD_TABLE || tbType == TSDB_VIRTUAL_NORMAL_TABLE)) {
468✔
754
    return true;
468✔
755
  }
756
  return false;
×
757
}
758

759
void getAlterColId(void* pVnode, int64_t uid, const char* colName, col_id_t* colId) {
468✔
760
  SSchemaWrapper *pSchema = metaGetTableSchema(((SVnode *)pVnode)->pMeta, uid, -1, 1, NULL, 0);
468✔
761
  if (pSchema == NULL) {
468✔
762
    return;
×
763
  }
764
  for (int32_t i = 0; i < pSchema->nCols; i++) {
1,170✔
765
    if (strncmp(pSchema->pSchema[i].name, colName, TSDB_COL_NAME_LEN) == 0) {
1,170✔
766
      *colId = pSchema->pSchema[i].colId;
468✔
767
      break;
468✔
768
    }
769
  }
770
  tDeleteSchemaWrapper(pSchema);
771
  return;
468✔
772
}
773

774
// Handle TSDB_ALTER_TABLE_ALTER_COLUMN_REF and TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
775
static int32_t scanAlterTableColumnRef(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, 
468✔
776
                                       SVAlterTbReq* pReq, uint64_t uid, int64_t ver) {
777
  int32_t code = 0;
468✔
778
  int32_t lino = 0;
468✔
779
  void* pTask = sStreamReaderInfo->pTask;
468✔
780
  SArray* uidListAdd = NULL;
468✔
781

782
  uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
468✔
783
  STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
468✔
784

785
  uint64_t id = 0;
468✔
786
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListOrigin(sStreamReaderInfo, sStreamReaderInfo->suid, uid, &id), TDB_CODE_SUCCESS);
468✔
787

788
  col_id_t colId = 0;
468✔
789
  getAlterColId(sStreamReaderInfo->pVnode, uid, pReq->colName, &colId);
468✔
790
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 0 && !isColIdInList(sStreamReaderInfo->triggerCols, colId)) {
468✔
791
    ST_TASK_ILOG("stream reader scan alter table %s, colId %d not in trigger cols", pReq->tbName, colId);
×
792
    goto end;
×
793
  }
794

795
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidListAdd, &uid), terrno);
468✔
796
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
468✔
797

798
  ST_TASK_DLOG("stream reader scan alter table column ref %s", pReq->tbName);
468✔
799

800
end:
468✔
801
  taosArrayDestroy(uidListAdd);
468✔
802
  STREAM_PRINT_LOG_END_WITHID(code, lino);
468✔
803
  return code;
468✔
804
}
805

806
static int32_t checkAlter(SStreamTriggerReaderInfo* sStreamReaderInfo, char* tbName, int8_t action, uint64_t *uid) {
20,781✔
807
  int32_t  code = 0;
20,781✔
808
  int32_t  lino = 0;
20,781✔
809
  ETableType tbType = 0;
20,781✔
810
  uint64_t suid = 0;
20,781✔
811

812
  STREAM_CHECK_RET_GOTO(metaGetTableTypeSuidByName(sStreamReaderInfo->pVnode, tbName, &tbType, &suid));
20,781✔
813
  STREAM_CHECK_CONDITION_GOTO(!isAlteredTable(action, tbType), TDB_CODE_SUCCESS);
20,781✔
814
  STREAM_CHECK_CONDITION_GOTO(suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
20,781✔
815
  if (action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
19,173✔
816
    *uid = suid;
×
817
    goto end;
×
818
  }
819
  STREAM_CHECK_RET_GOTO(metaGetTableUidByName(sStreamReaderInfo->pVnode, tbName, uid));
19,173✔
820

821
end:
20,781✔
822
  return code;
20,781✔
823
}
824

825
static SArray* getTableListForAlterSuperTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SVAlterTbReq* pReq){
20,313✔
826
  int32_t code = 0;
20,313✔
827
  int32_t lino = 0;
20,313✔
828
  void* pTask = sStreamReaderInfo->pTask;
20,313✔
829
  SArray* uidList = taosArrayInit(8, sizeof(tb_uid_t));
20,313✔
830
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
20,313✔
831
  for (int32_t i = 0; i < taosArrayGetSize(pReq->tables); i++) {
40,626✔
832
    SUpdateTableTagVal *pTable = taosArrayGet(pReq->tables, i);
20,313✔
833
    uint64_t uid = 0;
20,313✔
834
    code = checkAlter(sStreamReaderInfo, pTable->tbName, pReq->action, &uid);
20,313✔
835
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
20,313✔
836
      code = 0;
×
837
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", pTable->tbName);
×
838
      continue;
×
839
    }
840
    STREAM_CHECK_RET_GOTO(code);
20,313✔
841
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, (const void *)&uid), terrno);
20,313✔
842
  }
843

844
end:
20,313✔
845
  if (code != 0) {
20,313✔
846
    ST_TASK_ELOG("%s failed,code:%d", __func__, code);
×
847
    taosArrayDestroy(uidList);
×
848
    uidList = NULL;
×
849
  }
850
  return uidList;
20,313✔
851
}
852

853
// Handle TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL and TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
854
static int32_t scanAlterTableTagVal(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, 
20,313✔
855
                                    SArray* uidList, int64_t ver) {
856
  int32_t code = 0;
20,313✔
857
  int32_t lino = 0;
20,313✔
858
  void* pTask = sStreamReaderInfo->pTask;
20,313✔
859
  SArray* uidListAdd = NULL;
20,313✔
860
  SArray* uidListDel = NULL;
20,313✔
861
  SArray* tableList = NULL;
20,313✔
862

863
  if (sStreamReaderInfo->isVtableStream) {
20,313✔
864
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
1,407✔
865
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
1,407✔
866
  }
867

868
  uidListDel = taosArrayInit(8, sizeof(tb_uid_t));
20,313✔
869
  STREAM_CHECK_NULL_GOTO(uidListDel, terrno);
20,313✔
870

871
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
20,313✔
872
  STREAM_CHECK_RET_GOTO(qStreamGetDelTable(sStreamReaderInfo, uidList, uidListDel));
20,313✔
873

874
  if (rsp->checkAlter && taosArrayGetSize(uidListDel) > 0 && rsp->totalDataRows > 0) {
20,313✔
875
    rsp->needReturn = true;
×
876
    rsp->ver--;
×
877
    ST_TASK_DLOG("%s stream reader scan alter table need return data", __func__);
×
878
    goto end;
×
879
  }
880

881
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
20,313✔
882
  if (sStreamReaderInfo->isVtableStream) {
20,313✔
883
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
1,407✔
884
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
1,407✔
885
  }
886
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
20,313✔
887

888
  ST_TASK_DLOG("%s stream reader scan alter table tag val", __func__);
20,313✔
889

890
end:
20,313✔
891
  taosArrayDestroy(uidListAdd);
20,313✔
892
  taosArrayDestroy(uidListDel);
20,313✔
893
  taosArrayDestroy(tableList);
20,313✔
894
  STREAM_PRINT_LOG_END_WITHID(code, lino);
20,313✔
895
  return code;
20,313✔
896
}
897

898
static int32_t scanAlterTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len, int64_t ver) {
35,334✔
899
  int32_t  code = 0;
35,334✔
900
  int32_t  lino = 0;
35,334✔
901
  SDecoder decoder = {0};
35,334✔
902
  void* pTask = sStreamReaderInfo->pTask;
35,334✔
903
  SArray* uidList = NULL;
35,334✔
904

905
  ST_TASK_DLOG("%s start", __func__);
35,334✔
906

907
  SVAlterTbReq req = {0};
35,334✔
908
  tDecoderInit(&decoder, data, len);
35,334✔
909
  
910
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
35,334✔
911

912
  STREAM_CHECK_CONDITION_GOTO(req.action != TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL && req.action != TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL && 
35,334✔
913
    req.action != TSDB_ALTER_TABLE_ALTER_COLUMN_REF && req.action != TSDB_ALTER_TABLE_REMOVE_COLUMN_REF, TDB_CODE_SUCCESS);
914

915
  uint64_t uid = 0;
25,464✔
916
  if (req.action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || req.action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
25,464✔
917
    STREAM_CHECK_CONDITION_GOTO(!sStreamReaderInfo->isVtableStream, TDB_CODE_SUCCESS);
5,151✔
918
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
468✔
919
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
468✔
920
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", req.tbName);
×
921
      code = 0;
×
922
      goto end;
×
923
    }
924
    STREAM_CHECK_RET_GOTO(scanAlterTableColumnRef(sStreamReaderInfo, rsp, &req, uid, ver));
468✔
925
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
20,313✔
926
    uidList = getTableListForAlterSuperTable(sStreamReaderInfo, &req);
20,313✔
927
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
20,313✔
928
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
20,313✔
929
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
×
930
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
×
931
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
×
932
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", req.tbName);
×
933
      code = 0;
×
934
      goto end;
×
935
    }
936
    uidList = taosArrayInit(8, sizeof(uint64_t));
×
937
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
×
938
    STREAM_CHECK_RET_GOTO(vnodeGetCtbIdList(sStreamReaderInfo->pVnode, uid, uidList));
×
939
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
×
940
  }
941

942
  ST_TASK_DLOG("%s stream reader scan alter table", __func__);
20,781✔
943

944
end:
35,334✔
945
  destroyAlterTbReq(&req);
35,334✔
946

947
  taosArrayDestroy(uidList);
35,334✔
948
  tDecoderClear(&decoder);
35,334✔
949
  STREAM_PRINT_LOG_END_WITHID(code, lino);
35,334✔
950
  return code;
35,334✔
951
}
952

953
// static int32_t scanAlterSTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
954
//   int32_t  code = 0;
955
//   int32_t  lino = 0;
956
//   SDecoder decoder = {0};
957
//   SMAlterStbReq reqAlter = {0};
958
//   SVCreateStbReq req = {0};
959
//   tDecoderInit(&decoder, data, len);
960
//   void* pTask = sStreamReaderInfo->pTask;
961
  
962
//   STREAM_CHECK_RET_GOTO(tDecodeSVCreateStbReq(&decoder, &req));
963
//   STREAM_CHECK_CONDITION_GOTO(req.suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
964
//   if (req.alterOriData != 0) {
965
//     STREAM_CHECK_RET_GOTO(tDeserializeSMAlterStbReq(req.alterOriData, req.alterOriDataLen, &reqAlter));
966
//     STREAM_CHECK_CONDITION_GOTO(reqAlter.alterType != TSDB_ALTER_TABLE_DROP_TAG && reqAlter.alterType != TSDB_ALTER_TABLE_UPDATE_TAG_NAME, TDB_CODE_SUCCESS);
967
//   }
968
  
969
//   STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo));
970

971
//   ST_TASK_DLOG("stream reader scan alter suid %" PRId64, req.suid);
972
// end:
973
//   tFreeSMAltertbReq(&reqAlter);
974
//   tDecoderClear(&decoder);
975
//   return code;
976
// }
977

978
// static int32_t scanDropSTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len) {
979
//   int32_t  code = 0;
980
//   int32_t  lino = 0;
981
//   SDecoder decoder = {0};
982
//   void* pTask = sStreamReaderInfo->pTask;
983

984
//   SVDropStbReq req = {0};
985
//   tDecoderInit(&decoder, data, len);
986
//   STREAM_CHECK_RET_GOTO(tDecodeSVDropStbReq(&decoder, &req));
987
//   STREAM_CHECK_CONDITION_GOTO(req.suid != sStreamReaderInfo->suid, TDB_CODE_SUCCESS);
988

989
//   ST_TASK_DLOG("stream reader scan drop suid %" PRId64, req.suid);
990
// end:
991
//   tDecoderClear(&decoder);
992
//   return code;
993
// }
994

995
static int32_t scanSubmitTbDataForMeta(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* gidHash, int64_t ver) {
41,720,567✔
996
  int32_t code = 0;
41,720,567✔
997
  int32_t lino = 0;
41,720,567✔
998
  WalMetaResult walMeta = {0};
41,720,567✔
999
  SSubmitTbData submitTbData = {0};
41,719,795✔
1000
  
1001
  if (tStartDecode(pCoder) < 0) {
41,720,331✔
1002
    code = TSDB_CODE_INVALID_MSG;
×
1003
    TSDB_CHECK_CODE(code, lino, end);
×
1004
  }
1005

1006
  uint8_t       version = 0;
41,721,544✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
41,720,441✔
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
41,720,441✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
41,720,441✔
1013

1014
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1015
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
41,720,441✔
1016
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
5,266,591✔
1017
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
5,264,101✔
1018
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
5,264,101✔
1019
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
5,264,832✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
41,712,273✔
1024
    code = TSDB_CODE_INVALID_MSG;
×
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
41,719,630✔
1028
    code = TSDB_CODE_INVALID_MSG;
×
1029
    TSDB_CHECK_CODE(code, lino, end);
×
1030
  }
1031

1032
  if (!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &walMeta.id, false)){
41,719,630✔
1033
    goto end;
33,587,120✔
1034
  }
1035
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
8,133,442✔
1036
    code = TSDB_CODE_INVALID_MSG;
×
1037
    TSDB_CHECK_CODE(code, lino, end);
×
1038
  }
1039

1040
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
8,133,442✔
1041
    uint64_t nColData = 0;
×
1042
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1043
      code = TSDB_CODE_INVALID_MSG;
×
1044
      TSDB_CHECK_CODE(code, lino, end);
×
1045
    }
1046

1047
    SColData colData = {0};
×
1048
    code = tDecodeColData(version, pCoder, &colData, false);
×
1049
    if (code) {
×
1050
      code = TSDB_CODE_INVALID_MSG;
×
1051
      TSDB_CHECK_CODE(code, lino, end);
×
1052
    }
1053

1054
    if (colData.flag != HAS_VALUE) {
×
1055
      code = TSDB_CODE_INVALID_MSG;
×
1056
      TSDB_CHECK_CODE(code, lino, end);
×
1057
    }
1058
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
1059
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
1060

1061
    for (uint64_t i = 1; i < nColData; i++) {
×
1062
      code = tDecodeColData(version, pCoder, &colData, true);
×
1063
      if (code) {
×
1064
        code = TSDB_CODE_INVALID_MSG;
×
1065
        TSDB_CHECK_CODE(code, lino, end);
×
1066
      }
1067
    }
1068
  } else {
1069
    uint64_t nRow = 0;
8,133,442✔
1070
    if (tDecodeU64v(pCoder, &nRow) < 0) {
8,133,442✔
1071
      code = TSDB_CODE_INVALID_MSG;
×
1072
      TSDB_CHECK_CODE(code, lino, end);
×
1073
    }
1074

1075
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
17,323,278✔
1076
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,189,298✔
1077
      pCoder->pos += pRow->len;
9,189,836✔
1078
      if (iRow == 0){
9,190,070✔
1079
#ifndef NO_UNALIGNED_ACCESS
1080
        walMeta.skey = pRow->ts;
8,133,442✔
1081
#else
1082
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1083
#endif
1084
      }
1085
      if (iRow == nRow - 1) {
9,189,836✔
1086
#ifndef NO_UNALIGNED_ACCESS
1087
        walMeta.ekey = pRow->ts;
8,133,208✔
1088
#else
1089
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1090
#endif
1091
      }
1092
    }
1093
  }
1094

1095
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
8,133,208✔
1096
  if (data != NULL) {
8,132,031✔
1097
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
972✔
1098
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
972✔
1099
  } else {
1100
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
8,131,059✔
1101
  }
1102

1103
end:
40,064,520✔
1104
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
41,718,310✔
1105
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
41,718,345✔
1106
  tEndDecode(pCoder);
41,717,314✔
1107
  return code;
41,717,171✔
1108
}
1109

1110
static int32_t scanSubmitDataForMeta(SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, void* data, int32_t len, int64_t ver) {
41,720,690✔
1111
  int32_t  code = 0;
41,720,690✔
1112
  int32_t  lino = 0;
41,720,690✔
1113
  SDecoder decoder = {0};
41,720,690✔
1114
  SSHashObj* gidHash = NULL;
41,720,690✔
1115
  void* pTask = sStreamReaderInfo->pTask;
41,720,690✔
1116

1117
  tDecoderInit(&decoder, data, len);
41,720,219✔
1118
  if (tStartDecode(&decoder) < 0) {
41,717,133✔
1119
    code = TSDB_CODE_INVALID_MSG;
×
1120
    TSDB_CHECK_CODE(code, lino, end);
×
1121
  }
1122

1123
  uint64_t nSubmitTbData = 0;
41,719,295✔
1124
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
41,716,319✔
1125
    code = TSDB_CODE_INVALID_MSG;
×
1126
    TSDB_CHECK_CODE(code, lino, end);
×
1127
  }
1128

1129
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
41,716,319✔
1130
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
41,715,637✔
1131

1132
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
83,432,739✔
1133
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
41,716,773✔
1134
  }
1135
  tEndDecode(&decoder);
41,715,966✔
1136

1137
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
41,717,458✔
1138
  int32_t iter = 0;
41,718,444✔
1139
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
41,715,140✔
1140
  while (px != NULL) {
49,847,755✔
1141
    WalMetaResult* pMeta = (WalMetaResult*)px;
8,132,269✔
1142
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
8,132,269✔
1143
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
8,131,226✔
1144
    rsp->totalRows++;
8,131,226✔
1145
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
8,131,698✔
1146
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1147
    px = tSimpleHashIterate(gidHash, px, &iter);
8,131,698✔
1148
  }
1149
end:
41,715,486✔
1150
  tDecoderClear(&decoder);
41,715,486✔
1151
  tSimpleHashCleanup( gidHash);
41,718,224✔
1152
  return code;
41,715,838✔
1153
}
1154

1155
static int32_t createBlockForTsdbMeta(SSDataBlock** pBlock, bool isVTable) {
491,546✔
1156
  int32_t code = 0;
491,546✔
1157
  int32_t lino = 0;
491,546✔
1158
  SArray* schemas = taosArrayInit(8, sizeof(SSchema));
491,546✔
1159
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
491,546✔
1160

1161
  int32_t index = 1;
491,546✔
1162
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // skey
491,546✔
1163
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, index++))  // ekey
491,546✔
1164
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // uid
491,546✔
1165
  if (!isVTable) {
491,546✔
1166
    STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_UBIGINT, LONG_BYTES, index++))  // gid
59,825✔
1167
  }
1168
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))     // nrows
491,546✔
1169

1170
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
491,546✔
1171

1172
end:
491,546✔
1173
  taosArrayDestroy(schemas);
491,546✔
1174
  return code;
491,546✔
1175
}
1176

1177
static int32_t createBlockForWalMetaNew(SSDataBlock** pBlock) {
312,433✔
1178
  int32_t code = 0;
312,433✔
1179
  int32_t lino = 0;
312,433✔
1180
  SArray* schemas = NULL;
312,433✔
1181

1182
  schemas = taosArrayInit(8, sizeof(SSchema));
312,433✔
1183
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
312,433✔
1184

1185
  int32_t index = 0;
312,433✔
1186
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // gid non vtable/uid vtable
312,433✔
1187
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // skey
312,433✔
1188
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ekey
312,433✔
1189
  STREAM_CHECK_RET_GOTO(qStreamBuildSchema(schemas, TSDB_DATA_TYPE_BIGINT, LONG_BYTES, index++))  // ver
312,433✔
1190

1191
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
312,433✔
1192

1193
end:
312,433✔
1194
  taosArrayDestroy(schemas);
312,433✔
1195
  return code;
312,433✔
1196
}
1197

1198
static int32_t processMeta(int16_t msgType, SStreamTriggerReaderInfo* sStreamReaderInfo, void *data, int32_t len, SSTriggerWalNewRsp* rsp, int64_t ver) {
510,770✔
1199
  int32_t code = 0;
510,770✔
1200
  int32_t lino = 0;
510,770✔
1201
  void* pTask = sStreamReaderInfo->pTask;
510,770✔
1202

1203
  ST_TASK_DLOG("%s check meta msg, stream ver:%" PRId64 ", wal ver:%" PRId64, __func__, sStreamReaderInfo->tableList.version, ver);
510,770✔
1204

1205
  SDecoder dcoder = {0};
510,770✔
1206
  tDecoderInit(&dcoder, data, len);
510,770✔
1207
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
510,770✔
1208
    if (rsp->deleteBlock == NULL) {
30,392✔
1209
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
10,812✔
1210
    }
1211
      
1212
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
30,392✔
1213
  } else if (msgType == TDMT_VND_DROP_TABLE && 
480,378✔
1214
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
50,833✔
1215
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
31,597✔
1216
  // } else if (msgType == TDMT_VND_DROP_STB) {
1217
  //   STREAM_CHECK_RET_GOTO(scanDropSTableNew(sStreamReaderInfo, data, len));
1218
  } else if (msgType == TDMT_VND_CREATE_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
448,781✔
1219
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
26,201✔
1220
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
422,580✔
1221
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1222
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
397,525✔
1223
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
35,334✔
1224
  }
1225

1226
end:
510,770✔
1227
  tDecoderClear(&dcoder);
510,770✔
1228
  return code;
510,770✔
1229
}
1230
static int32_t processWalVerMetaNew(SVnode* pVnode, SSTriggerWalNewRsp* rsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
11,921,225✔
1231
                       int64_t ctime) {
1232
  int32_t code = 0;
11,921,225✔
1233
  int32_t lino = 0;
11,921,225✔
1234
  void* pTask = sStreamReaderInfo->pTask;
11,921,225✔
1235

1236
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
11,920,989✔
1237
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
11,918,061✔
1238
  code = walReaderSeekVer(pWalReader, rsp->ver);
11,918,061✔
1239
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
11,920,065✔
1240
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
6,889,624✔
1241
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
1242
      rsp->verTime = 0;
×
1243
    } else {
1244
      rsp->verTime = taosGetTimestampUs();
6,889,805✔
1245
    }
1246
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
6,888,753✔
1247
    code = TSDB_CODE_SUCCESS;
6,890,417✔
1248
    goto end;
6,890,417✔
1249
  }
1250
  STREAM_CHECK_RET_GOTO(code);
5,030,441✔
1251

1252
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
5,030,441✔
1253
  while (1) {
42,111,441✔
1254
    code = walNextValidMsg(pWalReader, true);
47,141,803✔
1255
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
47,142,243✔
1256
      rsp->verTime = taosGetTimestampUs();
5,028,127✔
1257
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
5,028,127✔
1258
      code = TSDB_CODE_SUCCESS;
5,028,328✔
1259
      goto end;
5,028,328✔
1260
    }
1261
    STREAM_CHECK_RET_GOTO(code);
42,112,834✔
1262
    rsp->ver = pWalReader->curVersion;
42,112,834✔
1263
    SWalCont* wCont = &pWalReader->pHead->head;
42,113,415✔
1264
    rsp->verTime = wCont->ingestTs;
42,112,498✔
1265
    if (wCont->ingestTs / 1000 > ctime) break;
42,112,857✔
1266
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
42,112,671✔
1267
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
42,113,127✔
1268
    int64_t ver = wCont->version;
42,111,036✔
1269

1270
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
42,114,042✔
1271
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1272
    if (wCont->msgType == TDMT_VND_SUBMIT) {
42,105,429✔
1273
      // return when getting data if there are meta data in vtable scan
1274
      if (sStreamReaderInfo->isVtableStream && rsp->tableBlock != NULL && ((SSDataBlock*)rsp->tableBlock)->info.rows > 0) {
41,722,723✔
1275
        rsp->ver--;
2,480✔
1276
        break;
2,480✔
1277
      }
1278
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
41,718,249✔
1279
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
41,718,248✔
1280
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
41,718,484✔
1281
    } else {
1282
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
393,823✔
1283
    }
1284

1285
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
42,074,150✔
1286
      break;
×
1287
    }
1288
  }
1289

1290
end:
11,921,225✔
1291
  walCloseReader(pWalReader);
11,921,225✔
1292
  return code;
11,918,665✔
1293
}
1294

1295
int32_t cacheTag(SVnode* pVnode, SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr, SStorageAPI* api, uint64_t uid, col_id_t colId, SRWLatch* lock) {
40,759,316✔
1296
  int32_t     code = 0;
40,759,316✔
1297
  int32_t     lino = 0;
40,759,316✔
1298
  SMetaReader mr = {0};
40,759,316✔
1299
  SArray* tagCache = NULL;
40,763,262✔
1300
  char* data = NULL;
40,765,275✔
1301

1302
  if (lock != NULL) taosWLockLatch(lock);
40,765,735✔
1303
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
40,772,348✔
1304
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,287,403✔
1305
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,287,682✔
1306
  if (uidData == NULL) {
2,287,682✔
1307
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,268,494✔
1308
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,268,494✔
1309
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,268,494✔
1310
      taosArrayDestroy(tagCache);
×
1311
      code = terrno;
×
1312
      goto end;
×
1313
    }
1314
  } else {
1315
    tagCache = *(SArray**)uidData;
19,188✔
1316
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
19,188✔
1317
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
19,188✔
1318
  }
1319
  
1320
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,287,682✔
1321
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,287,682✔
1322
  api->metaReaderFn.readerReleaseLock(&mr);
2,285,949✔
1323
  STREAM_CHECK_RET_GOTO(code);
2,286,533✔
1324
  
1325
  for (int32_t j = 0; j < numOfExpr; ++j) {
7,885,106✔
1326
    const SExprInfo* pExpr1 = &pExprInfo[j];
5,605,781✔
1327
    int32_t functionId = pExpr1->pExpr->_function.functionId;
5,605,781✔
1328
    col_id_t cid = 0;
5,608,535✔
1329
    // this is to handle the tbname
1330
    if (fmIsScanPseudoColumnFunc(functionId)) {
5,608,535✔
1331
      int32_t fType = pExpr1->pExpr->_function.functionType;
632,086✔
1332
      if (fType == FUNCTION_TYPE_TBNAME) {
632,998✔
1333
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
632,263✔
1334
        STREAM_CHECK_NULL_GOTO(data, terrno);
631,807✔
1335
        STR_TO_VARSTR(data, mr.me.name)
631,807✔
1336
      }
1337
      cid = -1;
632,263✔
1338
    } else {  // these are tags
1339
      const char* p = NULL;
4,974,661✔
1340
      char* pData = NULL;
4,974,661✔
1341
      int8_t type = pExpr1->base.resSchema.type;
4,974,661✔
1342
      int32_t len = pExpr1->base.resSchema.bytes;
4,974,661✔
1343
      STagVal tagVal = {0};
4,976,266✔
1344
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
4,975,777✔
1345
      cid = tagVal.cid;
4,976,307✔
1346
      if (colId != 0 && cid != colId) {
4,976,307✔
1347
        continue;
1,029✔
1348
      }
1349
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
4,975,278✔
1350

1351
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
4,972,677✔
1352
        pData = tTagValToData((const STagVal*)p, false);
4,970,022✔
1353
      } else {
1354
        pData = (char*)p;
2,655✔
1355
      }
1356

1357
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
4,973,847✔
1358
        if (type == TSDB_DATA_TYPE_JSON) {
2,478,865✔
1359
          len = getJsonValueLen(pData);
×
1360
        }
1361
        data = taosMemoryCalloc(1, len);
2,478,865✔
1362
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,478,104✔
1363
        (void)memcpy(data, pData, len);
2,478,104✔
1364
      } else {
1365
        data = pData;
2,494,982✔
1366
      }
1367
    }
1368
    if (uidData == NULL){
5,604,614✔
1369
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
11,136,191✔
1370
    } else {
1371
      void* pre = taosArrayGetP(tagCache, j);
36,945✔
1372
      taosMemoryFree(pre);
36,945✔
1373
      taosArraySet(tagCache, j, &data);
36,945✔
1374
    }
1375
    data = NULL;
5,604,022✔
1376
  }
1377

1378
end:
40,769,604✔
1379
  taosMemoryFree(data);
40,758,953✔
1380
  api->metaReaderFn.clearReader(&mr);
40,762,658✔
1381
  if (lock != NULL) taosWUnLockLatch(lock);
40,755,806✔
1382
  return code;
40,759,159✔
1383
}
1384

1385
int32_t fillTag(SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr,
110,256,211✔
1386
                uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, SRWLatch* lock) {
1387
  int32_t     code = 0;
110,256,211✔
1388
  int32_t     lino = 0;
110,256,211✔
1389
  SArray* tagCache = NULL;
110,256,211✔
1390
  if (numOfExpr == 0) {
110,256,211✔
1391
    return TSDB_CODE_SUCCESS;
37,954,785✔
1392
  }
1393

1394
  taosRLockLatch(lock);
72,301,426✔
1395
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
72,373,728✔
1396
  if (uidData == NULL) {
72,357,045✔
1397
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1398
  } else {
1399
    tagCache = *(SArray**)uidData;
72,357,045✔
1400
    if(taosArrayGetSize(tagCache) != numOfExpr) {
72,370,886✔
1401
      stError("%s numOfExpr:%d,tagCache size:%zu", __func__, numOfExpr, taosArrayGetSize(tagCache));
×
1402
      tagCache = NULL;
×
1403
    }
1404
  }
1405
  
1406
  for (int32_t j = 0; j < numOfExpr; ++j) {
311,795,404✔
1407
    const SExprInfo* pExpr1 = &pExprInfo[j];
239,438,205✔
1408
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
239,420,716✔
1409

1410
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
239,433,459✔
1411
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
239,307,308✔
1412
    int32_t functionId = pExpr1->pExpr->_function.functionId;
239,307,308✔
1413

1414
    // this is to handle the tbname
1415
    if (fmIsScanPseudoColumnFunc(functionId)) {
239,340,571✔
1416
      int32_t fType = pExpr1->pExpr->_function.functionType;
3,707,872✔
1417
      if (fType == FUNCTION_TYPE_TBNAME) {
3,706,857✔
1418
        pColInfoData->info.colId = -1;
3,707,092✔
1419
      }
1420
    } 
1421
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
239,231,658✔
1422

1423
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
239,076,411✔
1424
    if (isNullVal) {
239,085,589✔
1425
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1426
    } else {
1427
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
239,085,589✔
1428
        for (uint32_t i = 0; i < numOfRows; i++){
2,147,483,647✔
1429
          colDataClearNull_f(pColInfoData->nullbitmap, currentRow + i);
2,147,483,647✔
1430
        }
1431
      }
1432
      code = colDataSetNItems(pColInfoData, currentRow, (const char*)data, numOfRows, numOfBlocks, false);
238,034,524✔
1433
      STREAM_CHECK_RET_GOTO(code);
239,425,353✔
1434
    }
1435
  }
1436
end:
72,357,199✔
1437
  taosRUnLockLatch(lock);
72,357,199✔
1438
  return code;
72,378,771✔
1439
}
1440

1441
static int32_t processTag(SStreamTriggerReaderInfo* info, bool isCalc, 
3,599,325✔
1442
  uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks) {
1443
  int32_t     code = 0;
3,599,325✔
1444
  int32_t     lino = 0;
3,599,325✔
1445

1446
  void* pTask = info->pTask;
3,599,325✔
1447
  ST_TASK_DLOG("%s start. rows:%" PRIu32 ",uid:%"PRIu64, __func__,  numOfRows, uid);
3,599,572✔
1448
  
1449
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
3,599,556✔
1450
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
3,599,557✔
1451
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
3,599,323✔
1452
  
1453
  code = fillTag(metaCache, pExprInfo, numOfExpr, uid, pBlock, currentRow, numOfRows, numOfBlocks, &info->lock);
3,599,322✔
1454
  STREAM_CHECK_RET_GOTO(code);
3,599,054✔
1455

1456
end:
3,599,054✔
1457
  return code;
3,599,054✔
1458
}
1459

1460
int32_t getRowRange(SColData* pCol, STimeWindow* window, int32_t* rowStart, int32_t* rowEnd, int32_t* nRows) {
×
1461
  int32_t code = 0;
×
1462
  int32_t lino = 0;
×
1463
  *nRows = 0;
×
1464
  *rowStart = 0;
×
1465
  *rowEnd = pCol->nVal;
×
1466
  if (window != NULL) {
×
1467
    SColVal colVal = {0};
×
1468
    *rowStart = -1;
×
1469
    *rowEnd = -1;
×
1470
    for (int32_t k = 0; k < pCol->nVal; k++) {
×
1471
      STREAM_CHECK_RET_GOTO(tColDataGetValue(pCol, k, &colVal));
×
1472
      int64_t ts = VALUE_GET_TRIVIAL_DATUM(&colVal.value);
×
1473
      if (ts >= window->skey && *rowStart == -1) {
×
1474
        *rowStart = k;
×
1475
      }
1476
      if (ts > window->ekey && *rowEnd == -1) {
×
1477
        *rowEnd = k;
×
1478
      }
1479
    }
1480
    STREAM_CHECK_CONDITION_GOTO(*rowStart == -1 || *rowStart == *rowEnd, TDB_CODE_SUCCESS);
×
1481

1482
    if (*rowStart != -1 && *rowEnd == -1) {
×
1483
      *rowEnd = pCol->nVal;
×
1484
    }
1485
  }
1486
  *nRows = *rowEnd - *rowStart;
×
1487

1488
end:
×
1489
  return code;
×
1490
}
1491

1492
static int32_t setColData(int64_t rows, int32_t rowStart, int32_t rowEnd, SColData* colData, SColumnInfoData* pColData) {
×
1493
  int32_t code = 0;
×
1494
  int32_t lino = 0;
×
1495
  for (int32_t k = rowStart; k < rowEnd; k++) {
×
1496
    SColVal colVal = {0};
×
1497
    STREAM_CHECK_RET_GOTO(tColDataGetValue(colData, k, &colVal));
×
1498
    STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, rows + k - rowStart, VALUE_GET_DATUM(&colVal.value, colVal.value.type),
×
1499
                                        !COL_VAL_IS_VALUE(&colVal)));
1500
  }
1501
  end:
×
1502
  return code;
×
1503
}
1504

1505
static int32_t getColId(int64_t suid, int64_t uid, int16_t i, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* rsp, int16_t* colId) {
22,089,927✔
1506
  int32_t code = 0;
22,089,927✔
1507
  int32_t lino = 0;
22,089,927✔
1508
  int64_t id[2] = {suid, uid};
22,089,927✔
1509
  taosRLockLatch(&sStreamReaderInfo->lock);
22,089,927✔
1510
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
22,088,983✔
1511
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
22,089,455✔
1512
  SSHashObj* uInfo = *(SSHashObj **)px;
22,089,455✔
1513
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
22,089,455✔
1514
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
22,089,455✔
1515
  if (tmp != NULL) {
22,089,455✔
1516
    *colId = *tmp;
20,315,233✔
1517
  } else {
1518
    *colId = -1;
1,774,222✔
1519
  }
1520

1521
end:
22,089,691✔
1522
  taosRUnLockLatch(&sStreamReaderInfo->lock);
22,089,455✔
1523
  return code;
22,089,219✔
1524
}
1525

1526
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
10,499,749✔
1527
  int32_t code = 0;
10,499,749✔
1528
  int32_t lino = 0;
10,499,749✔
1529
  int64_t id = suid != 0 ? suid : uid;
10,499,749✔
1530
  if (sStreamReaderInfo->isVtableStream) {
10,502,299✔
1531
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
7,099,017✔
1532
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
7,098,781✔
1533
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
64,528✔
1534
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
64,528✔
1535
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
64,327✔
1536
      if (code != 0) {
64,327✔
1537
        taosMemoryFree(*schema);
×
1538
        goto end;
×
1539
      }
1540
    } else {
1541
      *schema = *schemaTmp;
7,034,253✔
1542
    }
1543
  } else {
1544
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
3,403,750✔
1545
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
85,437✔
1546
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
85,437✔
1547
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
85,437✔
1548
    }
1549
    *schema = sStreamReaderInfo->triggerTableSchema;
3,403,750✔
1550
  }
1551
  
1552
end:
10,502,767✔
1553
  return code;
10,502,767✔
1554
}
1555

1556
static int32_t scanSubmitTbData(SVnode* pVnode, SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, 
12,508,264✔
1557
  SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
1558
  int32_t code = 0;
12,508,264✔
1559
  int32_t lino = 0;
12,508,264✔
1560
  uint64_t id = 0;
12,508,264✔
1561
  WalMetaResult walMeta = {0};
12,508,497✔
1562
  void* pTask = sStreamReaderInfo->pTask;
12,509,035✔
1563
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
12,508,342✔
1564

1565
  if (tStartDecode(pCoder) < 0) {
12,508,880✔
1566
    ST_TASK_ELOG("vgId:%d %s invalid submit data", TD_VID(pVnode), __func__);
×
1567
    code = TSDB_CODE_INVALID_MSG;
×
1568
    TSDB_CHECK_CODE(code, lino, end);
×
1569
  }
1570

1571
  SSubmitTbData submitTbData = {0};
12,509,054✔
1572
  uint8_t       version = 0;
12,508,586✔
1573
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
12,507,346✔
1574
    ST_TASK_ELOG("vgId:%d %s invalid submit data flags", TD_VID(pVnode), __func__);
×
1575
    code = TSDB_CODE_INVALID_MSG;
×
1576
    TSDB_CHECK_CODE(code, lino, end);
×
1577
  }
1578
  version = (submitTbData.flags >> 8) & 0xff;
12,507,346✔
1579
  submitTbData.flags = submitTbData.flags & 0xff;
12,507,346✔
1580
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1581
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
12,507,346✔
1582
    if (tStartDecode(pCoder) < 0) {
619,460✔
1583
      ST_TASK_ELOG("vgId:%d %s invalid auto create table data", TD_VID(pVnode), __func__);
×
1584
      code = TSDB_CODE_INVALID_MSG;
×
1585
      TSDB_CHECK_CODE(code, lino, end);
×
1586
    }
1587
    tEndDecode(pCoder);
619,460✔
1588
  }
1589

1590
  // submit data
1591
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
12,506,813✔
1592
    ST_TASK_ELOG("vgId:%d %s invalid submit data suid", TD_VID(pVnode), __func__);
×
1593
    code = TSDB_CODE_INVALID_MSG;
×
1594
    TSDB_CHECK_CODE(code, lino, end);
×
1595
  }
1596
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
12,507,094✔
1597
    ST_TASK_ELOG("vgId:%d %s invalid submit data uid", TD_VID(pVnode), __func__);
×
1598
    code = TSDB_CODE_INVALID_MSG;
×
1599
    TSDB_CHECK_CODE(code, lino, end);
×
1600
  }
1601

1602
  ST_TASK_DLOG("%s uid:%" PRId64 ", suid:%" PRId64 ", ver:%" PRId64, __func__, submitTbData.uid, submitTbData.suid, ver);
12,507,094✔
1603

1604
  if (rsp->uidHash != NULL) {
12,508,113✔
1605
    uint64_t* gid = tSimpleHashGet(rsp->uidHash, &submitTbData.uid, LONG_BYTES);
8,651,779✔
1606
    STREAM_CHECK_CONDITION_GOTO(gid == NULL, TDB_CODE_SUCCESS);
8,651,307✔
1607
    ST_TASK_DLOG("%s get uid gid from uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, submitTbData.uid, submitTbData.suid, *gid);
8,651,307✔
1608
    id = *gid;
8,651,060✔
1609
  } else {
1610
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
3,857,271✔
1611
  }
1612

1613
  walMeta.id = id;
10,501,346✔
1614
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,501,346✔
1615

1616
  if (ranges != NULL){
10,502,282✔
1617
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
8,651,285✔
1618
    if (timerange == NULL) goto end;;
8,651,779✔
1619
    int64_t* pRange = (int64_t*)timerange;
8,651,779✔
1620
    window.skey = pRange[0];
8,651,779✔
1621
    window.ekey = pRange[1];
8,651,779✔
1622
    ST_TASK_DLOG("%s get time range from ranges, uid:%" PRId64 ", suid:%" PRId64 ", gid:%" PRIu64 ", skey:%" PRId64 ", ekey:%" PRId64,
8,651,779✔
1623
      __func__, submitTbData.uid, submitTbData.suid, id, window.skey, window.ekey);
1624
  }
1625
  
1626
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,501,127✔
1627
    ST_TASK_ELOG("vgId:%d %s invalid submit data sver", TD_VID(pVnode), __func__);
×
1628
    code = TSDB_CODE_INVALID_MSG;
×
1629
    TSDB_CHECK_CODE(code, lino, end);
×
1630
  }
1631

1632
  STSchema*    schema = NULL;
10,501,127✔
1633
  STREAM_CHECK_RET_GOTO(getSchemas(pVnode, submitTbData.suid, submitTbData.uid, submitTbData.sver, sStreamReaderInfo, &schema));
10,501,127✔
1634

1635
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
10,500,014✔
1636
  int32_t blockStart = 0;
10,502,097✔
1637
  int32_t numOfRows = 0;
10,502,097✔
1638
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,501,408✔
1639
    uint64_t nColData = 0;
×
1640
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1641
      ST_TASK_ELOG("vgId:%d %s invalid submit data nColData", TD_VID(pVnode), __func__);
×
1642
      code = TSDB_CODE_INVALID_MSG;
×
1643
      TSDB_CHECK_CODE(code, lino, end);
×
1644
    }
1645

1646
    SColData colData = {0};
×
1647
    code = tDecodeColData(version, pCoder, &colData, false);
×
1648
    if (code) {
×
1649
      ST_TASK_ELOG("vgId:%d %s invalid submit data colData", TD_VID(pVnode), __func__);
×
1650
      code = TSDB_CODE_INVALID_MSG;
×
1651
      TSDB_CHECK_CODE(code, lino, end);
×
1652
    }
1653

1654
    if (colData.flag != HAS_VALUE) {
×
1655
      ST_TASK_ELOG("vgId:%d %s invalid submit data colData flag", TD_VID(pVnode), __func__);
×
1656
      code = TSDB_CODE_INVALID_MSG;
×
1657
      TSDB_CHECK_CODE(code, lino, end);
×
1658
    }
1659
    
1660
    walMeta.skey = ((TSKEY *)colData.pData)[0];
×
1661
    walMeta.ekey = ((TSKEY *)colData.pData)[colData.nVal - 1];
×
1662

1663
    int32_t rowStart = 0;
×
1664
    int32_t rowEnd = 0;
×
1665
    STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, &numOfRows));
×
1666
    STREAM_CHECK_CONDITION_GOTO(numOfRows <= 0, TDB_CODE_SUCCESS);
×
1667

1668
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
×
1669
    blockStart = pSlice->currentRowIdx;
×
1670
    int32_t pos = pCoder->pos;
×
1671
    for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {
×
1672
      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
×
1673
      STREAM_CHECK_NULL_GOTO(pColData, terrno);
×
1674
      if (pColData->info.colId <= -1) {
×
1675
        pColData->hasNull = true;
×
1676
        continue;
×
1677
      }
1678
      if (pColData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
×
1679
        STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colData, pColData));
×
1680
        continue;
×
1681
      }
1682

1683
      pCoder->pos = pos;
×
1684

1685
      int16_t colId = 0;
×
1686
      if (sStreamReaderInfo->isVtableStream){
×
1687
        STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
×
1688
        ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
×
1689
      } else {
1690
        colId = pColData->info.colId;
×
1691
      }
1692
      
1693
      uint64_t j = 1;
×
1694
      for (; j < nColData; j++) {
×
1695
        int16_t cid = 0;
×
1696
        int32_t posTmp = pCoder->pos;
×
1697
        pCoder->pos += INT_BYTES;
×
1698
        if ((code = tDecodeI16v(pCoder, &cid))) return code;
×
1699
        pCoder->pos = posTmp;
×
1700
        if (cid == colId) {
×
1701
          SColData colDataTmp = {0};
×
1702
          code = tDecodeColData(version, pCoder, &colDataTmp, false);
×
1703
          if (code) {
×
1704
            code = TSDB_CODE_INVALID_MSG;
×
1705
            TSDB_CHECK_CODE(code, lino, end);
×
1706
          }
1707
          STREAM_CHECK_RET_GOTO(setColData(blockStart, rowStart, rowEnd, &colDataTmp, pColData));
×
1708
          break;
×
1709
        }
1710
        code = tDecodeColData(version, pCoder, &colData, true);
×
1711
        if (code) {
×
1712
          code = TSDB_CODE_INVALID_MSG;
×
1713
          TSDB_CHECK_CODE(code, lino, end);
×
1714
        }
1715
      }
1716
      if (j == nColData) {
×
1717
        colDataSetNNULL(pColData, blockStart, numOfRows);
×
1718
      }
1719
    }
1720
  } else {
1721
    uint64_t nRow = 0;
10,501,408✔
1722
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,501,177✔
1723
      code = TSDB_CODE_INVALID_MSG;
×
1724
      TSDB_CHECK_CODE(code, lino, end);
×
1725
    }
1726
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
22,365,872✔
1727
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
11,864,379✔
1728
      pCoder->pos += pRow->len;
11,865,352✔
1729

1730
      if (iRow == 0){
11,865,351✔
1731
#ifndef NO_UNALIGNED_ACCESS
1732
        walMeta.skey = pRow->ts;
10,501,410✔
1733
#else
1734
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1735
#endif
1736
      }
1737
      if (iRow == nRow - 1) {
11,865,334✔
1738
#ifndef NO_UNALIGNED_ACCESS
1739
        walMeta.ekey = pRow->ts;
10,501,393✔
1740
#else
1741
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1742
#endif
1743
      }
1744

1745
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
11,865,099✔
1746
        continue;
193,383✔
1747
      }
1748
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
11,670,774✔
1749
      blockStart = pSlice->currentRowIdx;
11,670,573✔
1750
     
1751
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
71,838,097✔
1752
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
60,160,402✔
1753
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
60,160,420✔
1754
        if (pColData->info.colId <= -1) {
60,160,420✔
1755
          pColData->hasNull = true;
20,562,567✔
1756
          continue;
20,563,038✔
1757
        }
1758
        int16_t colId = 0;
39,611,014✔
1759
        if (sStreamReaderInfo->isVtableStream){
39,611,250✔
1760
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
22,089,455✔
1761
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
22,089,219✔
1762
        } else {
1763
          colId = pColData->info.colId;
17,523,743✔
1764
        }
1765
        
1766
        SColVal colVal = {0};
39,613,649✔
1767
        int32_t sourceIdx = 0;
39,613,649✔
1768
        while (1) {
1769
          if (sourceIdx >= schema->numOfCols) {
108,192,763✔
1770
            break;
8,459,238✔
1771
          }
1772
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
99,732,004✔
1773
          if (colVal.cid == colId) {
99,735,345✔
1774
            break;
31,156,231✔
1775
          }
1776
          sourceIdx++;
68,579,114✔
1777
        }
1778
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
39,615,469✔
1779
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
28,719,058✔
1780
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
26,176✔
1781
            ST_TASK_TLOG("%s vtable colId:%d, i:%d, colData:%p, data:%s, len:%d, rowIndex:%d, offset:%d, uid:%" PRId64, __func__, colId, i, pColData, 
26,399✔
1782
              (const char*)colVal.value.pData, colVal.value.nData, blockStart+ numOfRows, pColData->varmeta.offset[blockStart+ numOfRows], submitTbData.uid);
1783
          } else {
1784
            STREAM_CHECK_RET_GOTO(colDataSetVal(pColData, blockStart + numOfRows, (const char*)(&(colVal.value.val)), !COL_VAL_IS_VALUE(&colVal)));
28,692,882✔
1785
          }
1786
        } else {
1787
          colDataSetNULL(pColData, blockStart + numOfRows);
10,896,411✔
1788
        }
1789
      }
1790
      
1791
      numOfRows++;
11,671,312✔
1792
    }
1793
  }
1794

1795
  if (numOfRows > 0) {
10,501,192✔
1796
    if (!sStreamReaderInfo->isVtableStream) {
10,501,192✔
1797
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, rsp->isCalc, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
3,402,846✔
1798
    }
1799
    
1800
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
10,501,392✔
1801
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
10,501,658✔
1802
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
10,501,658✔
1803

1804
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
10,502,097✔
1805
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
10,502,097✔
1806
      ", uid:%" PRId64 ", ver:%"PRId64 ", row index:%d, rows:%d", __func__, window.skey, window.ekey, 
1807
      id, submitTbData.uid, ver, pSlice->currentRowIdx, numOfRows);
1808
    pSlice->currentRowIdx += numOfRows;
10,502,599✔
1809
    pBlock->info.rows += numOfRows;
10,502,597✔
1810
  } else {
1811
    ST_TASK_DLOG("%s no valid data in time range:skey %" PRId64 ", ekey %" PRId64 ", uid:%" PRId64 ", suid:%" PRId64,
×
1812
      __func__, window.skey, window.ekey, submitTbData.uid, submitTbData.suid);
1813
  }
1814
  
1815
  if (gidHash == NULL) goto end;
10,501,883✔
1816

1817
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,850,540✔
1818
  if (data != NULL) {
1,850,084✔
1819
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
×
1820
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
×
1821
  } else {
1822
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
1,850,084✔
1823
  }
1824

1825
end:
11,439,522✔
1826
  if (code != 0) {                                                             \
12,508,582✔
1827
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
402✔
1828
  }
1829
  tEndDecode(pCoder);
12,508,582✔
1830
  return code;
12,504,758✔
1831
}
1832
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
12,508,352✔
1833
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1834
  int32_t  code = 0;
12,508,352✔
1835
  int32_t  lino = 0;
12,508,352✔
1836
  SDecoder decoder = {0};
12,508,352✔
1837
  SSHashObj* gidHash = NULL;
12,509,054✔
1838
  void* pTask = sStreamReaderInfo->pTask;
12,509,054✔
1839

1840
  tDecoderInit(&decoder, data, len);
12,508,585✔
1841
  if (tStartDecode(&decoder) < 0) {
12,507,414✔
1842
    code = TSDB_CODE_INVALID_MSG;
×
1843
    TSDB_CHECK_CODE(code, lino, end);
×
1844
  }
1845

1846
  uint64_t nSubmitTbData = 0;
12,508,115✔
1847
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
12,507,784✔
1848
    code = TSDB_CODE_INVALID_MSG;
×
1849
    TSDB_CHECK_CODE(code, lino, end);
×
1850
  }
1851

1852
  if (rsp->metaBlock != NULL){
12,507,784✔
1853
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,857,274✔
1854
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
3,854,853✔
1855
  }
1856

1857
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
25,014,144✔
1858
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
12,507,170✔
1859
  }
1860

1861
  tEndDecode(&decoder);
12,506,974✔
1862

1863
  if (rsp->metaBlock != NULL){
12,508,919✔
1864
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
3,857,542✔
1865
    int32_t iter = 0;
3,855,433✔
1866
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
3,855,433✔
1867
    while (px != NULL) {
5,706,452✔
1868
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,850,084✔
1869
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,850,084✔
1870
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,850,305✔
1871
      rsp->totalRows++;
1,850,540✔
1872
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,850,540✔
1873
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1874
      px = tSimpleHashIterate(gidHash, px, &iter);
1,850,787✔
1875
    }
1876
  }
1877
  
1878

1879
end:
11,437,892✔
1880
  tSimpleHashCleanup(gidHash);
12,507,878✔
1881
  tDecoderClear(&decoder);
12,508,571✔
1882
  return code;
12,508,337✔
1883
}
1884

1885
static int32_t scanSubmitTbDataPre(SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, SSHashObj* ranges, 
15,588,761✔
1886
  uint64_t* gid, int64_t* uid, int32_t* numOfRows, SSTriggerWalNewRsp* rsp, int64_t ver) {
1887
  int32_t code = 0;
15,588,761✔
1888
  int32_t lino = 0;
15,588,761✔
1889
  void* pTask = sStreamReaderInfo->pTask;
15,588,761✔
1890

1891
  if (tStartDecode(pCoder) < 0) {
15,589,462✔
1892
    code = TSDB_CODE_INVALID_MSG;
×
1893
    TSDB_CHECK_CODE(code, lino, end);
×
1894
  }
1895

1896
  SSubmitTbData submitTbData = {0};
15,593,622✔
1897
  uint8_t       version = 0;
15,593,856✔
1898
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
15,593,692✔
1899
    code = TSDB_CODE_INVALID_MSG;
×
1900
    TSDB_CHECK_CODE(code, lino, end);
×
1901
  }
1902
  version = (submitTbData.flags >> 8) & 0xff;
15,593,692✔
1903
  submitTbData.flags = submitTbData.flags & 0xff;
15,593,692✔
1904

1905
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1906
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
15,593,692✔
1907
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,857,048✔
1908
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,856,567✔
1909
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,856,567✔
1910
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
1,857,013✔
1911
  }
1912

1913
  // submit data
1914
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
15,589,768✔
1915
    code = TSDB_CODE_INVALID_MSG;
×
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  if (tDecodeI64(pCoder, uid) < 0) {
15,590,731✔
1919
    code = TSDB_CODE_INVALID_MSG;
×
1920
    TSDB_CHECK_CODE(code, lino, end);
×
1921
  }
1922
  ST_TASK_DLOG("%s uid:%" PRId64 ", suid:%" PRId64, __func__, *uid, submitTbData.suid);
15,590,731✔
1923
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
15,591,066✔
1924
  if (rsp->uidHash != NULL) {
10,505,851✔
1925
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
8,651,544✔
1926
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
8,651,063✔
1927
  }
1928
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
10,505,604✔
1929

1930
  if (ranges != NULL){
10,504,667✔
1931
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
8,651,310✔
1932
    if (timerange == NULL) goto end;;
8,651,311✔
1933
    int64_t* pRange = (int64_t*)timerange;
8,651,311✔
1934
    window.skey = pRange[0];
8,651,311✔
1935
    window.ekey = pRange[1];
8,651,311✔
1936
  }
1937
  
1938
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
10,502,831✔
1939
    code = TSDB_CODE_INVALID_MSG;
×
1940
    TSDB_CHECK_CODE(code, lino, end);
×
1941
  }
1942

1943
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
10,502,831✔
1944
    uint64_t nColData = 0;
×
1945
    if (tDecodeU64v(pCoder, &nColData) < 0) {
×
1946
      code = TSDB_CODE_INVALID_MSG;
×
1947
      TSDB_CHECK_CODE(code, lino, end);
×
1948
    }
1949

1950
    SColData colData = {0};
×
1951
    code = tDecodeColData(version, pCoder, &colData, false);
×
1952
    if (code) {
×
1953
      code = TSDB_CODE_INVALID_MSG;
×
1954
      TSDB_CHECK_CODE(code, lino, end);
×
1955
    }
1956

1957
    if (colData.flag != HAS_VALUE) {
×
1958
      code = TSDB_CODE_INVALID_MSG;
×
1959
      TSDB_CHECK_CODE(code, lino, end);
×
1960
    }
1961
    int32_t rowStart = 0;
×
1962
    int32_t rowEnd = 0;
×
1963
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) {
×
1964
      STREAM_CHECK_RET_GOTO(getRowRange(&colData, &window, &rowStart, &rowEnd, numOfRows));
×
1965
    } else {
1966
      (*numOfRows) = colData.nVal;
×
1967
    } 
1968
  } else {
1969
    uint64_t nRow = 0;
10,502,831✔
1970
    if (tDecodeU64v(pCoder, &nRow) < 0) {
10,504,653✔
1971
      code = TSDB_CODE_INVALID_MSG;
×
1972
      TSDB_CHECK_CODE(code, lino, end);
×
1973
    }
1974

1975
    if (window.skey != INT64_MIN || window.ekey != INT64_MAX) { 
10,504,653✔
1976
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
18,453,956✔
1977
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
9,804,064✔
1978
        pCoder->pos += pRow->len;
9,804,064✔
1979
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
9,804,311✔
1980
          continue;
193,383✔
1981
        }
1982
        (*numOfRows)++;
9,610,928✔
1983
      }
1984
    } else {
1985
      (*numOfRows) = nRow;
1,854,291✔
1986
    }
1987
  }
1988
  
1989
end:
15,592,915✔
1990
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
15,591,042✔
1991
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
15,590,561✔
1992
  tEndDecode(pCoder);
15,590,548✔
1993
  return code;
15,592,436✔
1994
}
1995

1996
static int32_t scanSubmitDataPre(SStreamTriggerReaderInfo* sStreamReaderInfo, void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
15,590,750✔
1997
  int32_t  code = 0;
15,590,750✔
1998
  int32_t  lino = 0;
15,590,750✔
1999
  SDecoder decoder = {0};
15,590,750✔
2000
  void* pTask = sStreamReaderInfo->pTask;
15,593,834✔
2001

2002
  tDecoderInit(&decoder, data, len);
15,593,833✔
2003
  if (tStartDecode(&decoder) < 0) {
15,588,447✔
2004
    code = TSDB_CODE_INVALID_MSG;
×
2005
    TSDB_CHECK_CODE(code, lino, end);
×
2006
  }
2007

2008
  uint64_t nSubmitTbData = 0;
15,590,561✔
2009
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
15,593,644✔
2010
    code = TSDB_CODE_INVALID_MSG;
×
2011
    TSDB_CHECK_CODE(code, lino, end);
×
2012
  }
2013
  ST_TASK_DLOG("%s nSubmitTbData:%" PRIu64 ", ver:%"PRId64 " bodyLen:%d", __func__, nSubmitTbData, ver, len);
15,593,644✔
2014

2015
  for (int32_t i = 0; i < nSubmitTbData; i++) {
31,180,949✔
2016
    uint64_t gid = -1;
15,591,524✔
2017
    int64_t  uid = 0;
15,592,258✔
2018
    int32_t numOfRows = 0;
15,592,961✔
2019
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
15,592,022✔
2020
    if (numOfRows <= 0) {
15,592,918✔
2021
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
5,087,538✔
2022
      continue;
5,087,327✔
2023
    }
2024
    rsp->totalRows += numOfRows;
10,505,380✔
2025
    rsp->totalDataRows += numOfRows;
10,506,082✔
2026

2027
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
10,505,613✔
2028
    if (pSlice != NULL) {
10,505,614✔
2029
      pSlice->numRows += numOfRows;
9,720,193✔
2030
      ST_TASK_DLOG("%s again uid:%" PRId64 ", gid:%" PRIu64 ", total numOfRows:%d, hash:%p %d, ver:%"PRId64, __func__, uid, gid, pSlice->numRows, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash), ver);
9,720,661✔
2031
      pSlice->gId = gid;
9,720,661✔
2032
    } else {
2033
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
785,421✔
2034
      ST_TASK_DLOG("%s first uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, hash:%p %d, ver:%"PRId64, __func__, uid, gid, tmp.numRows, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash), ver);
785,655✔
2035
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
785,655✔
2036
    } 
2037
  }
2038

2039
  tEndDecode(&decoder);
15,589,425✔
2040

2041
end:
15,591,533✔
2042
  tDecoderClear(&decoder);
15,592,235✔
2043
  return code;
15,594,329✔
2044
}
2045

2046
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
674,918✔
2047
  void*   pe = NULL;
674,918✔
2048
  int32_t iter = 0;
674,918✔
2049
  int32_t index = 0;
674,918✔
2050
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
1,460,573✔
2051
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
785,655✔
2052
    pInfo->startRowIdx = index;
785,655✔
2053
    pInfo->currentRowIdx = index;
785,655✔
2054
    index += pInfo->numRows;
785,655✔
2055
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
1,394,678✔
2056
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2057
  }
2058
}
674,918✔
2059

2060
static void printIndexHash(SSHashObj* indexHash, void* pTask){
674,516✔
2061
  if (qDebugFlag & DEBUG_TRACE) {
674,516✔
2062
    void*   pe = NULL;
8,575✔
2063
    int32_t iter = 0;
8,575✔
2064
    while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
20,632✔
2065
      SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
12,057✔
2066
      ST_TASK_TLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
12,278✔
2067
      pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2068
    }
2069
  }
2070
}
674,516✔
2071

2072
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
12,395✔
2073
  void*   pe = NULL;
12,395✔
2074
  int32_t iter = 0;
12,395✔
2075
  int32_t index = 0;
12,395✔
2076
  int32_t pIndex = 0;
12,395✔
2077
  int8_t* pIndicator = (int8_t*)pRet->pData;
12,395✔
2078
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
26,401✔
2079
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
14,006✔
2080
    pInfo->startRowIdx = index;
14,006✔
2081
    int32_t size = pInfo->numRows;
14,006✔
2082
    for (int32_t i = 0; i < pInfo->numRows; i++) {
200,575✔
2083
      if (pIndicator && !pIndicator[pIndex++]) {
186,569✔
2084
        size--;
63,069✔
2085
      }
2086
    }
2087
    pInfo->numRows = size;
14,006✔
2088
    index += pInfo->numRows;
14,006✔
2089
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
14,006✔
2090
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2091
  }
2092
}
12,395✔
2093

2094
static int32_t prepareIndexMetaData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, SSTriggerWalNewRsp* resultRsp){
3,407,660✔
2095
  int32_t      code = 0;
3,407,660✔
2096
  int32_t      lino = 0;
3,407,660✔
2097
  void* pTask = sStreamReaderInfo->pTask;
3,407,660✔
2098

2099
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,407,538✔
2100
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,405,445✔
2101
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,920,297✔
2102
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
2103
      resultRsp->verTime = 0;
×
2104
    } else {
2105
      resultRsp->verTime = taosGetTimestampUs();
2,919,941✔
2106
    }
2107
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
2,920,671✔
2108
    code = TSDB_CODE_SUCCESS;
2,920,668✔
2109
    goto end;
2,920,668✔
2110
  }
2111
  STREAM_CHECK_RET_GOTO(code);
485,148✔
2112

2113
  while (1) {
7,059,516✔
2114
    code = walNextValidMsg(pWalReader, true);
7,544,664✔
2115
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
7,544,201✔
2116
      resultRsp->verTime = taosGetTimestampUs();
485,818✔
2117
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
485,316✔
2118
      code = TSDB_CODE_SUCCESS;
485,584✔
2119
      goto end;
485,584✔
2120
    }
2121
    STREAM_CHECK_RET_GOTO(code);
7,058,051✔
2122
    resultRsp->ver = pWalReader->curVersion;
7,058,051✔
2123
    SWalCont* wCont = &pWalReader->pHead->head;
7,057,595✔
2124
    resultRsp->verTime = wCont->ingestTs;
7,056,085✔
2125
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
7,057,596✔
2126
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
7,057,964✔
2127
    int64_t ver = wCont->version;
7,057,525✔
2128
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
7,056,613✔
2129
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2130
    if (wCont->msgType == TDMT_VND_SUBMIT) {
7,057,406✔
2131
      // return when getting data if there are meta data in vtable scan
2132
      if (sStreamReaderInfo->isVtableStream && resultRsp->tableBlock != NULL && ((SSDataBlock*)resultRsp->tableBlock)->info.rows > 0) {
6,940,860✔
2133
        resultRsp->ver--;
×
2134
        break;
×
2135
      }
2136
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
6,941,093✔
2137
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
6,940,889✔
2138
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
6,940,889✔
2139
    } else {
2140
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
116,947✔
2141
    }
2142

2143
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
7,039,006✔
2144
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
7,039,280✔
2145
      break;
2146
    }
2147
  }
2148
  
UNCOV
2149
end:
×
2150
  STREAM_PRINT_LOG_END(code, lino);
3,405,784✔
2151
  return code;
3,406,019✔
2152
}
2153

2154
static int32_t prepareIndexData(SWalReader* pWalReader, SStreamTriggerReaderInfo* sStreamReaderInfo, 
8,305,650✔
2155
  SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp){
2156
  int32_t      code = 0;
8,305,650✔
2157
  int32_t      lino = 0;
8,305,650✔
2158
  void* pTask = sStreamReaderInfo->pTask;
8,305,650✔
2159

2160
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
16,958,503✔
2161
    int64_t *ver = taosArrayGet(versions, i);
8,650,303✔
2162
    if (ver == NULL) continue;
8,651,545✔
2163

2164
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,651,545✔
2165
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,651,307✔
2166
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
2167
      ST_TASK_TLOG("%s not data, skip, ver:%"PRId64, __func__, *ver);
×
2168
      continue;
×
2169
    }
2170
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,651,307✔
2171

2172
    SWalCont* wCont = &pWalReader->pHead->head;
8,651,074✔
2173
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,651,074✔
2174
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,651,074✔
2175

2176
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
8,651,074✔
2177
  }
2178
  
2179
end:
8,306,958✔
2180
  return code;
8,306,958✔
2181
}
2182

2183
static int32_t filterData(SSTriggerWalNewRsp* resultRsp, SStreamTriggerReaderInfo* sStreamReaderInfo) {
674,516✔
2184
  int32_t      code = 0;
674,516✔
2185
  int32_t       lino = 0;
674,516✔
2186
  SColumnInfoData* pRet = NULL;
674,516✔
2187

2188
  int64_t totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
674,516✔
2189
  STREAM_CHECK_RET_GOTO(qStreamFilter(((SSDataBlock*)resultRsp->dataBlock), sStreamReaderInfo->pFilterInfo, &pRet));
674,516✔
2190

2191
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
674,516✔
2192
    filterIndexHash(resultRsp->indexHash, pRet);
12,395✔
2193
  }
2194

2195
end:
674,516✔
2196
  colDataDestroy(pRet);
674,516✔
2197
  taosMemoryFree(pRet);
674,516✔
2198
  return code;
674,516✔
2199
}
2200

2201
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,405,758✔
2202
                                    SSTriggerWalNewRsp* resultRsp) {
2203
  int32_t      code = 0;
3,405,758✔
2204
  int32_t      lino = 0;
3,405,758✔
2205
  void* pTask = sStreamReaderInfo->pTask;
3,405,758✔
2206
                                        
2207
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,407,191✔
2208
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,404,306✔
2209
  blockDataEmpty(resultRsp->dataBlock);
3,404,306✔
2210
  blockDataEmpty(resultRsp->metaBlock);
3,401,779✔
2211
  int64_t lastVer = resultRsp->ver;                                      
3,402,725✔
2212
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,402,725✔
2213
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,405,550✔
2214

2215
  buildIndexHash(resultRsp->indexHash, pTask);
138,069✔
2216
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
138,069✔
2217
  while(lastVer < resultRsp->ver) {
4,046,159✔
2218
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
3,908,512✔
2219
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
3,906,888✔
2220
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
51,487✔
2221
      continue;
51,487✔
2222
    }
2223
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
3,855,856✔
2224
    SWalCont* wCont = &pWalReader->pHead->head;
3,857,003✔
2225
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
3,857,705✔
2226
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
3,857,705✔
2227
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
3,857,705✔
2228
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
3,857,975✔
2229
  }
2230

2231
  int32_t metaRows = resultRsp->totalRows - ((SSDataBlock*)resultRsp->dataBlock)->info.rows;
137,868✔
2232
  STREAM_CHECK_RET_GOTO(filterData(resultRsp, sStreamReaderInfo));
137,868✔
2233
  resultRsp->totalRows = ((SSDataBlock*)resultRsp->dataBlock)->info.rows + metaRows;
137,868✔
2234

2235
end:
3,405,551✔
2236
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
3,405,551✔
2237
          resultRsp->totalRows, resultRsp->ver, walGetAppliedVer(pWalReader->pWal));
2238
  walCloseReader(pWalReader);
3,405,551✔
2239
  return code;
3,406,020✔
2240
}
2241

2242
static int32_t processWalVerDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
8,304,878✔
2243
                                    SArray* versions, SSHashObj* ranges, SSTriggerWalNewRsp* rsp) {
2244
  int32_t      code = 0;
8,304,878✔
2245
  int32_t      lino = 0;
8,304,878✔
2246

2247
  void* pTask = sStreamReaderInfo->pTask;
8,304,878✔
2248
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
8,306,422✔
2249
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
8,305,415✔
2250
  
2251
  if (taosArrayGetSize(versions) > 0) {
8,305,415✔
2252
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
536,849✔
2253
  }
2254
  
2255
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
8,307,194✔
2256
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
8,306,958✔
2257

2258
  ST_TASK_TLOG("%s index hash:%p %d", __func__, rsp->indexHash, tSimpleHashGetSize(rsp->indexHash));
536,849✔
2259
  buildIndexHash(rsp->indexHash, pTask);
536,849✔
2260

2261
  blockDataEmpty(rsp->dataBlock);
536,849✔
2262
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
536,849✔
2263

2264
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
9,188,427✔
2265
    int64_t *ver = taosArrayGet(versions, i);
8,651,545✔
2266
    if (ver == NULL) continue;
8,651,545✔
2267
    ST_TASK_TLOG("vgId:%d %s scan wal process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, *ver, walGetAppliedVer(pWalReader->pWal));
8,651,545✔
2268

2269
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
8,651,545✔
2270
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
8,651,779✔
2271
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
×
2272
      continue;
×
2273
    }
2274
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
8,651,779✔
2275
    SWalCont* wCont = &pWalReader->pHead->head;
8,651,544✔
2276
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
8,651,544✔
2277
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
8,651,544✔
2278

2279
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
8,651,544✔
2280
  }
2281
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2282
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
536,648✔
2283
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
536,648✔
2284

2285
end:
8,306,958✔
2286
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
8,306,958✔
2287
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
2288
  walCloseReader(pWalReader);
8,309,509✔
2289
  return code;
8,307,730✔
2290
}
2291

2292
static int32_t buildScheamFromMeta(SVnode* pVnode, int64_t uid, SArray** schemas, SStorageAPI* api) {
440,157✔
2293
  int32_t code = 0;
440,157✔
2294
  int32_t lino = 0;
440,157✔
2295
  SMetaReader metaReader = {0};
440,157✔
2296
  *schemas = taosArrayInit(8, sizeof(SSchema));
440,157✔
2297
  STREAM_CHECK_NULL_GOTO(*schemas, terrno);
440,157✔
2298
  
2299
  api->metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &api->metaFn);
440,157✔
2300
  STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, uid));
440,157✔
2301

2302
  SSchemaWrapper* sSchemaWrapper = NULL;
436,297✔
2303
  if (metaReader.me.type == TD_CHILD_TABLE) {
436,297✔
2304
    int64_t suid = metaReader.me.ctbEntry.suid;
436,297✔
2305
    tDecoderClear(&metaReader.coder);
436,297✔
2306
    STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, suid));
436,297✔
2307
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
436,297✔
2308
  } else if (metaReader.me.type == TD_NORMAL_TABLE) {
×
2309
    sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
×
2310
  } else {
2311
    qError("invalid table type:%d", metaReader.me.type);
×
2312
  }
2313

2314
  for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
2,578,258✔
2315
    SSchema* s = sSchemaWrapper->pSchema + j;
2,141,961✔
2316
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
4,283,922✔
2317
  }
2318

2319
end:
440,157✔
2320
  api->metaReaderFn.clearReader(&metaReader);
440,157✔
2321
  STREAM_PRINT_LOG_END(code, lino);
440,157✔
2322
  if (code != 0)  {
440,157✔
2323
    taosArrayDestroy(*schemas);
3,860✔
2324
    *schemas = NULL;
3,860✔
2325
  }
2326
  return code;
440,157✔
2327
}
2328

2329
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
436,297✔
2330
  int32_t code = 0;
436,297✔
2331
  int32_t lino = 0;
436,297✔
2332
  size_t  schemaLen = taosArrayGetSize(schemas);
436,297✔
2333
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
436,297✔
2334
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
1,702,272✔
2335
    col_id_t* id = taosArrayGet(cols, i);
1,265,975✔
2336
    STREAM_CHECK_NULL_GOTO(id, terrno);
1,265,975✔
2337
    for (size_t i = 0; i < schemaLen; i++) {
3,314,150✔
2338
      SSchema* s = taosArrayGet(schemas, i);
3,314,150✔
2339
      STREAM_CHECK_NULL_GOTO(s, terrno);
3,314,150✔
2340
      if (*id == s->colId) {
3,314,150✔
2341
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
1,265,975✔
2342
        break;
1,265,975✔
2343
      }
2344
    }
2345
  }
2346
  taosArrayPopFrontBatch(schemas, schemaLen);
436,297✔
2347

2348
end:
436,297✔
2349
  return code;
436,297✔
2350
}
2351

2352
static int32_t createTSAndCondition(int64_t start, int64_t end, SLogicConditionNode** pCond,
×
2353
                                    STargetNode* pTargetNodeTs) {
2354
  int32_t code = 0;
×
2355
  int32_t lino = 0;
×
2356

2357
  SColumnNode*         pCol = NULL;
×
2358
  SColumnNode*         pCol1 = NULL;
×
2359
  SValueNode*          pVal = NULL;
×
2360
  SValueNode*          pVal1 = NULL;
×
2361
  SOperatorNode*       op = NULL;
×
2362
  SOperatorNode*       op1 = NULL;
×
2363
  SLogicConditionNode* cond = NULL;
×
2364

2365
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)&pCol));
×
2366
  pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
×
2367
  pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
×
2368
  pCol->node.resType.bytes = LONG_BYTES;
×
2369
  pCol->slotId = pTargetNodeTs->slotId;
×
2370
  pCol->dataBlockId = pTargetNodeTs->dataBlockId;
×
2371

2372
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pCol, (SNode**)&pCol1));
×
2373

2374
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal));
×
2375
  pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
×
2376
  pVal->node.resType.bytes = LONG_BYTES;
×
2377
  pVal->datum.i = start;
×
2378
  pVal->typeData = start;
×
2379

2380
  STREAM_CHECK_RET_GOTO(nodesCloneNode((SNode*)pVal, (SNode**)&pVal1));
×
2381
  pVal1->datum.i = end;
×
2382
  pVal1->typeData = end;
×
2383

2384
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op));
×
2385
  op->opType = OP_TYPE_GREATER_EQUAL;
×
2386
  op->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2387
  op->node.resType.bytes = CHAR_BYTES;
×
2388
  op->pLeft = (SNode*)pCol;
×
2389
  op->pRight = (SNode*)pVal;
×
2390
  pCol = NULL;
×
2391
  pVal = NULL;
×
2392

2393
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&op1));
×
2394
  op1->opType = OP_TYPE_LOWER_EQUAL;
×
2395
  op1->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2396
  op1->node.resType.bytes = CHAR_BYTES;
×
2397
  op1->pLeft = (SNode*)pCol1;
×
2398
  op1->pRight = (SNode*)pVal1;
×
2399
  pCol1 = NULL;
×
2400
  pVal1 = NULL;
×
2401

2402
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
×
2403
  cond->condType = LOGIC_COND_TYPE_AND;
×
2404
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
2405
  cond->node.resType.bytes = CHAR_BYTES;
×
2406
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
×
2407
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op));
×
2408
  op = NULL;
×
2409
  STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)op1));
×
2410
  op1 = NULL;
×
2411

2412
  *pCond = cond;
×
2413

2414
end:
×
2415
  if (code != 0) {
×
2416
    nodesDestroyNode((SNode*)pCol);
×
2417
    nodesDestroyNode((SNode*)pCol1);
×
2418
    nodesDestroyNode((SNode*)pVal);
×
2419
    nodesDestroyNode((SNode*)pVal1);
×
2420
    nodesDestroyNode((SNode*)op);
×
2421
    nodesDestroyNode((SNode*)op1);
×
2422
    nodesDestroyNode((SNode*)cond);
×
2423
  }
2424
  STREAM_PRINT_LOG_END(code, lino);
×
2425

2426
  return code;
×
2427
}
2428

2429
/*
2430
static int32_t createExternalConditions(SStreamRuntimeFuncInfo* data, SLogicConditionNode** pCond, STargetNode* pTargetNodeTs, STimeRangeNode* node) {
2431
  int32_t              code = 0;
2432
  int32_t              lino = 0;
2433
  SLogicConditionNode* pAndCondition = NULL;
2434
  SLogicConditionNode* cond = NULL;
2435

2436
  if (pTargetNodeTs == NULL) {
2437
    vError("stream reader %s no ts column", __func__);
2438
    return TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN;
2439
  }
2440
  STREAM_CHECK_RET_GOTO(nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&cond));
2441
  cond->condType = LOGIC_COND_TYPE_OR;
2442
  cond->node.resType.type = TSDB_DATA_TYPE_BOOL;
2443
  cond->node.resType.bytes = CHAR_BYTES;
2444
  STREAM_CHECK_RET_GOTO(nodesMakeList(&cond->pParameterList));
2445

2446
  for (int i = 0; i < taosArrayGetSize(data->pStreamPesudoFuncVals); ++i) {
2447
    data->curIdx = i;
2448

2449
    SReadHandle handle = {0};
2450
    calcTimeRange(node, data, &handle.winRange, &handle.winRangeValid);
2451
    if (!handle.winRangeValid) {
2452
      stError("stream reader %s invalid time range, skey:%" PRId64 ", ekey:%" PRId64, __func__, handle.winRange.skey,
2453
              handle.winRange.ekey);
2454
      continue;
2455
    }
2456
    STREAM_CHECK_RET_GOTO(createTSAndCondition(handle.winRange.skey, handle.winRange.ekey, &pAndCondition, pTargetNodeTs));
2457
    stDebug("%s create condition skey:%" PRId64 ", eksy:%" PRId64, __func__, handle.winRange.skey, handle.winRange.ekey);
2458
    STREAM_CHECK_RET_GOTO(nodesListAppend(cond->pParameterList, (SNode*)pAndCondition));
2459
    pAndCondition = NULL;
2460
  }
2461

2462
  *pCond = cond;
2463

2464
end:
2465
  if (code != 0) {
2466
    nodesDestroyNode((SNode*)pAndCondition);
2467
    nodesDestroyNode((SNode*)cond);
2468
  }
2469
  STREAM_PRINT_LOG_END(code, lino);
2470

2471
  return code;
2472
}
2473
*/
2474

2475
static int32_t processCalaTimeRange(SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo, SResFetchReq* req,
801,149✔
2476
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
2477
  int32_t code = 0;
801,149✔
2478
  int32_t lino = 0;
801,149✔
2479
  void* pTask = sStreamReaderCalcInfo->pTask;
801,149✔
2480
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
801,149✔
2481
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
801,149✔
2482
  
2483
  if (req->pStRtFuncInfo->withExternalWindow) {
801,149✔
2484
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
674,515✔
2485
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
674,515✔
2486
    sStreamReaderCalcInfo->tmpRtFuncInfo.isWindowTrigger = req->pStRtFuncInfo->isWindowTrigger;
674,515✔
2487
    sStreamReaderCalcInfo->tmpRtFuncInfo.precision = req->pStRtFuncInfo->precision;
674,515✔
2488

2489
    SSTriggerCalcParam* pFirst = NULL;
674,515✔
2490
    SSTriggerCalcParam* pLast = NULL;
674,515✔
2491
    if (req->pStRtFuncInfo->isMultiGroupCalc) {
674,515✔
NEW
2492
      SSTriggerGroupReadInfo* pGrp = taosArrayGet(req->pStRtFuncInfo->curGrpRead, 0);
×
NEW
2493
      pFirst = &pGrp->firstParam;
×
NEW
2494
      pLast = &pGrp->lastParam;
×
2495
    } else {
2496
      pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
674,515✔
2497
      pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
674,515✔
2498
      STREAM_CHECK_NULL_GOTO(pFirst, terrno);
674,515✔
2499
      STREAM_CHECK_NULL_GOTO(pLast, terrno);
674,515✔
2500
    }
2501

2502
    if (!node->needCalc) {
674,515✔
2503
      pWin->skey = pFirst->wstart;
523,277✔
2504
      pWin->ekey = pLast->wend;
523,277✔
2505
      *pValid = true;
523,277✔
2506
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
523,042✔
2507
        pWin->ekey--;
274,104✔
2508
      }
2509
    } else {
2510
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
151,238✔
2511
      memcpy(pTmp, pFirst, sizeof(*pTmp));
151,238✔
2512

2513
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
151,238✔
2514
      if (*pValid) {
151,238✔
2515
        int64_t skey = pWin->skey;
151,238✔
2516

2517
        memcpy(pTmp, pLast, sizeof(*pTmp));
151,238✔
2518
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
151,238✔
2519

2520
        if (*pValid) {
151,238✔
2521
          pWin->skey = skey;
151,238✔
2522
        }
2523
      }
2524
      pWin->ekey--;
151,238✔
2525
    }
2526
  } else {
2527
    if (!node->needCalc) {
126,634✔
2528
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
83,189✔
2529
      pWin->skey = pCurr->wstart;
83,189✔
2530
      pWin->ekey = pCurr->wend;
83,189✔
2531
      *pValid = true;
83,189✔
2532
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
83,189✔
2533
        pWin->ekey--;
35,052✔
2534
      }
2535
    } else {
2536
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
43,445✔
2537
      pWin->ekey--;
43,445✔
2538
    }
2539
  }
2540

2541
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
801,149✔
2542
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
2543

2544
end:
4,700✔
2545

2546
  if (code) {
801,149✔
UNCOV
2547
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
2548
  }
2549
  
2550
  return code;
801,149✔
2551
}
2552

2553
static int32_t createDataBlockTsUid(SSDataBlock** pBlockRet, uint32_t numOfRows) {
516,804✔
2554
  int32_t      code = 0;
516,804✔
2555
  int32_t      lino = 0;
516,804✔
2556
  SSDataBlock* pBlock = NULL;
516,804✔
2557
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
516,804✔
2558
  SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID);
516,804✔
2559
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
516,804✔
2560
  idata = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID + 1);
516,804✔
2561
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
516,804✔
2562
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, numOfRows));
516,804✔
2563

2564
end:
516,804✔
2565
  STREAM_PRINT_LOG_END(code, lino)
516,804✔
2566
  if (code != TSDB_CODE_SUCCESS) {
516,804✔
UNCOV
2567
    blockDataDestroy(pBlock);
×
UNCOV
2568
    pBlock = NULL;
×
2569
  }
2570
  *pBlockRet = pBlock;
516,804✔
2571
  return code;
516,804✔
2572
}
2573

2574
static int32_t processTsOutPutAllTables(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
324,110✔
2575
  int32_t code = 0;
324,110✔
2576
  int32_t lino = 0;
324,110✔
2577
  void* pTask = sStreamReaderInfo->pTask;
324,110✔
2578

2579
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
324,110✔
2580
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
324,110✔
2581
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
324,110✔
2582
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
324,110✔
2583
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
896,811✔
2584
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
1,145,402✔
UNCOV
2585
      continue;
×
2586
    }
2587
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
572,701✔
2588
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
572,701✔
2589
    if (order == TSDB_ORDER_ASC) {
572,701✔
2590
      tsInfo->ts = INT64_MAX;
310,860✔
2591
    } else {
2592
      tsInfo->ts = INT64_MIN;
261,841✔
2593
    }
2594
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
572,701✔
2595
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
572,701✔
2596
      tsInfo->ts = ts;
310,860✔
2597
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
261,841✔
2598
      tsInfo->ts = ts;
261,841✔
2599
    }
2600
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
572,701✔
2601
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
572,701✔
2602
  }
2603

2604
end:
324,110✔
2605
  return code;
324,110✔
2606
}
2607

2608
static int32_t processTsOutPutOneGroup(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
90,205✔
2609
  int32_t code = 0;
90,205✔
2610
  int32_t lino = 0;
90,205✔
2611
  void* pTask = sStreamReaderInfo->pTask;
90,205✔
2612

2613
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
89,971✔
2614
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
89,971✔
2615
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
89,736✔
2616
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
89,736✔
2617
  if (order == TSDB_ORDER_ASC) {
89,736✔
2618
    tsInfo->ts = INT64_MAX;
71,129✔
2619
  } else {
2620
    tsInfo->ts = INT64_MIN;
18,607✔
2621
  }
2622

2623
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
90,205✔
2624
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
89,971✔
2625
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
195,553✔
2626
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
212,572✔
UNCOV
2627
      continue;
×
2628
    }
2629
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
106,286✔
2630
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
106,755✔
2631
      tsInfo->ts = ts;
70,659✔
2632
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
35,862✔
2633
      tsInfo->ts = ts;
18,607✔
2634
    }
2635
  }
2636
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
89,970✔
2637
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
90,205✔
2638
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
89,971✔
2639

2640
end:
30,457✔
2641
  return code;
89,971✔
2642
}
2643

2644
static int32_t processTsOutPutAllGroups(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
7,459✔
2645
  int32_t code = 0;
7,459✔
2646
  int32_t lino = 0;
7,459✔
2647
  STableKeyInfo* pList = NULL;
7,459✔
2648
  StreamTableListInfo     tableInfo = {0};
7,459✔
2649

2650
  void* pTask = sStreamReaderInfo->pTask;
7,459✔
2651
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
7,459✔
2652

2653
  SSHashObj*   uidTsHash = tSimpleHashInit(pResBlock->info.rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,459✔
2654
  STREAM_CHECK_NULL_GOTO(uidTsHash, terrno);
7,459✔
2655
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
7,459✔
2656
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
7,459✔
2657
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
23,066✔
2658
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
31,214✔
UNCOV
2659
      continue;
×
2660
    }
2661
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
15,607✔
2662
    int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
15,607✔
2663
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(uidTsHash, &uid, LONG_BYTES, &ts, LONG_BYTES));
15,607✔
2664
  }
2665
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(sStreamReaderInfo), sizeof(STsInfo));
7,459✔
2666
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
7,459✔
2667
  while (true) {
15,205✔
2668
    int32_t        pNum = 0;
22,664✔
2669
    int64_t        suid = 0;
22,664✔
2670
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
22,664✔
2671
    if(pNum == 0) break;
22,664✔
2672
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
15,784✔
2673
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
15,784✔
2674
    if (order == TSDB_ORDER_ASC) {
15,784✔
2675
      tsInfo->ts = INT64_MAX;
7,412✔
2676
    } else {
2677
      tsInfo->ts = INT64_MIN;
8,372✔
2678
    }
2679
    for (int32_t i = 0; i < pNum; i++) {
30,989✔
2680
      int64_t uid = pList[i].uid;
15,784✔
2681
      int64_t *ts = tSimpleHashGet(uidTsHash, &uid, LONG_BYTES);
15,784✔
2682
      STREAM_CHECK_NULL_GOTO(ts, terrno);
15,784✔
2683
      if (order == TSDB_ORDER_ASC && *ts < tsInfo->ts) {
15,205✔
2684
        tsInfo->ts = *ts;
7,412✔
2685
      } else if (order == TSDB_ORDER_DESC && *ts > tsInfo->ts) {
7,793✔
2686
        tsInfo->ts = *ts;
7,793✔
2687
      }
2688
    }
2689
    int64_t uid = pList[0].uid;
15,205✔
2690
    tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
15,205✔
2691
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
15,205✔
2692
    taosMemoryFreeClear(pList);
15,205✔
2693
  }
2694

2695
end:
7,459✔
2696
  qStreamDestroyTableInfo(&tableInfo);
7,459✔
2697
  taosMemoryFreeClear(pList);
7,459✔
2698
  tSimpleHashCleanup(uidTsHash);
7,459✔
2699
  return code;
7,459✔
2700
}
2701

2702
// static bool stReaderTaskWaitQuit(SStreamTask* pTask) { return taosHasRWWFlag(&pTask->entryLock); }
2703

2704
static int32_t getAllTs(SVnode* pVnode, SSDataBlock*  pResBlock, SStreamReaderTaskInner* pTaskInner, STableKeyInfo* pList, int32_t pNum) {
389,639✔
2705
  int32_t code = 0;
389,639✔
2706
  int32_t lino = 0;
389,639✔
2707

2708
  stDebug("%s getAllTs enter: pNum:%d suid:%"PRId64" order:%d skey:%"PRId64" ekey:%"PRId64" verRange:[%"PRId64",%"PRId64"]",
389,639✔
2709
          pTaskInner->idStr, pNum, pTaskInner->options->suid, pTaskInner->options->order,
2710
          pTaskInner->options->twindows.skey, pTaskInner->options->twindows.ekey,
2711
          (int64_t)-1, pTaskInner->options->ver);
2712
  for (int32_t i = 0; i < pNum; i++) {
1,484,250✔
2713
    stDebug("%s getAllTs table[%d]: uid:%"PRId64, pTaskInner->idStr, i, pList[i].uid);
1,094,846✔
2714
  }
2715

2716
  STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdCreateFirstLastTsIter(pVnode, &pTaskInner->options->twindows, &(SVersionRange){.minVer = -1, .maxVer = pTaskInner->options->ver},
389,404✔
2717
                                                pTaskInner->options->suid, pList, pNum, pTaskInner->options->order, &pTaskInner->pReader, pTaskInner->idStr));
2718
  bool hasNext = true;
388,701✔
2719
  int32_t iterCount = 0;
388,701✔
2720
  while(1){
2721
    STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdNextFirstLastTsBlock(pTaskInner->pReader, pResBlock, &hasNext));
388,701✔
2722
    stDebug("%s getAllTs iter[%d]: hasNext:%d pResBlock->info.rows:%"PRId64, pTaskInner->idStr, iterCount++, hasNext, pResBlock->info.rows);
389,187✔
2723
    STREAM_CHECK_CONDITION_GOTO(!hasNext, TDB_CODE_SUCCESS);
389,404✔
2724
  }
2725

2726
end:
389,404✔
2727
  stDebug("%s getAllTs done: code:%d pResBlock->info.rows:%"PRId64, pTaskInner->idStr, code, pResBlock ? pResBlock->info.rows : -1);
389,404✔
2728
  pTaskInner->storageApi->tsdReader.tsdDestroyFirstLastTsIter(pTaskInner->pReader);
389,404✔
2729
  pTaskInner->pReader = NULL;
389,639✔
2730
  return code;
389,639✔
2731
}
2732

2733
static int32_t processTsVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
271,491✔
2734
                                  SStreamReaderTaskInner* pTaskInner) {
2735
  int32_t code = 0;
271,491✔
2736
  int32_t lino = 0;
271,491✔
2737
  STableKeyInfo* pList = NULL;
271,491✔
2738
  StreamTableListInfo     tableInfo = {0};
271,491✔
2739

2740
  void* pTask = sStreamReaderInfo->pTask;
271,491✔
2741
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
271,491✔
2742

2743
  SSDataBlock*  pResBlock = NULL;
271,491✔
2744
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, qStreamGetTableListNum(sStreamReaderInfo)));
271,491✔
2745

2746
  while (true) {
144,326✔
2747
    int32_t        pNum = 0;
415,817✔
2748
    int64_t        suid = 0;
415,817✔
2749
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
415,817✔
2750
    if(pNum == 0) break;
415,817✔
2751
    pTaskInner->options->suid = suid;
144,326✔
2752
    STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
144,326✔
2753
    taosMemoryFreeClear(pList);
144,326✔
2754
  }
2755

2756
  STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, pTaskInner->options->order));
271,491✔
2757

2758
end:
271,491✔
2759
  qStreamDestroyTableInfo(&tableInfo);
271,491✔
2760
  taosMemoryFreeClear(pList);
271,491✔
2761
  blockDataDestroy(pResBlock);
271,491✔
2762
  STREAM_PRINT_LOG_END_WITHID(code, lino);
271,491✔
2763
  return code;
271,491✔
2764
}
2765

2766
static int32_t processTsNonVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
234,073✔
2767
                                  SStreamReaderTaskInner* pTaskInner) {
2768
  int32_t code = 0;
234,073✔
2769
  int32_t lino = 0;
234,073✔
2770
  STableKeyInfo* pList = NULL;
234,073✔
2771
  void* pTask = sStreamReaderInfo->pTask;
234,073✔
2772

2773
  SSDataBlock*  pResBlock = NULL;
234,073✔
2774

2775
  int32_t        pNum = 0;
234,073✔
2776
  int64_t        suid = 0;
234,073✔
2777
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, 0, &pList, &pNum));
234,073✔
2778
  ST_TASK_DLOG("vgId:%d %s qStreamGetTableList returned pNum:%d", TD_VID(pVnode), __func__, pNum);
234,073✔
2779
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
234,073✔
2780
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
201,667✔
2781

2782
  pTaskInner->options->suid = sStreamReaderInfo->suid;
201,667✔
2783
  ST_TASK_DLOG("vgId:%d %s calling getAllTs: suid:%"PRId64" order:%d skey:%"PRId64" ekey:%"PRId64" ver:%"PRId64,
201,667✔
2784
               TD_VID(pVnode), __func__, pTaskInner->options->suid, pTaskInner->options->order,
2785
               pTaskInner->options->twindows.skey, pTaskInner->options->twindows.ekey, pTaskInner->options->ver);
2786
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
201,667✔
2787
  ST_TASK_DLOG("vgId:%d %s getAllTs done: pResBlock rows:%"PRId64, TD_VID(pVnode), __func__, pResBlock->info.rows);
201,667✔
2788
  int32_t order = pTaskInner->options->order;
201,667✔
2789
  if (pResBlock->info.rows == 0 && sStreamReaderInfo->groupByTbname) {
201,667✔
2790
    tsRsp->tsInfo = taosArrayInit(pNum, sizeof(STsInfo));
37,119✔
2791
    STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
37,119✔
2792
    for (int32_t i = 0; i < pNum; i++) {
136,870✔
2793
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
99,751✔
2794
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno);
99,751✔
2795
      tsInfo->gId = pList[i].uid;
99,751✔
2796
      tsInfo->ts = 0;
99,751✔
2797
      ST_TASK_DLOG("%s no data but return gId (uid):%" PRIu64 " for tbname partition", __func__, tsInfo->gId);
99,751✔
2798
    }
2799
    goto end;
37,119✔
2800
  }
2801

2802
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
164,548✔
2803

2804
  if (sStreamReaderInfo->groupByTbname) {
106,637✔
2805
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
52,619✔
2806
  } else if (sStreamReaderInfo->partitionCols == NULL) {
54,018✔
2807
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
46,559✔
2808
  } else {
2809
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
7,459✔
2810
  }                             
2811
end:
233,834✔
2812
  blockDataDestroy(pResBlock);
234,073✔
2813
  taosMemoryFreeClear(pList);
234,073✔
2814
  STREAM_PRINT_LOG_END_WITHID(code, lino);
234,073✔
2815
  return code;
234,073✔
2816
}
2817

2818
static int32_t processTsOnce(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
59,341✔
2819
                                  SStreamReaderTaskInner* pTaskInner, uint64_t gid) {
2820
  int32_t code = 0;
59,341✔
2821
  int32_t lino = 0;
59,341✔
2822
  STableKeyInfo* pList = NULL;
59,341✔
2823
  void* pTask = sStreamReaderInfo->pTask;
59,341✔
2824
  
2825
  SSDataBlock*  pResBlock = NULL;
59,341✔
2826

2827
  int32_t        pNum = 0;
59,341✔
2828
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
59,341✔
2829
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
59,341✔
2830
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
43,646✔
2831

2832
  pTaskInner->options->suid = sStreamReaderInfo->suid;
43,646✔
2833
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
43,646✔
2834
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
43,646✔
2835
  int32_t order = pTaskInner->options->order;
43,412✔
2836

2837
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
43,411✔
2838
end:
59,341✔
2839
  blockDataDestroy(pResBlock);
59,341✔
2840
  taosMemoryFreeClear(pList);
58,638✔
2841
  STREAM_PRINT_LOG_END_WITHID(code, lino);
58,872✔
2842
  return code;
58,872✔
2843
}
2844

2845
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
505,360✔
2846
                                  SStreamReaderTaskInner* pTaskInner) {
2847
  if (sStreamReaderInfo->isVtableStream) {
505,360✔
2848
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
271,491✔
2849
  }
2850

2851
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
234,073✔
2852
}
2853

2854
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
134,218✔
2855
  int32_t code = 0;
134,218✔
2856
  int32_t lino = 0;
134,218✔
2857
  void*   buf = NULL;
134,218✔
2858
  size_t  size = 0;
134,218✔
2859
  void* pTask = sStreamReaderInfo->pTask;
134,218✔
2860

2861
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d, appver:%"PRId64, TD_VID(pVnode), __func__,
134,454✔
2862
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc), pVnode->state.applied);
2863

2864
  taosWLockLatch(&sStreamReaderInfo->lock);
134,454✔
2865
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
134,454✔
2866
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
134,454✔
2867
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
134,454✔
2868
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
134,218✔
2869

2870
  qStreamClearTableInfo(&sStreamReaderInfo->vSetTableList);
134,454✔
2871
  STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->vSetTableList));
134,454✔
2872
  STREAM_CHECK_RET_GOTO(qBuildVTableList(sStreamReaderInfo));
134,454✔
2873
end:
134,454✔
2874
  taosWUnLockLatch(&sStreamReaderInfo->lock);
134,454✔
2875
  STREAM_PRINT_LOG_END_WITHID(code, lino);
134,454✔
2876
  SRpcMsg rsp = {
134,454✔
2877
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2878
  tmsgSendRsp(&rsp);
134,454✔
2879
  return code;
134,454✔
2880
}
2881

2882
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
291,549✔
2883
  int32_t                 code = 0;
291,549✔
2884
  int32_t                 lino = 0;
291,549✔
2885
  SStreamReaderTaskInner* pTaskInner = NULL;
291,549✔
2886
  SStreamTsResponse       tsRsp = {0};
292,218✔
2887
  void*                   buf = NULL;
292,218✔
2888
  size_t                  size = 0;
292,218✔
2889

2890
  void* pTask = sStreamReaderInfo->pTask;
292,218✔
2891

2892
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
292,218✔
2893

2894
  BUILD_OPTION(options, 0, sStreamReaderInfo->tableList.version, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, NULL, false, NULL);
292,218✔
2895
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
292,218✔
2896

2897
  tsRsp.ver = sStreamReaderInfo->tableList.version + 1;
292,218✔
2898

2899
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
292,218✔
2900
  
2901
end:
292,218✔
2902
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
292,014✔
2903
  code = buildTsRsp(&tsRsp, &buf, &size);
292,014✔
2904
  STREAM_PRINT_LOG_END_WITHID(code, lino);
291,999✔
2905
  SRpcMsg rsp = {
292,218✔
2906
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2907
  tmsgSendRsp(&rsp);
292,218✔
2908
  taosArrayDestroy(tsRsp.tsInfo);
292,218✔
2909
  taosMemoryFree(pTaskInner);
292,218✔
2910
  return code;
292,218✔
2911
}
2912

2913
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
272,687✔
2914
  int32_t                 code = 0;
272,687✔
2915
  int32_t                 lino = 0;
272,687✔
2916
  SStreamReaderTaskInner* pTaskInner = NULL;
272,687✔
2917
  SStreamTsResponse       tsRsp = {0};
272,687✔
2918
  void*                   buf = NULL;
272,687✔
2919
  size_t                  size = 0;
272,687✔
2920

2921
  void* pTask = sStreamReaderInfo->pTask;
272,687✔
2922
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64
272,687✔
2923
               " applied:%"PRId64" tableListNum:%d isVtable:%d groupByTbname:%d partitionCols:%p",
2924
               TD_VID(pVnode), __func__, req->firstTsReq.startTime, req->firstTsReq.ver, req->firstTsReq.gid,
2925
               pVnode->state.applied, qStreamGetTableListNum(sStreamReaderInfo),
2926
               sStreamReaderInfo->isVtableStream, sStreamReaderInfo->groupByTbname, sStreamReaderInfo->partitionCols);
2927
  int32_t        pNum = 0;
272,687✔
2928

2929
  tsRsp.ver = pVnode->state.applied;
272,687✔
2930

2931
  BUILD_OPTION(options, 0, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, NULL, false, NULL);
272,687✔
2932
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
272,687✔
2933

2934
  if (req->firstTsReq.gid != 0) {
272,453✔
2935
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
59,341✔
2936
  } else {
2937
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
213,346✔
2938
  }
2939

2940
end:
272,687✔
2941
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
272,687✔
2942
  code = buildTsRsp(&tsRsp, &buf, &size);
272,687✔
2943
  STREAM_PRINT_LOG_END_WITHID(code, lino);
272,331✔
2944
  SRpcMsg rsp = {
272,331✔
2945
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2946
  tmsgSendRsp(&rsp);
272,218✔
2947
  taosArrayDestroy(tsRsp.tsInfo);
272,687✔
2948
  taosMemoryFree(pTaskInner);
272,687✔
2949
  return code;
272,687✔
2950
}
2951

2952
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
491,546✔
2953
  int32_t code = 0;
491,546✔
2954
  int32_t lino = 0;
491,546✔
2955
  void*   buf = NULL;
491,546✔
2956
  size_t  size = 0;
491,546✔
2957
  STableKeyInfo* pList = NULL;
491,546✔
2958

2959
  void* pTask = sStreamReaderInfo->pTask;
491,546✔
2960
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64 ",skey:%" PRId64 ",ekey:%" PRId64 ",gid:%" PRId64, TD_VID(pVnode),
491,546✔
2961
               __func__, req->tsdbMetaReq.ver, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime,
2962
               req->tsdbMetaReq.gid);
2963

2964
  SStreamReaderTaskInner* pTaskInner = NULL;
491,546✔
2965
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
491,546✔
2966

2967
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
491,546✔
2968
    int32_t        pNum = 0;
491,546✔
2969
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbMetaReq.gid, &pList, &pNum));
491,546✔
2970
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, 
491,546✔
2971
                          sStreamReaderInfo->tsSchemas, true, NULL);
2972
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, pList, pNum, &sStreamReaderInfo->storageApi));
491,546✔
2973
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
491,546✔
2974
    
2975
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
491,546✔
2976
  } else {
UNCOV
2977
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
2978
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
2979
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
2980
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2981
  }
2982

2983
  blockDataCleanup(pTaskInner->pResBlockDst);
491,546✔
2984
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
491,546✔
2985
  bool hasNext = true;
491,546✔
2986
  while (true) {
379,177✔
2987
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
870,723✔
2988
    if (!hasNext) {
870,723✔
2989
      break;
491,546✔
2990
    }
2991
    pTaskInner->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
379,177✔
2992
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
379,177✔
2993

2994
    int32_t index = 0;
379,177✔
2995
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
379,177✔
2996
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
379,177✔
2997
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
379,177✔
2998
    if (!sStreamReaderInfo->isVtableStream) {
379,177✔
2999
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
140,626✔
3000
    }
3001
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
379,177✔
3002

3003
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
379,177✔
3004
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3005
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3006
            pTaskInner->pResBlockDst->info.rows++;
379,177✔
3007
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
379,177✔
UNCOV
3008
      break;
×
3009
    }
3010
  }
3011

3012
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
491,546✔
3013
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
491,546✔
3014
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
491,546✔
3015
  if (!hasNext) {
491,546✔
3016
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
491,546✔
3017
  }
3018

3019
end:
491,546✔
3020
  STREAM_PRINT_LOG_END_WITHID(code, lino);
491,546✔
3021
  SRpcMsg rsp = {
491,546✔
3022
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3023
  tmsgSendRsp(&rsp);
491,546✔
3024
  taosMemoryFree(pList);
491,546✔
3025
  return code;
491,546✔
3026
}
3027

3028
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
134,098✔
3029
  int32_t                 code = 0;
134,098✔
3030
  int32_t                 lino = 0;
134,098✔
3031
  SStreamReaderTaskInner* pTaskInner = NULL;
134,098✔
3032
  void*                   buf = NULL;
134,098✔
3033
  size_t                  size = 0;
134,098✔
3034
  SSDataBlock*            pBlockRes = NULL;
134,098✔
3035

3036
  void* pTask = sStreamReaderInfo->pTask;
134,098✔
3037
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
134,098✔
3038
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3039
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3040

3041
  int32_t        pNum = 1;
134,098✔
3042
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
134,098✔
3043
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
134,098✔
3044
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
134,098✔
3045
               sStreamReaderInfo->triggerCols, false, NULL);
3046
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
134,098✔
3047
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
134,098✔
3048
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
134,098✔
3049

3050
  while (1) {
134,098✔
3051
    bool hasNext = false;
268,196✔
3052
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
268,196✔
3053
    if (!hasNext) {
268,196✔
3054
      break;
134,098✔
3055
    }
3056
    // if (!sStreamReaderInfo->isVtableStream){
3057
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
134,098✔
3058
    // }
3059

3060
    SSDataBlock* pBlock = NULL;
134,098✔
3061
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
134,098✔
3062
    if (pBlock != NULL && pBlock->info.rows > 0) {
134,098✔
3063
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
134,098✔
3064
          0, pBlock->info.rows, 1));
3065
    }
3066
    
3067
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
134,098✔
3068
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
134,098✔
3069
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
134,098✔
3070
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3071
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3072
  }
3073

3074
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
134,098✔
3075

3076
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
134,098✔
3077
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
134,098✔
3078

3079
end:
134,098✔
3080
  STREAM_PRINT_LOG_END_WITHID(code, lino);
134,098✔
3081
  SRpcMsg rsp = {
134,098✔
3082
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3083
  tmsgSendRsp(&rsp);
134,098✔
3084
  blockDataDestroy(pBlockRes);
134,098✔
3085

3086
  releaseStreamTask(&pTaskInner);
134,098✔
3087
  return code;
134,098✔
3088
}
3089

3090
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
1,544✔
3091
  int32_t                 code = 0;
1,544✔
3092
  int32_t                 lino = 0;
1,544✔
3093
  SStreamReaderTaskInner* pTaskInner = NULL;
1,544✔
3094
  void*                   buf = NULL;
1,544✔
3095
  size_t                  size = 0;
1,544✔
3096
  SSDataBlock*            pBlockRes = NULL;
1,544✔
3097

3098
  void* pTask = sStreamReaderInfo->pTask;
1,544✔
3099
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
1,544✔
3100
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3101
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3102

3103
  int32_t        pNum = 1;
1,544✔
3104
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
1,544✔
3105
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
1,544✔
3106
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
1,544✔
3107
               sStreamReaderInfo->tsSchemas, true, NULL);
3108
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
1,544✔
3109
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
1,544✔
3110

3111
  while (1) {
1,544✔
3112
    bool hasNext = false;
3,088✔
3113
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
3,088✔
3114
    if (!hasNext) {
3,088✔
3115
      break;
1,544✔
3116
    }
3117

3118
    SSDataBlock* pBlock = NULL;
1,544✔
3119
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
1,544✔
3120
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
1,544✔
3121
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
1,544✔
3122
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
3123
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
3124
  }
3125

3126
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
1,544✔
3127
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
1,544✔
3128

3129
end:
1,544✔
3130
  STREAM_PRINT_LOG_END_WITHID(code, lino);
1,544✔
3131
  SRpcMsg rsp = {
1,544✔
3132
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3133
  tmsgSendRsp(&rsp);
1,544✔
3134
  blockDataDestroy(pBlockRes);
1,544✔
3135

3136
  releaseStreamTask(&pTaskInner);
1,544✔
3137
  return code;
1,544✔
3138
}
3139

3140
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
113,300✔
3141
  int32_t code = 0;
113,300✔
3142
  int32_t lino = 0;
113,300✔
3143
  void*   buf = NULL;
113,300✔
3144
  size_t  size = 0;
113,300✔
3145
  STableKeyInfo* pList = NULL;
113,300✔
3146
  SArray*        pResList = NULL;
113,300✔
3147
  SSDataBlock*   pBlockTmp = NULL;
113,300✔
3148

3149
  SStreamReaderTaskInner* pTaskInner = NULL;
113,300✔
3150
  void* pTask = sStreamReaderInfo->pTask;
113,300✔
3151
  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);
113,300✔
3152
  
3153
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
113,300✔
3154

3155
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
113,300✔
3156
    int32_t        pNum = 0;
56,650✔
3157
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbTriggerDataReq.gid, &pList, &pNum));
56,650✔
3158
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
56,650✔
3159
                 sStreamReaderInfo->triggerCols, false, NULL);
3160
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
56,650✔
3161
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
56,650✔
3162
  } else {
3163
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
56,650✔
3164
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
56,650✔
UNCOV
3165
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
3166
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3167
  }
3168

3169
  blockDataCleanup(pTaskInner->pResBlockDst);
56,650✔
3170
  bool hasNext = true;
56,650✔
3171
  int32_t totalRows = 0;
56,650✔
3172
    
3173
  pResList = taosArrayInit(4, POINTER_BYTES);
56,650✔
3174
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
56,650✔
3175
  while (1) {
61,910✔
3176
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
118,560✔
3177
    if (!hasNext) {
118,560✔
3178
      break;
56,650✔
3179
    }
3180
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
61,910✔
3181
    // pTaskInner->pResBlockDst->info.id.groupId = pTaskInner->pResBlock->info.id.groupId;
3182

3183
    SSDataBlock* pBlock = NULL;
61,910✔
3184
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
61,910✔
3185
    if (pBlock != NULL && pBlock->info.rows > 0) {
61,910✔
3186
      STREAM_CHECK_RET_GOTO(
61,910✔
3187
        processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
3188
    }
3189
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
61,910✔
3190
    // STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3191
    ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
61,910✔
3192
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
61,910✔
3193
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
61,910✔
3194
    totalRows += blockDataGetNumOfRows(pBlockTmp);
61,910✔
3195
    pBlockTmp = NULL;
61,910✔
3196

3197
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
61,910✔
3198
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3199
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3200
    if (totalRows >= STREAM_RETURN_ROWS_NUM) {  //todo optimize send multi blocks in one group
61,910✔
UNCOV
3201
      break;
×
3202
    }
3203
  }
3204

3205
  STREAM_CHECK_RET_GOTO(buildArrayRsp(pResList, &buf, &size));
56,650✔
3206
  if (!hasNext) {
56,650✔
3207
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
56,650✔
3208
  }
3209

3210
end:
113,066✔
3211
  STREAM_PRINT_LOG_END_WITHID(code, lino);
113,300✔
3212
  SRpcMsg rsp = {
113,300✔
3213
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3214
  tmsgSendRsp(&rsp);
113,066✔
3215
  taosMemoryFree(pList);
113,300✔
3216
  blockDataDestroy(pBlockTmp);
113,300✔
3217
  taosArrayDestroyP(pResList, (FDelete)blockDataDestroy);
113,300✔
3218
  return code;
113,300✔
3219
}
3220

3221
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
6,467,761✔
3222
  int32_t code = 0;
6,467,761✔
3223
  int32_t lino = 0;
6,467,761✔
3224
  void*   buf = NULL;
6,467,761✔
3225
  size_t  size = 0;
6,468,222✔
3226
  SSDataBlock*   pBlockRes = NULL;
6,468,222✔
3227
  STableKeyInfo* pList = NULL;
6,468,222✔
3228

3229

3230
  void* pTask = sStreamReaderInfo->pTask;
6,468,222✔
3231
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
6,468,222✔
3232
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid, req->tsdbCalcDataReq.ver);
3233

3234
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
6,468,222✔
3235

3236
  SStreamReaderTaskInner* pTaskInner = NULL;
6,468,222✔
3237
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
6,468,222✔
3238

3239
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
6,468,222✔
3240
    int32_t        pNum = 0;
6,468,222✔
3241
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbCalcDataReq.gid, &pList, &pNum));
6,468,222✔
3242
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
6,468,008✔
3243
                 sStreamReaderInfo->triggerCols, false, NULL);
3244
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
6,468,008✔
3245

3246
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
6,464,816✔
3247
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
6,465,886✔
3248
  } else {
UNCOV
3249
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
3250
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
3251
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
3252
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3253
  }
3254

3255
  blockDataCleanup(pTaskInner->pResBlockDst);
6,465,654✔
3256
  bool hasNext = true;
6,463,104✔
3257
  while (1) {
766,632✔
3258
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
7,230,987✔
3259
    if (!hasNext) {
7,231,626✔
3260
      break;
6,466,082✔
3261
    }
3262
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
765,544✔
3263

3264
    SSDataBlock* pBlock = NULL;
767,406✔
3265
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
767,406✔
3266
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
766,828✔
3267
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
766,772✔
3268
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
766,828✔
UNCOV
3269
      break;
×
3270
    }
3271
  }
3272

3273
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
6,463,300✔
3274
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
6,468,222✔
3275
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
6,466,314✔
3276
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
6,465,835✔
3277
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
6,464,765✔
3278
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
6,462,429✔
3279
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
6,466,905✔
3280

3281
  if (!hasNext) {
6,468,222✔
3282
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
6,468,222✔
3283
  }
3284

3285
end:
6,469,190✔
3286
  STREAM_PRINT_LOG_END_WITHID(code, lino);
6,467,152✔
3287
  SRpcMsg rsp = {
6,468,008✔
3288
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3289
  tmsgSendRsp(&rsp);
6,468,222✔
3290
  blockDataDestroy(pBlockRes);
6,467,366✔
3291
  taosMemoryFree(pList);
6,467,366✔
3292
  return code;
6,466,296✔
3293
}
3294

3295
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
440,157✔
3296
  int32_t code = 0;
440,157✔
3297
  int32_t lino = 0;
440,157✔
3298
  void*   buf = NULL;
440,157✔
3299
  size_t  size = 0;
440,157✔
3300
  int32_t* slotIdList = NULL;
440,157✔
3301
  SArray* sortedCid = NULL;
440,157✔
3302
  SArray* schemas = NULL;
440,157✔
3303
  SSDataBlock*   pBlockRes = NULL;
440,157✔
3304
  
3305
  void* pTask = sStreamReaderInfo->pTask;
440,157✔
3306
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
440,157✔
3307
    req->tsdbDataReq.skey, req->tsdbDataReq.ekey, req->tsdbDataReq.uid, req->tsdbDataReq.ver);
3308
    
3309
  SStreamReaderTaskInner* pTaskInner = NULL;
440,157✔
3310
  int64_t key = req->tsdbDataReq.uid;
440,157✔
3311

3312
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
440,157✔
3313
    // sort cid and build slotIdList
3314
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
440,157✔
3315
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
440,157✔
3316
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
440,157✔
3317
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
440,157✔
3318
    taosArraySort(sortedCid, sortCid);
440,157✔
3319
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
1,717,712✔
3320
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
1,277,555✔
3321
      STREAM_CHECK_NULL_GOTO(cid, terrno);
1,277,555✔
3322
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
2,519,206✔
3323
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
2,519,206✔
3324
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
2,519,206✔
3325
        if (*cid == *cidSorted) {
2,519,206✔
3326
          slotIdList[j] = i;
1,277,555✔
3327
          break;
1,277,555✔
3328
        }
3329
      }
3330
    }
3331

3332
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas, &sStreamReaderInfo->storageApi));
440,157✔
3333
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
436,297✔
3334
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlockRes));
436,297✔
3335

3336
    taosArraySort(schemas, sortSSchema);
436,297✔
3337
    BUILD_OPTION(options, req->tsdbDataReq.suid, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
436,297✔
3338
                    req->tsdbDataReq.ekey, schemas, true, &slotIdList);
3339
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid, .groupId = 0};
436,297✔
3340
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, pBlockRes, &keyInfo, 1, &sStreamReaderInfo->storageApi));
436,297✔
3341
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
436,297✔
3342
    pTaskInner->pResBlockDst = pBlockRes;
436,297✔
3343
    pBlockRes = NULL;
436,297✔
3344
  } else {
UNCOV
3345
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
UNCOV
3346
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
UNCOV
3347
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
UNCOV
3348
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3349
  }
3350

3351
  blockDataCleanup(pTaskInner->pResBlockDst);
436,297✔
3352
  bool hasNext = true;
436,297✔
3353
  while (1) {
436,297✔
3354
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
872,594✔
3355
    if (!hasNext) {
872,594✔
3356
      break;
436,297✔
3357
    }
3358

3359
    SSDataBlock* pBlock = NULL;
436,297✔
3360
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
436,297✔
3361
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
436,297✔
3362
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
436,297✔
UNCOV
3363
      break;
×
3364
    }
3365
  }
3366
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
436,297✔
3367
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
436,297✔
3368
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
436,297✔
3369
  if (!hasNext) {
436,297✔
3370
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
436,297✔
3371
  }
3372

3373
end:
440,157✔
3374
  STREAM_PRINT_LOG_END_WITHID(code, lino);
440,157✔
3375
  SRpcMsg rsp = {
440,157✔
3376
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3377
  tmsgSendRsp(&rsp);
440,157✔
3378
  taosMemFree(slotIdList);
440,157✔
3379
  taosArrayDestroy(sortedCid);
440,157✔
3380
  taosArrayDestroy(schemas);
440,157✔
3381
  blockDataDestroy(pBlockRes);
440,157✔
3382
  return code;
440,157✔
3383
}
3384

3385
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
11,921,089✔
3386
  int32_t      code = 0;
11,921,089✔
3387
  int32_t      lino = 0;
11,921,089✔
3388
  void*        buf = NULL;
11,921,089✔
3389
  size_t       size = 0;
11,921,089✔
3390
  int64_t      lastVer = 0;
11,921,089✔
3391
  SSTriggerWalNewRsp resultRsp = {0};
11,921,089✔
3392

3393
  void* pTask = sStreamReaderInfo->pTask;
11,921,040✔
3394
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
11,920,854✔
3395

3396
  if (sStreamReaderInfo->metaBlock == NULL) {
11,920,286✔
3397
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
200,168✔
3398
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
200,168✔
3399
  }
3400
  blockDataEmpty(sStreamReaderInfo->metaBlock);
11,921,226✔
3401
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
11,918,647✔
3402
  resultRsp.ver = req->walMetaNewReq.lastVer;
11,918,647✔
3403
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
11,918,883✔
3404

3405
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
11,919,017✔
3406
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
11,921,461✔
3407
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
471,904✔
3408
  buf = rpcMallocCont(size);
471,904✔
3409
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
471,904✔
3410
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
471,727✔
3411
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
471,904✔
3412
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
471,727✔
3413

3414
end:
11,921,461✔
3415
  if (code == 0 && resultRsp.totalRows == 0) {
11,921,461✔
3416
    code = TSDB_CODE_STREAM_NO_DATA;
11,449,323✔
3417
    size = sizeof(int64_t) * 2;
11,449,323✔
3418
    buf = rpcMallocCont(size);
11,449,323✔
3419
    *(int64_t*)buf = resultRsp.ver;
11,448,407✔
3420
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
11,448,407✔
3421
  }
3422
  SRpcMsg rsp = {
11,920,778✔
3423
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3424
  tmsgSendRsp(&rsp);
11,919,353✔
3425
  if (code == TSDB_CODE_STREAM_NO_DATA){
11,920,263✔
3426
    code = 0;
11,448,570✔
3427
  }
3428
  STREAM_PRINT_LOG_END_WITHID(code, lino);
11,920,263✔
3429
  blockDataDestroy(resultRsp.deleteBlock);
11,920,689✔
3430
  blockDataDestroy(resultRsp.tableBlock);
11,921,027✔
3431

3432
  return code;
11,921,461✔
3433
}
3434
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,407,660✔
3435
  int32_t      code = 0;
3,407,660✔
3436
  int32_t      lino = 0;
3,407,660✔
3437
  void*        buf = NULL;
3,407,660✔
3438
  size_t       size = 0;
3,407,660✔
3439
  SSTriggerWalNewRsp resultRsp = {0};
3,407,660✔
3440
  
3441
  void* pTask = sStreamReaderInfo->pTask;
3,406,756✔
3442
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,405,819✔
3443

3444
  if (sStreamReaderInfo->metaBlock == NULL) {
3,406,020✔
3445
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
101,453✔
3446
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
101,453✔
3447
  }
3448

3449
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,407,192✔
3450
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
3,407,894✔
3451
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,405,415✔
3452
  resultRsp.checkAlter = true;
3,405,552✔
3453
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,405,552✔
3454
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
3,403,975✔
3455

3456
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,403,975✔
3457

3458
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,405,819✔
3459
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
138,103✔
3460
  buf = rpcMallocCont(size);
137,868✔
3461
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
137,868✔
3462
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
137,868✔
3463
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
137,868✔
3464
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
137,868✔
3465
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
137,868✔
3466
  printIndexHash(resultRsp.indexHash, pTask);
137,868✔
3467

3468
end:
3,405,785✔
3469
  if (resultRsp.totalRows == 0) {
3,406,020✔
3470
    code = TSDB_CODE_STREAM_NO_DATA;
3,269,123✔
3471
    size = sizeof(int64_t) * 2;
3,269,123✔
3472
    buf = rpcMallocCont(size);
3,269,123✔
3473
    *(int64_t*)buf = resultRsp.ver;
3,266,079✔
3474
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
3,266,547✔
3475
  }
3476
  SRpcMsg rsp = {
3,404,147✔
3477
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3478
  tmsgSendRsp(&rsp);
3,406,020✔
3479
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,407,660✔
3480
    code = 0;
3,269,591✔
3481
  }
3482
  blockDataDestroy(resultRsp.dataBlock);
3,407,660✔
3483
  blockDataDestroy(resultRsp.deleteBlock);
3,406,297✔
3484
  blockDataDestroy(resultRsp.tableBlock);
3,406,315✔
3485
  tSimpleHashCleanup(resultRsp.indexHash);
3,406,662✔
3486

3487
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,402,651✔
3488

3489
  return code;
3,404,033✔
3490
}
3491

3492
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
7,342,143✔
3493
  int32_t      code = 0;
7,342,143✔
3494
  int32_t      lino = 0;
7,342,143✔
3495
  void*        buf = NULL;
7,342,143✔
3496
  size_t       size = 0;
7,342,143✔
3497
  SSTriggerWalNewRsp resultRsp = {0};
7,342,143✔
3498

3499
  void* pTask = sStreamReaderInfo->pTask;
7,342,143✔
3500
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
7,342,143✔
3501

3502
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
7,342,143✔
3503
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,342,143✔
3504
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
7,341,155✔
3505
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,341,155✔
3506
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
7,339,611✔
3507

3508
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
7,339,611✔
3509
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
7,341,706✔
3510

3511
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
7,341,706✔
3512

3513
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
284,379✔
3514
  buf = rpcMallocCont(size);
284,615✔
3515
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
284,615✔
3516
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
284,615✔
3517
  printIndexHash(resultRsp.indexHash, pTask);
284,615✔
3518

3519
end:
7,342,143✔
3520
  if (resultRsp.totalRows == 0) {
7,342,143✔
3521
    buf = rpcMallocCont(sizeof(int64_t));
7,057,327✔
3522
    *(int64_t *)buf = resultRsp.ver;
7,057,327✔
3523
    size = sizeof(int64_t);
7,057,327✔
3524
    code = TSDB_CODE_STREAM_NO_DATA;
7,057,327✔
3525
  }
3526
  SRpcMsg rsp = {
7,342,143✔
3527
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3528
  tmsgSendRsp(&rsp);
7,341,371✔
3529
  if (code == TSDB_CODE_STREAM_NO_DATA){
7,342,143✔
3530
    code = 0;
7,057,327✔
3531
  }
3532

3533
  blockDataDestroy(resultRsp.dataBlock);
7,342,143✔
3534
  blockDataDestroy(resultRsp.deleteBlock);
7,341,371✔
3535
  blockDataDestroy(resultRsp.tableBlock);
7,341,371✔
3536
  tSimpleHashCleanup(resultRsp.indexHash);
7,342,143✔
3537
  tSimpleHashCleanup(resultRsp.uidHash);
7,342,143✔
3538
  STREAM_PRINT_LOG_END_WITHID(code, lino);
7,339,827✔
3539

3540
  return code;
7,342,143✔
3541
}
3542

3543
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
965,823✔
3544
  int32_t      code = 0;
965,823✔
3545
  int32_t      lino = 0;
965,823✔
3546
  void*        buf = NULL;
965,823✔
3547
  size_t       size = 0;
965,823✔
3548
  SSTriggerWalNewRsp resultRsp = {0};
965,823✔
3549
  SSDataBlock* pBlock1 = NULL;
965,823✔
3550
  SSDataBlock* pBlock2 = NULL;
965,823✔
3551
  
3552
  void* pTask = sStreamReaderInfo->pTask;
965,823✔
3553
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
965,823✔
3554

3555
  SSDataBlock* dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
965,823✔
3556
  STREAM_CHECK_RET_GOTO(createOneDataBlock(dataBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
965,823✔
3557
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
965,823✔
3558
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
965,823✔
3559
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
965,051✔
3560
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
965,051✔
3561
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
965,823✔
3562

3563
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
965,823✔
3564
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
965,823✔
3565

3566
  if (!sStreamReaderInfo->isVtableStream){
252,033✔
3567
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
153,091✔
3568
  
3569
    blockDataTransform(pBlock2, resultRsp.dataBlock);
153,091✔
3570
    blockDataDestroy(resultRsp.dataBlock);
153,091✔
3571
    resultRsp.dataBlock = pBlock2;
153,091✔
3572
    pBlock2 = NULL;
153,091✔
3573
  }
3574

3575
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
252,033✔
3576
  buf = rpcMallocCont(size);
251,799✔
3577
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
252,033✔
3578
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
251,799✔
3579
  printIndexHash(resultRsp.indexHash, pTask);
252,033✔
3580

3581
end:
965,823✔
3582
  if (resultRsp.totalRows == 0) {
965,823✔
3583
    buf = rpcMallocCont(sizeof(int64_t));
713,790✔
3584
    *(int64_t *)buf = resultRsp.ver;
713,790✔
3585
    size = sizeof(int64_t);
713,790✔
3586
    code = TSDB_CODE_STREAM_NO_DATA;
713,790✔
3587
  }
3588
  SRpcMsg rsp = {
965,823✔
3589
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3590
  tmsgSendRsp(&rsp);
965,051✔
3591
  if (code == TSDB_CODE_STREAM_NO_DATA){
965,823✔
3592
    code = 0;
713,790✔
3593
  }
3594

3595
  blockDataDestroy(pBlock1);
965,823✔
3596
  blockDataDestroy(pBlock2);
965,823✔
3597
  blockDataDestroy(resultRsp.dataBlock);
965,823✔
3598
  blockDataDestroy(resultRsp.deleteBlock);
965,823✔
3599
  blockDataDestroy(resultRsp.tableBlock);
965,823✔
3600
  tSimpleHashCleanup(resultRsp.indexHash);
965,823✔
3601
  tSimpleHashCleanup(resultRsp.uidHash);
965,823✔
3602
  STREAM_PRINT_LOG_END_WITHID(code, lino);
965,587✔
3603

3604
  return code;
965,587✔
3605
}
3606

3607
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
293,775✔
3608
  int32_t code = 0;
293,775✔
3609
  int32_t lino = 0;
293,775✔
3610
  void*   buf = NULL;
293,775✔
3611
  size_t  size = 0;
293,775✔
3612
  SArray** gInfo = NULL;
293,775✔
3613
  
3614
  void* pTask = sStreamReaderInfo->pTask;
293,775✔
3615
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
293,952✔
3616

3617
  gInfo = taosHashAcquire(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
293,952✔
3618
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
293,952✔
3619
  SStreamGroupInfo pGroupInfo = {0};
293,952✔
3620
  pGroupInfo.gInfo = *gInfo;
293,952✔
3621

3622
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
293,952✔
3623
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3624
  buf = rpcMallocCont(size);
293,952✔
3625
  STREAM_CHECK_NULL_GOTO(buf, terrno);
293,775✔
3626
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
293,775✔
3627
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3628
end:
293,952✔
3629
  taosHashRelease(sStreamReaderInfo->groupIdMap, gInfo);
293,952✔
3630
  if (code != 0) {
293,952✔
UNCOV
3631
    rpcFreeCont(buf);
×
UNCOV
3632
    buf = NULL;
×
UNCOV
3633
    size = 0;
×
3634
  }
3635
  STREAM_PRINT_LOG_END_WITHID(code, lino);
293,952✔
3636
  SRpcMsg rsp = {
293,952✔
3637
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3638
  tmsgSendRsp(&rsp);
293,952✔
3639

3640
  return code;
293,952✔
3641
}
3642

3643
static int32_t setVtableInfo(SVnode* pVnode, SArray* infos, SArray* cids, int64_t uid, uint64_t gid, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo) {
187,466✔
3644
  int32_t              code = 0;
187,466✔
3645
  int32_t              lino = 0;
187,466✔
3646
  void* pTask = sStreamReaderInfo->pTask;
187,466✔
3647

3648
  VTableInfo* vTable = taosArrayReserve(infos, 1);
187,466✔
3649
  STREAM_CHECK_NULL_GOTO(vTable, terrno);
187,466✔
3650
  vTable->uid = uid;
187,466✔
3651
  vTable->gId = gid;
187,466✔
3652

3653
  ST_TASK_DLOG("vgId:%d %s put vtable uid:%"PRId64, TD_VID(pVnode), __func__, uid);
187,466✔
3654

3655
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, ver, uid);
187,466✔
3656
  if (code != 0) {
187,466✔
UNCOV
3657
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
UNCOV
3658
    goto end;
×
3659
  }
3660
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
187,466✔
3661
    vTable->cols.nCols = metaReader->me.colRef.nCols;
10,840✔
3662
    vTable->cols.version = metaReader->me.colRef.version;
10,840✔
3663
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
10,840✔
3664
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
10,840✔
3665
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
65,040✔
3666
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
54,200✔
3667
    }
3668
  } else {
3669
    vTable->cols.nCols = taosArrayGetSize(cids);
176,626✔
3670
    vTable->cols.version = metaReader->me.colRef.version;
176,626✔
3671
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
176,626✔
3672
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
176,626✔
3673
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
672,366✔
3674
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
2,087,748✔
3675
        if (metaReader->me.colRef.pColRef[j].hasRef &&
1,910,420✔
3676
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
1,410,280✔
3677
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
318,412✔
3678
          break;
318,412✔
3679
        }
3680
      }
3681
    }
3682
  }
3683
  tDecoderClear(&metaReader->coder);
187,466✔
3684

3685
end:
187,466✔
3686
  return code;
187,466✔
3687
}
3688

3689
static int32_t getAllVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
75,656✔
3690
  int32_t              code = 0;
75,656✔
3691
  int32_t              lino = 0;
75,656✔
3692
  void* pTask = sStreamReaderInfo->pTask;
75,656✔
3693
  SArray*              pTableListArray = NULL;
75,656✔
3694

3695

3696
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
75,656✔
3697
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
75,656✔
3698

3699
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
75,656✔
3700
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
75,656✔
3701

3702
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
263,122✔
3703
    SStreamTableKeyInfo* pKeyInfo = taosArrayGetP(pTableListArray, i);
187,466✔
3704
    if (pKeyInfo == NULL || pKeyInfo->markedDeleted) {
187,466✔
UNCOV
3705
      continue;
×
3706
    }
3707
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, pKeyInfo->uid, pKeyInfo->groupId, ver, metaReader, sStreamReaderInfo);
187,466✔
3708
    if (code != 0) {
187,466✔
UNCOV
3709
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, pKeyInfo->uid, tstrerror(code));
×
UNCOV
3710
      code = 0;
×
UNCOV
3711
      continue;
×
3712
    }
3713
  }
3714

3715
end:
75,656✔
3716
  taosArrayDestroyP(pTableListArray, taosMemFree);
75,656✔
3717
  return code;
75,656✔
3718
}
3719

UNCOV
3720
static int32_t getSpicificVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* uids, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
×
UNCOV
3721
  int32_t              code = 0;
×
UNCOV
3722
  int32_t              lino = 0;
×
UNCOV
3723
  void* pTask = sStreamReaderInfo->pTask;
×
3724

UNCOV
3725
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(uids), sizeof(VTableInfo));
×
UNCOV
3726
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
×
3727

UNCOV
3728
  for (size_t i = 0; i < taosArrayGetSize(uids); i++) {
×
UNCOV
3729
    int64_t* uid = taosArrayGet(uids, i);
×
UNCOV
3730
    STREAM_CHECK_NULL_GOTO(uid, terrno);
×
3731

UNCOV
3732
    taosRLockLatch(&sStreamReaderInfo->lock);
×
UNCOV
3733
    uint64_t groupId = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, *uid);
×
UNCOV
3734
    taosRUnLockLatch(&sStreamReaderInfo->lock);
×
UNCOV
3735
    if (groupId == -1) {
×
UNCOV
3736
      ST_TASK_WLOG("vgId:%d %s uid:%"PRId64" not found in stream group", TD_VID(pVnode), __func__, *uid);
×
UNCOV
3737
      continue;
×
3738
    }
UNCOV
3739
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, *uid, groupId, ver, metaReader, sStreamReaderInfo);
×
UNCOV
3740
    if (code != 0) {
×
UNCOV
3741
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, *uid, tstrerror(code));
×
UNCOV
3742
      code = 0;
×
UNCOV
3743
      continue;
×
3744
    }
3745
  }
3746
  
UNCOV
3747
end:
×
UNCOV
3748
  return code;
×
3749
}
3750

3751
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
75,656✔
3752
  int32_t              code = 0;
75,656✔
3753
  int32_t              lino = 0;
75,656✔
3754
  void*                buf = NULL;
75,656✔
3755
  size_t               size = 0;
75,656✔
3756
  SStreamMsgVTableInfo vTableInfo = {0};
75,656✔
3757
  SMetaReader          metaReader = {0};
75,656✔
3758

3759
  void* pTask = sStreamReaderInfo->pTask;
75,656✔
3760
  ST_TASK_DLOG("vgId:%d %s start, version:%"PRId64, TD_VID(pVnode), __func__, req->virTableInfoReq.ver);
75,656✔
3761

3762
  SArray* cids = req->virTableInfoReq.cids;
75,656✔
3763
  STREAM_CHECK_NULL_GOTO(cids, terrno);
75,656✔
3764

3765
  if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
75,656✔
3766
    (void)atomic_val_compare_exchange_8(&sStreamReaderInfo->isVtableOnlyTs, 0, 1);
10,840✔
3767
  }
3768
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
75,656✔
3769

3770
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
75,656✔
3771
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
75,656✔
3772
  } else {
3773
    STREAM_CHECK_RET_GOTO(getSpicificVinfo(pVnode, &vTableInfo, req->virTableInfoReq.uids, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
×
3774
  }
3775
  ST_TASK_DLOG("vgId:%d %s end, size:%"PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(vTableInfo.infos));
75,656✔
3776
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
75,656✔
3777

3778
end:
75,656✔
3779
  tDestroySStreamMsgVTableInfo(&vTableInfo);
75,656✔
3780
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
75,656✔
3781
  STREAM_PRINT_LOG_END_WITHID(code, lino);
75,656✔
3782
  SRpcMsg rsp = {
75,656✔
3783
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3784
  tmsgSendRsp(&rsp);
75,656✔
3785
  return code;
75,656✔
3786
}
3787

3788
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
134,454✔
3789
  int32_t                   code = 0;
134,454✔
3790
  int32_t                   lino = 0;
134,454✔
3791
  void*                     buf = NULL;
134,454✔
3792
  size_t                    size = 0;
134,454✔
3793
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
134,454✔
3794
  SMetaReader               metaReader = {0};
134,454✔
3795
  void*                     pTask = sStreamReaderInfo->pTask;
134,454✔
3796

3797
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64, TD_VID(pVnode), __func__, req->origTableInfoReq.ver);
134,454✔
3798

3799
  SArray* cols = req->origTableInfoReq.cols;
134,454✔
3800
  STREAM_CHECK_NULL_GOTO(cols, terrno);
134,454✔
3801

3802
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
134,454✔
3803

3804
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
134,454✔
3805

3806
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
134,454✔
3807
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
496,025✔
3808
    OTableInfo*    oInfo = taosArrayGet(cols, i);
361,772✔
3809
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
361,772✔
3810
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
361,772✔
3811
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
361,772✔
3812
    code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionName(&metaReader, req->origTableInfoReq.ver, oInfo->refTableName);
361,772✔
3813
    if (code != 0) {
361,000✔
3814
      code = 0;
201✔
3815
      ST_TASK_ELOG("vgId:%d %s get table entry by name:%s failed, msg:%s", TD_VID(pVnode), __func__, oInfo->refTableName, tstrerror(code));
201✔
3816
      continue;
201✔
3817
    }
3818
    vTableInfo->uid = metaReader.me.uid;
360,799✔
3819
    ST_TASK_DLOG("vgId:%d %s get original uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
360,799✔
3820

3821
    SSchemaWrapper* sSchemaWrapper = NULL;
361,571✔
3822
    if (metaReader.me.type == TD_CHILD_TABLE) {
361,571✔
3823
      int64_t suid = metaReader.me.ctbEntry.suid;
359,706✔
3824
      vTableInfo->suid = suid;
359,706✔
3825
      tDecoderClear(&metaReader.coder);
359,706✔
3826
      STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->origTableInfoReq.ver, suid));
359,706✔
3827
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
359,505✔
3828
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
1,865✔
3829
      vTableInfo->suid = 0;
1,865✔
3830
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
1,865✔
3831
    } else {
UNCOV
3832
      ST_TASK_ELOG("invalid table type:%d", metaReader.me.type);
×
3833
    }
3834

3835
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
1,236,720✔
3836
      SSchema* s = sSchemaWrapper->pSchema + j;
1,236,519✔
3837
      if (strcmp(s->name, oInfo->refColName) == 0) {
1,236,720✔
3838
        vTableInfo->cid = s->colId;
361,571✔
3839
        break;
361,571✔
3840
      }
3841
    }
3842
    if (vTableInfo->cid == 0) {
361,772✔
UNCOV
3843
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
3844
              oInfo->refTableName);
3845
    }
3846
    tDecoderClear(&metaReader.coder);
361,571✔
3847
  }
3848

3849
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
134,253✔
3850

3851
end:
134,454✔
3852
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
134,454✔
3853
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
134,454✔
3854
  STREAM_PRINT_LOG_END_WITHID(code, lino);
134,239✔
3855
  SRpcMsg rsp = {
134,454✔
3856
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3857
  tmsgSendRsp(&rsp);
134,454✔
3858
  return code;
134,454✔
3859
}
3860

3861
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
866,654✔
3862
  int32_t                   code = 0;
866,654✔
3863
  int32_t                   lino = 0;
866,654✔
3864
  void*                     buf = NULL;
866,654✔
3865
  size_t                    size = 0;
866,654✔
3866
  SSDataBlock* pBlock = NULL;
866,654✔
3867

3868
  SMetaReader               metaReader = {0};
866,654✔
3869
  SMetaReader               metaReaderStable = {0};
866,654✔
3870
  int64_t streamId = req->base.streamId;
866,654✔
3871
  stsDebug("vgId:%d %s start, ver:%"PRId64, TD_VID(pVnode), __func__, req->virTablePseudoColReq.ver);
866,654✔
3872

3873
  SArray* cols = req->virTablePseudoColReq.cids;
866,654✔
3874
  STREAM_CHECK_NULL_GOTO(cols, terrno);
866,654✔
3875

3876
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
866,654✔
3877
  STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->virTablePseudoColReq.ver, req->virTablePseudoColReq.uid));
866,654✔
3878

3879
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
866,418✔
3880

3881
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
866,418✔
3882
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
866,654✔
3883
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
2,113✔
3884
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
2,113✔
3885
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
2,113✔
3886
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
2,113✔
3887
    pBlock->info.rows = 1;
2,113✔
3888
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
2,113✔
3889
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,113✔
3890
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
2,113✔
3891
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
864,541✔
3892
    int64_t suid = metaReader.me.ctbEntry.suid;
864,541✔
3893
    sStreamReaderInfo->storageApi.metaReaderFn.readerReleaseLock(&metaReader);
864,541✔
3894
    sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
864,541✔
3895

3896
    STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReaderStable, req->virTablePseudoColReq.ver, suid));
864,541✔
3897
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
864,541✔
3898
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
2,137,430✔
3899
      col_id_t* id = taosArrayGet(cols, i);
1,272,889✔
3900
      STREAM_CHECK_NULL_GOTO(id, terrno);
1,272,889✔
3901
      if (*id == -1) {
1,272,889✔
3902
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
858,365✔
3903
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
858,365✔
3904
        continue;
858,365✔
3905
      }
3906
      size_t j = 0;
414,524✔
3907
      for (; j < sSchemaWrapper->nCols; j++) {
789,248✔
3908
        SSchema* s = sSchemaWrapper->pSchema + j;
789,248✔
3909
        if (s->colId == *id) {
789,248✔
3910
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
414,524✔
3911
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
414,524✔
3912
          break;
414,524✔
3913
        }
3914
      }
3915
      if (j == sSchemaWrapper->nCols) {
414,524✔
UNCOV
3916
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
UNCOV
3917
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3918
      }
3919
    }
3920
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
864,541✔
3921
    pBlock->info.rows = 1;
864,541✔
3922
    
3923
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
2,137,430✔
3924
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
1,272,889✔
3925
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
1,272,889✔
3926

3927
      if (pDst->info.colId == -1) {
1,272,889✔
3928
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
858,365✔
3929
        continue;
858,365✔
3930
      }
3931
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
414,524✔
UNCOV
3932
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
UNCOV
3933
        continue;
×
3934
      }
3935

3936
      STagVal val = {0};
414,524✔
3937
      val.cid = pDst->info.colId;
414,524✔
3938
      const char* p = sStreamReaderInfo->storageApi.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
414,524✔
3939

3940
      char* data = NULL;
414,524✔
3941
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
414,524✔
3942
        data = tTagValToData((const STagVal*)p, false);
414,524✔
3943
      } else {
UNCOV
3944
        data = (char*)p;
×
3945
      }
3946

3947
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
414,524✔
3948
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3949

3950
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
414,524✔
3951
          (data != NULL)) {
3952
        taosMemoryFree(data);
368,704✔
3953
      }
3954
    }
3955
  } else {
UNCOV
3956
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3957
    code = TSDB_CODE_INVALID_PARA;
×
3958
    goto end;
×
3959
  }
3960
  
3961
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
866,654✔
3962
  printDataBlock(pBlock, __func__, "", streamId);
866,654✔
3963
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
866,654✔
3964

3965
end:
866,654✔
3966
  if(size == 0){
866,654✔
UNCOV
3967
    code = TSDB_CODE_STREAM_NO_DATA;
×
3968
  }
3969
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReaderStable);
866,654✔
3970
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
866,654✔
3971
  STREAM_PRINT_LOG_END(code, lino);
866,654✔
3972
  SRpcMsg rsp = {
866,654✔
3973
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3974
  tmsgSendRsp(&rsp);
866,654✔
3975
  blockDataDestroy(pBlock);
866,654✔
3976
  return code;
866,654✔
3977
}
3978

3979
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
6,871,024✔
3980
  int32_t            code = 0;
6,871,024✔
3981
  int32_t            lino = 0;
6,871,024✔
3982
  void*              buf = NULL;
6,871,024✔
3983
  size_t             size = 0;
6,871,024✔
3984
  void*              taskAddr = NULL;
6,871,024✔
3985
  SArray*            pResList = NULL;
6,871,024✔
3986
  bool               hasNext = false;
6,871,024✔
3987
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = NULL;
6,871,024✔
3988

3989
  SResFetchReq req = {0};
6,871,024✔
3990
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
6,871,024✔
3991
                              TSDB_CODE_QRY_INVALID_INPUT);
3992
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
6,870,243✔
3993
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
6,871,024✔
3994

3995
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
6,769,578✔
3996
  sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
6,769,578✔
3997
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
6,769,578✔
3998
  sStreamReaderCalcInfo->rtInfo.execId = req.execId;
6,769,578✔
3999

4000
  void* pTask = sStreamReaderCalcInfo->pTask;
6,769,578✔
4001
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
6,769,578✔
4002
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
4003

4004
  if (req.reset) {
6,769,578✔
4005
    int64_t uid = 0;
4,546,579✔
4006
    if (req.dynTbname && !req.pStRtFuncInfo->isMultiGroupCalc) {
4,546,579✔
4007
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
86,808✔
4008
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
86,808✔
4009
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
86,808✔
4010
        if (pValue != NULL && pValue->isTbname) {
86,808✔
4011
          uid = pValue->uid;
86,808✔
4012
          break;
86,808✔
4013
        }
4014
      }
4015
    }
4016
    
4017
    SReadHandle handle = {0};
4,546,579✔
4018
    handle.vnode = pVnode;
4,546,579✔
4019
    handle.pMsgCb = &pVnode->msgCb;
4,546,579✔
4020
    handle.pWorkerCb = pInfo->workerCb;
4,546,579✔
4021
    handle.uid = uid;
4,546,579✔
4022
    handle.cacheSttStatis = true;
4,546,579✔
4023

4024
    initStorageAPI(&handle.api);
4,546,579✔
4025
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
4,546,579✔
4026
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
3,457,902✔
4027
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,650,230✔
4028
      if (node != NULL) {
3,650,230✔
4029
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
723,610✔
4030
      } else {
4031
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
2,926,620✔
4032
      }
4033

4034
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
3,650,230✔
4035
      if (node != NULL) {
3,650,230✔
4036
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
77,539✔
4037
      } else {
4038
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
3,572,691✔
4039
      }      
4040
    }
4041

4042
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
4,546,579✔
4043
    sStreamReaderCalcInfo->rtInfo.funcInfo.hasPlaceHolder = sStreamReaderCalcInfo->hasPlaceHolder;
4,546,579✔
4044
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
4,546,579✔
4045

4046
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
4,546,579✔
4047
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
592,822✔
4048
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
592,822✔
4049
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
4050
                                                    req.taskId));
4051
      STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
592,822✔
4052
    } else {
4053
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
3,953,757✔
4054
    }
4055

4056
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
4,546,322✔
4057
  }
4058

4059
  if (req.pOpParam != NULL) {
6,769,064✔
4060
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
334,458✔
4061
  }
4062

4063
  pResList = taosArrayInit(4, POINTER_BYTES);
6,769,064✔
4064
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
6,769,316✔
4065
  uint64_t ts = 0;
6,769,316✔
4066
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
6,769,578✔
4067

4068
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
17,348,602✔
4069
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
10,580,689✔
4070
    if (pBlock == NULL) continue;
10,580,689✔
4071
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
10,580,689✔
4072
/*    
4073
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
4074
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
4075
      printDataBlock(pBlock, __func__, "fetch filter");
4076
    }
4077
*/    
4078
  }
4079

4080
end:
6,871,423✔
4081
  code = streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision);
6,871,001✔
4082

4083
  if (sStreamReaderCalcInfo && sStreamReaderCalcInfo->rtInfo.funcInfo.isMultiGroupCalc) {
6,871,024✔
NEW
4084
    sStreamReaderCalcInfo->rtInfo.funcInfo.pStreamPesudoFuncVals = NULL;
×
NEW
4085
    sStreamReaderCalcInfo->rtInfo.funcInfo.pStreamPartColVals = NULL;
×
4086
  }
4087
  
4088
  taosArrayDestroy(pResList);
6,871,024✔
4089
  streamReleaseTask(taskAddr);
6,871,024✔
4090
  
4091
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
6,871,024✔
UNCOV
4092
    code = TDB_CODE_SUCCESS;
×
4093
  }
4094
  STREAM_PRINT_LOG_END(code, lino);
6,871,024✔
4095
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
6,871,024✔
4096
  tmsgSendRsp(&rsp);
6,871,024✔
4097
  tDestroySResFetchReq(&req);
6,870,207✔
4098
  if (TDB_CODE_SUCCESS != code) {
6,871,024✔
UNCOV
4099
    ST_TASK_ELOG("vgId:%d %s failed, code:%d - %s", TD_VID(pVnode), __func__,
×
4100
                 code, tstrerror(code));
4101
  }
4102
  return code;
6,871,024✔
4103
}
4104

4105
static int32_t initTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SVnode* pVnode) {
33,353,721✔
4106
  int32_t code = 0;
33,353,721✔
4107
  if (sStreamReaderInfo->tableList.pTableList != NULL) {  
33,353,721✔
4108
    return code;
33,053,739✔
4109
  }
4110
  taosWLockLatch(&sStreamReaderInfo->lock);
301,621✔
4111
  sStreamReaderInfo->pVnode = pVnode;
301,621✔
4112
  initStorageAPI(&sStreamReaderInfo->storageApi);
301,621✔
4113
  if (sStreamReaderInfo->tableList.pTableList == NULL) {
301,405✔
4114
    code = initStreamTableListInfo(&sStreamReaderInfo->tableList);
301,621✔
4115
    if (code == 0) {
301,621✔
4116
      code = generateTablistForStreamReader(pVnode, sStreamReaderInfo);
301,621✔
4117
      if (code != 0) {
301,621✔
UNCOV
4118
        qStreamDestroyTableInfo(&sStreamReaderInfo->tableList);
×
4119
      } else {
4120
        sStreamReaderInfo->tableList.version = pVnode->state.applied;
301,621✔
4121
        stDebug("vgId:%d %s init table list for stream reader, table num:%zu, version:%" PRId64,
301,621✔
4122
                TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList), sStreamReaderInfo->tableList.version);
4123
      }
4124
    }
4125
  }
4126
  taosWUnLockLatch(&sStreamReaderInfo->lock);
301,621✔
4127
  return code;
301,621✔
4128
}
4129

4130
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
40,385,959✔
4131
  int32_t                   code = 0;
40,385,959✔
4132
  int32_t                   lino = 0;
40,385,959✔
4133
  SSTriggerPullRequestUnion req = {0};
40,385,959✔
4134
  void*                     taskAddr = NULL;
40,387,400✔
4135
  bool                      sendRsp = false;
40,382,781✔
4136

4137
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
40,382,781✔
4138
  if (!syncIsReadyForRead(pVnode->sync)) {
40,384,763✔
4139
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
140,037✔
4140
    return 0;
140,037✔
4141
  }
4142

4143
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
40,246,034✔
4144
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
6,871,024✔
4145
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
33,369,392✔
4146
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
33,375,996✔
4147
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
33,376,231✔
4148
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
33,375,996✔
4149
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
33,373,070✔
4150
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId, pVnode->state.applied);
4151
    SStreamTriggerReaderInfo* sStreamReaderInfo = qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
33,374,614✔
4152
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
33,375,224✔
4153
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
33,354,250✔
4154
    sendRsp = true;
33,355,159✔
4155
    switch (req.base.type) {
33,355,159✔
4156
      case STRIGGER_PULL_SET_TABLE:
134,454✔
4157
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
134,454✔
4158
        break;
134,454✔
4159
      case STRIGGER_PULL_LAST_TS:
292,218✔
4160
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
292,218✔
4161
        break;
292,218✔
4162
      case STRIGGER_PULL_FIRST_TS:
272,687✔
4163
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
272,687✔
4164
        break;
272,687✔
4165
      case STRIGGER_PULL_TSDB_META:
491,546✔
4166
      case STRIGGER_PULL_TSDB_META_NEXT:
4167
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
491,546✔
4168
        break;
491,546✔
4169
      case STRIGGER_PULL_TSDB_TS_DATA:
135,642✔
4170
        if (sStreamReaderInfo->isVtableStream) {
135,642✔
4171
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
1,544✔
4172
        } else {
4173
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
134,098✔
4174
        }
4175
        break;
135,642✔
4176
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
113,300✔
4177
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4178
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
113,300✔
4179
        break;
56,650✔
4180
      case STRIGGER_PULL_TSDB_CALC_DATA:
6,468,222✔
4181
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4182
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
6,468,222✔
4183
        break;
6,466,296✔
4184
      case STRIGGER_PULL_TSDB_DATA:
440,157✔
4185
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4186
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
440,157✔
4187
        break;
436,297✔
4188
      case STRIGGER_PULL_GROUP_COL_VALUE:
293,952✔
4189
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
293,952✔
4190
        break;
293,952✔
4191
      case STRIGGER_PULL_VTABLE_INFO:
75,656✔
4192
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
75,656✔
4193
        break;
75,656✔
4194
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
866,654✔
4195
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
866,654✔
4196
        break;
866,654✔
4197
      case STRIGGER_PULL_OTABLE_INFO:
134,454✔
4198
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
134,454✔
4199
        break;
134,454✔
4200
      case STRIGGER_PULL_WAL_META_NEW:
11,920,990✔
4201
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
11,920,990✔
4202
        break;
11,919,917✔
4203
      case STRIGGER_PULL_WAL_DATA_NEW:
7,342,143✔
4204
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
7,342,143✔
4205
        break;
7,341,942✔
4206
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,407,660✔
4207
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,407,660✔
4208
        break;
3,406,054✔
4209
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
965,823✔
4210
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
965,823✔
4211
        break;
965,823✔
4212
      default:
16✔
4213
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
16✔
4214
        sendRsp = false;
1,058✔
4215
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
1,058✔
4216
    }
4217
  } else {
4218
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
1✔
UNCOV
4219
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4220
  }
4221
end:
33,364,246✔
4222

4223
  streamReleaseTask(taskAddr);
33,373,400✔
4224

4225
  tDestroySTriggerPullRequest(&req);
33,376,577✔
4226
  STREAM_PRINT_LOG_END(code, lino);
33,366,925✔
4227
  if (!sendRsp) {
33,374,426✔
4228
    SRpcMsg rsp = {
41,948✔
4229
      .code = code,
4230
      .pCont = pMsg->info.rsp,
20,974✔
4231
      .contLen = pMsg->info.rspLen,
20,974✔
4232
      .info = pMsg->info,
4233
    };
4234
    tmsgSendRsp(&rsp);
20,974✔
4235
  }
4236
  return code;
33,374,426✔
4237
}
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