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

taosdata / TDengine / #5054

13 May 2026 12:00PM UTC coverage: 73.358% (-0.04%) from 73.397%
#5054

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

771 existing lines in 142 files now uncovered.

281543 of 383795 relevant lines covered (73.36%)

133389099.84 hits per line

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

83.89
/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,758,973✔
65
  int64_t suid = 0;
7,758,973✔
66
  if (!sStreamReaderInfo->isVtableStream) {
7,758,973✔
67
    suid = sStreamReaderInfo->suid;
7,676,411✔
68
    goto end;
7,676,153✔
69
  }
70

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

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

84
end:
7,758,715✔
85
  return suid;
7,758,715✔
86
}
87

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

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

94
  if (*c1 < *c2) {
134,502✔
95
    return -1;
133,482✔
96
  } else if (*c1 > *c2) {
1,020✔
97
    return 1;
1,020✔
98
  }
99

100
  return 0;
×
101
}
102

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

107
  if (c1->colId < c2->colId) {
134,502✔
108
    return -1;
133,482✔
109
  } else if (c1->colId > c2->colId) {
1,020✔
110
    return 1;
1,020✔
111
  }
112

113
  return 0;
×
114
}
115

116
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
10,756,684✔
117
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
10,756,684✔
118
  if (pSrc == NULL) {
10,759,428✔
119
    return terrno;
×
120
  }
121

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
10,759,428✔
123
  return 0;
10,754,656✔
124
}
125

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

132
  return code;
9,057,164✔
133
}
134

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

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

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

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
1,777,400✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
1,777,400✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
781,047✔
165
      suid == sStreamReaderInfo->suid) {
456,458✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
13,019✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
13,019✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
13,019✔
169
    if (gid == (uint64_t)-1) return true;
13,019✔
170
  }
171
  return false;
1,765,027✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
12,366,038✔
175
  int32_t  ret = false;
12,366,038✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
12,366,038✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
7,294,507✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
2,688,421✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
7,759,094✔
181
  if (*id == -1) goto end;
7,761,957✔
182
  ret = true;
4,902,833✔
183

184
end:
12,375,916✔
185
  stTrace("%s ret:%d %p %p check suid:%" PRId64 " uid:%" PRId64 " gid:%"PRIu64, __func__, ret, sStreamReaderInfo, sStreamReaderInfo->tableList.gIdMap, suid, uid, *id);
12,375,916✔
186
  return ret;
12,371,708✔
187
}
188

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

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
15,176,041✔
194
  bool ret = false;
15,176,041✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
15,176,041✔
196
  if (sStreamReaderInfo->isVtableStream) {
15,176,953✔
197
    int64_t tmp[2] = {suid, uid};
2,828,425✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
2,828,425✔
199
      *id = uid;
1,361,916✔
200
      ret = true;
1,361,916✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
12,347,149✔
204
  }
205

206
end:
15,178,386✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
15,178,386✔
208
  return ret;
15,182,876✔
209
}
210

211
static int32_t  qTransformStreamTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, void* pTableListInfo, StreamTableListInfo* tableInfo){
255,625✔
212
  SArray* pList = qStreamGetTableListArray(pTableListInfo);
255,625✔
213
  int32_t totalSize = taosArrayGetSize(pList);
255,625✔
214
  int32_t code = 0;
255,625✔
215
  void* pTask = sStreamReaderInfo->pTask;
255,625✔
216
  for (int32_t i = 0; i < totalSize; ++i) {
719,173✔
217
    STableKeyInfo* info = taosArrayGet(pList, i);
463,548✔
218
    if (info == NULL) {
463,548✔
219
      continue;
×
220
    }
221
    code = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
463,548✔
222
    if (code != 0){
463,265✔
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);
463,265✔
227
    if (code != 0){
462,804✔
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);
462,804✔
232
    if (code != 0){
463,548✔
233
      return code;
×
234
    }
235
  }
236
  return 0;
255,625✔
237
}
238

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

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

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

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

281
static int32_t buildTsRsp(const SStreamTsResponse* tsRsp, void** data, size_t* size) {
435,550✔
282
  int32_t code = 0;
435,550✔
283
  int32_t lino = 0;
435,550✔
284
  void*   buf = NULL;
435,550✔
285
  int32_t len = tSerializeSStreamTsResponse(NULL, 0, tsRsp);
435,550✔
286
  STREAM_CHECK_CONDITION_GOTO(len <= 0, TSDB_CODE_INVALID_PARA);
434,979✔
287
  buf = rpcMallocCont(len);
434,979✔
288
  STREAM_CHECK_NULL_GOTO(buf, terrno);
435,833✔
289
  int32_t actLen = tSerializeSStreamTsResponse(buf, len, tsRsp);
435,833✔
290
  STREAM_CHECK_CONDITION_GOTO(actLen != len, TSDB_CODE_INVALID_PARA);
435,541✔
291
  *data = buf;
435,541✔
292
  *size = len;
435,541✔
293
  buf = NULL;
434,509✔
294
end:
434,509✔
295
  rpcFreeCont(buf);
434,509✔
296
  return code;
435,537✔
297
}
298

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
7,815,721✔
301
  int32_t code = 0;
7,815,721✔
302
  int32_t lino = 0;
7,815,721✔
303
  void*   buf = NULL;
7,815,721✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
7,815,721✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
730,228✔
306
  buf = rpcMallocCont(dataEncodeSize);
730,228✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
729,998✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
729,998✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
729,988✔
310
  *data = buf;
729,988✔
311
  *size = dataEncodeSize;
729,988✔
312
  buf = NULL;
729,988✔
313
end:
7,821,415✔
314
  rpcFreeCont(buf);
7,821,415✔
315
  return code;
7,817,527✔
316
}
317

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

322
  void*   buf = NULL;
160,965✔
323

324
  int32_t blockNum = 0;
160,965✔
325
  size_t  dataEncodeBufSize = 0;
160,965✔
326
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
376,704✔
327
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
215,451✔
328
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
215,739✔
329
    int32_t blockSize = blockGetEncodeSize(pBlock);
215,739✔
330
    dataEncodeBufSize += blockSize;
215,739✔
331
    blockNum++;
215,739✔
332
  }
333
  buf = rpcMallocCont(INT_BYTES + dataEncodeBufSize);
161,253✔
334
  STREAM_CHECK_NULL_GOTO(buf, terrno);
160,965✔
335

336
  char* dataBuf = (char*)buf;
160,965✔
337
  *((int32_t*)(dataBuf)) = blockNum;
160,965✔
338
  dataBuf += INT_BYTES;
160,965✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
376,704✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
215,739✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
215,739✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
215,739✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
215,739✔
344
    dataBuf += actualLen;
215,739✔
345
  }
346
  *data = buf;
160,965✔
347
  *size = INT_BYTES + dataEncodeBufSize;
161,253✔
348
  buf = NULL;
161,253✔
349
end:
161,253✔
350
  rpcFreeCont(buf);
161,253✔
351
  return code;
161,253✔
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) {
2,540,943✔
375
  int32_t code = 0;
2,540,943✔
376
  int32_t lino = 0;
2,540,943✔
377
  int32_t index = 0;
2,540,943✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
2,540,943✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
2,540,483✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
2,540,411✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
2,539,546✔
382

383
end:
2,540,410✔
384
  return code;
2,540,410✔
385
}
386

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

395
end:
4,260✔
396
  return code;
4,260✔
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,
29,412✔
408
                              int64_t ver) {
409
  int32_t    code = 0;
29,412✔
410
  int32_t    lino = 0;
29,412✔
411
  SDecoder   decoder = {0};
29,412✔
412
  SDeleteRes req = {0};
29,412✔
413
  void* pTask = sStreamReaderInfo->pTask;
29,412✔
414

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

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

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

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

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

451
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
3,688✔
452

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

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

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

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

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

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

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

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

554
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
43,522✔
555
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
21,761✔
556
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
21,761✔
557
    uint64_t id = 0;
21,761✔
558
    if(!uidInTableListOrigin(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id)) {
21,761✔
559
      continue;
20,679✔
560
    }
561

562
    if (sStreamReaderInfo->deleteOutTbl != 0) {
1,082✔
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) {
1,082✔
570
      if (uidList == NULL) {
1,082✔
571
        uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,082✔
572
        STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,082✔
573
      }
574
      STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pDropTbReq->uid), terrno);
2,164✔
575
    }
576
    
577
    ST_TASK_DLOG("stream reader scan drop uid %" PRId64 ", id %" PRIu64, pDropTbReq->uid, id);
1,082✔
578
  }
579
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDelOutTbl, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_DROP));
21,761✔
580

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

596
static int32_t qStreamModifyTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SArray* tableListAdd, SArray* tableListDel) {
106,192✔
597
  int32_t      code = 0;
106,192✔
598
  int32_t      lino = 0;
106,192✔
599
  void* pTask = sStreamReaderInfo->pTask;
106,192✔
600
  
601
  taosWLockLatch(&sStreamReaderInfo->lock);
106,192✔
602
  int32_t totalSize = taosArrayGetSize(tableListDel);
106,192✔
603
  for (int32_t i = 0; i < totalSize; ++i) {
105,972✔
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);
105,972✔
612
  for (int32_t i = 0; i < totalSize; ++i) {
143,014✔
613
    STableKeyInfo* info = taosArrayGet(tableListAdd, i);
36,822✔
614
    if (info == NULL) {
36,822✔
615
      continue;
×
616
    }
617
    int ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheTrigger, sStreamReaderInfo->pExprInfoTriggerTag, sStreamReaderInfo->numOfExprTriggerTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
36,822✔
618
    if (ret != 0){
36,822✔
619
      ST_TASK_WLOG("%s cacheTag trigger failed for uid:%" PRId64",code:%d", __func__, info->uid, ret);
7,863✔
620
      continue;
7,863✔
621
    }
622
    ret = cacheTag(sStreamReaderInfo->pVnode, sStreamReaderInfo->pTableMetaCacheCalc, sStreamReaderInfo->pExprInfoCalcTag, sStreamReaderInfo->numOfExprCalcTag, &sStreamReaderInfo->storageApi, info->uid, 0, NULL);
28,959✔
623
    if (ret != 0){
28,959✔
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));
28,959✔
628
    STREAM_CHECK_RET_GOTO(qStreamSetTableList(&sStreamReaderInfo->tableList, info->uid, info->groupId));
29,179✔
629
  }
630

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

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

641
  if (taosArrayGetSize(uidList) == 0) {
106,192✔
642
    return 0;
69,150✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
37,042✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
37,042✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

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

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

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

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

672
  if (sStreamReaderInfo->isVtableStream) {
79,145✔
673
    uidListAdd = taosArrayInit(8, sizeof(tb_uid_t));
6,368✔
674
    STREAM_CHECK_NULL_GOTO(uidListAdd, terrno);
6,368✔
675
  }
676
  
677
  SVCreateTbReq* pCreateReq = NULL;
79,145✔
678
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
158,290✔
679
    pCreateReq = req.pReqs + iReq;
79,145✔
680
    if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false)) {
79,145✔
681
      ST_TASK_DLOG("stream reader scan create table jump, %s", pCreateReq->name);
69,150✔
682
      continue;
69,150✔
683
    }
684
    ST_TASK_ILOG("stream reader scan create table %s", pCreateReq->name);
9,995✔
685
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
19,990✔
686
  }
687
  
688
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
79,145✔
689
  STREAM_CHECK_RET_GOTO(qStreamGetAddTable(sStreamReaderInfo, tableList, uidListAdd));
79,145✔
690
  if (sStreamReaderInfo->isVtableStream) {
79,145✔
691
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
6,368✔
692
  }
693

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

704
static int32_t processAutoCreateTableNew(SStreamTriggerReaderInfo* sStreamReaderInfo, SVCreateTbReq* pCreateReq, int64_t ver) {
1,697,674✔
705
  int32_t  code = 0;
1,697,674✔
706
  int32_t  lino = 0;
1,697,674✔
707
  void*    pTask = sStreamReaderInfo->pTask;
1,697,674✔
708
  SArray*  uidList = NULL;
1,698,835✔
709
  SArray*  tableList = NULL;
1,698,835✔
710

711
  ST_TASK_DLOG("%s start, name:%s uid:%"PRId64, __func__, pCreateReq->name, pCreateReq->uid);
1,698,547✔
712
  if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false) ||
1,701,351✔
713
      ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
2,378✔
714
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
1,696,523✔
715
    goto end;
1,696,242✔
716
  }
717
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,732✔
718
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,732✔
719
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
3,464✔
720
  ST_TASK_DLOG("stream reader scan auto create table %s", pCreateReq->name);
1,732✔
721

722
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,732✔
723
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,732✔
724
end:
1,694,874✔
725
  taosArrayDestroy(uidList);
1,698,835✔
726
  taosArrayDestroy(tableList);
1,697,748✔
727
  return code;
1,698,259✔
728
}
729

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

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

759
void getAlterColId(void* pVnode, int64_t uid, const char* colName, col_id_t* colId) {
566✔
760
  SSchemaWrapper *pSchema = metaGetTableSchema(((SVnode *)pVnode)->pMeta, uid, -1, 1, NULL, 0, false);
566✔
761
  if (pSchema == NULL) {
566✔
762
    return;
×
763
  }
764
  for (int32_t i = 0; i < pSchema->nCols; i++) {
1,415✔
765
    if (strncmp(pSchema->pSchema[i].name, colName, TSDB_COL_NAME_LEN) == 0) {
1,415✔
766
      *colId = pSchema->pSchema[i].colId;
566✔
767
      break;
566✔
768
    }
769
  }
770
  tDeleteSchemaWrapper(pSchema);
771
  return;
566✔
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, 
566✔
776
                                       SVAlterTbReq* pReq, uint64_t uid, int64_t ver) {
777
  int32_t code = 0;
566✔
778
  int32_t lino = 0;
566✔
779
  void* pTask = sStreamReaderInfo->pTask;
566✔
780
  SArray* uidListAdd = NULL;
566✔
781

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

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

788
  col_id_t colId = 0;
566✔
789
  getAlterColId(sStreamReaderInfo->pVnode, uid, pReq->colName, &colId);
566✔
790
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 0 && !isColIdInList(sStreamReaderInfo->triggerCols, colId)) {
566✔
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);
566✔
796
  STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
566✔
797

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

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

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

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

821
end:
25,881✔
822
  return code;
25,881✔
823
}
824

825
static SArray* getTableListForAlterSuperTable(SStreamTriggerReaderInfo* sStreamReaderInfo, SVAlterTbReq* pReq){
25,315✔
826
  int32_t code = 0;
25,315✔
827
  int32_t lino = 0;
25,315✔
828
  void* pTask = sStreamReaderInfo->pTask;
25,315✔
829
  SArray* uidList = taosArrayInit(8, sizeof(tb_uid_t));
25,315✔
830
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
25,315✔
831
  for (int32_t i = 0; i < taosArrayGetSize(pReq->tables); i++) {
50,630✔
832
    SUpdateTableTagVal *pTable = taosArrayGet(pReq->tables, i);
25,315✔
833
    uint64_t uid = 0;
25,315✔
834
    code = checkAlter(sStreamReaderInfo, pTable->tbName, pReq->action, &uid);
25,315✔
835
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
25,315✔
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);
25,315✔
841
    STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, (const void *)&uid), terrno);
25,315✔
842
  }
843

844
end:
25,315✔
845
  if (code != 0) {
25,315✔
846
    ST_TASK_ELOG("%s failed,code:%d", __func__, code);
×
847
    taosArrayDestroy(uidList);
×
848
    uidList = NULL;
×
849
  }
850
  return uidList;
25,315✔
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, 
25,315✔
855
                                    SArray* uidList, int64_t ver) {
856
  int32_t code = 0;
25,315✔
857
  int32_t lino = 0;
25,315✔
858
  void* pTask = sStreamReaderInfo->pTask;
25,315✔
859
  SArray* uidListAdd = NULL;
25,315✔
860
  SArray* uidListDel = NULL;
25,315✔
861
  SArray* tableList = NULL;
25,315✔
862

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

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

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

874
  if (rsp->checkAlter && taosArrayGetSize(uidListDel) > 0 && rsp->totalDataRows > 0) {
25,315✔
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));
25,315✔
882
  if (sStreamReaderInfo->isVtableStream) {
25,315✔
883
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListAdd, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_ADD));
1,785✔
884
    STREAM_CHECK_RET_GOTO(addUidListToBlock(uidListDel, &rsp->tableBlock, ver, &rsp->totalRows, TABLE_BLOCK_RETIRE));
1,785✔
885
  }
886
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
25,315✔
887

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

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

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

905
  ST_TASK_DLOG("%s start", __func__);
43,563✔
906

907
  SVAlterTbReq req = {0};
43,563✔
908
  tDecoderInit(&decoder, data, len);
43,563✔
909
  
910
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
43,563✔
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 && 
43,563✔
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;
31,551✔
916
  if (req.action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || req.action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
31,551✔
917
    STREAM_CHECK_CONDITION_GOTO(!sStreamReaderInfo->isVtableStream, TDB_CODE_SUCCESS);
6,236✔
918
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
566✔
919
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
566✔
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));
566✔
925
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
25,315✔
926
    uidList = getTableListForAlterSuperTable(sStreamReaderInfo, &req);
25,315✔
927
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
25,315✔
928
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
25,315✔
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__);
25,881✔
943

944
end:
43,563✔
945
  destroyAlterTbReq(&req);
43,563✔
946

947
  taosArrayDestroy(uidList);
43,563✔
948
  tDecoderClear(&decoder);
43,563✔
949
  STREAM_PRINT_LOG_END_WITHID(code, lino);
43,563✔
950
  return code;
43,563✔
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) {
6,071,665✔
996
  int32_t code = 0;
6,071,665✔
997
  int32_t lino = 0;
6,071,665✔
998
  WalMetaResult walMeta = {0};
6,071,665✔
999
  SSubmitTbData submitTbData = {0};
6,074,283✔
1000
  
1001
  if (tStartDecode(pCoder) < 0) {
6,074,569✔
1002
    code = TSDB_CODE_INVALID_MSG;
×
1003
    TSDB_CHECK_CODE(code, lino, end);
×
1004
  }
1005

1006
  uint8_t       version = 0;
6,074,281✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
6,073,799✔
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
6,073,799✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
6,073,799✔
1013

1014
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1015
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
6,073,799✔
1016
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
500,364✔
1017
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
500,364✔
1018
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
500,364✔
1019
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
500,364✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
6,074,314✔
1024
    code = TSDB_CODE_INVALID_MSG;
×
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
6,074,310✔
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)){
6,074,310✔
1033
    goto end;
5,140,525✔
1034
  }
1035
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
934,113✔
1036
    code = TSDB_CODE_INVALID_MSG;
×
1037
    TSDB_CHECK_CODE(code, lino, end);
×
1038
  }
1039

1040
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
934,113✔
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;
934,113✔
1070
    if (tDecodeU64v(pCoder, &nRow) < 0) {
934,113✔
1071
      code = TSDB_CODE_INVALID_MSG;
×
1072
      TSDB_CHECK_CODE(code, lino, end);
×
1073
    }
1074

1075
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
3,298,093✔
1076
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
2,364,236✔
1077
      pCoder->pos += pRow->len;
2,363,980✔
1078
      if (iRow == 0){
2,363,980✔
1079
#ifndef NO_UNALIGNED_ACCESS
1080
        walMeta.skey = pRow->ts;
933,601✔
1081
#else
1082
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1083
#endif
1084
      }
1085
      if (iRow == nRow - 1) {
2,364,492✔
1086
#ifndef NO_UNALIGNED_ACCESS
1087
        walMeta.ekey = pRow->ts;
933,857✔
1088
#else
1089
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1090
#endif
1091
      }
1092
    }
1093
  }
1094

1095
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
933,857✔
1096
  if (data != NULL) {
934,113✔
1097
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
1,168✔
1098
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
1,168✔
1099
  } else {
1100
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
932,945✔
1101
  }
1102

1103
end:
6,067,343✔
1104
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
6,074,026✔
1105
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
6,073,992✔
1106
  tEndDecode(pCoder);
6,073,992✔
1107
  return code;
6,073,767✔
1108
}
1109

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

1117
  tDecoderInit(&decoder, data, len);
6,073,146✔
1118
  if (tStartDecode(&decoder) < 0) {
6,072,279✔
1119
    code = TSDB_CODE_INVALID_MSG;
×
1120
    TSDB_CHECK_CODE(code, lino, end);
×
1121
  }
1122

1123
  uint64_t nSubmitTbData = 0;
6,073,368✔
1124
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
6,073,398✔
1125
    code = TSDB_CODE_INVALID_MSG;
×
1126
    TSDB_CHECK_CODE(code, lino, end);
×
1127
  }
1128

1129
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
6,073,398✔
1130
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
6,073,112✔
1131

1132
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
12,146,879✔
1133
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
6,074,280✔
1134
  }
1135
  tEndDecode(&decoder);
6,072,599✔
1136

1137
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
6,072,825✔
1138
  int32_t iter = 0;
6,071,086✔
1139
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
6,071,086✔
1140
  while (px != NULL) {
7,005,225✔
1141
    WalMetaResult* pMeta = (WalMetaResult*)px;
932,657✔
1142
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
932,657✔
1143
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
932,877✔
1144
    rsp->totalRows++;
932,877✔
1145
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
932,877✔
1146
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1147
    px = tSimpleHashIterate(gidHash, px, &iter);
932,877✔
1148
  }
1149
end:
6,072,568✔
1150
  tDecoderClear(&decoder);
6,072,568✔
1151
  tSimpleHashCleanup( gidHash);
6,073,690✔
1152
  return code;
6,072,875✔
1153
}
1154

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

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

1170
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
129,524✔
1171

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

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

1182
  schemas = taosArrayInit(8, sizeof(SSchema));
264,458✔
1183
  STREAM_CHECK_NULL_GOTO(schemas, terrno);
264,999✔
1184

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

1191
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
264,999✔
1192

1193
end:
264,999✔
1194
  taosArrayDestroy(schemas);
264,999✔
1195
  return code;
264,744✔
1196
}
1197

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

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

1205
  SDecoder dcoder = {0};
439,462✔
1206
  tDecoderInit(&dcoder, data, len);
439,462✔
1207
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
439,462✔
1208
    if (rsp->deleteBlock == NULL) {
29,412✔
1209
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
9,374✔
1210
    }
1211
      
1212
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
29,412✔
1213
  } else if (msgType == TDMT_VND_DROP_TABLE && 
410,050✔
1214
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
40,989✔
1215
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
21,761✔
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)) {
388,289✔
1219
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
79,145✔
1220
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
309,144✔
1221
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1222
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
276,626✔
1223
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
43,563✔
1224
  }
1225

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

1236
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,222,829✔
1237
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,222,105✔
1238
  code = walReaderSeekVer(pWalReader, rsp->ver);
3,222,105✔
1239
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,221,704✔
1240
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,871,107✔
1241
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
1242
      rsp->verTime = 0;
×
1243
    } else {
1244
      rsp->verTime = taosGetTimestampUs();
2,870,696✔
1245
    }
1246
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
2,870,696✔
1247
    code = TSDB_CODE_SUCCESS;
2,871,395✔
1248
    goto end;
2,871,395✔
1249
  }
1250
  STREAM_CHECK_RET_GOTO(code);
350,597✔
1251

1252
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
350,597✔
1253
  while (1) {
6,319,697✔
1254
    code = walNextValidMsg(pWalReader, true);
6,670,324✔
1255
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
6,668,865✔
1256
      rsp->verTime = taosGetTimestampUs();
348,023✔
1257
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
348,023✔
1258
      code = TSDB_CODE_SUCCESS;
348,023✔
1259
      goto end;
348,023✔
1260
    }
1261
    STREAM_CHECK_RET_GOTO(code);
6,320,838✔
1262
    rsp->ver = pWalReader->curVersion;
6,320,838✔
1263
    SWalCont* wCont = &pWalReader->pHead->head;
6,322,256✔
1264
    rsp->verTime = wCont->ingestTs;
6,321,678✔
1265
    if (wCont->ingestTs / 1000 > ctime) break;
6,322,490✔
1266
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
6,321,642✔
1267
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
6,320,839✔
1268
    int64_t ver = wCont->version;
6,321,956✔
1269

1270
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
6,321,956✔
1271
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1272
    if (wCont->msgType == TDMT_VND_SUBMIT) {
6,323,015✔
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) {
6,075,686✔
1275
        rsp->ver--;
3,122✔
1276
        break;
3,122✔
1277
      }
1278
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
6,072,275✔
1279
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
6,072,857✔
1280
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
6,073,112✔
1281
    } else {
1282
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
246,536✔
1283
    }
1284

1285
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
6,319,697✔
1286
      break;
×
1287
    }
1288
  }
1289

1290
end:
3,222,540✔
1291
  walCloseReader(pWalReader);
3,222,540✔
1292
  return code;
3,222,559✔
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) {
46,394,628✔
1296
  int32_t     code = 0;
46,394,628✔
1297
  int32_t     lino = 0;
46,394,628✔
1298
  SMetaReader mr = {0};
46,394,628✔
1299
  SArray* tagCache = NULL;
46,402,276✔
1300
  char* data = NULL;
46,409,891✔
1301

1302
  if (lock != NULL) taosWLockLatch(lock);
46,410,528✔
1303
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
46,414,004✔
1304
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,562,231✔
1305
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,562,231✔
1306
  if (uidData == NULL) {
2,562,514✔
1307
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,538,346✔
1308
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,538,346✔
1309
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,538,346✔
1310
      taosArrayDestroy(tagCache);
×
1311
      code = terrno;
×
1312
      goto end;
×
1313
    }
1314
  } else {
1315
    tagCache = *(SArray**)uidData;
24,168✔
1316
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
24,168✔
1317
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
24,168✔
1318
  }
1319
  
1320
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,562,514✔
1321
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,562,514✔
1322
  api->metaReaderFn.readerReleaseLock(&mr);
2,561,383✔
1323
  STREAM_CHECK_RET_GOTO(code);
2,561,365✔
1324
  
1325
  for (int32_t j = 0; j < numOfExpr; ++j) {
8,975,477✔
1326
    const SExprInfo* pExpr1 = &pExprInfo[j];
6,422,338✔
1327
    int32_t functionId = pExpr1->pExpr->_function.functionId;
6,421,488✔
1328
    col_id_t cid = 0;
6,424,491✔
1329
    // this is to handle the tbname
1330
    if (fmIsScanPseudoColumnFunc(functionId)) {
6,424,491✔
1331
      int32_t fType = pExpr1->pExpr->_function.functionType;
654,842✔
1332
      if (fType == FUNCTION_TYPE_TBNAME) {
655,345✔
1333
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
655,345✔
1334
        STREAM_CHECK_NULL_GOTO(data, terrno);
655,125✔
1335
        STR_TO_VARSTR(data, mr.me.name)
655,125✔
1336
      }
1337
      cid = -1;
655,057✔
1338
    } else {  // these are tags
1339
      const char* p = NULL;
5,766,480✔
1340
      char* pData = NULL;
5,766,480✔
1341
      int8_t type = pExpr1->base.resSchema.type;
5,766,480✔
1342
      int32_t len = pExpr1->base.resSchema.bytes;
5,766,410✔
1343
      STagVal tagVal = {0};
5,767,899✔
1344
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
5,767,346✔
1345
      cid = tagVal.cid;
5,768,119✔
1346
      if (colId != 0 && cid != colId) {
5,768,119✔
1347
        continue;
1,540✔
1348
      }
1349
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
5,766,579✔
1350

1351
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
5,765,499✔
1352
        pData = tTagValToData((const STagVal*)p, false);
5,761,099✔
1353
      } else {
1354
        pData = (char*)p;
4,400✔
1355
      }
1356

1357
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
5,764,564✔
1358
        if (type == TSDB_DATA_TYPE_JSON) {
2,938,022✔
1359
          len = getJsonValueLen(pData);
×
1360
        }
1361
        data = taosMemoryCalloc(1, len);
2,938,022✔
1362
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,938,414✔
1363
        (void)memcpy(data, pData, len);
2,938,414✔
1364
      } else {
1365
        data = pData;
2,826,542✔
1366
      }
1367
    }
1368
    if (uidData == NULL){
6,420,854✔
1369
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
12,750,426✔
1370
    } else {
1371
      void* pre = taosArrayGetP(tagCache, j);
46,066✔
1372
      taosMemoryFree(pre);
46,286✔
1373
      taosArraySet(tagCache, j, &data);
46,286✔
1374
    }
1375
    data = NULL;
6,420,435✔
1376
  }
1377

1378
end:
46,411,525✔
1379
  taosMemoryFree(data);
46,412,799✔
1380
  api->metaReaderFn.clearReader(&mr);
46,412,802✔
1381
  if (lock != NULL) taosWUnLockLatch(lock);
46,402,619✔
1382
  return code;
46,410,744✔
1383
}
1384

1385
int32_t fillTag(SHashObj* metaCache, SExprInfo* pExprInfo, int32_t numOfExpr,
383,142,737✔
1386
                uint64_t uid, SSDataBlock* pBlock, uint32_t currentRow, uint32_t numOfRows, uint32_t numOfBlocks, SRWLatch* lock) {
1387
  int32_t     code = 0;
383,142,737✔
1388
  int32_t     lino = 0;
383,142,737✔
1389
  SArray* tagCache = NULL;
383,142,737✔
1390
  if (numOfExpr == 0) {
383,142,737✔
1391
    return TSDB_CODE_SUCCESS;
43,349,863✔
1392
  }
1393

1394
  taosRLockLatch(lock);
339,792,874✔
1395
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
339,888,429✔
1396
  if (uidData == NULL) {
339,833,313✔
1397
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1398
  } else {
1399
    tagCache = *(SArray**)uidData;
339,833,313✔
1400
    if(taosArrayGetSize(tagCache) != numOfExpr) {
339,865,289✔
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) {
1,182,821,955✔
1407
    const SExprInfo* pExpr1 = &pExprInfo[j];
843,044,868✔
1408
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
843,024,808✔
1409

1410
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
843,051,571✔
1411
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
843,009,582✔
1412
    int32_t functionId = pExpr1->pExpr->_function.functionId;
843,009,582✔
1413

1414
    // this is to handle the tbname
1415
    if (fmIsScanPseudoColumnFunc(functionId)) {
843,046,940✔
1416
      int32_t fType = pExpr1->pExpr->_function.functionType;
3,424,212✔
1417
      if (fType == FUNCTION_TYPE_TBNAME) {
3,424,496✔
1418
        pColInfoData->info.colId = -1;
3,424,496✔
1419
      }
1420
    } 
1421
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
842,910,188✔
1422

1423
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
842,605,744✔
1424
    if (isNullVal) {
842,874,717✔
1425
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1426
    } else {
1427
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
842,874,717✔
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);
844,170,994✔
1433
      STREAM_CHECK_RET_GOTO(code);
842,940,699✔
1434
    }
1435
  }
1436
end:
339,777,087✔
1437
  taosRUnLockLatch(lock);
339,777,455✔
1438
  return code;
339,888,372✔
1439
}
1440

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

1446
  void* pTask = info->pTask;
3,242,810✔
1447
  ST_TASK_DLOG("%s start. rows:%" PRIu32 ",uid:%"PRIu64, __func__,  numOfRows, uid);
3,243,957✔
1448
  
1449
  SHashObj* metaCache = isCalc ? info->pTableMetaCacheCalc : info->pTableMetaCacheTrigger;
3,243,102✔
1450
  SExprInfo*   pExprInfo = isCalc ? info->pExprInfoCalcTag : info->pExprInfoTriggerTag; 
3,243,390✔
1451
  int32_t      numOfExpr = isCalc ? info->numOfExprCalcTag : info->numOfExprTriggerTag;
3,243,102✔
1452
  
1453
  code = fillTag(metaCache, pExprInfo, numOfExpr, uid, pBlock, currentRow, numOfRows, numOfBlocks, &info->lock);
3,243,674✔
1454
  STREAM_CHECK_RET_GOTO(code);
3,244,240✔
1455

1456
end:
3,244,240✔
1457
  return code;
3,244,240✔
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) {
1,952,852✔
1506
  int32_t code = 0;
1,952,852✔
1507
  int32_t lino = 0;
1,952,852✔
1508
  int64_t id[2] = {suid, uid};
1,952,852✔
1509
  taosRLockLatch(&sStreamReaderInfo->lock);
1,952,852✔
1510
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
1,953,719✔
1511
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
1,953,464✔
1512
  SSHashObj* uInfo = *(SSHashObj **)px;
1,953,464✔
1513
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
1,953,464✔
1514
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
1,953,464✔
1515
  if (tmp != NULL) {
1,952,280✔
1516
    *colId = *tmp;
1,677,537✔
1517
  } else {
1518
    *colId = -1;
274,743✔
1519
  }
1520

1521
end:
1,954,008✔
1522
  taosRUnLockLatch(&sStreamReaderInfo->lock);
1,952,569✔
1523
  return code;
1,953,467✔
1524
}
1525

1526
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
3,713,285✔
1527
  int32_t code = 0;
3,713,285✔
1528
  int32_t lino = 0;
3,713,285✔
1529
  int64_t id = suid != 0 ? suid : uid;
3,713,285✔
1530
  if (sStreamReaderInfo->isVtableStream) {
3,714,428✔
1531
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
765,994✔
1532
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
766,572✔
1533
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
22,886✔
1534
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
22,308✔
1535
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
22,308✔
1536
      if (code != 0) {
22,308✔
1537
        taosMemoryFree(*schema);
×
1538
        goto end;
×
1539
      }
1540
    } else {
1541
      *schema = *schemaTmp;
743,397✔
1542
    }
1543
  } else {
1544
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
2,948,713✔
1545
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
110,666✔
1546
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
110,666✔
1547
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
110,094✔
1548
    }
1549
    *schema = sStreamReaderInfo->triggerTableSchema;
2,949,005✔
1550
  }
1551
  
1552
end:
3,714,993✔
1553
  return code;
3,715,282✔
1554
}
1555

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

1565
  if (tStartDecode(pCoder) < 0) {
4,724,558✔
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};
4,727,378✔
1572
  uint8_t       version = 0;
4,726,233✔
1573
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
4,725,660✔
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;
4,725,660✔
1579
  submitTbData.flags = submitTbData.flags & 0xff;
4,725,660✔
1580
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1581
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
4,725,660✔
1582
    if (tStartDecode(pCoder) < 0) {
212,393✔
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);
212,685✔
1588
  }
1589

1590
  // submit data
1591
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
4,725,962✔
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) {
4,726,818✔
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);
4,726,818✔
1603

1604
  if (rsp->uidHash != NULL) {
4,729,079✔
1605
    uint64_t* gid = tSimpleHashGet(rsp->uidHash, &submitTbData.uid, LONG_BYTES);
2,126,570✔
1606
    STREAM_CHECK_CONDITION_GOTO(gid == NULL, TDB_CODE_SUCCESS);
2,126,570✔
1607
    ST_TASK_DLOG("%s get uid gid from uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, submitTbData.uid, submitTbData.suid, *gid);
2,126,570✔
1608
    id = *gid;
2,126,570✔
1609
  } else {
1610
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
2,600,233✔
1611
  }
1612

1613
  walMeta.id = id;
3,715,582✔
1614
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
3,715,582✔
1615

1616
  if (ranges != NULL){
3,715,865✔
1617
    void* timerange = tSimpleHashGet(ranges, &id, sizeof(id));
2,125,998✔
1618
    if (timerange == NULL) goto end;;
2,126,570✔
1619
    int64_t* pRange = (int64_t*)timerange;
2,126,570✔
1620
    window.skey = pRange[0];
2,126,570✔
1621
    window.ekey = pRange[1];
2,126,570✔
1622
    ST_TASK_DLOG("%s get time range from ranges, uid:%" PRId64 ", suid:%" PRId64 ", gid:%" PRIu64 ", skey:%" PRId64 ", ekey:%" PRId64,
2,126,286✔
1623
      __func__, submitTbData.uid, submitTbData.suid, id, window.skey, window.ekey);
1624
  }
1625
  
1626
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,715,867✔
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;
3,715,867✔
1633
  STREAM_CHECK_RET_GOTO(getSchemas(pVnode, submitTbData.suid, submitTbData.uid, submitTbData.sver, sStreamReaderInfo, &schema));
3,715,010✔
1634

1635
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
3,714,706✔
1636
  int32_t blockStart = 0;
3,716,726✔
1637
  int32_t numOfRows = 0;
3,716,726✔
1638
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
3,716,145✔
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;
3,716,145✔
1722
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,713,289✔
1723
      code = TSDB_CODE_INVALID_MSG;
×
1724
      TSDB_CHECK_CODE(code, lino, end);
×
1725
    }
1726
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
9,128,426✔
1727
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
5,411,935✔
1728
      pCoder->pos += pRow->len;
5,414,518✔
1729

1730
      if (iRow == 0){
5,414,523✔
1731
#ifndef NO_UNALIGNED_ACCESS
1732
        walMeta.skey = pRow->ts;
3,715,866✔
1733
#else
1734
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1735
#endif
1736
      }
1737
      if (iRow == nRow - 1) {
5,412,797✔
1738
#ifndef NO_UNALIGNED_ACCESS
1739
        walMeta.ekey = pRow->ts;
3,714,138✔
1740
#else
1741
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1742
#endif
1743
      }
1744

1745
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
5,412,802✔
1746
        continue;
11,282✔
1747
      }
1748
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
5,400,954✔
1749
      blockStart = pSlice->currentRowIdx;
5,400,699✔
1750
     
1751
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
35,847,093✔
1752
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
30,441,795✔
1753
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
30,442,888✔
1754
        if (pColData->info.colId <= -1) {
30,442,888✔
1755
          pColData->hasNull = true;
10,471,636✔
1756
          continue;
10,471,344✔
1757
        }
1758
        int16_t colId = 0;
19,978,987✔
1759
        if (sStreamReaderInfo->isVtableStream){
19,978,699✔
1760
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
1,952,852✔
1761
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
1,953,467✔
1762
        } else {
1763
          colId = pColData->info.colId;
18,025,557✔
1764
        }
1765
        
1766
        SColVal colVal = {0};
19,978,732✔
1767
        int32_t sourceIdx = 0;
19,979,012✔
1768
        while (1) {
1769
          if (sourceIdx >= schema->numOfCols) {
50,026,792✔
1770
            break;
8,114,588✔
1771
          }
1772
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
41,909,971✔
1773
          if (colVal.cid == colId) {
41,917,596✔
1774
            break;
11,869,816✔
1775
          }
1776
          sourceIdx++;
30,047,780✔
1777
        }
1778
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
19,984,404✔
1779
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
11,751,204✔
1780
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
53,173✔
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, 
52,040✔
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)));
11,698,031✔
1785
          }
1786
        } else {
1787
          colDataSetNULL(pColData, blockStart + numOfRows);
8,233,200✔
1788
        }
1789
      }
1790
      
1791
      numOfRows++;
5,403,855✔
1792
    }
1793
  }
1794

1795
  if (numOfRows > 0) {
3,715,327✔
1796
    if (!sStreamReaderInfo->isVtableStream) {
3,715,327✔
1797
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, rsp->isCalc, submitTbData.uid, pBlock, blockStart, numOfRows, 1));
2,949,327✔
1798
    }
1799
    
1800
    SColumnInfoData* pColData = taosArrayGetLast(pBlock->pDataBlock);
3,715,610✔
1801
    STREAM_CHECK_NULL_GOTO(pColData, terrno);
3,715,346✔
1802
    STREAM_CHECK_RET_GOTO(colDataSetNItems(pColData, blockStart, (const char*)&ver, numOfRows, 1, false));
3,715,346✔
1803

1804
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
3,715,321✔
1805
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
3,715,321✔
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;
3,715,321✔
1809
    pBlock->info.rows += numOfRows;
3,715,043✔
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;
3,714,184✔
1816

1817
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
1,589,047✔
1818
  if (data != NULL) {
1,588,175✔
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,588,175✔
1823
  }
1824

1825
end:
4,722,203✔
1826
  if (code != 0) {                                                             \
4,725,084✔
1827
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
255✔
1828
  }
1829
  tEndDecode(pCoder);
4,725,084✔
1830
  return code;
4,725,932✔
1831
}
1832
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
4,725,663✔
1833
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1834
  int32_t  code = 0;
4,725,663✔
1835
  int32_t  lino = 0;
4,725,663✔
1836
  SDecoder decoder = {0};
4,725,663✔
1837
  SSHashObj* gidHash = NULL;
4,725,657✔
1838
  void* pTask = sStreamReaderInfo->pTask;
4,725,657✔
1839

1840
  tDecoderInit(&decoder, data, len);
4,725,945✔
1841
  if (tStartDecode(&decoder) < 0) {
4,727,661✔
1842
    code = TSDB_CODE_INVALID_MSG;
×
1843
    TSDB_CHECK_CODE(code, lino, end);
×
1844
  }
1845

1846
  uint64_t nSubmitTbData = 0;
4,726,807✔
1847
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
4,725,105✔
1848
    code = TSDB_CODE_INVALID_MSG;
×
1849
    TSDB_CHECK_CODE(code, lino, end);
×
1850
  }
1851

1852
  if (rsp->metaBlock != NULL){
4,725,105✔
1853
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
2,598,820✔
1854
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
2,597,690✔
1855
  }
1856

1857
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
9,449,346✔
1858
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
4,724,558✔
1859
  }
1860

1861
  tEndDecode(&decoder);
4,724,788✔
1862

1863
  if (rsp->metaBlock != NULL){
4,724,238✔
1864
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
2,599,966✔
1865
    int32_t iter = 0;
2,597,078✔
1866
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
2,597,078✔
1867
    while (px != NULL) {
4,189,560✔
1868
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,589,007✔
1869
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,589,007✔
1870
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,588,758✔
1871
      rsp->totalRows++;
1,588,758✔
1872
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,588,474✔
1873
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1874
      px = tSimpleHashIterate(gidHash, px, &iter);
1,588,766✔
1875
    }
1876
  }
1877
  
1878

1879
end:
4,722,616✔
1880
  tSimpleHashCleanup(gidHash);
4,726,523✔
1881
  tDecoderClear(&decoder);
4,726,525✔
1882
  return code;
4,727,966✔
1883
}
1884

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

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

1896
  SSubmitTbData submitTbData = {0};
6,479,556✔
1897
  uint8_t       version = 0;
6,478,984✔
1898
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
6,480,425✔
1899
    code = TSDB_CODE_INVALID_MSG;
×
1900
    TSDB_CHECK_CODE(code, lino, end);
×
1901
  }
1902
  version = (submitTbData.flags >> 8) & 0xff;
6,480,425✔
1903
  submitTbData.flags = submitTbData.flags & 0xff;
6,480,425✔
1904

1905
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1906
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
6,480,425✔
1907
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
1,197,900✔
1908
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
1,197,607✔
1909
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
1,197,607✔
1910
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
1,197,473✔
1911
  }
1912

1913
  // submit data
1914
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
6,480,981✔
1915
    code = TSDB_CODE_INVALID_MSG;
×
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  if (tDecodeI64(pCoder, uid) < 0) {
6,481,024✔
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);
6,481,024✔
1923
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
6,481,113✔
1924
  if (rsp->uidHash != NULL) {
3,720,687✔
1925
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
2,126,287✔
1926
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
2,126,281✔
1927
  }
1928
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
3,720,393✔
1929

1930
  if (ranges != NULL){
3,720,109✔
1931
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
2,125,997✔
1932
    if (timerange == NULL) goto end;;
2,126,570✔
1933
    int64_t* pRange = (int64_t*)timerange;
2,126,570✔
1934
    window.skey = pRange[0];
2,126,570✔
1935
    window.ekey = pRange[1];
2,126,570✔
1936
  }
1937
  
1938
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,720,391✔
1939
    code = TSDB_CODE_INVALID_MSG;
×
1940
    TSDB_CHECK_CODE(code, lino, end);
×
1941
  }
1942

1943
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
3,720,391✔
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;
3,720,391✔
1970
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,720,393✔
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) { 
3,720,393✔
1976
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
5,618,857✔
1977
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
3,493,721✔
1978
        pCoder->pos += pRow->len;
3,493,149✔
1979
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
3,493,433✔
1980
          continue;
11,570✔
1981
        }
1982
        (*numOfRows)++;
3,481,290✔
1983
      }
1984
    } else {
1985
      (*numOfRows) = nRow;
1,594,396✔
1986
    }
1987
  }
1988
  
1989
end:
6,481,859✔
1990
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
6,480,424✔
1991
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
6,478,696✔
1992
  tEndDecode(pCoder);
6,478,107✔
1993
  return code;
6,479,268✔
1994
}
1995

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

2002
  tDecoderInit(&decoder, data, len);
6,483,000✔
2003
  if (tStartDecode(&decoder) < 0) {
6,480,741✔
2004
    code = TSDB_CODE_INVALID_MSG;
×
2005
    TSDB_CHECK_CODE(code, lino, end);
×
2006
  }
2007

2008
  uint64_t nSubmitTbData = 0;
6,479,268✔
2009
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
6,479,281✔
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);
6,479,281✔
2014

2015
  for (int32_t i = 0; i < nSubmitTbData; i++) {
12,958,844✔
2016
    uint64_t gid = -1;
6,478,995✔
2017
    int64_t  uid = 0;
6,478,420✔
2018
    int32_t numOfRows = 0;
6,478,709✔
2019
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
6,478,997✔
2020
    if (numOfRows <= 0) {
6,479,280✔
2021
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
2,760,887✔
2022
      continue;
2,760,887✔
2023
    }
2024
    rsp->totalRows += numOfRows;
3,718,393✔
2025
    rsp->totalDataRows += numOfRows;
3,718,677✔
2026

2027
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
3,718,389✔
2028
    if (pSlice != NULL) {
3,720,393✔
2029
      pSlice->numRows += numOfRows;
3,245,600✔
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);
3,245,889✔
2031
      pSlice->gId = gid;
3,245,889✔
2032
    } else {
2033
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
474,793✔
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);
474,793✔
2035
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
474,793✔
2036
    } 
2037
  }
2038

2039
  tEndDecode(&decoder);
6,479,849✔
2040

2041
end:
6,479,294✔
2042
  tDecoderClear(&decoder);
6,479,291✔
2043
  return code;
6,483,288✔
2044
}
2045

2046
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
405,326✔
2047
  void*   pe = NULL;
405,326✔
2048
  int32_t iter = 0;
405,326✔
2049
  int32_t index = 0;
405,326✔
2050
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
880,403✔
2051
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
475,365✔
2052
    pInfo->startRowIdx = index;
475,365✔
2053
    pInfo->currentRowIdx = index;
475,365✔
2054
    index += pInfo->numRows;
475,077✔
2055
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
736,268✔
2056
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2057
  }
2058
}
405,038✔
2059

2060
static void printIndexHash(SSHashObj* indexHash, void* pTask){
404,498✔
2061
  if (qDebugFlag & DEBUG_TRACE) {
404,498✔
2062
    void*   pe = NULL;
10,319✔
2063
    int32_t iter = 0;
10,319✔
2064
    while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
24,859✔
2065
      SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
14,540✔
2066
      ST_TASK_TLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
14,810✔
2067
      pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2068
    }
2069
  }
2070
}
404,498✔
2071

2072
static void filterIndexHash(SSHashObj* indexHash, SColumnInfoData* pRet){
6,944✔
2073
  void*   pe = NULL;
6,944✔
2074
  int32_t iter = 0;
6,944✔
2075
  int32_t index = 0;
6,944✔
2076
  int32_t pIndex = 0;
6,944✔
2077
  int8_t* pIndicator = (int8_t*)pRet->pData;
6,944✔
2078
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
15,571✔
2079
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
8,627✔
2080
    pInfo->startRowIdx = index;
8,627✔
2081
    int32_t size = pInfo->numRows;
8,627✔
2082
    for (int32_t i = 0; i < pInfo->numRows; i++) {
85,913✔
2083
      if (pIndicator && !pIndicator[pIndex++]) {
77,286✔
2084
        size--;
26,147✔
2085
      }
2086
    }
2087
    pInfo->numRows = size;
8,627✔
2088
    index += pInfo->numRows;
8,627✔
2089
    stTrace("stream reader re build index hash uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
8,627✔
2090
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2091
  }
2092
}
6,944✔
2093

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

2099
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
5,722,471✔
2100
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,720,293✔
2101
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
5,028,130✔
2102
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
2103
      resultRsp->verTime = 0;
×
2104
    } else {
2105
      resultRsp->verTime = taosGetTimestampUs();
5,027,512✔
2106
    }
2107
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
5,025,806✔
2108
    code = TSDB_CODE_SUCCESS;
5,028,720✔
2109
    goto end;
5,028,720✔
2110
  }
2111
  STREAM_CHECK_RET_GOTO(code);
692,163✔
2112

2113
  while (1) {
4,549,644✔
2114
    code = walNextValidMsg(pWalReader, true);
5,241,807✔
2115
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,240,742✔
2116
      resultRsp->verTime = taosGetTimestampUs();
693,388✔
2117
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
693,388✔
2118
      code = TSDB_CODE_SUCCESS;
693,104✔
2119
      goto end;
693,104✔
2120
    }
2121
    STREAM_CHECK_RET_GOTO(code);
4,547,366✔
2122
    resultRsp->ver = pWalReader->curVersion;
4,547,366✔
2123
    SWalCont* wCont = &pWalReader->pHead->head;
4,548,208✔
2124
    resultRsp->verTime = wCont->ingestTs;
4,547,306✔
2125
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
4,546,566✔
2126
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
4,546,880✔
2127
    int64_t ver = wCont->version;
4,546,009✔
2128
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
4,544,722✔
2129
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2130
    if (wCont->msgType == TDMT_VND_SUBMIT) {
4,547,657✔
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) {
4,355,578✔
2133
        resultRsp->ver--;
×
2134
        break;
×
2135
      }
2136
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
4,355,581✔
2137
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
4,355,865✔
2138
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
4,356,433✔
2139
    } else {
2140
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
192,926✔
2141
    }
2142

2143
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
4,549,073✔
2144
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
4,547,366✔
2145
      break;
2146
    }
2147
  }
2148
  
2149
end:
×
2150
  STREAM_PRINT_LOG_END(code, lino);
5,721,540✔
2151
  return code;
5,723,539✔
2152
}
2153

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

2160
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
3,160,837✔
2161
    int64_t *ver = taosArrayGet(versions, i);
2,125,444✔
2162
    if (ver == NULL) continue;
2,125,144✔
2163

2164
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
2,125,144✔
2165
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
2,125,998✔
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));
2,125,715✔
2171

2172
    SWalCont* wCont = &pWalReader->pHead->head;
2,125,120✔
2173
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
2,125,414✔
2174
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
2,125,714✔
2175

2176
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
2,125,998✔
2177
  }
2178
  
2179
end:
1,035,663✔
2180
  return code;
1,035,663✔
2181
}
2182

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

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

2191
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
405,071✔
2192
    filterIndexHash(resultRsp->indexHash, pRet);
6,944✔
2193
  }
2194

2195
end:
405,071✔
2196
  colDataDestroy(pRet);
405,071✔
2197
  taosMemoryFree(pRet);
405,071✔
2198
  return code;
404,787✔
2199
}
2200

2201
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
5,723,115✔
2202
                                    SSTriggerWalNewRsp* resultRsp) {
2203
  int32_t      code = 0;
5,723,115✔
2204
  int32_t      lino = 0;
5,723,115✔
2205
  void* pTask = sStreamReaderInfo->pTask;
5,723,115✔
2206
                                        
2207
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
5,722,823✔
2208
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
5,717,610✔
2209
  blockDataEmpty(resultRsp->dataBlock);
5,717,610✔
2210
  blockDataEmpty(resultRsp->metaBlock);
5,715,530✔
2211
  int64_t lastVer = resultRsp->ver;                                      
5,719,215✔
2212
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
5,719,641✔
2213
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
5,720,401✔
2214

2215
  buildIndexHash(resultRsp->indexHash, pTask);
156,873✔
2216
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
156,873✔
2217
  while(lastVer < resultRsp->ver) {
2,806,540✔
2218
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
2,650,210✔
2219
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
2,648,783✔
2220
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
49,376✔
2221
      continue;
49,376✔
2222
    }
2223
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
2,599,974✔
2224
    SWalCont* wCont = &pWalReader->pHead->head;
2,597,259✔
2225
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
2,599,419✔
2226
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
2,601,118✔
2227
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
2,601,118✔
2228
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
2,597,906✔
2229
  }
2230

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

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

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

2247
  void* pTask = sStreamReaderInfo->pTask;
1,035,663✔
2248
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
1,035,663✔
2249
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
1,035,663✔
2250
  
2251
  if (taosArrayGetSize(versions) > 0) {
1,035,663✔
2252
    rsp->ver = *(int64_t*)taosArrayGetLast(versions);
248,453✔
2253
  }
2254
  
2255
  STREAM_CHECK_RET_GOTO(prepareIndexData(pWalReader, sStreamReaderInfo, versions, ranges, rsp));
1,035,663✔
2256
  STREAM_CHECK_CONDITION_GOTO(rsp->totalRows == 0, TDB_CODE_SUCCESS);
1,035,663✔
2257

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

2261
  blockDataEmpty(rsp->dataBlock);
248,165✔
2262
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->dataBlock, rsp->totalRows));
248,453✔
2263

2264
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
2,373,289✔
2265
    int64_t *ver = taosArrayGet(versions, i);
2,124,842✔
2266
    if (ver == NULL) continue;
2,124,847✔
2267
    ST_TASK_TLOG("vgId:%d %s scan wal process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, *ver, walGetAppliedVer(pWalReader->pWal));
2,124,847✔
2268

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

2279
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
2,126,287✔
2280
  }
2281
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2282
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
248,453✔
2283
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
248,169✔
2284

2285
end:
1,035,379✔
2286
  ST_TASK_DLOG("vgId:%d %s end, get result totalRows:%d, process:%"PRId64"/%"PRId64, TD_VID(pVnode), __func__, 
1,035,379✔
2287
            rsp->totalRows, rsp->ver, walGetAppliedVer(pWalReader->pWal));
2288
  walCloseReader(pWalReader);
1,035,379✔
2289
  return code;
1,035,090✔
2290
}
2291

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

2302
  SSchemaWrapper* sSchemaWrapper = NULL;
58,381✔
2303
  if (metaReader.me.type == TD_CHILD_TABLE) {
58,381✔
2304
    int64_t suid = metaReader.me.ctbEntry.suid;
58,381✔
2305
    tDecoderClear(&metaReader.coder);
58,381✔
2306
    STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, suid));
58,381✔
2307
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
58,381✔
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++) {
301,364✔
2315
    SSchema* s = sSchemaWrapper->pSchema + j;
242,983✔
2316
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
485,966✔
2317
  }
2318

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

2329
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
58,381✔
2330
  int32_t code = 0;
58,381✔
2331
  int32_t lino = 0;
58,381✔
2332
  size_t  schemaLen = taosArrayGetSize(schemas);
58,381✔
2333
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
58,381✔
2334
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
182,993✔
2335
    col_id_t* id = taosArrayGet(cols, i);
124,612✔
2336
    STREAM_CHECK_NULL_GOTO(id, terrno);
124,612✔
2337
    for (size_t i = 0; i < schemaLen; i++) {
277,670✔
2338
      SSchema* s = taosArrayGet(schemas, i);
277,670✔
2339
      STREAM_CHECK_NULL_GOTO(s, terrno);
277,670✔
2340
      if (*id == s->colId) {
277,670✔
2341
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
124,612✔
2342
        break;
124,612✔
2343
      }
2344
    }
2345
  }
2346
  taosArrayPopFrontBatch(schemas, schemaLen);
58,381✔
2347

2348
end:
58,381✔
2349
  return code;
58,381✔
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,
447,673✔
2476
                                    STimeRangeNode* node, SReadHandle* handle, bool isExtWin) {
2477
  int32_t code = 0;
447,673✔
2478
  int32_t lino = 0;
447,673✔
2479
  void* pTask = sStreamReaderCalcInfo->pTask;
447,673✔
2480
  STimeWindow* pWin = isExtWin ? &handle->extWinRange : &handle->winRange;
447,673✔
2481
  bool* pValid = isExtWin ? &handle->extWinRangeValid : &handle->winRangeValid;
447,673✔
2482
  
2483
  if (req->pStRtFuncInfo->withExternalWindow) {
447,673✔
2484
    sStreamReaderCalcInfo->tmpRtFuncInfo.curIdx = 0;
282,536✔
2485
    sStreamReaderCalcInfo->tmpRtFuncInfo.triggerType = req->pStRtFuncInfo->triggerType;
282,536✔
2486
    sStreamReaderCalcInfo->tmpRtFuncInfo.isWindowTrigger = req->pStRtFuncInfo->isWindowTrigger;
282,366✔
2487
    sStreamReaderCalcInfo->tmpRtFuncInfo.precision = req->pStRtFuncInfo->precision;
282,366✔
2488

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

2502
    if (!node->needCalc) {
282,366✔
2503
      pWin->skey = pFirst->wstart;
264,455✔
2504
      pWin->ekey = pLast->wend;
264,455✔
2505
      *pValid = true;
264,455✔
2506
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
264,455✔
2507
        pWin->ekey--;
172,772✔
2508
      }
2509
    } else {
2510
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
17,911✔
2511
      memcpy(pTmp, pFirst, sizeof(*pTmp));
18,081✔
2512

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

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

2520
        if (*pValid) {
18,081✔
2521
          pWin->skey = skey;
18,081✔
2522
        }
2523
      }
2524
      pWin->ekey--;
18,081✔
2525
    }
2526
  } else {
2527
    if (!node->needCalc) {
165,137✔
2528
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
115,773✔
2529
      pWin->skey = pCurr->wstart;
115,773✔
2530
      pWin->ekey = pCurr->wend;
115,773✔
2531
      *pValid = true;
115,773✔
2532
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
115,773✔
2533
        pWin->ekey--;
59,990✔
2534
      }
2535
    } else {
2536
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
49,364✔
2537
      pWin->ekey--;
49,364✔
2538
    }
2539
  }
2540

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

2544
end:
5,732✔
2545

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

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

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

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

2579
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
117,929✔
2580
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
117,929✔
2581
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
117,929✔
2582
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
117,929✔
2583
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
414,986✔
2584
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
594,114✔
2585
      continue;
×
2586
    }
2587
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
297,057✔
2588
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
297,057✔
2589
    if (order == TSDB_ORDER_ASC) {
297,057✔
2590
      tsInfo->ts = INT64_MAX;
153,504✔
2591
    } else {
2592
      tsInfo->ts = INT64_MIN;
143,553✔
2593
    }
2594
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
297,057✔
2595
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
297,057✔
2596
      tsInfo->ts = ts;
153,504✔
2597
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
143,553✔
2598
      tsInfo->ts = ts;
143,553✔
2599
    }
2600
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
297,057✔
2601
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
297,057✔
2602
  }
2603

2604
end:
117,929✔
2605
  return code;
117,929✔
2606
}
2607

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

2613
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
122,041✔
2614
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
121,753✔
2615
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
121,182✔
2616
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
122,041✔
2617
  if (order == TSDB_ORDER_ASC) {
122,041✔
2618
    tsInfo->ts = INT64_MAX;
94,718✔
2619
  } else {
2620
    tsInfo->ts = INT64_MIN;
27,323✔
2621
  }
2622

2623
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
120,898✔
2624
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
121,753✔
2625
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
261,984✔
2626
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
282,172✔
2627
      continue;
×
2628
    }
2629
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
141,086✔
2630
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
140,513✔
2631
      tsInfo->ts = ts;
93,863✔
2632
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
46,929✔
2633
      tsInfo->ts = ts;
27,323✔
2634
    }
2635
  }
2636
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
121,470✔
2637
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
121,753✔
2638
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
122,041✔
2639

2640
end:
37,309✔
2641
  return code;
121,757✔
2642
}
2643

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

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

2653
  SSHashObj*   uidTsHash = tSimpleHashInit(pResBlock->info.rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
9,784✔
2654
  STREAM_CHECK_NULL_GOTO(uidTsHash, terrno);
9,784✔
2655
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
9,784✔
2656
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
9,784✔
2657
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
30,488✔
2658
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
41,408✔
2659
      continue;
×
2660
    }
2661
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
20,704✔
2662
    int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
20,704✔
2663
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(uidTsHash, &uid, LONG_BYTES, &ts, LONG_BYTES));
20,704✔
2664
  }
2665
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(sStreamReaderInfo), sizeof(STsInfo));
9,784✔
2666
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
9,784✔
2667
  while (true) {
19,734✔
2668
    int32_t        pNum = 0;
29,518✔
2669
    int64_t        suid = 0;
29,518✔
2670
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
29,518✔
2671
    if(pNum == 0) break;
29,518✔
2672
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
20,464✔
2673
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
20,464✔
2674
    if (order == TSDB_ORDER_ASC) {
20,464✔
2675
      tsInfo->ts = INT64_MAX;
9,630✔
2676
    } else {
2677
      tsInfo->ts = INT64_MIN;
10,834✔
2678
    }
2679
    for (int32_t i = 0; i < pNum; i++) {
40,658✔
2680
      int64_t uid = pList[i].uid;
20,924✔
2681
      int64_t *ts = tSimpleHashGet(uidTsHash, &uid, LONG_BYTES);
20,924✔
2682
      STREAM_CHECK_NULL_GOTO(ts, terrno);
20,924✔
2683
      if (order == TSDB_ORDER_ASC && *ts < tsInfo->ts) {
20,194✔
2684
        tsInfo->ts = *ts;
9,630✔
2685
      } else if (order == TSDB_ORDER_DESC && *ts > tsInfo->ts) {
10,564✔
2686
        tsInfo->ts = *ts;
10,104✔
2687
      }
2688
    }
2689
    int64_t uid = pList[0].uid;
19,734✔
2690
    tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
19,734✔
2691
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
19,734✔
2692
    taosMemoryFreeClear(pList);
19,734✔
2693
  }
2694

2695
end:
9,784✔
2696
  qStreamDestroyTableInfo(&tableInfo);
9,784✔
2697
  taosMemoryFreeClear(pList);
9,784✔
2698
  tSimpleHashCleanup(uidTsHash);
9,784✔
2699
  return code;
9,784✔
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) {
368,813✔
2705
  int32_t code = 0;
368,813✔
2706
  int32_t lino = 0;
368,813✔
2707

2708
  stDebug("%s getAllTs enter: pNum:%d suid:%"PRId64" order:%d skey:%"PRId64" ekey:%"PRId64" verRange:[%"PRId64",%"PRId64"]",
368,813✔
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,100,641✔
2713
    stDebug("%s getAllTs table[%d]: uid:%"PRId64, pTaskInner->idStr, i, pList[i].uid);
731,963✔
2714
  }
2715

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

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

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

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

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

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

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

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

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

2773
  SSDataBlock*  pResBlock = NULL;
325,453✔
2774

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

2782
  pTaskInner->options->suid = sStreamReaderInfo->suid;
286,297✔
2783
  ST_TASK_DLOG("vgId:%d %s calling getAllTs: suid:%"PRId64" order:%d skey:%"PRId64" ekey:%"PRId64" ver:%"PRId64,
286,297✔
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));
286,297✔
2787
  ST_TASK_DLOG("vgId:%d %s getAllTs done: pResBlock rows:%"PRId64, TD_VID(pVnode), __func__, pResBlock->info.rows);
285,722✔
2788
  int32_t order = pTaskInner->options->order;
286,475✔
2789
  if (pResBlock->info.rows == 0 && sStreamReaderInfo->groupByTbname) {
286,014✔
2790
    tsRsp->tsInfo = taosArrayInit(pNum, sizeof(STsInfo));
45,105✔
2791
    STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
44,822✔
2792
    for (int32_t i = 0; i < pNum; i++) {
165,659✔
2793
      STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
120,554✔
2794
      STREAM_CHECK_NULL_GOTO(tsInfo, terrno);
121,120✔
2795
      tsInfo->gId = pList[i].uid;
121,120✔
2796
      tsInfo->ts = 0;
120,837✔
2797
      ST_TASK_DLOG("%s no data but return gId (uid):%" PRIu64 " for tbname partition", __func__, tsInfo->gId);
120,837✔
2798
    }
2799
    goto end;
45,105✔
2800
  }
2801

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

2804
  if (sStreamReaderInfo->groupByTbname) {
154,146✔
2805
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
71,611✔
2806
  } else if (sStreamReaderInfo->partitionCols == NULL) {
82,535✔
2807
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
72,751✔
2808
  } else {
2809
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
9,784✔
2810
  }                             
2811
end:
325,177✔
2812
  blockDataDestroy(pResBlock);
325,453✔
2813
  taosMemoryFreeClear(pList);
325,170✔
2814
  STREAM_PRINT_LOG_END_WITHID(code, lino);
325,170✔
2815
  return code;
325,170✔
2816
}
2817

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

2827
  int32_t        pNum = 0;
64,346✔
2828
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
64,346✔
2829
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
64,346✔
2830
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
49,290✔
2831

2832
  pTaskInner->options->suid = sStreamReaderInfo->suid;
49,007✔
2833
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
49,007✔
2834
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
49,290✔
2835
  int32_t order = pTaskInner->options->order;
48,723✔
2836

2837
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
48,151✔
2838
end:
64,346✔
2839
  blockDataDestroy(pResBlock);
64,346✔
2840
  taosMemoryFreeClear(pList);
64,629✔
2841
  STREAM_PRINT_LOG_END_WITHID(code, lino);
64,346✔
2842
  return code;
64,346✔
2843
}
2844

2845
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
371,335✔
2846
                                  SStreamReaderTaskInner* pTaskInner) {
2847
  if (sStreamReaderInfo->isVtableStream) {
371,335✔
2848
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
46,318✔
2849
  }
2850

2851
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
325,453✔
2852
}
2853

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

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

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

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

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

2890
  void* pTask = sStreamReaderInfo->pTask;
242,851✔
2891

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

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

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

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

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

2921
  void* pTask = sStreamReaderInfo->pTask;
193,008✔
2922
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64
193,008✔
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;
193,008✔
2928

2929
  tsRsp.ver = pVnode->state.applied;
193,008✔
2930

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

2934
  if (req->firstTsReq.gid != 0) {
192,725✔
2935
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
64,346✔
2936
  } else {
2937
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
128,662✔
2938
  }
2939

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

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

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

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

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

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

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

3003
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
126,750✔
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++;
126,750✔
3007
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
126,750✔
3008
      break;
×
3009
    }
3010
  }
3011

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

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

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

3036
  void* pTask = sStreamReaderInfo->pTask;
78,891✔
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, 
78,891✔
3038
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3039
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3040

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

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

3060
    SSDataBlock* pBlock = NULL;
78,891✔
3061
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
78,891✔
3062
    if (pBlock != NULL && pBlock->info.rows > 0) {
78,891✔
3063
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
78,891✔
3064
          0, pBlock->info.rows, 1));
3065
    }
3066
    
3067
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
78,891✔
3068
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
78,891✔
3069
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
78,891✔
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);
78,891✔
3075

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

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

3086
  releaseStreamTask(&pTaskInner);
78,891✔
3087
  return code;
78,891✔
3088
}
3089

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

UNCOV
3098
  void* pTask = sStreamReaderInfo->pTask;
×
UNCOV
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, 
×
3100
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3101
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3102

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

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

UNCOV
3118
    SSDataBlock* pBlock = NULL;
×
UNCOV
3119
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
×
UNCOV
3120
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
×
UNCOV
3121
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
×
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

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

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

UNCOV
3136
  releaseStreamTask(&pTaskInner);
×
UNCOV
3137
  return code;
×
3138
}
3139

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

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

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

3169
  blockDataCleanup(pTaskInner->pResBlockDst);
161,253✔
3170
  bool hasNext = true;
161,253✔
3171
  int32_t totalRows = 0;
161,253✔
3172
    
3173
  pResList = taosArrayInit(4, POINTER_BYTES);
161,253✔
3174
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
161,253✔
3175
  while (1) {
156,539✔
3176
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
317,792✔
3177
    if (!hasNext) {
317,504✔
3178
      break;
101,765✔
3179
    }
3180
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
215,739✔
3181
    // pTaskInner->pResBlockDst->info.id.groupId = pTaskInner->pResBlock->info.id.groupId;
3182

3183
    SSDataBlock* pBlock = NULL;
215,739✔
3184
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
215,739✔
3185
    if (pBlock != NULL && pBlock->info.rows > 0) {
215,451✔
3186
      STREAM_CHECK_RET_GOTO(
215,451✔
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));
215,739✔
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);
215,739✔
3192
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
215,739✔
3193
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
215,451✔
3194
    totalRows += blockDataGetNumOfRows(pBlockTmp);
215,451✔
3195
    pBlockTmp = NULL;
215,451✔
3196

3197
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
215,451✔
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
215,451✔
3201
      break;
59,200✔
3202
    }
3203
  }
3204

3205
  STREAM_CHECK_RET_GOTO(buildArrayRsp(pResList, &buf, &size));
160,965✔
3206
  if (!hasNext) {
161,253✔
3207
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
102,053✔
3208
  }
3209

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

3221
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
7,447,996✔
3222
  int32_t code = 0;
7,447,996✔
3223
  int32_t lino = 0;
7,447,996✔
3224
  void*   buf = NULL;
7,447,996✔
3225
  size_t  size = 0;
7,448,247✔
3226
  SSDataBlock*   pBlockRes = NULL;
7,448,247✔
3227
  STableKeyInfo* pList = NULL;
7,448,247✔
3228

3229

3230
  void* pTask = sStreamReaderInfo->pTask;
7,448,505✔
3231
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
7,448,247✔
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);
7,448,247✔
3235

3236
  SStreamReaderTaskInner* pTaskInner = NULL;
7,448,505✔
3237
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
7,448,505✔
3238

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

3246
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
7,442,589✔
3247
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
7,447,473✔
3248
  } else {
3249
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3250
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3251
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3252
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3253
  }
3254

3255
  blockDataCleanup(pTaskInner->pResBlockDst);
7,445,409✔
3256
  bool hasNext = true;
7,446,699✔
3257
  while (1) {
769,616✔
3258
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
8,216,315✔
3259
    if (!hasNext) {
8,210,141✔
3260
      break;
7,440,507✔
3261
    }
3262
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
769,634✔
3263

3264
    SSDataBlock* pBlock = NULL;
769,846✔
3265
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
769,846✔
3266
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
769,146✔
3267
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
769,606✔
3268
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
769,606✔
3269
      break;
×
3270
    }
3271
  }
3272

3273
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
7,441,023✔
3274
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
7,447,749✔
3275
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
7,444,911✔
3276
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
7,446,975✔
3277
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
7,442,331✔
3278
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
7,442,589✔
3279
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
7,449,519✔
3280

3281
  if (!hasNext) {
7,448,505✔
3282
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
7,448,505✔
3283
  }
3284

3285
end:
7,448,763✔
3286
  STREAM_PRINT_LOG_END_WITHID(code, lino);
7,447,013✔
3287
  SRpcMsg rsp = {
7,449,021✔
3288
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3289
  tmsgSendRsp(&rsp);
7,448,247✔
3290
  blockDataDestroy(pBlockRes);
7,446,957✔
3291
  taosMemoryFree(pList);
7,447,473✔
3292
  return code;
7,447,473✔
3293
}
3294

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

3312
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
58,381✔
3313
    // sort cid and build slotIdList
3314
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
58,381✔
3315
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
58,381✔
3316
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
58,381✔
3317
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
58,381✔
3318
    taosArraySort(sortedCid, sortCid);
58,381✔
3319
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
182,993✔
3320
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
124,612✔
3321
      STREAM_CHECK_NULL_GOTO(cid, terrno);
124,612✔
3322
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
200,733✔
3323
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
200,733✔
3324
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
200,733✔
3325
        if (*cid == *cidSorted) {
200,733✔
3326
          slotIdList[j] = i;
124,612✔
3327
          break;
124,612✔
3328
        }
3329
      }
3330
    }
3331

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

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

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

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

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

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

3393
  void* pTask = sStreamReaderInfo->pTask;
3,222,829✔
3394
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
3,222,540✔
3395

3396
  if (sStreamReaderInfo->metaBlock == NULL) {
3,222,985✔
3397
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
113,812✔
3398
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
113,812✔
3399
  }
3400
  blockDataEmpty(sStreamReaderInfo->metaBlock);
3,222,829✔
3401
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,222,100✔
3402
  resultRsp.ver = req->walMetaNewReq.lastVer;
3,222,100✔
3403
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
3,222,389✔
3404

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

3414
end:
3,222,829✔
3415
  if (code == 0 && resultRsp.totalRows == 0) {
3,222,829✔
3416
    code = TSDB_CODE_STREAM_NO_DATA;
3,106,764✔
3417
    size = sizeof(int64_t) * 2;
3,106,764✔
3418
    buf = rpcMallocCont(size);
3,106,764✔
3419
    *(int64_t*)buf = resultRsp.ver;
3,106,186✔
3420
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
3,106,186✔
3421
  }
3422
  SRpcMsg rsp = {
3,222,540✔
3423
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3424
  tmsgSendRsp(&rsp);
3,221,679✔
3425
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,222,131✔
3426
    code = 0;
3,106,066✔
3427
  }
3428
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,222,131✔
3429
  blockDataDestroy(resultRsp.deleteBlock);
3,222,829✔
3430
  blockDataDestroy(resultRsp.tableBlock);
3,222,829✔
3431

3432
  return code;
3,222,829✔
3433
}
3434
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
5,724,396✔
3435
  int32_t      code = 0;
5,724,396✔
3436
  int32_t      lino = 0;
5,724,396✔
3437
  void*        buf = NULL;
5,724,396✔
3438
  size_t       size = 0;
5,724,396✔
3439
  SSTriggerWalNewRsp resultRsp = {0};
5,724,396✔
3440
  
3441
  void* pTask = sStreamReaderInfo->pTask;
5,724,103✔
3442
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
5,724,683✔
3443

3444
  if (sStreamReaderInfo->metaBlock == NULL) {
5,724,683✔
3445
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
141,813✔
3446
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
141,813✔
3447
  }
3448

3449
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
5,724,391✔
3450
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
5,724,967✔
3451
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
5,721,930✔
3452
  resultRsp.checkAlter = true;
5,722,181✔
3453
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
5,722,181✔
3454
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
5,721,438✔
3455

3456
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
5,721,438✔
3457

3458
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
5,721,005✔
3459
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
156,597✔
3460
  buf = rpcMallocCont(size);
156,618✔
3461
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
156,618✔
3462
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
156,618✔
3463
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
156,618✔
3464
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
156,618✔
3465
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
156,618✔
3466
  printIndexHash(resultRsp.indexHash, pTask);
156,618✔
3467

3468
end:
5,720,715✔
3469
  if (resultRsp.totalRows == 0) {
5,720,250✔
3470
    code = TSDB_CODE_STREAM_NO_DATA;
5,565,264✔
3471
    size = sizeof(int64_t) * 2;
5,565,264✔
3472
    buf = rpcMallocCont(size);
5,565,264✔
3473
    *(int64_t*)buf = resultRsp.ver;
5,561,476✔
3474
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
5,561,760✔
3475
  }
3476
  SRpcMsg rsp = {
5,718,633✔
3477
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3478
  tmsgSendRsp(&rsp);
5,717,946✔
3479
  if (code == TSDB_CODE_STREAM_NO_DATA){
5,722,971✔
3480
    code = 0;
5,566,673✔
3481
  }
3482
  blockDataDestroy(resultRsp.dataBlock);
5,722,971✔
3483
  blockDataDestroy(resultRsp.deleteBlock);
5,719,183✔
3484
  blockDataDestroy(resultRsp.tableBlock);
5,719,756✔
3485
  tSimpleHashCleanup(resultRsp.indexHash);
5,720,187✔
3486

3487
  STREAM_PRINT_LOG_END_WITHID(code, lino);
5,716,821✔
3488

3489
  return code;
5,718,701✔
3490
}
3491

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

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

3502
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
782,661✔
3503
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
782,661✔
3504
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
782,661✔
3505
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
782,661✔
3506
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
782,661✔
3507

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

3511
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
782,661✔
3512

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

3519
end:
782,661✔
3520
  if (resultRsp.totalRows == 0) {
782,661✔
3521
    buf = rpcMallocCont(sizeof(int64_t));
741,003✔
3522
    *(int64_t *)buf = resultRsp.ver;
740,744✔
3523
    size = sizeof(int64_t);
741,003✔
3524
    code = TSDB_CODE_STREAM_NO_DATA;
741,003✔
3525
  }
3526
  SRpcMsg rsp = {
782,661✔
3527
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3528
  tmsgSendRsp(&rsp);
782,402✔
3529
  if (code == TSDB_CODE_STREAM_NO_DATA){
782,372✔
3530
    code = 0;
740,714✔
3531
  }
3532

3533
  blockDataDestroy(resultRsp.dataBlock);
782,372✔
3534
  blockDataDestroy(resultRsp.deleteBlock);
782,117✔
3535
  blockDataDestroy(resultRsp.tableBlock);
781,828✔
3536
  tSimpleHashCleanup(resultRsp.indexHash);
781,828✔
3537
  tSimpleHashCleanup(resultRsp.uidHash);
782,113✔
3538
  STREAM_PRINT_LOG_END_WITHID(code, lino);
781,858✔
3539

3540
  return code;
782,372✔
3541
}
3542

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

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

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

3566
  if (!sStreamReaderInfo->isVtableStream){
206,506✔
3567
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
176,161✔
3568
  
3569
    blockDataTransform(pBlock2, resultRsp.dataBlock);
176,161✔
3570
    blockDataDestroy(resultRsp.dataBlock);
175,877✔
3571
    resultRsp.dataBlock = pBlock2;
175,877✔
3572
    pBlock2 = NULL;
175,877✔
3573
  }
3574

3575
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
205,938✔
3576
  buf = rpcMallocCont(size);
206,222✔
3577
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
206,222✔
3578
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
206,511✔
3579
  printIndexHash(resultRsp.indexHash, pTask);
206,222✔
3580

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

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

3604
  return code;
252,718✔
3605
}
3606

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

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

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

3640
  return code;
293,325✔
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) {
40,849✔
3644
  int32_t              code = 0;
40,849✔
3645
  int32_t              lino = 0;
40,849✔
3646
  void* pTask = sStreamReaderInfo->pTask;
40,849✔
3647

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

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

3655
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, ver, uid);
40,563✔
3656
  if (code != 0) {
40,849✔
3657
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
3658
    goto end;
×
3659
  }
3660
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
40,849✔
3661
    vTable->cols.nCols = metaReader->me.colRef.nCols;
1,020✔
3662
    vTable->cols.version = metaReader->me.colRef.version;
1,020✔
3663
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
1,020✔
3664
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
1,020✔
3665
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
6,120✔
3666
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
5,100✔
3667
    }
3668
  } else {
3669
    vTable->cols.nCols = taosArrayGetSize(cids);
39,829✔
3670
    vTable->cols.version = metaReader->me.colRef.version;
39,829✔
3671
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
39,829✔
3672
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
39,829✔
3673
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
128,491✔
3674
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
390,372✔
3675
        if (metaReader->me.colRef.pColRef[j].hasRef &&
349,694✔
3676
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
255,691✔
3677
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
47,984✔
3678
          break;
47,984✔
3679
        }
3680
      }
3681
    }
3682
  }
3683
  tDecoderClear(&metaReader->coder);
40,849✔
3684

3685
end:
40,849✔
3686
  return code;
40,849✔
3687
}
3688

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

3695

3696
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
27,137✔
3697
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
27,137✔
3698

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

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

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

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

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

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

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

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

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

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

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

3770
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
27,137✔
3771
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
27,137✔
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));
27,137✔
3776
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
27,137✔
3777

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

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

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

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

3802
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
32,864✔
3803

3804
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
32,864✔
3805

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

3821
    SSchemaWrapper* sSchemaWrapper = NULL;
51,809✔
3822
    if (metaReader.me.type == TD_CHILD_TABLE) {
51,809✔
3823
      int64_t suid = metaReader.me.ctbEntry.suid;
49,546✔
3824
      vTableInfo->suid = suid;
49,546✔
3825
      tDecoderClear(&metaReader.coder);
49,546✔
3826
      STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->origTableInfoReq.ver, suid));
48,968✔
3827
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
49,546✔
3828
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
2,263✔
3829
      vTableInfo->suid = 0;
2,263✔
3830
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
2,263✔
3831
    } else {
3832
      ST_TASK_ELOG("invalid table type:%d", metaReader.me.type);
×
3833
    }
3834

3835
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
238,573✔
3836
      SSchema* s = sSchemaWrapper->pSchema + j;
238,573✔
3837
      if (strcmp(s->name, oInfo->refColName) == 0) {
238,284✔
3838
        vTableInfo->cid = s->colId;
51,809✔
3839
        break;
51,809✔
3840
      }
3841
    }
3842
    if (vTableInfo->cid == 0) {
51,520✔
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);
51,809✔
3847
  }
3848

3849
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
32,864✔
3850

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

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

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

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

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

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

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

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

3927
      if (pDst->info.colId == -1) {
189,176✔
3928
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
107,122✔
3929
        continue;
107,122✔
3930
      }
3931
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
82,054✔
3932
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3933
        continue;
×
3934
      }
3935

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

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

3947
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
82,054✔
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) &&
82,054✔
3951
          (data != NULL)) {
3952
        taosMemoryFree(data);
25,382✔
3953
      }
3954
    }
3955
  } else {
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);
109,690✔
3962
  printDataBlock(pBlock, __func__, "", streamId);
109,690✔
3963
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
109,690✔
3964

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

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

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

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

4000
  void* pTask = sStreamReaderCalcInfo->pTask;
7,533,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,
7,533,578✔
4002
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
4003

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

4024
    initStorageAPI(&handle.api);
3,950,313✔
4025
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
3,949,918✔
4026
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
3,052,934✔
4027
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,757,434✔
4028
      if (node != NULL) {
3,757,434✔
4029
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
360,278✔
4030
      } else {
4031
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
3,397,156✔
4032
      }
4033

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

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

4046
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
3,950,313✔
4047
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
517,709✔
4048
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
517,709✔
4049
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
4050
                                                    req.taskId));
4051
      STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
517,709✔
4052
    } else {
4053
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
3,432,604✔
4054
    }
4055

4056
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
3,949,999✔
4057
  }
4058

4059
  if (req.pOpParam != NULL) {
7,533,251✔
4060
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
183,302✔
4061
  }
4062

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

4068
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
19,586,680✔
4069
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
12,055,128✔
4070
    if (pBlock == NULL) continue;
12,055,128✔
4071
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
12,055,128✔
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:
7,532,668✔
4081
  code = streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision);
7,533,280✔
4082

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

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

4130
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
26,635,818✔
4131
  int32_t                   code = 0;
26,635,818✔
4132
  int32_t                   lino = 0;
26,635,818✔
4133
  SSTriggerPullRequestUnion req = {0};
26,635,818✔
4134
  void*                     taskAddr = NULL;
26,636,362✔
4135
  bool                      sendRsp = false;
26,633,595✔
4136

4137
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
26,633,595✔
4138
  if (!syncIsReadyForRead(pVnode->sync)) {
26,634,806✔
4139
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
153,885✔
4140
    return 0;
153,659✔
4141
  }
4142

4143
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
26,481,345✔
4144
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
7,533,578✔
4145
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
18,947,763✔
4146
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
18,948,546✔
4147
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
18,948,724✔
4148
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
18,948,720✔
4149
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
18,948,186✔
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);
18,949,059✔
4152
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
18,947,595✔
4153
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
18,918,462✔
4154
    sendRsp = true;
18,919,652✔
4155
    switch (req.base.type) {
18,919,652✔
4156
      case STRIGGER_PULL_SET_TABLE:
32,864✔
4157
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
32,864✔
4158
        break;
32,864✔
4159
      case STRIGGER_PULL_LAST_TS:
243,109✔
4160
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
243,109✔
4161
        break;
243,109✔
4162
      case STRIGGER_PULL_FIRST_TS:
193,008✔
4163
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
193,008✔
4164
        break;
193,008✔
4165
      case STRIGGER_PULL_TSDB_META:
129,524✔
4166
      case STRIGGER_PULL_TSDB_META_NEXT:
4167
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
129,524✔
4168
        break;
129,524✔
4169
      case STRIGGER_PULL_TSDB_TS_DATA:
78,891✔
4170
        if (sStreamReaderInfo->isVtableStream) {
78,891✔
UNCOV
4171
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
4172
        } else {
4173
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
78,891✔
4174
        }
4175
        break;
78,891✔
4176
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
290,260✔
4177
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4178
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
290,260✔
4179
        break;
160,681✔
4180
      case STRIGGER_PULL_TSDB_CALC_DATA:
7,448,505✔
4181
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4182
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
7,448,505✔
4183
        break;
7,447,215✔
4184
      case STRIGGER_PULL_TSDB_DATA:
58,381✔
4185
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4186
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
58,381✔
4187
        break;
58,381✔
4188
      case STRIGGER_PULL_GROUP_COL_VALUE:
293,325✔
4189
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
293,325✔
4190
        break;
293,325✔
4191
      case STRIGGER_PULL_VTABLE_INFO:
27,137✔
4192
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
27,137✔
4193
        break;
27,137✔
4194
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
109,690✔
4195
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
109,690✔
4196
        break;
109,690✔
4197
      case STRIGGER_PULL_OTABLE_INFO:
32,864✔
4198
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
32,864✔
4199
        break;
32,864✔
4200
      case STRIGGER_PULL_WAL_META_NEW:
3,222,604✔
4201
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,222,604✔
4202
        break;
3,222,573✔
4203
      case STRIGGER_PULL_WAL_DATA_NEW:
782,372✔
4204
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
782,372✔
4205
        break;
782,372✔
4206
      case STRIGGER_PULL_WAL_META_DATA_NEW:
5,724,108✔
4207
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
5,724,108✔
4208
        break;
5,721,291✔
4209
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
253,002✔
4210
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
253,002✔
4211
        break;
253,002✔
4212
      default:
9✔
4213
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
9✔
4214
        sendRsp = false;
4✔
4215
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
4✔
4216
    }
4217
  } else {
4218
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
8✔
4219
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4220
  }
4221
end:
18,934,493✔
4222

4223
  streamReleaseTask(taskAddr);
18,944,901✔
4224

4225
  tDestroySTriggerPullRequest(&req);
18,947,635✔
4226
  STREAM_PRINT_LOG_END(code, lino);
18,937,138✔
4227
  if (!sendRsp) {
18,943,866✔
4228
    SRpcMsg rsp = {
58,266✔
4229
      .code = code,
4230
      .pCont = pMsg->info.rsp,
29,133✔
4231
      .contLen = pMsg->info.rspLen,
29,133✔
4232
      .info = pMsg->info,
4233
    };
4234
    tmsgSendRsp(&rsp);
29,133✔
4235
  }
4236
  return code;
18,943,277✔
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