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

taosdata / TDengine / #5008

29 Mar 2026 04:32AM UTC coverage: 72.241% (-0.009%) from 72.25%
#5008

push

travis-ci

web-flow
refactor: do some internal refactor for TDgpt. (#34955)

253593 of 351039 relevant lines covered (72.24%)

130989730.42 hits per line

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

83.58
/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) {
6,240,994✔
65
  int64_t suid = 0;
6,240,994✔
66
  if (!sStreamReaderInfo->isVtableStream) {
6,240,994✔
67
    suid = sStreamReaderInfo->suid;
6,171,395✔
68
    goto end;
6,171,395✔
69
  }
70

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

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

84
end:
6,240,994✔
85
  return suid;
6,240,994✔
86
}
87

88
static int64_t getSessionKey(int64_t session, int64_t type) { return (session | (type << 32)); }
6,130,153✔
89

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

94
  if (*c1 < *c2) {
143,672✔
95
    return -1;
142,852✔
96
  } else if (*c1 > *c2) {
820✔
97
    return 1;
820✔
98
  }
99

100
  return 0;
×
101
}
102

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

107
  if (c1->colId < c2->colId) {
143,672✔
108
    return -1;
142,852✔
109
  } else if (c1->colId > c2->colId) {
820✔
110
    return 1;
820✔
111
  }
112

113
  return 0;
×
114
}
115

116
static int32_t addColData(SSDataBlock* pResBlock, int32_t index, void* data) {
9,468,623✔
117
  SColumnInfoData* pSrc = taosArrayGet(pResBlock->pDataBlock, index);
9,468,623✔
118
  if (pSrc == NULL) {
9,471,000✔
119
    return terrno;
×
120
  }
121

122
  memcpy(pSrc->pData + pResBlock->info.rows * pSrc->info.bytes, data, pSrc->info.bytes);
9,471,000✔
123
  return 0;
9,469,653✔
124
}
125

126
static int32_t getTableDataInfo(SStreamReaderTaskInner* pTask, bool* hasNext) {
7,415,448✔
127
  int32_t code = pTask->storageApi->tsdReader.tsdNextDataBlock(pTask->pReader, hasNext);
7,415,448✔
128
  if (code != TSDB_CODE_SUCCESS) {
7,414,850✔
129
    pTask->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTask->pReader);
×
130
  }
131

132
  return code;
7,414,457✔
133
}
134

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

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

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

162
static bool needReLoadTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int8_t tableType, int64_t suid, int64_t uid, bool isCalc){
1,298,433✔
163
  if ((tableType == TD_CHILD_TABLE || tableType == TD_VIRTUAL_CHILD_TABLE) &&
1,298,433✔
164
      sStreamReaderInfo->tableType == TD_SUPER_TABLE && 
597,007✔
165
      suid == sStreamReaderInfo->suid) {
344,132✔
166
    taosRLockLatch(&sStreamReaderInfo->lock);
10,349✔
167
    uint64_t gid = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
10,349✔
168
    taosRUnLockLatch(&sStreamReaderInfo->lock);
10,349✔
169
    if (gid == (uint64_t)-1) return true;
10,349✔
170
  }
171
  return false;
1,288,842✔
172
}
173

174
static bool uidInTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id){
9,744,304✔
175
  int32_t  ret = false;
9,744,304✔
176
  if (sStreamReaderInfo->tableType == TD_SUPER_TABLE) {
9,744,304✔
177
    if (suid != sStreamReaderInfo->suid) goto end;
5,868,084✔
178
    if (qStreamGetTableListNum(sStreamReaderInfo) == 0) goto end;
2,165,572✔
179
  } 
180
  *id = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, uid);
6,039,352✔
181
  if (*id == -1) goto end;
6,037,258✔
182
  ret = true;
3,902,753✔
183

184
end:
9,745,257✔
185
  stTrace("%s ret:%d %p %p check suid:%" PRId64 " uid:%" PRId64 " gid:%"PRIu64, __func__, ret, sStreamReaderInfo, sStreamReaderInfo->tableList.gIdMap, suid, uid, *id);
9,745,257✔
186
  return ret;
9,743,146✔
187
}
188

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

193
static bool uidInTableListSet(SStreamTriggerReaderInfo* sStreamReaderInfo, int64_t suid, int64_t uid, uint64_t* id, bool isCalc) {
12,344,101✔
194
  bool ret = false;
12,344,101✔
195
  taosRLockLatch(&sStreamReaderInfo->lock);
12,344,101✔
196
  if (sStreamReaderInfo->isVtableStream) {
12,345,042✔
197
    int64_t tmp[2] = {suid, uid};
2,614,579✔
198
    if(tSimpleHashGet(isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, tmp, sizeof(tmp)) != NULL) {
2,614,579✔
199
      *id = uid;
1,358,139✔
200
      ret = true;
1,358,139✔
201
    }
202
  } else {
203
    ret = uidInTableList(sStreamReaderInfo, suid, uid, id);
9,729,518✔
204
  }
205

206
end:
12,341,024✔
207
  taosRUnLockLatch(&sStreamReaderInfo->lock);
12,341,024✔
208
  return ret;
12,346,158✔
209
}
210

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

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

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

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

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

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

299

300
static int32_t buildRsp(SSDataBlock* pBlock, void** data, size_t* size) {
6,359,330✔
301
  int32_t code = 0;
6,359,330✔
302
  int32_t lino = 0;
6,359,330✔
303
  void*   buf = NULL;
6,359,330✔
304
  STREAM_CHECK_CONDITION_GOTO(pBlock == NULL || pBlock->info.rows == 0, TSDB_CODE_SUCCESS);
6,359,330✔
305
  size_t dataEncodeSize = blockGetEncodeSize(pBlock);
722,445✔
306
  buf = rpcMallocCont(dataEncodeSize);
722,445✔
307
  STREAM_CHECK_NULL_GOTO(buf, terrno);
722,445✔
308
  int32_t actualLen = blockEncode(pBlock, buf, dataEncodeSize, taosArrayGetSize(pBlock->pDataBlock));
722,445✔
309
  STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
722,445✔
310
  *data = buf;
722,445✔
311
  *size = dataEncodeSize;
722,257✔
312
  buf = NULL;
722,445✔
313
end:
6,360,355✔
314
  rpcFreeCont(buf);
6,360,355✔
315
  return code;
6,359,330✔
316
}
317

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

322
  void*   buf = NULL;
55,579✔
323

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

336
  char* dataBuf = (char*)buf;
55,579✔
337
  *((int32_t*)(dataBuf)) = blockNum;
55,579✔
338
  dataBuf += INT_BYTES;
55,579✔
339
  for(size_t i = 0; i < taosArrayGetSize(pBlockList); i++){
116,302✔
340
    SSDataBlock* pBlock = taosArrayGetP(pBlockList, i);
60,723✔
341
    if (pBlock == NULL || pBlock->info.rows == 0) continue;
60,723✔
342
    int32_t actualLen = blockEncode(pBlock, dataBuf, dataEncodeBufSize, taosArrayGetSize(pBlock->pDataBlock));
60,723✔
343
    STREAM_CHECK_CONDITION_GOTO(actualLen < 0, terrno);
60,723✔
344
    dataBuf += actualLen;
60,723✔
345
  }
346
  *data = buf;
55,579✔
347
  *size = INT_BYTES + dataEncodeBufSize;
55,579✔
348
  buf = NULL;
55,579✔
349
end:
55,579✔
350
  rpcFreeCont(buf);
55,579✔
351
  return code;
55,579✔
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,106,245✔
375
  int32_t code = 0;
2,106,245✔
376
  int32_t lino = 0;
2,106,245✔
377
  int32_t index = 0;
2,106,245✔
378
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &id));
2,106,245✔
379
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &skey));
2,106,020✔
380
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ekey));
2,106,420✔
381
  STREAM_CHECK_RET_GOTO(addColData(pBlock, index++, &ver));
2,106,420✔
382

383
end:
2,106,650✔
384
  return code;
2,106,650✔
385
}
386

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

554
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
29,660✔
555
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
14,830✔
556
    STREAM_CHECK_NULL_GOTO(pDropTbReq, TSDB_CODE_INVALID_PARA);
14,830✔
557
    uint64_t id = 0;
14,830✔
558
    if(!uidInTableListOrigin(sStreamReaderInfo, pDropTbReq->suid, pDropTbReq->uid, &id)) {
14,830✔
559
      continue;
13,960✔
560
    }
561

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

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

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

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

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

641
  if (taosArrayGetSize(uidList) == 0) {
45,734✔
642
    return 0;
16,676✔
643
  }
644
  STREAM_CHECK_RET_GOTO(nodesCloneList(sStreamReaderInfo->partitionCols, &groupNew));  
29,058✔
645
  STREAM_CHECK_RET_GOTO(qStreamFilterTableListForReader(sStreamReaderInfo->pVnode, uidList, groupNew, sStreamReaderInfo->pTagCond,
29,058✔
646
                                                    sStreamReaderInfo->pTagIndexCond, &sStreamReaderInfo->storageApi,
647
                                                    sStreamReaderInfo->groupIdMap, sStreamReaderInfo->suid, tableList));
648

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

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

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

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

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

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

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

711
  ST_TASK_DLOG("%s start, name:%s uid:%"PRId64, __func__, pCreateReq->name, pCreateReq->uid);
1,274,212✔
712
  if (!needReLoadTableList(sStreamReaderInfo, pCreateReq->type, pCreateReq->ctb.suid, pCreateReq->uid, false) ||
1,275,909✔
713
      ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
1,936✔
714
    ST_TASK_DLOG("stream reader scan auto create table jump, %s", pCreateReq->name);
1,272,694✔
715
    goto end;
1,273,172✔
716
  }
717
  uidList = taosArrayInit(8, sizeof(tb_uid_t));
1,408✔
718
  STREAM_CHECK_NULL_GOTO(uidList, terrno);
1,408✔
719
  STREAM_CHECK_NULL_GOTO(taosArrayPush(uidList, &pCreateReq->uid), terrno);
2,816✔
720
  ST_TASK_DLOG("stream reader scan auto create table %s", pCreateReq->name);
1,408✔
721

722
  STREAM_CHECK_RET_GOTO(processTableList(sStreamReaderInfo, uidList, &tableList));
1,408✔
723
  STREAM_CHECK_RET_GOTO(qStreamModifyTableList(sStreamReaderInfo, tableList, uidList));
1,408✔
724
end:
1,272,193✔
725
  taosArrayDestroy(uidList);
1,274,350✔
726
  taosArrayDestroy(tableList);
1,274,350✔
727
  return code;
1,274,580✔
728
}
729

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

905
  ST_TASK_DLOG("%s start", __func__);
34,532✔
906

907
  SVAlterTbReq req = {0};
34,532✔
908
  tDecoderInit(&decoder, data, len);
34,532✔
909
  
910
  STREAM_CHECK_RET_GOTO(tDecodeSVAlterTbReq(&decoder, &req));
34,532✔
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 && 
34,532✔
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;
24,872✔
916
  if (req.action == TSDB_ALTER_TABLE_ALTER_COLUMN_REF || req.action == TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
24,872✔
917
    STREAM_CHECK_CONDITION_GOTO(!sStreamReaderInfo->isVtableStream, TDB_CODE_SUCCESS);
5,107✔
918
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
466✔
919
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
466✔
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));
466✔
925
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL) {
19,765✔
926
    uidList = getTableListForAlterSuperTable(sStreamReaderInfo, &req);
19,765✔
927
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
19,765✔
928
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
19,765✔
929
  } else if (req.action == TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL) {
×
930
    code = checkAlter(sStreamReaderInfo, req.tbName, req.action, &uid);
×
931
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
×
932
      ST_TASK_WLOG("stream reader scan alter table %s not exist, metaGetTableUidByName", req.tbName);
×
933
      code = 0;
×
934
      goto end;
×
935
    }
936
    uidList = taosArrayInit(8, sizeof(uint64_t));
×
937
    STREAM_CHECK_NULL_GOTO(uidList, terrno);
×
938
    STREAM_CHECK_RET_GOTO(vnodeGetCtbIdList(sStreamReaderInfo->pVnode, uid, uidList));
×
939
    STREAM_CHECK_RET_GOTO(scanAlterTableTagVal(sStreamReaderInfo, rsp, uidList, ver));
×
940
  }
941

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

944
end:
34,532✔
945
  destroyAlterTbReq(&req);
34,532✔
946

947
  taosArrayDestroy(uidList);
34,532✔
948
  tDecoderClear(&decoder);
34,532✔
949
  STREAM_PRINT_LOG_END_WITHID(code, lino);
34,532✔
950
  return code;
34,532✔
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) {
5,092,099✔
996
  int32_t code = 0;
5,092,099✔
997
  int32_t lino = 0;
5,092,099✔
998
  WalMetaResult walMeta = {0};
5,092,099✔
999
  SSubmitTbData submitTbData = {0};
5,092,099✔
1000
  
1001
  if (tStartDecode(pCoder) < 0) {
5,091,409✔
1002
    code = TSDB_CODE_INVALID_MSG;
×
1003
    TSDB_CHECK_CODE(code, lino, end);
×
1004
  }
1005

1006
  uint8_t       version = 0;
5,092,127✔
1007
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
5,091,412✔
1008
    code = TSDB_CODE_INVALID_MSG;
×
1009
    TSDB_CHECK_CODE(code, lino, end);
×
1010
  }
1011
  version = (submitTbData.flags >> 8) & 0xff;
5,091,412✔
1012
  submitTbData.flags = submitTbData.flags & 0xff;
5,091,412✔
1013

1014
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1015
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
5,091,412✔
1016
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
399,747✔
1017
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
399,537✔
1018
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
399,537✔
1019
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
399,537✔
1020
  }
1021

1022
  // submit data
1023
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
5,091,387✔
1024
    code = TSDB_CODE_INVALID_MSG;
×
1025
    TSDB_CHECK_CODE(code, lino, end);
×
1026
  }
1027
  if (tDecodeI64(pCoder, &submitTbData.uid) < 0) {
5,091,432✔
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)){
5,091,432✔
1033
    goto end;
4,262,813✔
1034
  }
1035
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
828,874✔
1036
    code = TSDB_CODE_INVALID_MSG;
×
1037
    TSDB_CHECK_CODE(code, lino, end);
×
1038
  }
1039

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

1075
    for (int32_t iRow = 0; iRow < nRow; ++iRow) {
2,705,539✔
1076
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
1,876,635✔
1077
      pCoder->pos += pRow->len;
1,876,635✔
1078
      if (iRow == 0){
1,876,635✔
1079
#ifndef NO_UNALIGNED_ACCESS
1080
        walMeta.skey = pRow->ts;
828,904✔
1081
#else
1082
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1083
#endif
1084
      }
1085
      if (iRow == nRow - 1) {
1,876,635✔
1086
#ifndef NO_UNALIGNED_ACCESS
1087
        walMeta.ekey = pRow->ts;
828,904✔
1088
#else
1089
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1090
#endif
1091
      }
1092
    }
1093
  }
1094

1095
  WalMetaResult* data = (WalMetaResult*)tSimpleHashGet(gidHash, &walMeta.id, LONG_BYTES);
828,904✔
1096
  if (data != NULL) {
828,904✔
1097
    if (walMeta.skey < data->skey) data->skey = walMeta.skey;
944✔
1098
    if (walMeta.ekey > data->ekey) data->ekey = walMeta.ekey;
944✔
1099
  } else {
1100
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(gidHash, &walMeta.id, LONG_BYTES, &walMeta, sizeof(WalMetaResult)));
827,960✔
1101
  }
1102

1103
end:
5,085,764✔
1104
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
5,091,177✔
1105
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
5,090,262✔
1106
  tEndDecode(pCoder);
5,090,262✔
1107
  return code;
5,090,267✔
1108
}
1109

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

1117
  tDecoderInit(&decoder, data, len);
5,091,183✔
1118
  if (tStartDecode(&decoder) < 0) {
5,088,713✔
1119
    code = TSDB_CODE_INVALID_MSG;
×
1120
    TSDB_CHECK_CODE(code, lino, end);
×
1121
  }
1122

1123
  uint64_t nSubmitTbData = 0;
5,090,553✔
1124
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
5,090,133✔
1125
    code = TSDB_CODE_INVALID_MSG;
×
1126
    TSDB_CHECK_CODE(code, lino, end);
×
1127
  }
1128

1129
  gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
5,090,133✔
1130
  STREAM_CHECK_NULL_GOTO(gidHash, terrno);
5,090,515✔
1131

1132
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
10,181,267✔
1133
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataForMeta(&decoder, sStreamReaderInfo, gidHash, ver));
5,091,689✔
1134
  }
1135
  tEndDecode(&decoder);
5,089,578✔
1136

1137
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
5,090,983✔
1138
  int32_t iter = 0;
5,089,843✔
1139
  void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
5,090,298✔
1140
  while (px != NULL) {
5,914,613✔
1141
    WalMetaResult* pMeta = (WalMetaResult*)px;
827,330✔
1142
    STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
827,330✔
1143
    ((SSDataBlock*)rsp->metaBlock)->info.rows++;
828,160✔
1144
    rsp->totalRows++;
828,160✔
1145
    ST_TASK_DLOG("stream reader scan submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
828,160✔
1146
          ", ver:%"PRId64, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1147
    px = tSimpleHashIterate(gidHash, px, &iter);
828,160✔
1148
  }
1149
end:
5,087,283✔
1150
  tDecoderClear(&decoder);
5,090,068✔
1151
  tSimpleHashCleanup( gidHash);
5,089,850✔
1152
  return code;
5,088,988✔
1153
}
1154

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

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

1170
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
117,583✔
1171

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

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

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

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

1191
  STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, pBlock));
198,026✔
1192

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

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

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

1205
  SDecoder dcoder = {0};
296,230✔
1206
  tDecoderInit(&dcoder, data, len);
296,230✔
1207
  if (msgType == TDMT_VND_DELETE && sStreamReaderInfo->deleteReCalc != 0) {
296,230✔
1208
    if (rsp->deleteBlock == NULL) {
26,940✔
1209
      STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&rsp->deleteBlock));
8,008✔
1210
    }
1211
      
1212
    STREAM_CHECK_RET_GOTO(scanDeleteDataNew(sStreamReaderInfo, rsp, data, len, ver));
26,940✔
1213
  } else if (msgType == TDMT_VND_DROP_TABLE && 
269,290✔
1214
    (sStreamReaderInfo->deleteOutTbl != 0 || sStreamReaderInfo->isVtableStream)) {
30,671✔
1215
    STREAM_CHECK_RET_GOTO(scanDropTableNew(sStreamReaderInfo, rsp, data, len, ver));
14,830✔
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)) {
254,460✔
1219
    STREAM_CHECK_RET_GOTO(scanCreateTableNew(sStreamReaderInfo, rsp, data, len, ver));
24,561✔
1220
  } else if (msgType == TDMT_VND_ALTER_STB && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
229,899✔
1221
    // STREAM_CHECK_RET_GOTO(scanAlterSTableNew(sStreamReaderInfo, data, len));
1222
  } else if (msgType == TDMT_VND_ALTER_TABLE && !ignoreMetaChange(sStreamReaderInfo->tableList.version, ver)) {
203,779✔
1223
    STREAM_CHECK_RET_GOTO(scanAlterTableNew(sStreamReaderInfo, rsp, data, len, ver));
34,532✔
1224
  }
1225

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

1236
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
2,862,748✔
1237
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
2,861,941✔
1238
  code = walReaderSeekVer(pWalReader, rsp->ver);
2,861,941✔
1239
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
2,861,490✔
1240
    if (rsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,574,029✔
1241
      rsp->ver = walGetFirstVer(pWalReader->pWal);
×
1242
      rsp->verTime = 0;
×
1243
    } else {
1244
      rsp->verTime = taosGetTimestampUs();
2,574,030✔
1245
    }
1246
    ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
2,573,142✔
1247
    code = TSDB_CODE_SUCCESS;
2,575,032✔
1248
    goto end;
2,575,032✔
1249
  }
1250
  STREAM_CHECK_RET_GOTO(code);
287,461✔
1251

1252
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, STREAM_RETURN_ROWS_NUM));
287,461✔
1253
  while (1) {
5,279,928✔
1254
    code = walNextValidMsg(pWalReader, true);
5,567,184✔
1255
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
5,567,529✔
1256
      rsp->verTime = taosGetTimestampUs();
285,206✔
1257
      ST_TASK_DLOG("vgId:%d %s scan wal end:%s", TD_VID(pVnode), __func__, tstrerror(code));
285,206✔
1258
      code = TSDB_CODE_SUCCESS;
285,206✔
1259
      goto end;
285,206✔
1260
    }
1261
    STREAM_CHECK_RET_GOTO(code);
5,282,013✔
1262
    rsp->ver = pWalReader->curVersion;
5,282,013✔
1263
    SWalCont* wCont = &pWalReader->pHead->head;
5,282,233✔
1264
    rsp->verTime = wCont->ingestTs;
5,283,083✔
1265
    if (wCont->ingestTs / 1000 > ctime) break;
5,282,665✔
1266
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
5,282,343✔
1267
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
5,283,560✔
1268
    int64_t ver = wCont->version;
5,282,678✔
1269

1270
    ST_TASK_DLOG("vgId:%d stream reader scan wal ver:%" PRId64 "/%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d",
5,282,858✔
1271
      TD_VID(pVnode), ver, walGetAppliedVer(pWalReader->pWal), TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl);
1272
    if (wCont->msgType == TDMT_VND_SUBMIT) {
5,284,812✔
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) {
5,093,263✔
1275
        rsp->ver--;
2,510✔
1276
        break;
2,510✔
1277
      }
1278
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
5,090,983✔
1279
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
5,091,413✔
1280
      STREAM_CHECK_RET_GOTO(scanSubmitDataForMeta(sStreamReaderInfo, rsp, data, len, ver));
5,091,413✔
1281
    } else {
1282
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, rsp, ver));
190,520✔
1283
    }
1284

1285
    if (rsp->totalRows >= STREAM_RETURN_ROWS_NUM) {
5,279,728✔
1286
      break;
×
1287
    }
1288
  }
1289

1290
end:
2,862,748✔
1291
  walCloseReader(pWalReader);
2,862,748✔
1292
  return code;
2,862,518✔
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) {
39,772,820✔
1296
  int32_t     code = 0;
39,772,820✔
1297
  int32_t     lino = 0;
39,772,820✔
1298
  SMetaReader mr = {0};
39,772,820✔
1299
  SArray* tagCache = NULL;
39,779,061✔
1300
  char* data = NULL;
39,785,581✔
1301

1302
  if (lock != NULL) taosWLockLatch(lock);
39,788,885✔
1303
  STREAM_CHECK_CONDITION_GOTO(numOfExpr == 0, code);
39,801,943✔
1304
  stDebug("%s start,uid:%"PRIu64, __func__, uid);
2,105,367✔
1305
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
2,106,121✔
1306
  if (uidData == NULL) {
2,105,367✔
1307
    tagCache = taosArrayInit(numOfExpr, POINTER_BYTES);
2,086,972✔
1308
    STREAM_CHECK_NULL_GOTO(tagCache, terrno);
2,086,972✔
1309
    if(taosHashPut(metaCache, &uid, LONG_BYTES, &tagCache, POINTER_BYTES) != 0) {
2,086,972✔
1310
      taosArrayDestroy(tagCache);
×
1311
      code = terrno;
×
1312
      goto end;
×
1313
    }
1314
  } else {
1315
    tagCache = *(SArray**)uidData;
18,395✔
1316
    stDebug("%s found tagCache, size:%zu %d, uid:%"PRIu64, __func__, taosArrayGetSize(tagCache), numOfExpr, uid);
18,395✔
1317
    STREAM_CHECK_CONDITION_GOTO(taosArrayGetSize(tagCache) != numOfExpr, TSDB_CODE_INVALID_PARA);
18,395✔
1318
  }
1319
  
1320
  api->metaReaderFn.initReader(&mr, pVnode, META_READER_LOCK, &api->metaFn);
2,105,367✔
1321
  code = api->metaReaderFn.getEntryGetUidCache(&mr, uid);
2,105,367✔
1322
  api->metaReaderFn.readerReleaseLock(&mr);
2,104,616✔
1323
  STREAM_CHECK_RET_GOTO(code);
2,104,426✔
1324
  
1325
  for (int32_t j = 0; j < numOfExpr; ++j) {
7,452,758✔
1326
    const SExprInfo* pExpr1 = &pExprInfo[j];
5,354,968✔
1327
    int32_t functionId = pExpr1->pExpr->_function.functionId;
5,354,254✔
1328
    col_id_t cid = 0;
5,356,017✔
1329
    // this is to handle the tbname
1330
    if (fmIsScanPseudoColumnFunc(functionId)) {
5,356,017✔
1331
      int32_t fType = pExpr1->pExpr->_function.functionType;
483,735✔
1332
      if (fType == FUNCTION_TYPE_TBNAME) {
484,152✔
1333
        data = taosMemoryCalloc(1, strlen(mr.me.name) + VARSTR_HEADER_SIZE);
484,152✔
1334
        STREAM_CHECK_NULL_GOTO(data, terrno);
483,778✔
1335
        STR_TO_VARSTR(data, mr.me.name)
483,778✔
1336
      }
1337
      cid = -1;
483,962✔
1338
    } else {  // these are tags
1339
      const char* p = NULL;
4,870,357✔
1340
      char* pData = NULL;
4,870,357✔
1341
      int8_t type = pExpr1->base.resSchema.type;
4,870,357✔
1342
      int32_t len = pExpr1->base.resSchema.bytes;
4,871,111✔
1343
      STagVal tagVal = {0};
4,870,734✔
1344
      tagVal.cid = pExpr1->base.pParam[0].pCol->colId;
4,870,734✔
1345
      cid = tagVal.cid;
4,870,757✔
1346
      if (colId != 0 && cid != colId) {
4,870,757✔
1347
        continue;
1,020✔
1348
      }
1349
      p = api->metaFn.extractTagVal(mr.me.ctbEntry.pTags, type, &tagVal);
4,869,737✔
1350

1351
      if (type != TSDB_DATA_TYPE_JSON && p != NULL) {
4,867,452✔
1352
        pData = tTagValToData((const STagVal*)p, false);
4,864,032✔
1353
      } else {
1354
        pData = (char*)p;
3,420✔
1355
      }
1356

1357
      if (pData != NULL && (type == TSDB_DATA_TYPE_JSON || !IS_VAR_DATA_TYPE(type))) {
4,869,337✔
1358
        if (type == TSDB_DATA_TYPE_JSON) {
2,476,170✔
1359
          len = getJsonValueLen(pData);
×
1360
        }
1361
        data = taosMemoryCalloc(1, len);
2,476,170✔
1362
        STREAM_CHECK_NULL_GOTO(data, terrno);
2,476,170✔
1363
        (void)memcpy(data, pData, len);
2,476,170✔
1364
      } else {
1365
        data = pData;
2,393,167✔
1366
      }
1367
    }
1368
    if (uidData == NULL){
5,352,925✔
1369
      STREAM_CHECK_NULL_GOTO(taosArrayPush(tagCache, &data), terrno);
10,636,134✔
1370
    } else {
1371
      void* pre = taosArrayGetP(tagCache, j);
35,565✔
1372
      taosMemoryFree(pre);
35,565✔
1373
      taosArraySet(tagCache, j, &data);
35,565✔
1374
    }
1375
    data = NULL;
5,353,524✔
1376
  }
1377

1378
end:
39,800,080✔
1379
  taosMemoryFree(data);
39,780,408✔
1380
  api->metaReaderFn.clearReader(&mr);
39,793,247✔
1381
  if (lock != NULL) taosWUnLockLatch(lock);
39,793,537✔
1382
  return code;
39,789,826✔
1383
}
1384

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

1394
  taosRLockLatch(lock);
68,820,094✔
1395
  void* uidData = taosHashGet(metaCache, &uid, LONG_BYTES);
68,879,522✔
1396
  if (uidData == NULL) {
68,874,963✔
1397
    stError("%s error uidData is null,uid:%"PRIu64, __func__, uid);
×
1398
  } else {
1399
    tagCache = *(SArray**)uidData;
68,874,963✔
1400
    if(taosArrayGetSize(tagCache) != numOfExpr) {
68,874,599✔
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) {
300,241,455✔
1407
    const SExprInfo* pExpr1 = &pExprInfo[j];
231,370,310✔
1408
    int32_t          dstSlotId = pExpr1->base.resSchema.slotId;
231,372,872✔
1409

1410
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
231,383,488✔
1411
    STREAM_CHECK_NULL_GOTO(pColInfoData, terrno);
231,362,185✔
1412
    int32_t functionId = pExpr1->pExpr->_function.functionId;
231,362,185✔
1413

1414
    // this is to handle the tbname
1415
    if (fmIsScanPseudoColumnFunc(functionId)) {
231,371,366✔
1416
      int32_t fType = pExpr1->pExpr->_function.functionType;
2,698,437✔
1417
      if (fType == FUNCTION_TYPE_TBNAME) {
2,698,437✔
1418
        pColInfoData->info.colId = -1;
2,698,437✔
1419
      }
1420
    } 
1421
    char* data = tagCache == NULL ? NULL : taosArrayGetP(tagCache, j);
231,317,475✔
1422

1423
    bool isNullVal = (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data));
231,284,979✔
1424
    if (isNullVal) {
231,286,684✔
1425
      colDataSetNNULL(pColInfoData, currentRow, numOfRows);
×
1426
    } else {
1427
      if (!IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
231,286,684✔
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);
230,962,227✔
1433
      STREAM_CHECK_RET_GOTO(code);
231,375,378✔
1434
    }
1435
  }
1436
end:
68,871,145✔
1437
  taosRUnLockLatch(lock);
68,871,145✔
1438
  return code;
68,878,787✔
1439
}
1440

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

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

1456
end:
2,591,431✔
1457
  return code;
2,591,431✔
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,997,273✔
1506
  int32_t code = 0;
1,997,273✔
1507
  int32_t lino = 0;
1,997,273✔
1508
  int64_t id[2] = {suid, uid};
1,997,273✔
1509
  taosRLockLatch(&sStreamReaderInfo->lock);
1,997,273✔
1510
  void *px = tSimpleHashGet(rsp->isCalc ? sStreamReaderInfo->uidHashCalc : sStreamReaderInfo->uidHashTrigger, id, sizeof(id));
1,997,893✔
1511
  STREAM_CHECK_NULL_GOTO(px, TSDB_CODE_INVALID_PARA);
1,997,693✔
1512
  SSHashObj* uInfo = *(SSHashObj **)px;
1,997,693✔
1513
  STREAM_CHECK_NULL_GOTO(uInfo, TSDB_CODE_INVALID_PARA);
1,997,693✔
1514
  int16_t*  tmp = tSimpleHashGet(uInfo, &i, sizeof(i));
1,997,693✔
1515
  if (tmp != NULL) {
1,997,413✔
1516
    *colId = *tmp;
1,704,986✔
1517
  } else {
1518
    *colId = -1;
292,427✔
1519
  }
1520

1521
end:
1,997,893✔
1522
  taosRUnLockLatch(&sStreamReaderInfo->lock);
1,997,203✔
1523
  return code;
1,997,893✔
1524
}
1525

1526
static int32_t getSchemas(SVnode* pVnode, int64_t suid, int64_t uid, int32_t sver, SStreamTriggerReaderInfo* sStreamReaderInfo, STSchema** schema) {
3,153,151✔
1527
  int32_t code = 0;
3,153,151✔
1528
  int32_t lino = 0;
3,153,151✔
1529
  int64_t id = suid != 0 ? suid : uid;
3,153,151✔
1530
  if (sStreamReaderInfo->isVtableStream) {
3,153,351✔
1531
    STSchema** schemaTmp = taosHashGet(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES);
789,063✔
1532
    if (schemaTmp == NULL || *schemaTmp == NULL || (*schemaTmp)->version != sver) {
788,863✔
1533
      *schema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
21,748✔
1534
      STREAM_CHECK_NULL_GOTO(*schema, terrno);
21,538✔
1535
      code = taosHashPut(sStreamReaderInfo->triggerTableSchemaMapVTable, &id, LONG_BYTES, schema, POINTER_BYTES);
21,538✔
1536
      if (code != 0) {
21,538✔
1537
        taosMemoryFree(*schema);
×
1538
        goto end;
×
1539
      }
1540
    } else {
1541
      *schema = *schemaTmp;
767,115✔
1542
    }
1543
  } else {
1544
    if (sStreamReaderInfo->triggerTableSchema == NULL || sStreamReaderInfo->triggerTableSchema->version != sver) {
2,364,058✔
1545
      taosMemoryFree(sStreamReaderInfo->triggerTableSchema);
77,643✔
1546
      sStreamReaderInfo->triggerTableSchema = metaGetTbTSchema(pVnode->pMeta, id, sver, 1);
77,643✔
1547
      STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerTableSchema, terrno);
77,643✔
1548
    }
1549
    *schema = sStreamReaderInfo->triggerTableSchema;
2,364,058✔
1550
  }
1551
  
1552
end:
3,152,941✔
1553
  return code;
3,152,941✔
1554
}
1555

1556
static int32_t scanSubmitTbData(SVnode* pVnode, SDecoder *pCoder, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,826,418✔
1557
  SSHashObj* ranges, SSHashObj* gidHash, SSTriggerWalNewRsp* rsp, int64_t ver) {
1558
  int32_t code = 0;
3,826,418✔
1559
  int32_t lino = 0;
3,826,418✔
1560
  uint64_t id = 0;
3,826,418✔
1561
  WalMetaResult walMeta = {0};
3,826,614✔
1562
  void* pTask = sStreamReaderInfo->pTask;
3,826,154✔
1563
  SSDataBlock * pBlock = (SSDataBlock*)rsp->dataBlock;
3,826,384✔
1564

1565
  if (tStartDecode(pCoder) < 0) {
3,826,614✔
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};
3,826,844✔
1572
  uint8_t       version = 0;
3,825,667✔
1573
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
3,827,113✔
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;
3,827,113✔
1579
  submitTbData.flags = submitTbData.flags & 0xff;
3,827,113✔
1580
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1581
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
3,827,113✔
1582
    if (tStartDecode(pCoder) < 0) {
116,137✔
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);
116,137✔
1588
  }
1589

1590
  // submit data
1591
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
3,826,623✔
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) {
3,826,147✔
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);
3,826,147✔
1603

1604
  if (rsp->uidHash != NULL) {
3,826,393✔
1605
    uint64_t* gid = tSimpleHashGet(rsp->uidHash, &submitTbData.uid, LONG_BYTES);
1,892,162✔
1606
    STREAM_CHECK_CONDITION_GOTO(gid == NULL, TDB_CODE_SUCCESS);
1,892,622✔
1607
    ST_TASK_DLOG("%s get uid gid from uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, submitTbData.uid, submitTbData.suid, *gid);
1,892,622✔
1608
    id = *gid;
1,892,622✔
1609
  } else {
1610
    STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, submitTbData.uid, &id, rsp->isCalc), TDB_CODE_SUCCESS);
1,934,461✔
1611
  }
1612

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

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

1635
  SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &submitTbData.uid, LONG_BYTES);
3,152,721✔
1636
  int32_t blockStart = 0;
3,153,581✔
1637
  int32_t numOfRows = 0;
3,153,581✔
1638
  if (submitTbData.flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
3,153,371✔
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,153,371✔
1722
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,152,741✔
1723
      code = TSDB_CODE_INVALID_MSG;
×
1724
      TSDB_CHECK_CODE(code, lino, end);
×
1725
    }
1726
    for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
7,657,174✔
1727
      SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
4,504,923✔
1728
      pCoder->pos += pRow->len;
4,504,923✔
1729

1730
      if (iRow == 0){
4,505,153✔
1731
#ifndef NO_UNALIGNED_ACCESS
1732
        walMeta.skey = pRow->ts;
3,153,151✔
1733
#else
1734
        walMeta.skey = taosGetInt64Aligned(&pRow->ts);
1735
#endif
1736
      }
1737
      if (iRow == nRow - 1) {
4,505,153✔
1738
#ifndef NO_UNALIGNED_ACCESS
1739
        walMeta.ekey = pRow->ts;
3,153,151✔
1740
#else
1741
        walMeta.ekey = taosGetInt64Aligned(&pRow->ts);
1742
#endif
1743
      }
1744

1745
      if (pRow->ts < window.skey || pRow->ts > window.ekey) {
4,504,943✔
1746
        continue;
190,870✔
1747
      }
1748
      STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
4,314,283✔
1749
      blockStart = pSlice->currentRowIdx;
4,314,283✔
1750
     
1751
      for (int16_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {  // reader todo test null
28,056,461✔
1752
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
23,741,479✔
1753
        STREAM_CHECK_NULL_GOTO(pColData, terrno);
23,742,221✔
1754
        if (pColData->info.colId <= -1) {
23,742,221✔
1755
          pColData->hasNull = true;
8,267,827✔
1756
          continue;
8,267,807✔
1757
        }
1758
        int16_t colId = 0;
15,474,450✔
1759
        if (sStreamReaderInfo->isVtableStream){
15,475,680✔
1760
          STREAM_CHECK_RET_GOTO(getColId(submitTbData.suid, submitTbData.uid, i, sStreamReaderInfo, rsp, &colId));
1,996,853✔
1761
          ST_TASK_TLOG("%s vtable colId:%d, i:%d, uid:%" PRId64, __func__, colId, i, submitTbData.uid);
1,997,903✔
1762
        } else {
1763
          colId = pColData->info.colId;
13,479,717✔
1764
        }
1765
        
1766
        SColVal colVal = {0};
15,477,850✔
1767
        int32_t sourceIdx = 0;
15,477,380✔
1768
        while (1) {
1769
          if (sourceIdx >= schema->numOfCols) {
38,410,097✔
1770
            break;
6,095,708✔
1771
          }
1772
          STREAM_CHECK_RET_GOTO(tRowGet(pRow, schema, sourceIdx, &colVal));
32,313,771✔
1773
          if (colVal.cid == colId) {
32,315,140✔
1774
            break;
9,382,423✔
1775
          }
1776
          sourceIdx++;
22,932,717✔
1777
        }
1778
        if (colVal.cid == colId && COL_VAL_IS_VALUE(&colVal)) {
15,478,131✔
1779
          if (IS_VAR_DATA_TYPE(colVal.value.type) || colVal.value.type == TSDB_DATA_TYPE_DECIMAL){
9,307,933✔
1780
            STREAM_CHECK_RET_GOTO(varColSetVarData(pColData, blockStart+ numOfRows, (const char*)colVal.value.pData, colVal.value.nData, !COL_VAL_IS_VALUE(&colVal)));
24,966✔
1781
            ST_TASK_TLOG("%s vtable colId:%d, i:%d, colData:%p, data:%s, len:%d, rowIndex:%d, offset:%d, uid:%" PRId64, __func__, colId, i, pColData, 
26,095✔
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)));
9,282,967✔
1785
          }
1786
        } else {
1787
          colDataSetNULL(pColData, blockStart + numOfRows);
6,170,198✔
1788
        }
1789
      }
1790
      
1791
      numOfRows++;
4,313,563✔
1792
    }
1793
  }
1794

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

1804
    STREAM_CHECK_NULL_GOTO(pSlice, TSDB_CODE_INVALID_PARA);
3,152,961✔
1805
    ST_TASK_DLOG("%s process submit data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
3,152,961✔
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,153,381✔
1809
    pBlock->info.rows += numOfRows;
3,153,142✔
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,153,151✔
1816

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

1825
end:
3,824,161✔
1826
  if (code != 0) {                                                             \
3,827,104✔
1827
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code)); \
×
1828
  }
1829
  tEndDecode(pCoder);
3,827,104✔
1830
  return code;
3,826,423✔
1831
}
1832
static int32_t scanSubmitData(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo,
3,826,595✔
1833
  void* data, int32_t len, SSHashObj* ranges, SSTriggerWalNewRsp* rsp, int64_t ver) {
1834
  int32_t  code = 0;
3,826,595✔
1835
  int32_t  lino = 0;
3,826,595✔
1836
  SDecoder decoder = {0};
3,826,595✔
1837
  SSHashObj* gidHash = NULL;
3,826,853✔
1838
  void* pTask = sStreamReaderInfo->pTask;
3,826,853✔
1839

1840
  tDecoderInit(&decoder, data, len);
3,827,083✔
1841
  if (tStartDecode(&decoder) < 0) {
3,826,623✔
1842
    code = TSDB_CODE_INVALID_MSG;
×
1843
    TSDB_CHECK_CODE(code, lino, end);
×
1844
  }
1845

1846
  uint64_t nSubmitTbData = 0;
3,827,313✔
1847
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
3,827,083✔
1848
    code = TSDB_CODE_INVALID_MSG;
×
1849
    TSDB_CHECK_CODE(code, lino, end);
×
1850
  }
1851

1852
  if (rsp->metaBlock != NULL){
3,827,083✔
1853
    gidHash = tSimpleHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
1,934,461✔
1854
    STREAM_CHECK_NULL_GOTO(gidHash, terrno);
1,932,330✔
1855
  }
1856

1857
  for (uint64_t i = 0; i < nSubmitTbData; i++) {
7,651,145✔
1858
    STREAM_CHECK_RET_GOTO(scanSubmitTbData(pVnode, &decoder, sStreamReaderInfo, ranges, gidHash, rsp, ver));
3,825,924✔
1859
  }
1860

1861
  tEndDecode(&decoder);
3,825,221✔
1862

1863
  if (rsp->metaBlock != NULL){
3,826,883✔
1864
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(rsp->metaBlock, ((SSDataBlock*)rsp->metaBlock)->info.rows + tSimpleHashGetSize(gidHash)));
1,934,691✔
1865
    int32_t iter = 0;
1,934,001✔
1866
    void*   px = tSimpleHashIterate(gidHash, NULL, &iter);
1,934,001✔
1867
    while (px != NULL) {
3,195,181✔
1868
      WalMetaResult* pMeta = (WalMetaResult*)px;
1,260,729✔
1869
      STREAM_CHECK_RET_GOTO(buildWalMetaBlockNew(rsp->metaBlock, pMeta->id, pMeta->skey, pMeta->ekey, ver));
1,260,729✔
1870
      ((SSDataBlock*)rsp->metaBlock)->info.rows++;
1,260,959✔
1871
      rsp->totalRows++;
1,260,959✔
1872
      ST_TASK_DLOG("%s process meta data:skey %" PRId64 ", ekey %" PRId64 ", id %" PRIu64
1,260,959✔
1873
            ", ver:%"PRId64, __func__, pMeta->skey, pMeta->ekey, pMeta->id, ver);
1874
      px = tSimpleHashIterate(gidHash, px, &iter);
1,260,959✔
1875
    }
1876
  }
1877
  
1878

1879
end:
3,823,354✔
1880
  tSimpleHashCleanup(gidHash);
3,826,644✔
1881
  tDecoderClear(&decoder);
3,826,223✔
1882
  return code;
3,826,414✔
1883
}
1884

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

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

1896
  SSubmitTbData submitTbData = {0};
5,294,987✔
1897
  uint8_t       version = 0;
5,294,987✔
1898
  if (tDecodeI32v(pCoder, &submitTbData.flags) < 0) {
5,295,008✔
1899
    code = TSDB_CODE_INVALID_MSG;
×
1900
    TSDB_CHECK_CODE(code, lino, end);
×
1901
  }
1902
  version = (submitTbData.flags >> 8) & 0xff;
5,295,008✔
1903
  submitTbData.flags = submitTbData.flags & 0xff;
5,295,008✔
1904

1905
  // STREAM_CHECK_CONDITION_GOTO(version < 2, TDB_CODE_SUCCESS);
1906
  if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
5,295,008✔
1907
    submitTbData.pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
874,603✔
1908
    STREAM_CHECK_NULL_GOTO(submitTbData.pCreateTbReq, terrno);
874,143✔
1909
    STREAM_CHECK_RET_GOTO(tDecodeSVCreateTbReq(pCoder, submitTbData.pCreateTbReq));
874,143✔
1910
    STREAM_CHECK_RET_GOTO(processAutoCreateTableNew(sStreamReaderInfo, submitTbData.pCreateTbReq, ver));
874,465✔
1911
  }
1912

1913
  // submit data
1914
  if (tDecodeI64(pCoder, &submitTbData.suid) < 0) {
5,295,668✔
1915
    code = TSDB_CODE_INVALID_MSG;
×
1916
    TSDB_CHECK_CODE(code, lino, end);
×
1917
  }
1918
  if (tDecodeI64(pCoder, uid) < 0) {
5,295,217✔
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);
5,295,217✔
1923
  STREAM_CHECK_CONDITION_GOTO(!uidInTableListSet(sStreamReaderInfo, submitTbData.suid, *uid, gid, rsp->isCalc), TDB_CODE_SUCCESS);
5,294,971✔
1924
  if (rsp->uidHash != NULL) {
3,153,581✔
1925
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->uidHash, uid, LONG_BYTES, gid, LONG_BYTES));
1,892,622✔
1926
    ST_TASK_DLOG("%s put uid into uidHash, uid:%" PRId64 ", suid:%" PRId64 " gid:%"PRIu64, __func__, *uid, submitTbData.suid, *gid);
1,892,622✔
1927
  }
1928
  STimeWindow window = {.skey = INT64_MIN, .ekey = INT64_MAX};
3,153,581✔
1929

1930
  if (ranges != NULL){
3,153,581✔
1931
    void* timerange = tSimpleHashGet(ranges, gid, sizeof(*gid));
1,892,622✔
1932
    if (timerange == NULL) goto end;;
1,892,622✔
1933
    int64_t* pRange = (int64_t*)timerange;
1,892,622✔
1934
    window.skey = pRange[0];
1,892,622✔
1935
    window.ekey = pRange[1];
1,892,622✔
1936
  }
1937
  
1938
  if (tDecodeI32v(pCoder, &submitTbData.sver) < 0) {
3,152,912✔
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,152,912✔
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,152,912✔
1970
    if (tDecodeU64v(pCoder, &nRow) < 0) {
3,153,142✔
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,153,142✔
1976
      for (uint64_t iRow = 0; iRow < nRow; ++iRow) {
4,928,580✔
1977
        SRow *pRow = (SRow *)(pCoder->data + pCoder->pos);
3,035,958✔
1978
        pCoder->pos += pRow->len;
3,035,958✔
1979
        if (pRow->ts < window.skey || pRow->ts > window.ekey) {
3,036,197✔
1980
          continue;
190,870✔
1981
        }
1982
        (*numOfRows)++;
2,845,327✔
1983
      }
1984
    } else {
1985
      (*numOfRows) = nRow;
1,260,959✔
1986
    }
1987
  }
1988
  
1989
end:
5,295,874✔
1990
  tDestroySVSubmitCreateTbReq(submitTbData.pCreateTbReq, TSDB_MSG_FLG_DECODE);
5,295,193✔
1991
  taosMemoryFreeClear(submitTbData.pCreateTbReq);
5,294,353✔
1992
  tEndDecode(pCoder);
5,293,982✔
1993
  return code;
5,295,166✔
1994
}
1995

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

2002
  tDecoderInit(&decoder, data, len);
5,295,907✔
2003
  if (tStartDecode(&decoder) < 0) {
5,294,327✔
2004
    code = TSDB_CODE_INVALID_MSG;
×
2005
    TSDB_CHECK_CODE(code, lino, end);
×
2006
  }
2007

2008
  uint64_t nSubmitTbData = 0;
5,295,477✔
2009
  if (tDecodeU64v(&decoder, &nSubmitTbData) < 0) {
5,294,757✔
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);
5,294,757✔
2014

2015
  for (int32_t i = 0; i < nSubmitTbData; i++) {
10,590,894✔
2016
    uint64_t gid = -1;
5,295,907✔
2017
    int64_t  uid = 0;
5,295,907✔
2018
    int32_t numOfRows = 0;
5,296,137✔
2019
    STREAM_CHECK_RET_GOTO(scanSubmitTbDataPre(&decoder, sStreamReaderInfo, ranges, &gid, &uid, &numOfRows, rsp, ver));
5,296,137✔
2020
    if (numOfRows <= 0) {
5,295,494✔
2021
      ST_TASK_DLOG("%s no valid data uid:%" PRId64 ", gid:%" PRIu64 ", numOfRows:%d, ver:%"PRId64, __func__, uid, gid, numOfRows, ver);
2,141,913✔
2022
      continue;
2,142,326✔
2023
    }
2024
    rsp->totalRows += numOfRows;
3,153,581✔
2025
    rsp->totalDataRows += numOfRows;
3,153,351✔
2026

2027
    SStreamWalDataSlice* pSlice = (SStreamWalDataSlice*)tSimpleHashGet(rsp->indexHash, &uid, LONG_BYTES);
3,153,351✔
2028
    if (pSlice != NULL) {
3,153,121✔
2029
      pSlice->numRows += numOfRows;
2,771,959✔
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);
2,771,959✔
2031
      pSlice->gId = gid;
2,772,198✔
2032
    } else {
2033
      SStreamWalDataSlice tmp = {.gId=gid,.numRows=numOfRows,.currentRowIdx=0,.startRowIdx=0};
381,162✔
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);
381,162✔
2035
      STREAM_CHECK_RET_GOTO(tSimpleHashPut(rsp->indexHash, &uid, LONG_BYTES, &tmp, sizeof(tmp)));
381,162✔
2036
    } 
2037
  }
2038

2039
  tEndDecode(&decoder);
5,294,987✔
2040

2041
end:
5,295,217✔
2042
  tDecoderClear(&decoder);
5,295,217✔
2043
  return code;
5,295,677✔
2044
}
2045

2046
static void buildIndexHash(SSHashObj* indexHash, void* pTask){
318,886✔
2047
  void*   pe = NULL;
318,886✔
2048
  int32_t iter = 0;
318,886✔
2049
  int32_t index = 0;
318,886✔
2050
  while ((pe = tSimpleHashIterate(indexHash, pe, &iter)) != NULL) {
700,048✔
2051
    SStreamWalDataSlice* pInfo = (SStreamWalDataSlice*)pe;
381,162✔
2052
    pInfo->startRowIdx = index;
381,162✔
2053
    pInfo->currentRowIdx = index;
381,162✔
2054
    index += pInfo->numRows;
381,162✔
2055
    ST_TASK_DLOG("%s uid:%" PRId64 ", gid:%" PRIu64 ", startRowIdx:%d, numRows:%d", __func__, *(int64_t*)(tSimpleHashGetKey(pe, NULL)),
568,334✔
2056
    pInfo->gId, pInfo->startRowIdx, pInfo->numRows);
2057
  }
2058
}
318,886✔
2059

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

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

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

2099
  code = walReaderSeekVer(pWalReader, resultRsp->ver);
3,087,359✔
2100
  if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,085,913✔
2101
    if (resultRsp->ver < walGetFirstVer(pWalReader->pWal)) {
2,637,230✔
2102
      resultRsp->ver = walGetFirstVer(pWalReader->pWal);
×
2103
      resultRsp->verTime = 0;
×
2104
    } else {
2105
      resultRsp->verTime = taosGetTimestampUs();
2,636,940✔
2106
    }
2107
    ST_TASK_DLOG("%s scan wal end:%s",  __func__, tstrerror(code));
2,637,523✔
2108
    code = TSDB_CODE_SUCCESS;
2,637,992✔
2109
    goto end;
2,637,992✔
2110
  }
2111
  STREAM_CHECK_RET_GOTO(code);
448,683✔
2112

2113
  while (1) {
3,508,995✔
2114
    code = walNextValidMsg(pWalReader, true);
3,957,678✔
2115
    if (code == TSDB_CODE_WAL_LOG_NOT_EXIST){
3,957,703✔
2116
      resultRsp->verTime = taosGetTimestampUs();
449,045✔
2117
      ST_TASK_DLOG("%s scan wal end:%s", __func__, tstrerror(code));
449,045✔
2118
      code = TSDB_CODE_SUCCESS;
449,045✔
2119
      goto end;
449,045✔
2120
    }
2121
    STREAM_CHECK_RET_GOTO(code);
3,508,649✔
2122
    resultRsp->ver = pWalReader->curVersion;
3,508,649✔
2123
    SWalCont* wCont = &pWalReader->pHead->head;
3,508,854✔
2124
    resultRsp->verTime = wCont->ingestTs;
3,508,265✔
2125
    void*   data = POINTER_SHIFT(wCont->body, sizeof(SMsgHead));
3,508,394✔
2126
    int32_t len = wCont->bodyLen - sizeof(SMsgHead);
3,508,158✔
2127
    int64_t ver = wCont->version;
3,507,560✔
2128
    ST_TASK_DLOG("%s scan wal ver:%" PRId64 ", type:%s, deleteData:%d, deleteTb:%d, msg len:%d", __func__,
3,506,550✔
2129
      ver, TMSG_INFO(wCont->msgType), sStreamReaderInfo->deleteReCalc, sStreamReaderInfo->deleteOutTbl, len);
2130
    if (wCont->msgType == TDMT_VND_SUBMIT) {
3,508,050✔
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) {
3,402,607✔
2133
        resultRsp->ver--;
×
2134
        break;
×
2135
      }
2136
      data = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
3,403,067✔
2137
      len = wCont->bodyLen - sizeof(SSubmitReq2Msg);
3,402,841✔
2138
      STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, data, len, NULL, resultRsp, ver));
3,402,841✔
2139
    } else {
2140
      STREAM_CHECK_RET_GOTO(processMeta(wCont->msgType, sStreamReaderInfo, data, len, resultRsp, ver));
105,710✔
2141
    }
2142

2143
    ST_TASK_DLOG("%s scan wal next ver:%" PRId64 ", totalRows:%d", __func__, resultRsp->ver, resultRsp->totalRows);
3,508,765✔
2144
    if (resultRsp->totalRows >= STREAM_RETURN_ROWS_NUM || resultRsp->needReturn) {
3,508,765✔
2145
      break;
2146
    }
2147
  }
2148
  
2149
end:
×
2150
  STREAM_PRINT_LOG_END(code, lino);
3,086,577✔
2151
  return code;
3,086,807✔
2152
}
2153

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

2160
  for(int32_t i = 0; i < taosArrayGetSize(versions); i++) {
2,776,122✔
2161
    int64_t *ver = taosArrayGet(versions, i);
1,892,622✔
2162
    if (ver == NULL) continue;
1,892,212✔
2163

2164
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, *ver));
1,892,212✔
2165
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
1,892,622✔
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));
1,892,622✔
2171

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

2176
    STREAM_CHECK_RET_GOTO(scanSubmitDataPre(sStreamReaderInfo, pBody, bodyLen, ranges, rsp, *ver));
1,892,221✔
2177
  }
2178
  
2179
end:
883,500✔
2180
  return code;
883,500✔
2181
}
2182

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

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

2191
  if (((SSDataBlock*)resultRsp->dataBlock)->info.rows < totalRows) {
318,886✔
2192
    filterIndexHash(resultRsp->indexHash, pRet);
5,347✔
2193
  }
2194

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

2201
static int32_t processWalVerMetaDataNew(SVnode* pVnode, SStreamTriggerReaderInfo* sStreamReaderInfo, 
3,086,773✔
2202
                                    SSTriggerWalNewRsp* resultRsp) {
2203
  int32_t      code = 0;
3,086,773✔
2204
  int32_t      lino = 0;
3,086,773✔
2205
  void* pTask = sStreamReaderInfo->pTask;
3,086,773✔
2206
                                        
2207
  SWalReader* pWalReader = walOpenReader(pVnode->pWal, 0);
3,086,773✔
2208
  STREAM_CHECK_NULL_GOTO(pWalReader, terrno);
3,085,521✔
2209
  blockDataEmpty(resultRsp->dataBlock);
3,085,521✔
2210
  blockDataEmpty(resultRsp->metaBlock);
3,083,562✔
2211
  int64_t lastVer = resultRsp->ver;                                      
3,082,415✔
2212
  STREAM_CHECK_RET_GOTO(prepareIndexMetaData(pWalReader, sStreamReaderInfo, resultRsp));
3,083,007✔
2213
  STREAM_CHECK_CONDITION_GOTO(resultRsp->totalRows == 0, TDB_CODE_SUCCESS);
3,085,657✔
2214

2215
  buildIndexHash(resultRsp->indexHash, pTask);
114,255✔
2216
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(((SSDataBlock*)resultRsp->dataBlock), resultRsp->totalRows));
114,255✔
2217
  while(lastVer < resultRsp->ver) {
2,087,141✔
2218
    STREAM_CHECK_RET_GOTO(walFetchHead(pWalReader, lastVer++));
1,973,815✔
2219
    if(pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
1,972,895✔
2220
      TAOS_CHECK_RETURN(walSkipFetchBody(pWalReader));
39,584✔
2221
      continue;
39,584✔
2222
    }
2223
    STREAM_CHECK_RET_GOTO(walFetchBody(pWalReader));
1,933,541✔
2224
    SWalCont* wCont = &pWalReader->pHead->head;
1,934,691✔
2225
    void*   pBody = POINTER_SHIFT(wCont->body, sizeof(SSubmitReq2Msg));
1,934,691✔
2226
    int32_t bodyLen = wCont->bodyLen - sizeof(SSubmitReq2Msg);
1,934,691✔
2227
    ST_TASK_DLOG("process wal ver:%" PRId64 ", type:%d, bodyLen:%d", wCont->version, wCont->msgType, bodyLen);
1,934,691✔
2228
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, NULL, resultRsp, wCont->version));
1,934,691✔
2229
  }
2230

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

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

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

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

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

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

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

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

2279
    STREAM_CHECK_RET_GOTO(scanSubmitData(pVnode, sStreamReaderInfo, pBody, bodyLen, ranges, rsp, wCont->version));
1,892,622✔
2280
  }
2281
  // printDataBlock(rsp->dataBlock, __func__, "processWalVerDataNew");
2282
  STREAM_CHECK_RET_GOTO(filterData(rsp, sStreamReaderInfo));
204,631✔
2283
  rsp->totalRows = ((SSDataBlock*)rsp->dataBlock)->info.rows;
204,631✔
2284

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

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

2302
  SSchemaWrapper* sSchemaWrapper = NULL;
65,356✔
2303
  if (metaReader.me.type == TD_CHILD_TABLE) {
65,356✔
2304
    int64_t suid = metaReader.me.ctbEntry.suid;
65,356✔
2305
    tDecoderClear(&metaReader.coder);
65,356✔
2306
    STREAM_CHECK_RET_GOTO(api->metaReaderFn.getTableEntryByUid(&metaReader, suid));
65,356✔
2307
    sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
65,356✔
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++) {
290,633✔
2315
    SSchema* s = sSchemaWrapper->pSchema + j;
225,277✔
2316
    STREAM_CHECK_NULL_GOTO(taosArrayPush(*schemas, s), terrno);
450,554✔
2317
  }
2318

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

2329
static int32_t shrinkScheams(SArray* cols, SArray* schemas) {
65,356✔
2330
  int32_t code = 0;
65,356✔
2331
  int32_t lino = 0;
65,356✔
2332
  size_t  schemaLen = taosArrayGetSize(schemas);
65,356✔
2333
  STREAM_CHECK_RET_GOTO(taosArrayEnsureCap(schemas, schemaLen + taosArrayGetSize(cols)));
65,356✔
2334
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
201,728✔
2335
    col_id_t* id = taosArrayGet(cols, i);
136,372✔
2336
    STREAM_CHECK_NULL_GOTO(id, terrno);
136,372✔
2337
    for (size_t i = 0; i < schemaLen; i++) {
265,088✔
2338
      SSchema* s = taosArrayGet(schemas, i);
265,088✔
2339
      STREAM_CHECK_NULL_GOTO(s, terrno);
265,088✔
2340
      if (*id == s->colId) {
265,088✔
2341
        STREAM_CHECK_NULL_GOTO(taosArrayPush(schemas, s), terrno);
136,372✔
2342
        break;
136,372✔
2343
      }
2344
    }
2345
  }
2346
  taosArrayPopFrontBatch(schemas, schemaLen);
65,356✔
2347

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

2489
    SSTriggerCalcParam* pFirst = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, 0);
219,603✔
2490
    SSTriggerCalcParam* pLast = taosArrayGetLast(req->pStRtFuncInfo->pStreamPesudoFuncVals);
219,603✔
2491
    STREAM_CHECK_NULL_GOTO(pFirst, terrno);
219,603✔
2492
    STREAM_CHECK_NULL_GOTO(pLast, terrno);
219,603✔
2493

2494
    if (!node->needCalc) {
219,603✔
2495
      pWin->skey = pFirst->wstart;
204,891✔
2496
      pWin->ekey = pLast->wend;
204,891✔
2497
      *pValid = true;
204,891✔
2498
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
204,891✔
2499
        pWin->ekey--;
131,329✔
2500
      }
2501
    } else {
2502
      SSTriggerCalcParam* pTmp = taosArrayGet(sStreamReaderCalcInfo->tmpRtFuncInfo.pStreamPesudoFuncVals, 0);
14,712✔
2503
      memcpy(pTmp, pFirst, sizeof(*pTmp));
14,844✔
2504

2505
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 1));
14,844✔
2506
      if (*pValid) {
14,844✔
2507
        int64_t skey = pWin->skey;
14,844✔
2508

2509
        memcpy(pTmp, pLast, sizeof(*pTmp));
14,844✔
2510
        STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, &sStreamReaderCalcInfo->tmpRtFuncInfo, pWin, pValid, 2));
14,844✔
2511

2512
        if (*pValid) {
14,844✔
2513
          pWin->skey = skey;
14,844✔
2514
        }
2515
      }
2516
      pWin->ekey--;
14,844✔
2517
    }
2518
  } else {
2519
    if (!node->needCalc) {
136,629✔
2520
      SSTriggerCalcParam* pCurr = taosArrayGet(req->pStRtFuncInfo->pStreamPesudoFuncVals, req->pStRtFuncInfo->curIdx);
93,411✔
2521
      pWin->skey = pCurr->wstart;
93,411✔
2522
      pWin->ekey = pCurr->wend;
93,411✔
2523
      *pValid = true;
93,411✔
2524
      if (req->pStRtFuncInfo->triggerType == STREAM_TRIGGER_SLIDING) {
93,411✔
2525
        pWin->ekey--;
45,647✔
2526
      }
2527
    } else {
2528
      STREAM_CHECK_RET_GOTO(streamCalcCurrWinTimeRange(node, req->pStRtFuncInfo, pWin, pValid, 3));
43,218✔
2529
      pWin->ekey--;
43,218✔
2530
    }
2531
  }
2532

2533
  ST_TASK_DLOG("%s type:%s, withExternalWindow:%d, skey:%" PRId64 ", ekey:%" PRId64 ", validRange:%d", 
356,364✔
2534
      __func__, isExtWin ? "interp range" : "scan time range", req->pStRtFuncInfo->withExternalWindow, pWin->skey, pWin->ekey, *pValid);
2535

2536
end:
6,200✔
2537

2538
  if (code) {
356,364✔
2539
    ST_TASK_ELOG("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
2540
  }
2541
  
2542
  return code;
356,364✔
2543
}
2544

2545
static int32_t createDataBlockTsUid(SSDataBlock** pBlockRet, uint32_t numOfRows) {
278,024✔
2546
  int32_t      code = 0;
278,024✔
2547
  int32_t      lino = 0;
278,024✔
2548
  SSDataBlock* pBlock = NULL;
278,024✔
2549
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
278,631✔
2550
  SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID);
278,444✔
2551
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
278,444✔
2552
  idata = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, LONG_BYTES, PRIMARYKEY_TIMESTAMP_COL_ID + 1);
278,631✔
2553
  STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
278,444✔
2554
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, numOfRows));
278,631✔
2555

2556
end:
278,444✔
2557
  STREAM_PRINT_LOG_END(code, lino)
278,444✔
2558
  if (code != TSDB_CODE_SUCCESS) {
278,631✔
2559
    blockDataDestroy(pBlock);
×
2560
    pBlock = NULL;
×
2561
  }
2562
  *pBlockRet = pBlock;
278,631✔
2563
  return code;
278,631✔
2564
}
2565

2566
static int32_t processTsOutPutAllTables(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
98,579✔
2567
  int32_t code = 0;
98,579✔
2568
  int32_t lino = 0;
98,579✔
2569
  void* pTask = sStreamReaderInfo->pTask;
98,579✔
2570

2571
  tsRsp->tsInfo = taosArrayInit(pResBlock->info.rows, sizeof(STsInfo));
98,579✔
2572
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
98,579✔
2573
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
98,579✔
2574
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
98,389✔
2575
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
350,218✔
2576
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
503,468✔
2577
      continue;
×
2578
    }
2579
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
251,639✔
2580
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
251,829✔
2581
    if (order == TSDB_ORDER_ASC) {
251,829✔
2582
      tsInfo->ts = INT64_MAX;
136,815✔
2583
    } else {
2584
      tsInfo->ts = INT64_MIN;
115,014✔
2585
    }
2586
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
251,639✔
2587
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
251,829✔
2588
      tsInfo->ts = ts;
136,815✔
2589
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
115,014✔
2590
      tsInfo->ts = ts;
115,014✔
2591
    }
2592
    tsInfo->gId = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
251,829✔
2593
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
251,639✔
2594
  }
2595

2596
end:
98,579✔
2597
  return code;
98,579✔
2598
}
2599

2600
static int32_t processTsOutPutOneGroup(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
80,486✔
2601
  int32_t code = 0;
80,486✔
2602
  int32_t lino = 0;
80,486✔
2603
  void* pTask = sStreamReaderInfo->pTask;
80,486✔
2604

2605
  tsRsp->tsInfo = taosArrayInit(1, sizeof(STsInfo));
80,256✔
2606
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
80,486✔
2607
  STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
80,486✔
2608
  STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
80,486✔
2609
  if (order == TSDB_ORDER_ASC) {
80,486✔
2610
    tsInfo->ts = INT64_MAX;
65,272✔
2611
  } else {
2612
    tsInfo->ts = INT64_MIN;
15,214✔
2613
  }
2614

2615
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
80,069✔
2616
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
80,026✔
2617
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
175,922✔
2618
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
191,835✔
2619
      continue;
×
2620
    }
2621
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
96,356✔
2622
    if (order == TSDB_ORDER_ASC && ts < tsInfo->ts) {
96,169✔
2623
      tsInfo->ts = ts;
65,042✔
2624
    } else if (order == TSDB_ORDER_DESC && ts > tsInfo->ts) {
30,897✔
2625
      tsInfo->ts = ts;
15,027✔
2626
    }
2627
  }
2628
  int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, 0);
80,026✔
2629
  tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
79,839✔
2630
  ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
80,486✔
2631

2632
end:
30,130✔
2633
  return code;
80,486✔
2634
}
2635

2636
static int32_t processTsOutPutAllGroups(SStreamTriggerReaderInfo* sStreamReaderInfo, SStreamTsResponse* tsRsp, SSDataBlock* pResBlock, int32_t order) {
7,729✔
2637
  int32_t code = 0;
7,729✔
2638
  int32_t lino = 0;
7,729✔
2639
  STableKeyInfo* pList = NULL;
7,729✔
2640
  StreamTableListInfo     tableInfo = {0};
7,729✔
2641

2642
  void* pTask = sStreamReaderInfo->pTask;
7,729✔
2643
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
7,541✔
2644

2645
  SSHashObj*   uidTsHash = tSimpleHashInit(pResBlock->info.rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
7,729✔
2646
  STREAM_CHECK_NULL_GOTO(uidTsHash, terrno);
7,729✔
2647
  SColumnInfoData* pColInfoDataTs = taosArrayGet(pResBlock->pDataBlock, 0);
7,729✔
2648
  SColumnInfoData* pColInfoDataUid = taosArrayGet(pResBlock->pDataBlock, 1);
7,729✔
2649
  for (int32_t j = 0; j < pResBlock->info.rows; j++) {
24,050✔
2650
    if (colDataIsNull_s(pColInfoDataTs, j) || pColInfoDataTs->pData == NULL) {
32,642✔
2651
      continue;
×
2652
    }
2653
    int64_t ts = *(int64_t*)colDataGetNumData(pColInfoDataTs, j);
16,321✔
2654
    int64_t uid = *(int64_t*)colDataGetNumData(pColInfoDataUid, j);
16,321✔
2655
    STREAM_CHECK_RET_GOTO(tSimpleHashPut(uidTsHash, &uid, LONG_BYTES, &ts, LONG_BYTES));
16,321✔
2656
  }
2657
  tsRsp->tsInfo = taosArrayInit(qStreamGetTableListGroupNum(sStreamReaderInfo), sizeof(STsInfo));
7,729✔
2658
  STREAM_CHECK_NULL_GOTO(tsRsp->tsInfo, terrno);
7,729✔
2659
  while (true) {
15,535✔
2660
    int32_t        pNum = 0;
23,264✔
2661
    int64_t        suid = 0;
23,264✔
2662
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
23,264✔
2663
    if(pNum == 0) break;
23,264✔
2664
    STsInfo* tsInfo = taosArrayReserve(tsRsp->tsInfo, 1);
16,116✔
2665
    STREAM_CHECK_NULL_GOTO(tsInfo, terrno)
16,116✔
2666
    if (order == TSDB_ORDER_ASC) {
16,116✔
2667
      tsInfo->ts = INT64_MAX;
7,581✔
2668
    } else {
2669
      tsInfo->ts = INT64_MIN;
8,535✔
2670
    }
2671
    for (int32_t i = 0; i < pNum; i++) {
32,027✔
2672
      int64_t uid = pList[i].uid;
16,492✔
2673
      int64_t *ts = tSimpleHashGet(uidTsHash, &uid, LONG_BYTES);
16,492✔
2674
      STREAM_CHECK_NULL_GOTO(ts, terrno);
16,492✔
2675
      if (order == TSDB_ORDER_ASC && *ts < tsInfo->ts) {
15,911✔
2676
        tsInfo->ts = *ts;
7,581✔
2677
      } else if (order == TSDB_ORDER_DESC && *ts > tsInfo->ts) {
8,330✔
2678
        tsInfo->ts = *ts;
7,954✔
2679
      }
2680
    }
2681
    int64_t uid = pList[0].uid;
15,535✔
2682
    tsInfo->gId = qStreamGetGroupIdFromSet(sStreamReaderInfo, uid);
15,535✔
2683
    ST_TASK_DLOG("%s get ts:%" PRId64 ", gId:%" PRIu64 ", ver:%" PRId64, __func__, tsInfo->ts, tsInfo->gId, tsRsp->ver);
15,535✔
2684
    taosMemoryFreeClear(pList);
15,535✔
2685
  }
2686

2687
end:
7,729✔
2688
  qStreamDestroyTableInfo(&tableInfo);
7,729✔
2689
  taosMemoryFreeClear(pList);
7,729✔
2690
  tSimpleHashCleanup(uidTsHash);
7,729✔
2691
  return code;
7,729✔
2692
}
2693

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

2696
static int32_t getAllTs(SVnode* pVnode, SSDataBlock*  pResBlock, SStreamReaderTaskInner* pTaskInner, STableKeyInfo* pList, int32_t pNum) {
269,019✔
2697
  int32_t code = 0;
269,019✔
2698
  int32_t lino = 0;
269,019✔
2699

2700
  STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdCreateFirstLastTsIter(pVnode, &pTaskInner->options->twindows, &(SVersionRange){.minVer = -1, .maxVer = pTaskInner->options->ver},
269,019✔
2701
                                                pTaskInner->options->suid, pList, pNum, pTaskInner->options->order, &pTaskInner->pReader, pTaskInner->idStr));
2702
  bool hasNext = true;
268,791✔
2703
  while(1){
2704
    STREAM_CHECK_RET_GOTO(pTaskInner->storageApi->tsdReader.tsdNextFirstLastTsBlock(pTaskInner->pReader, pResBlock, &hasNext));
268,791✔
2705
    STREAM_CHECK_CONDITION_GOTO(!hasNext, TDB_CODE_SUCCESS);
268,816✔
2706
  }
2707

2708
end:
268,816✔
2709
  pTaskInner->storageApi->tsdReader.tsdDestroyFirstLastTsIter(pTaskInner->pReader);
268,816✔
2710
  pTaskInner->pReader = NULL;
269,019✔
2711
  return code;
269,019✔
2712
}
2713

2714
static int32_t processTsVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
44,235✔
2715
                                  SStreamReaderTaskInner* pTaskInner) {
2716
  int32_t code = 0;
44,235✔
2717
  int32_t lino = 0;
44,235✔
2718
  STableKeyInfo* pList = NULL;
44,235✔
2719
  StreamTableListInfo     tableInfo = {0};
44,235✔
2720

2721
  void* pTask = sStreamReaderInfo->pTask;
44,235✔
2722
  STREAM_CHECK_RET_GOTO(qStreamCopyTableInfo(sStreamReaderInfo, &tableInfo));
44,235✔
2723

2724
  SSDataBlock*  pResBlock = NULL;
44,235✔
2725
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, qStreamGetTableListNum(sStreamReaderInfo)));
44,235✔
2726

2727
  while (true) {
34,623✔
2728
    int32_t        pNum = 0;
78,858✔
2729
    int64_t        suid = 0;
78,858✔
2730
    STREAM_CHECK_RET_GOTO(qStreamIterTableList(&tableInfo, &pList, &pNum, &suid));
78,858✔
2731
    if(pNum == 0) break;
78,858✔
2732
    pTaskInner->options->suid = suid;
34,623✔
2733
    STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
34,623✔
2734
    taosMemoryFreeClear(pList);
34,623✔
2735
  }
2736

2737
  STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, pTaskInner->options->order));
44,235✔
2738

2739
end:
44,235✔
2740
  qStreamDestroyTableInfo(&tableInfo);
44,235✔
2741
  taosMemoryFreeClear(pList);
44,235✔
2742
  blockDataDestroy(pResBlock);
44,235✔
2743
  STREAM_PRINT_LOG_END_WITHID(code, lino);
44,235✔
2744
  return code;
44,235✔
2745
}
2746

2747
static int32_t processTsNonVTable(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
226,956✔
2748
                                  SStreamReaderTaskInner* pTaskInner) {
2749
  int32_t code = 0;
226,956✔
2750
  int32_t lino = 0;
226,956✔
2751
  STableKeyInfo* pList = NULL;
226,956✔
2752
  void* pTask = sStreamReaderInfo->pTask;
226,956✔
2753
  
2754
  SSDataBlock*  pResBlock = NULL;
226,956✔
2755

2756
  int32_t        pNum = 0;
226,956✔
2757
  int64_t        suid = 0;
226,956✔
2758
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, 0, &pList, &pNum));
226,956✔
2759
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
227,088✔
2760
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
195,332✔
2761

2762
  pTaskInner->options->suid = sStreamReaderInfo->suid;
195,332✔
2763
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
195,332✔
2764
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
195,332✔
2765
  int32_t order = pTaskInner->options->order;
103,495✔
2766

2767
  if (sStreamReaderInfo->groupByTbname) {
103,495✔
2768
    STREAM_CHECK_RET_GOTO(processTsOutPutAllTables(sStreamReaderInfo, tsRsp, pResBlock, order));
54,344✔
2769
  } else if (sStreamReaderInfo->partitionCols == NULL) {
49,151✔
2770
    STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
41,422✔
2771
  } else {
2772
    STREAM_CHECK_RET_GOTO(processTsOutPutAllGroups(sStreamReaderInfo, tsRsp, pResBlock, order));
7,729✔
2773
  }                             
2774
end:
226,849✔
2775
  blockDataDestroy(pResBlock);
227,088✔
2776
  taosMemoryFreeClear(pList);
226,510✔
2777
  STREAM_PRINT_LOG_END_WITHID(code, lino);
226,728✔
2778
  return code;
226,860✔
2779
}
2780

2781
static int32_t processTsOnce(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
50,650✔
2782
                                  SStreamReaderTaskInner* pTaskInner, uint64_t gid) {
2783
  int32_t code = 0;
50,650✔
2784
  int32_t lino = 0;
50,650✔
2785
  STableKeyInfo* pList = NULL;
50,650✔
2786
  void* pTask = sStreamReaderInfo->pTask;
50,650✔
2787
  
2788
  SSDataBlock*  pResBlock = NULL;
50,650✔
2789

2790
  int32_t        pNum = 0;
50,650✔
2791
  STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, gid, &pList, &pNum));
50,650✔
2792
  STREAM_CHECK_CONDITION_GOTO(pNum == 0, TSDB_CODE_SUCCESS);
50,650✔
2793
  STREAM_CHECK_RET_GOTO(createDataBlockTsUid(&pResBlock, pNum));
39,064✔
2794

2795
  pTaskInner->options->suid = sStreamReaderInfo->suid;
39,064✔
2796
  STREAM_CHECK_RET_GOTO(getAllTs(pVnode, pResBlock, pTaskInner, pList, pNum));
39,064✔
2797
  STREAM_CHECK_CONDITION_GOTO(pResBlock->info.rows == 0, TDB_CODE_SUCCESS);
39,064✔
2798
  int32_t order = pTaskInner->options->order;
39,064✔
2799

2800
  STREAM_CHECK_RET_GOTO(processTsOutPutOneGroup(sStreamReaderInfo, tsRsp, pResBlock, order));
39,064✔
2801
end:
50,650✔
2802
  blockDataDestroy(pResBlock);
50,650✔
2803
  taosMemoryFreeClear(pList);
50,650✔
2804
  STREAM_PRINT_LOG_END_WITHID(code, lino);
50,650✔
2805
  return code;
50,650✔
2806
}
2807

2808
static int32_t processTs(SVnode* pVnode, SStreamTsResponse* tsRsp, SStreamTriggerReaderInfo* sStreamReaderInfo,
271,004✔
2809
                                  SStreamReaderTaskInner* pTaskInner) {
2810
  if (sStreamReaderInfo->isVtableStream) {
271,004✔
2811
    return processTsVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
44,235✔
2812
  }
2813

2814
  return processTsNonVTable(pVnode, tsRsp, sStreamReaderInfo, pTaskInner);
227,088✔
2815
}
2816

2817
static int32_t vnodeProcessStreamSetTableReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
30,082✔
2818
  int32_t code = 0;
30,082✔
2819
  int32_t lino = 0;
30,082✔
2820
  void*   buf = NULL;
30,082✔
2821
  size_t  size = 0;
30,082✔
2822
  void* pTask = sStreamReaderInfo->pTask;
30,082✔
2823

2824
  ST_TASK_DLOG("vgId:%d %s start, trigger hash size:%d, calc hash size:%d, appver:%"PRId64, TD_VID(pVnode), __func__,
30,082✔
2825
                tSimpleHashGetSize(req->setTableReq.uidInfoTrigger), tSimpleHashGetSize(req->setTableReq.uidInfoCalc), pVnode->state.applied);
2826

2827
  taosWLockLatch(&sStreamReaderInfo->lock);
30,082✔
2828
  TSWAP(sStreamReaderInfo->uidHashTrigger, req->setTableReq.uidInfoTrigger);
30,082✔
2829
  TSWAP(sStreamReaderInfo->uidHashCalc, req->setTableReq.uidInfoCalc);
30,082✔
2830
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashTrigger, TSDB_CODE_INVALID_PARA);
30,082✔
2831
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->uidHashCalc, TSDB_CODE_INVALID_PARA);
30,082✔
2832

2833
  qStreamClearTableInfo(&sStreamReaderInfo->vSetTableList);
30,082✔
2834
  STREAM_CHECK_RET_GOTO(initStreamTableListInfo(&sStreamReaderInfo->vSetTableList));
30,082✔
2835
  STREAM_CHECK_RET_GOTO(qBuildVTableList(sStreamReaderInfo));
30,082✔
2836
end:
30,082✔
2837
  taosWUnLockLatch(&sStreamReaderInfo->lock);
30,082✔
2838
  STREAM_PRINT_LOG_END_WITHID(code, lino);
30,082✔
2839
  SRpcMsg rsp = {
30,082✔
2840
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2841
  tmsgSendRsp(&rsp);
30,082✔
2842
  return code;
30,082✔
2843
}
2844

2845
static int32_t vnodeProcessStreamLastTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
179,884✔
2846
  int32_t                 code = 0;
179,884✔
2847
  int32_t                 lino = 0;
179,884✔
2848
  SStreamReaderTaskInner* pTaskInner = NULL;
179,884✔
2849
  SStreamTsResponse       tsRsp = {0};
181,009✔
2850
  void*                   buf = NULL;
181,009✔
2851
  size_t                  size = 0;
181,009✔
2852

2853
  void* pTask = sStreamReaderInfo->pTask;
181,009✔
2854

2855
  ST_TASK_DLOG("vgId:%d %s start", TD_VID(pVnode), __func__);
181,009✔
2856

2857
  BUILD_OPTION(options, 0, sStreamReaderInfo->tableList.version, TSDB_ORDER_DESC, INT64_MIN, INT64_MAX, NULL, false, NULL);
181,009✔
2858
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
181,009✔
2859

2860
  tsRsp.ver = sStreamReaderInfo->tableList.version + 1;
181,009✔
2861

2862
  STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
181,009✔
2863
  
2864
end:
181,009✔
2865
  ST_TASK_DLOG("vgId:%d %s get result size:%"PRIzu", ver:%"PRId64, TD_VID(pVnode), __func__, taosArrayGetSize(tsRsp.tsInfo), tsRsp.ver);
181,009✔
2866
  code = buildTsRsp(&tsRsp, &buf, &size);
181,009✔
2867
  STREAM_PRINT_LOG_END_WITHID(code, lino);
180,647✔
2868
  SRpcMsg rsp = {
180,779✔
2869
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2870
  tmsgSendRsp(&rsp);
181,009✔
2871
  taosArrayDestroy(tsRsp.tsInfo);
181,009✔
2872
  taosMemoryFree(pTaskInner);
181,009✔
2873
  return code;
181,009✔
2874
}
2875

2876
static int32_t vnodeProcessStreamFirstTsReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
140,964✔
2877
  int32_t                 code = 0;
140,964✔
2878
  int32_t                 lino = 0;
140,964✔
2879
  SStreamReaderTaskInner* pTaskInner = NULL;
140,964✔
2880
  SStreamTsResponse       tsRsp = {0};
140,964✔
2881
  void*                   buf = NULL;
140,964✔
2882
  size_t                  size = 0;
140,964✔
2883

2884
  void* pTask = sStreamReaderInfo->pTask;
140,964✔
2885
  ST_TASK_DLOG("vgId:%d %s start, startTime:%"PRId64" ver:%"PRId64" gid:%"PRId64, TD_VID(pVnode), __func__, req->firstTsReq.startTime, req->firstTsReq.ver, req->firstTsReq.gid);
140,964✔
2886
  int32_t        pNum = 0;
140,964✔
2887

2888
  tsRsp.ver = pVnode->state.applied;
140,964✔
2889

2890
  BUILD_OPTION(options, 0, req->firstTsReq.ver, TSDB_ORDER_ASC, req->firstTsReq.startTime, INT64_MAX, NULL, false, NULL);
140,964✔
2891
  STREAM_CHECK_RET_GOTO(createStreamTaskForTs(&options, &pTaskInner, &sStreamReaderInfo->storageApi));
140,964✔
2892

2893
  if (req->firstTsReq.gid != 0) {
140,964✔
2894
    STREAM_CHECK_RET_GOTO(processTsOnce(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner, req->firstTsReq.gid));
50,650✔
2895
  } else {
2896
    STREAM_CHECK_RET_GOTO(processTs(pVnode, &tsRsp, sStreamReaderInfo, pTaskInner));
90,314✔
2897
  }
2898

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

2911
static int32_t vnodeProcessStreamTsdbMetaReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
117,583✔
2912
  int32_t code = 0;
117,583✔
2913
  int32_t lino = 0;
117,583✔
2914
  void*   buf = NULL;
117,583✔
2915
  size_t  size = 0;
117,583✔
2916
  STableKeyInfo* pList = NULL;
117,583✔
2917

2918
  void* pTask = sStreamReaderInfo->pTask;
117,583✔
2919
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64 ",skey:%" PRId64 ",ekey:%" PRId64 ",gid:%" PRId64, TD_VID(pVnode),
117,583✔
2920
               __func__, req->tsdbMetaReq.ver, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime,
2921
               req->tsdbMetaReq.gid);
2922

2923
  SStreamReaderTaskInner* pTaskInner = NULL;
117,583✔
2924
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_META);
117,583✔
2925

2926
  if (req->base.type == STRIGGER_PULL_TSDB_META) {
117,583✔
2927
    int32_t        pNum = 0;
117,583✔
2928
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbMetaReq.gid, &pList, &pNum));
117,583✔
2929
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbMetaReq.ver, req->tsdbMetaReq.order, req->tsdbMetaReq.startTime, req->tsdbMetaReq.endTime, 
117,583✔
2930
                          sStreamReaderInfo->tsSchemas, true, NULL);
2931
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, NULL, pList, pNum, &sStreamReaderInfo->storageApi));
117,583✔
2932
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
117,583✔
2933
    
2934
    STREAM_CHECK_RET_GOTO(createBlockForTsdbMeta(&pTaskInner->pResBlockDst, sStreamReaderInfo->isVtableStream));
117,583✔
2935
  } else {
2936
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
2937
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
2938
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
2939
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
2940
  }
2941

2942
  blockDataCleanup(pTaskInner->pResBlockDst);
117,583✔
2943
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pTaskInner->pResBlockDst, STREAM_RETURN_ROWS_NUM));
117,583✔
2944
  bool hasNext = true;
117,583✔
2945
  while (true) {
216,509✔
2946
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
334,092✔
2947
    if (!hasNext) {
334,092✔
2948
      break;
117,583✔
2949
    }
2950
    pTaskInner->storageApi->tsdReader.tsdReaderReleaseDataBlock(pTaskInner->pReader);
216,509✔
2951
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
216,509✔
2952

2953
    int32_t index = 0;
216,509✔
2954
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.skey));
216,509✔
2955
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.window.ekey));
216,509✔
2956
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.uid));
216,509✔
2957
    if (!sStreamReaderInfo->isVtableStream) {
216,321✔
2958
      STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.id.groupId));
172,643✔
2959
    }
2960
    STREAM_CHECK_RET_GOTO(addColData(pTaskInner->pResBlockDst, index++, &pTaskInner->pResBlock->info.rows));
216,509✔
2961

2962
    stDebug("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
216,509✔
2963
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
2964
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
2965
            pTaskInner->pResBlockDst->info.rows++;
216,509✔
2966
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
216,509✔
2967
      break;
×
2968
    }
2969
  }
2970

2971
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
117,583✔
2972
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
117,583✔
2973
  printDataBlock(pTaskInner->pResBlockDst, __func__, "meta", ((SStreamTask *)sStreamReaderInfo->pTask)->streamId);
117,583✔
2974
  if (!hasNext) {
117,583✔
2975
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
117,583✔
2976
  }
2977

2978
end:
117,395✔
2979
  STREAM_PRINT_LOG_END_WITHID(code, lino);
117,395✔
2980
  SRpcMsg rsp = {
117,583✔
2981
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
2982
  tmsgSendRsp(&rsp);
117,583✔
2983
  taosMemoryFree(pList);
117,583✔
2984
  return code;
117,583✔
2985
}
2986

2987
static int32_t vnodeProcessStreamTsdbTsDataReqNonVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
166,420✔
2988
  int32_t                 code = 0;
166,420✔
2989
  int32_t                 lino = 0;
166,420✔
2990
  SStreamReaderTaskInner* pTaskInner = NULL;
166,420✔
2991
  void*                   buf = NULL;
166,420✔
2992
  size_t                  size = 0;
166,420✔
2993
  SSDataBlock*            pBlockRes = NULL;
166,420✔
2994

2995
  void* pTask = sStreamReaderInfo->pTask;
166,420✔
2996
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
166,420✔
2997
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
2998
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
2999

3000
  int32_t        pNum = 1;
166,420✔
3001
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
166,420✔
3002
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
166,420✔
3003
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
166,420✔
3004
               sStreamReaderInfo->triggerCols, false, NULL);
3005
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
166,420✔
3006
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
166,420✔
3007
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
166,420✔
3008

3009
  while (1) {
166,420✔
3010
    bool hasNext = false;
332,840✔
3011
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
332,840✔
3012
    if (!hasNext) {
332,840✔
3013
      break;
166,420✔
3014
    }
3015
    // if (!sStreamReaderInfo->isVtableStream){
3016
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
166,420✔
3017
    // }
3018

3019
    SSDataBlock* pBlock = NULL;
166,420✔
3020
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
166,420✔
3021
    if (pBlock != NULL && pBlock->info.rows > 0) {
166,420✔
3022
      STREAM_CHECK_RET_GOTO(processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock,
166,420✔
3023
          0, pBlock->info.rows, 1));
3024
    }
3025
    
3026
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
166,420✔
3027
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
166,420✔
3028
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
166,420✔
3029
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3030
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3031
  }
3032

3033
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
166,420✔
3034

3035
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
166,420✔
3036
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
166,420✔
3037

3038
end:
166,420✔
3039
  STREAM_PRINT_LOG_END_WITHID(code, lino);
166,420✔
3040
  SRpcMsg rsp = {
166,420✔
3041
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3042
  tmsgSendRsp(&rsp);
166,420✔
3043
  blockDataDestroy(pBlockRes);
166,420✔
3044

3045
  releaseStreamTask(&pTaskInner);
166,420✔
3046
  return code;
166,420✔
3047
}
3048

3049
static int32_t vnodeProcessStreamTsdbTsDataReqVTable(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
×
3050
  int32_t                 code = 0;
×
3051
  int32_t                 lino = 0;
×
3052
  SStreamReaderTaskInner* pTaskInner = NULL;
×
3053
  void*                   buf = NULL;
×
3054
  size_t                  size = 0;
×
3055
  SSDataBlock*            pBlockRes = NULL;
×
3056

3057
  void* pTask = sStreamReaderInfo->pTask;
×
3058
  ST_TASK_DLOG("vgId:%d %s start, ver:%"PRId64",skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",suid:%"PRId64, TD_VID(pVnode), __func__, req->tsdbTsDataReq.ver, 
×
3059
                req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey, 
3060
                req->tsdbTsDataReq.uid, req->tsdbTsDataReq.suid);
3061

3062
  int32_t        pNum = 1;
×
3063
  STableKeyInfo  pList = {.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, req->tsdbTsDataReq.uid), .uid = req->tsdbTsDataReq.uid};
×
3064
  STREAM_CHECK_CONDITION_GOTO(pList.groupId == -1, TSDB_CODE_INVALID_PARA);
×
3065
  BUILD_OPTION(options, getSuid(sStreamReaderInfo, &pList), req->tsdbTsDataReq.ver, TSDB_ORDER_ASC, req->tsdbTsDataReq.skey, req->tsdbTsDataReq.ekey,
×
3066
               sStreamReaderInfo->tsSchemas, true, NULL);
3067
  STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->tsBlock, &pList, pNum, &sStreamReaderInfo->storageApi));
×
3068
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->tsBlock, false, &pBlockRes));
×
3069

3070
  while (1) {
×
3071
    bool hasNext = false;
×
3072
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
×
3073
    if (!hasNext) {
×
3074
      break;
×
3075
    }
3076

3077
    SSDataBlock* pBlock = NULL;
×
3078
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
×
3079
    STREAM_CHECK_RET_GOTO(blockDataMerge(pBlockRes, pBlock));
×
3080
    ST_TASK_DLOG("vgId:%d %s get  skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
×
3081
            TD_VID(pVnode), __func__, pBlockRes->info.window.skey, pBlockRes->info.window.ekey,
3082
            pBlockRes->info.id.uid, pBlockRes->info.id.groupId, pBlockRes->info.rows);
3083
  }
3084

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

3088
end:
×
3089
  STREAM_PRINT_LOG_END_WITHID(code, lino);
×
3090
  SRpcMsg rsp = {
×
3091
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3092
  tmsgSendRsp(&rsp);
×
3093
  blockDataDestroy(pBlockRes);
×
3094

3095
  releaseStreamTask(&pTaskInner);
×
3096
  return code;
×
3097
}
3098

3099
static int32_t vnodeProcessStreamTsdbTriggerDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
111,158✔
3100
  int32_t code = 0;
111,158✔
3101
  int32_t lino = 0;
111,158✔
3102
  void*   buf = NULL;
111,158✔
3103
  size_t  size = 0;
111,158✔
3104
  STableKeyInfo* pList = NULL;
111,158✔
3105
  SArray*        pResList = NULL;
111,158✔
3106
  SSDataBlock*   pBlockTmp = NULL;
111,158✔
3107

3108
  SStreamReaderTaskInner* pTaskInner = NULL;
111,158✔
3109
  void* pTask = sStreamReaderInfo->pTask;
111,158✔
3110
  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);
111,158✔
3111
  
3112
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_TRIGGER_DATA);
111,158✔
3113

3114
  if (req->base.type == STRIGGER_PULL_TSDB_TRIGGER_DATA) {
111,158✔
3115
    int32_t        pNum = 0;
55,579✔
3116
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbTriggerDataReq.gid, &pList, &pNum));
55,579✔
3117
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbTriggerDataReq.ver, req->tsdbTriggerDataReq.order, req->tsdbTriggerDataReq.startTime, INT64_MAX,
55,579✔
3118
                 sStreamReaderInfo->triggerCols, false, NULL);
3119
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
55,579✔
3120
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
55,579✔
3121
  } else {
3122
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
55,579✔
3123
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
55,579✔
3124
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3125
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3126
  }
3127

3128
  blockDataCleanup(pTaskInner->pResBlockDst);
55,579✔
3129
  bool hasNext = true;
55,579✔
3130
  int32_t totalRows = 0;
55,579✔
3131
    
3132
  pResList = taosArrayInit(4, POINTER_BYTES);
55,579✔
3133
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
55,579✔
3134
  while (1) {
60,723✔
3135
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
116,302✔
3136
    if (!hasNext) {
116,302✔
3137
      break;
55,579✔
3138
    }
3139
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
60,723✔
3140
    // pTaskInner->pResBlockDst->info.id.groupId = pTaskInner->pResBlock->info.id.groupId;
3141

3142
    SSDataBlock* pBlock = NULL;
60,723✔
3143
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
60,723✔
3144
    if (pBlock != NULL && pBlock->info.rows > 0) {
60,723✔
3145
      STREAM_CHECK_RET_GOTO(
60,723✔
3146
        processTag(sStreamReaderInfo, false, pBlock->info.id.uid, pBlock, 0, pBlock->info.rows, 1));
3147
    }
3148
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
60,723✔
3149
    // STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
3150
    ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
60,723✔
3151
    STREAM_CHECK_RET_GOTO(createOneDataBlock(pBlock, true, &pBlockTmp));
60,723✔
3152
    STREAM_CHECK_NULL_GOTO(taosArrayPush(pResList, &pBlockTmp), terrno);
60,723✔
3153
    totalRows += blockDataGetNumOfRows(pBlockTmp);
60,723✔
3154
    pBlockTmp = NULL;
60,723✔
3155

3156
    ST_TASK_DLOG("vgId:%d %s get skey:%" PRId64 ", eksy:%" PRId64 ", uid:%" PRId64 ", gId:%" PRIu64 ", rows:%" PRId64,
60,723✔
3157
            TD_VID(pVnode), __func__, pTaskInner->pResBlock->info.window.skey, pTaskInner->pResBlock->info.window.ekey,
3158
            pTaskInner->pResBlock->info.id.uid, pTaskInner->pResBlock->info.id.groupId, pTaskInner->pResBlock->info.rows);
3159
    if (totalRows >= STREAM_RETURN_ROWS_NUM) {  //todo optimize send multi blocks in one group
60,723✔
3160
      break;
×
3161
    }
3162
  }
3163

3164
  STREAM_CHECK_RET_GOTO(buildArrayRsp(pResList, &buf, &size));
55,579✔
3165
  if (!hasNext) {
55,579✔
3166
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
55,579✔
3167
  }
3168

3169
end:
111,158✔
3170
  STREAM_PRINT_LOG_END_WITHID(code, lino);
111,158✔
3171
  SRpcMsg rsp = {
111,158✔
3172
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3173
  tmsgSendRsp(&rsp);
111,158✔
3174
  taosMemoryFree(pList);
111,158✔
3175
  blockDataDestroy(pBlockTmp);
111,158✔
3176
  taosArrayDestroyP(pResList, (FDelete)blockDataDestroy);
111,158✔
3177
  return code;
111,158✔
3178
}
3179

3180
static int32_t vnodeProcessStreamTsdbCalcDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
5,901,224✔
3181
  int32_t code = 0;
5,901,224✔
3182
  int32_t lino = 0;
5,901,224✔
3183
  void*   buf = NULL;
5,901,224✔
3184
  size_t  size = 0;
5,901,412✔
3185
  SSDataBlock*   pBlockRes = NULL;
5,901,412✔
3186
  STableKeyInfo* pList = NULL;
5,901,412✔
3187

3188

3189
  void* pTask = sStreamReaderInfo->pTask;
5,901,412✔
3190
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",gid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
5,901,412✔
3191
    req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey, req->tsdbCalcDataReq.gid, req->tsdbCalcDataReq.ver);
3192

3193
  STREAM_CHECK_NULL_GOTO(sStreamReaderInfo->triggerCols, TSDB_CODE_STREAM_NOT_TABLE_SCAN_PLAN);
5,901,412✔
3194

3195
  SStreamReaderTaskInner* pTaskInner = NULL;
5,901,412✔
3196
  int64_t                 key = getSessionKey(req->base.sessionId, STRIGGER_PULL_TSDB_CALC_DATA);
5,901,412✔
3197

3198
  if (req->base.type == STRIGGER_PULL_TSDB_CALC_DATA) {
5,901,412✔
3199
    int32_t        pNum = 0;
5,901,412✔
3200
    STREAM_CHECK_RET_GOTO(qStreamGetTableList(sStreamReaderInfo, req->tsdbCalcDataReq.gid, &pList, &pNum));
5,901,412✔
3201
    BUILD_OPTION(options, getSuid(sStreamReaderInfo, pList), req->tsdbCalcDataReq.ver, TSDB_ORDER_ASC, req->tsdbCalcDataReq.skey, req->tsdbCalcDataReq.ekey,
5,901,412✔
3202
                 sStreamReaderInfo->triggerCols, false, NULL);
3203
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, sStreamReaderInfo->triggerResBlock, pList, pNum, &sStreamReaderInfo->storageApi));
5,901,412✔
3204

3205
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
5,900,182✔
3206
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerResBlock, false, &pTaskInner->pResBlockDst));
5,901,002✔
3207
  } else {
3208
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3209
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3210
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3211
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3212
  }
3213

3214
  blockDataCleanup(pTaskInner->pResBlockDst);
5,899,977✔
3215
  bool hasNext = true;
5,899,977✔
3216
  while (1) {
601,508✔
3217
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
6,501,485✔
3218
    if (!hasNext) {
6,500,699✔
3219
      break;
5,899,772✔
3220
    }
3221
    pTaskInner->pResBlock->info.id.groupId = qStreamGetGroupIdFromSet(sStreamReaderInfo, pTaskInner->pResBlock->info.id.uid);
600,927✔
3222

3223
    SSDataBlock* pBlock = NULL;
601,508✔
3224
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
601,508✔
3225
    STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderInfo->pFilterInfo, NULL));
601,320✔
3226
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
601,508✔
3227
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
601,320✔
3228
      break;
×
3229
    }
3230
  }
3231

3232
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcResBlock, false, &pBlockRes));
5,899,772✔
3233
  STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlockRes, pTaskInner->pResBlockDst->info.capacity));
5,901,224✔
3234
  blockDataTransform(pBlockRes, pTaskInner->pResBlockDst);
5,900,387✔
3235
  STREAM_CHECK_RET_GOTO(buildRsp(pBlockRes, &buf, &size));
5,900,797✔
3236
  printDataBlock(pBlockRes, __func__, "tsdb_calc_data", ((SStreamTask*)pTask)->streamId);
5,899,772✔
3237
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlockRes->info.rows);
5,899,994✔
3238
  printDataBlock(pBlockRes, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
5,901,412✔
3239

3240
  if (!hasNext) {
5,901,412✔
3241
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
5,901,412✔
3242
  }
3243

3244
end:
5,902,027✔
3245
  STREAM_PRINT_LOG_END_WITHID(code, lino);
5,901,002✔
3246
  SRpcMsg rsp = {
5,901,412✔
3247
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3248
  tmsgSendRsp(&rsp);
5,901,412✔
3249
  blockDataDestroy(pBlockRes);
5,901,207✔
3250
  taosMemoryFree(pList);
5,901,207✔
3251
  return code;
5,901,207✔
3252
}
3253

3254
static int32_t vnodeProcessStreamTsdbVirtalDataReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
65,356✔
3255
  int32_t code = 0;
65,356✔
3256
  int32_t lino = 0;
65,356✔
3257
  void*   buf = NULL;
65,356✔
3258
  size_t  size = 0;
65,356✔
3259
  int32_t* slotIdList = NULL;
65,356✔
3260
  SArray* sortedCid = NULL;
65,356✔
3261
  SArray* schemas = NULL;
65,356✔
3262
  SSDataBlock*   pBlockRes = NULL;
65,356✔
3263
  
3264
  void* pTask = sStreamReaderInfo->pTask;
65,356✔
3265
  ST_TASK_DLOG("vgId:%d %s start, skey:%"PRId64",ekey:%"PRId64",uid:%"PRId64",ver:%"PRId64, TD_VID(pVnode), __func__, 
65,356✔
3266
    req->tsdbDataReq.skey, req->tsdbDataReq.ekey, req->tsdbDataReq.uid, req->tsdbDataReq.ver);
3267
    
3268
  SStreamReaderTaskInner* pTaskInner = NULL;
65,356✔
3269
  int64_t key = req->tsdbDataReq.uid;
65,356✔
3270

3271
  if (req->base.type == STRIGGER_PULL_TSDB_DATA) {
65,356✔
3272
    // sort cid and build slotIdList
3273
    slotIdList = taosMemoryMalloc(taosArrayGetSize(req->tsdbDataReq.cids) * sizeof(int32_t));
65,356✔
3274
    STREAM_CHECK_NULL_GOTO(slotIdList, terrno);
65,356✔
3275
    sortedCid = taosArrayDup(req->tsdbDataReq.cids, NULL);
65,356✔
3276
    STREAM_CHECK_NULL_GOTO(sortedCid, terrno);
65,356✔
3277
    taosArraySort(sortedCid, sortCid);
65,356✔
3278
    for (int32_t i = 0; i < taosArrayGetSize(req->tsdbDataReq.cids); i++) {
201,728✔
3279
      int16_t* cid = taosArrayGet(req->tsdbDataReq.cids, i);
136,372✔
3280
      STREAM_CHECK_NULL_GOTO(cid, terrno);
136,372✔
3281
      for (int32_t j = 0; j < taosArrayGetSize(sortedCid); j++) {
214,688✔
3282
        int16_t* cidSorted = taosArrayGet(sortedCid, j);
214,688✔
3283
        STREAM_CHECK_NULL_GOTO(cidSorted, terrno);
214,688✔
3284
        if (*cid == *cidSorted) {
214,688✔
3285
          slotIdList[j] = i;
136,372✔
3286
          break;
136,372✔
3287
        }
3288
      }
3289
    }
3290

3291
    STREAM_CHECK_RET_GOTO(buildScheamFromMeta(pVnode, req->tsdbDataReq.uid, &schemas, &sStreamReaderInfo->storageApi));
65,356✔
3292
    STREAM_CHECK_RET_GOTO(shrinkScheams(req->tsdbDataReq.cids, schemas));
65,356✔
3293
    STREAM_CHECK_RET_GOTO(createDataBlockForStream(schemas, &pBlockRes));
65,356✔
3294

3295
    taosArraySort(schemas, sortSSchema);
65,356✔
3296
    BUILD_OPTION(options, req->tsdbDataReq.suid, req->tsdbDataReq.ver, req->tsdbDataReq.order, req->tsdbDataReq.skey,
65,356✔
3297
                    req->tsdbDataReq.ekey, schemas, true, &slotIdList);
3298
    STableKeyInfo       keyInfo = {.uid = req->tsdbDataReq.uid, .groupId = 0};
65,356✔
3299
    STREAM_CHECK_RET_GOTO(createStreamTask(pVnode, &options, &pTaskInner, pBlockRes, &keyInfo, 1, &sStreamReaderInfo->storageApi));
65,356✔
3300
    STREAM_CHECK_RET_GOTO(taosHashPut(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES, &pTaskInner, sizeof(pTaskInner)));
65,356✔
3301
    pTaskInner->pResBlockDst = pBlockRes;
65,356✔
3302
    pBlockRes = NULL;
65,356✔
3303
  } else {
3304
    void** tmp = taosHashGet(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES);
×
3305
    STREAM_CHECK_NULL_GOTO(tmp, TSDB_CODE_STREAM_NO_CONTEXT);
×
3306
    pTaskInner = *(SStreamReaderTaskInner**)tmp;
×
3307
    STREAM_CHECK_NULL_GOTO(pTaskInner, TSDB_CODE_INTERNAL_ERROR);
×
3308
  }
3309

3310
  blockDataCleanup(pTaskInner->pResBlockDst);
65,356✔
3311
  bool hasNext = true;
65,356✔
3312
  while (1) {
65,356✔
3313
    STREAM_CHECK_RET_GOTO(getTableDataInfo(pTaskInner, &hasNext));
130,712✔
3314
    if (!hasNext) {
130,712✔
3315
      break;
65,356✔
3316
    }
3317

3318
    SSDataBlock* pBlock = NULL;
65,356✔
3319
    STREAM_CHECK_RET_GOTO(getTableData(pTaskInner, &pBlock));
65,356✔
3320
    STREAM_CHECK_RET_GOTO(blockDataMerge(pTaskInner->pResBlockDst, pBlock));
65,356✔
3321
    if (pTaskInner->pResBlockDst->info.rows >= STREAM_RETURN_ROWS_NUM) {
65,356✔
3322
      break;
×
3323
    }
3324
  }
3325
  STREAM_CHECK_RET_GOTO(buildRsp(pTaskInner->pResBlockDst, &buf, &size));
65,356✔
3326
  ST_TASK_DLOG("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pTaskInner->pResBlockDst->info.rows);
65,356✔
3327
  printDataBlock(pTaskInner->pResBlockDst, __func__, "tsdb_data", ((SStreamTask*)pTask)->streamId);
65,356✔
3328
  if (!hasNext) {
65,356✔
3329
    STREAM_CHECK_RET_GOTO(taosHashRemove(sStreamReaderInfo->streamTaskMap, &key, LONG_BYTES));
65,356✔
3330
  }
3331

3332
end:
65,356✔
3333
  STREAM_PRINT_LOG_END_WITHID(code, lino);
65,356✔
3334
  SRpcMsg rsp = {
65,356✔
3335
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3336
  tmsgSendRsp(&rsp);
65,356✔
3337
  taosMemFree(slotIdList);
65,356✔
3338
  taosArrayDestroy(sortedCid);
65,356✔
3339
  taosArrayDestroy(schemas);
65,356✔
3340
  blockDataDestroy(pBlockRes);
65,356✔
3341
  return code;
65,356✔
3342
}
3343

3344
static int32_t vnodeProcessStreamWalMetaNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
2,862,548✔
3345
  int32_t      code = 0;
2,862,548✔
3346
  int32_t      lino = 0;
2,862,548✔
3347
  void*        buf = NULL;
2,862,548✔
3348
  size_t       size = 0;
2,862,548✔
3349
  int64_t      lastVer = 0;
2,862,548✔
3350
  SSTriggerWalNewRsp resultRsp = {0};
2,862,548✔
3351

3352
  void* pTask = sStreamReaderInfo->pTask;
2,862,548✔
3353
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaNewReq.lastVer);
2,862,318✔
3354

3355
  if (sStreamReaderInfo->metaBlock == NULL) {
2,862,318✔
3356
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
94,901✔
3357
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
94,901✔
3358
  }
3359
  blockDataEmpty(sStreamReaderInfo->metaBlock);
2,862,548✔
3360
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
2,862,118✔
3361
  resultRsp.ver = req->walMetaNewReq.lastVer;
2,862,118✔
3362
  STREAM_CHECK_RET_GOTO(processWalVerMetaNew(pVnode, &resultRsp, sStreamReaderInfo, req->walMetaNewReq.ctime));
2,862,348✔
3363

3364
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
2,862,288✔
3365
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
2,862,748✔
3366
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
91,881✔
3367
  buf = rpcMallocCont(size);
91,881✔
3368
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
91,881✔
3369
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
91,881✔
3370
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
91,651✔
3371
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
91,651✔
3372

3373
end:
2,862,518✔
3374
  if (code == 0 && resultRsp.totalRows == 0) {
2,862,518✔
3375
    code = TSDB_CODE_STREAM_NO_DATA;
2,770,867✔
3376
    size = sizeof(int64_t) * 2;
2,770,867✔
3377
    buf = rpcMallocCont(size);
2,770,867✔
3378
    *(int64_t*)buf = resultRsp.ver;
2,769,786✔
3379
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
2,769,786✔
3380
  }
3381
  SRpcMsg rsp = {
2,861,888✔
3382
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3383
  tmsgSendRsp(&rsp);
2,862,748✔
3384
  if (code == TSDB_CODE_STREAM_NO_DATA){
2,862,156✔
3385
    code = 0;
2,770,665✔
3386
  }
3387
  STREAM_PRINT_LOG_END_WITHID(code, lino);
2,862,156✔
3388
  blockDataDestroy(resultRsp.deleteBlock);
2,862,548✔
3389
  blockDataDestroy(resultRsp.tableBlock);
2,862,748✔
3390

3391
  return code;
2,862,748✔
3392
}
3393
static int32_t vnodeProcessStreamWalMetaDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
3,087,037✔
3394
  int32_t      code = 0;
3,087,037✔
3395
  int32_t      lino = 0;
3,087,037✔
3396
  void*        buf = NULL;
3,087,037✔
3397
  size_t       size = 0;
3,087,037✔
3398
  SSTriggerWalNewRsp resultRsp = {0};
3,087,037✔
3399
  
3400
  void* pTask = sStreamReaderInfo->pTask;
3,087,497✔
3401
  ST_TASK_DLOG("vgId:%d %s start, request paras lastVer:%" PRId64, TD_VID(pVnode), __func__, req->walMetaDataNewReq.lastVer);
3,087,037✔
3402

3403
  if (sStreamReaderInfo->metaBlock == NULL) {
3,087,037✔
3404
    STREAM_CHECK_RET_GOTO(createBlockForWalMetaNew((SSDataBlock**)&sStreamReaderInfo->metaBlock));
95,117✔
3405
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(sStreamReaderInfo->metaBlock, STREAM_RETURN_ROWS_NUM));
95,117✔
3406
  }
3407

3408
  resultRsp.metaBlock = sStreamReaderInfo->metaBlock;
3,087,727✔
3409
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
3,087,497✔
3410
  resultRsp.ver = req->walMetaDataNewReq.lastVer;
3,086,577✔
3411
  resultRsp.checkAlter = true;
3,085,950✔
3412
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
3,085,950✔
3413
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
3,086,420✔
3414

3415
  STREAM_CHECK_RET_GOTO(processWalVerMetaDataNew(pVnode, sStreamReaderInfo, &resultRsp));
3,086,420✔
3416

3417
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
3,086,791✔
3418
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
114,255✔
3419
  buf = rpcMallocCont(size);
114,255✔
3420
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
114,255✔
3421
  printDataBlock(sStreamReaderInfo->metaBlock, __func__, "meta", ((SStreamTask*)pTask)->streamId);
114,255✔
3422
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
114,255✔
3423
  printDataBlock(resultRsp.deleteBlock, __func__, "delete", ((SStreamTask*)pTask)->streamId);
114,255✔
3424
  printDataBlock(resultRsp.tableBlock, __func__, "table", ((SStreamTask*)pTask)->streamId);
114,255✔
3425
  printIndexHash(resultRsp.indexHash, pTask);
114,255✔
3426

3427
end:
3,086,791✔
3428
  if (resultRsp.totalRows == 0) {
3,086,561✔
3429
    code = TSDB_CODE_STREAM_NO_DATA;
2,972,766✔
3430
    size = sizeof(int64_t) * 2;
2,972,766✔
3431
    buf = rpcMallocCont(size);
2,972,766✔
3432
    *(int64_t*)buf = resultRsp.ver;
2,971,156✔
3433
    *(((int64_t*)buf) + 1) = resultRsp.verTime;
2,971,156✔
3434
  }
3435
  SRpcMsg rsp = {
3,086,101✔
3436
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3437
  tmsgSendRsp(&rsp);
3,086,561✔
3438
  if (code == TSDB_CODE_STREAM_NO_DATA){
3,086,313✔
3439
    code = 0;
2,972,420✔
3440
  }
3441
  blockDataDestroy(resultRsp.dataBlock);
3,086,313✔
3442
  blockDataDestroy(resultRsp.deleteBlock);
3,086,625✔
3443
  blockDataDestroy(resultRsp.tableBlock);
3,087,003✔
3444
  tSimpleHashCleanup(resultRsp.indexHash);
3,086,313✔
3445

3446
  STREAM_PRINT_LOG_END_WITHID(code, lino);
3,084,121✔
3447

3448
  return code;
3,084,763✔
3449
}
3450

3451
static int32_t vnodeProcessStreamWalDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
668,736✔
3452
  int32_t      code = 0;
668,736✔
3453
  int32_t      lino = 0;
668,736✔
3454
  void*        buf = NULL;
668,736✔
3455
  size_t       size = 0;
668,736✔
3456
  SSTriggerWalNewRsp resultRsp = {0};
668,736✔
3457

3458
  void* pTask = sStreamReaderInfo->pTask;
668,736✔
3459
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
668,736✔
3460

3461
  STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->triggerBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
668,736✔
3462
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
668,736✔
3463
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
668,736✔
3464
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
668,736✔
3465
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
668,736✔
3466

3467
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
668,736✔
3468
  ST_TASK_DLOG("vgId:%d %s get result last ver:%"PRId64" rows:%d", TD_VID(pVnode), __func__, resultRsp.ver, resultRsp.totalRows);
668,736✔
3469

3470
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
668,736✔
3471

3472
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
31,164✔
3473
  buf = rpcMallocCont(size);
31,164✔
3474
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
31,164✔
3475
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
31,164✔
3476
  printIndexHash(resultRsp.indexHash, pTask);
31,164✔
3477

3478
end:
668,736✔
3479
  if (resultRsp.totalRows == 0) {
668,736✔
3480
    buf = rpcMallocCont(sizeof(int64_t));
637,572✔
3481
    *(int64_t *)buf = resultRsp.ver;
637,112✔
3482
    size = sizeof(int64_t);
637,112✔
3483
    code = TSDB_CODE_STREAM_NO_DATA;
637,112✔
3484
  }
3485
  SRpcMsg rsp = {
668,276✔
3486
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3487
  tmsgSendRsp(&rsp);
668,276✔
3488
  if (code == TSDB_CODE_STREAM_NO_DATA){
668,736✔
3489
    code = 0;
637,572✔
3490
  }
3491

3492
  blockDataDestroy(resultRsp.dataBlock);
668,736✔
3493
  blockDataDestroy(resultRsp.deleteBlock);
668,736✔
3494
  blockDataDestroy(resultRsp.tableBlock);
668,736✔
3495
  tSimpleHashCleanup(resultRsp.indexHash);
668,736✔
3496
  tSimpleHashCleanup(resultRsp.uidHash);
668,736✔
3497
  STREAM_PRINT_LOG_END_WITHID(code, lino);
668,736✔
3498

3499
  return code;
668,736✔
3500
}
3501

3502
static int32_t vnodeProcessStreamWalCalcDataNewReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
214,974✔
3503
  int32_t      code = 0;
214,974✔
3504
  int32_t      lino = 0;
214,974✔
3505
  void*        buf = NULL;
214,974✔
3506
  size_t       size = 0;
214,974✔
3507
  SSTriggerWalNewRsp resultRsp = {0};
214,974✔
3508
  SSDataBlock* pBlock1 = NULL;
214,974✔
3509
  SSDataBlock* pBlock2 = NULL;
214,974✔
3510
  
3511
  void* pTask = sStreamReaderInfo->pTask;
214,974✔
3512
  ST_TASK_DLOG("vgId:%d %s start, request paras size:%zu", TD_VID(pVnode), __func__, taosArrayGetSize(req->walDataNewReq.versions));
214,974✔
3513

3514
  SSDataBlock* dataBlock = sStreamReaderInfo->isVtableStream ? sStreamReaderInfo->calcBlock : sStreamReaderInfo->triggerBlock;
214,974✔
3515
  STREAM_CHECK_RET_GOTO(createOneDataBlock(dataBlock, false, (SSDataBlock**)&resultRsp.dataBlock));
214,974✔
3516
  resultRsp.isCalc = sStreamReaderInfo->isVtableStream ? true : false;
214,744✔
3517
  resultRsp.indexHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
214,744✔
3518
  STREAM_CHECK_NULL_GOTO(resultRsp.indexHash, terrno);
214,974✔
3519
  resultRsp.uidHash = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
214,974✔
3520
  STREAM_CHECK_NULL_GOTO(resultRsp.uidHash, terrno);
214,974✔
3521

3522
  STREAM_CHECK_RET_GOTO(processWalVerDataNew(pVnode, sStreamReaderInfo, req->walDataNewReq.versions, req->walDataNewReq.ranges, &resultRsp));
214,974✔
3523
  STREAM_CHECK_CONDITION_GOTO(resultRsp.totalRows == 0, TDB_CODE_SUCCESS);
214,974✔
3524

3525
  if (!sStreamReaderInfo->isVtableStream){
173,467✔
3526
    STREAM_CHECK_RET_GOTO(createOneDataBlock(sStreamReaderInfo->calcBlock, false, &pBlock2));
137,321✔
3527
  
3528
    blockDataTransform(pBlock2, resultRsp.dataBlock);
137,321✔
3529
    blockDataDestroy(resultRsp.dataBlock);
137,321✔
3530
    resultRsp.dataBlock = pBlock2;
137,321✔
3531
    pBlock2 = NULL;
137,321✔
3532
  }
3533

3534
  size = tSerializeSStreamWalDataResponse(NULL, 0, &resultRsp);
173,467✔
3535
  buf = rpcMallocCont(size);
173,467✔
3536
  size = tSerializeSStreamWalDataResponse(buf, size, &resultRsp);
173,467✔
3537
  printDataBlock(resultRsp.dataBlock, __func__, "data", ((SStreamTask*)pTask)->streamId);
173,467✔
3538
  printIndexHash(resultRsp.indexHash, pTask);
173,467✔
3539

3540
end:
214,974✔
3541
  if (resultRsp.totalRows == 0) {
214,974✔
3542
    buf = rpcMallocCont(sizeof(int64_t));
41,507✔
3543
    *(int64_t *)buf = resultRsp.ver;
41,507✔
3544
    size = sizeof(int64_t);
41,507✔
3545
    code = TSDB_CODE_STREAM_NO_DATA;
41,507✔
3546
  }
3547
  SRpcMsg rsp = {
214,974✔
3548
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3549
  tmsgSendRsp(&rsp);
214,974✔
3550
  if (code == TSDB_CODE_STREAM_NO_DATA){
214,974✔
3551
    code = 0;
41,507✔
3552
  }
3553

3554
  blockDataDestroy(pBlock1);
214,974✔
3555
  blockDataDestroy(pBlock2);
214,974✔
3556
  blockDataDestroy(resultRsp.dataBlock);
214,974✔
3557
  blockDataDestroy(resultRsp.deleteBlock);
214,974✔
3558
  blockDataDestroy(resultRsp.tableBlock);
214,974✔
3559
  tSimpleHashCleanup(resultRsp.indexHash);
214,974✔
3560
  tSimpleHashCleanup(resultRsp.uidHash);
214,974✔
3561
  STREAM_PRINT_LOG_END_WITHID(code, lino);
214,974✔
3562

3563
  return code;
214,974✔
3564
}
3565

3566
static int32_t vnodeProcessStreamGroupColValueReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
242,709✔
3567
  int32_t code = 0;
242,709✔
3568
  int32_t lino = 0;
242,709✔
3569
  void*   buf = NULL;
242,709✔
3570
  size_t  size = 0;
242,709✔
3571
  SArray** gInfo = NULL;
242,709✔
3572
  
3573
  void* pTask = sStreamReaderInfo->pTask;
242,709✔
3574
  ST_TASK_DLOG("vgId:%d %s start, request gid:%" PRId64, TD_VID(pVnode), __func__, req->groupColValueReq.gid);
242,709✔
3575

3576
  gInfo = taosHashAcquire(sStreamReaderInfo->groupIdMap, &req->groupColValueReq.gid, POINTER_BYTES);
242,709✔
3577
  STREAM_CHECK_NULL_GOTO(gInfo, TSDB_CODE_STREAM_NO_CONTEXT);
242,709✔
3578
  SStreamGroupInfo pGroupInfo = {0};
242,709✔
3579
  pGroupInfo.gInfo = *gInfo;
242,709✔
3580

3581
  size = tSerializeSStreamGroupInfo(NULL, 0, &pGroupInfo, TD_VID(pVnode));
242,709✔
3582
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3583
  buf = rpcMallocCont(size);
242,709✔
3584
  STREAM_CHECK_NULL_GOTO(buf, terrno);
242,709✔
3585
  size = tSerializeSStreamGroupInfo(buf, size, &pGroupInfo, TD_VID(pVnode));
242,709✔
3586
  STREAM_CHECK_CONDITION_GOTO(size < 0, size);
3587
end:
242,709✔
3588
  taosHashRelease(sStreamReaderInfo->groupIdMap, gInfo);
242,709✔
3589
  if (code != 0) {
242,709✔
3590
    rpcFreeCont(buf);
×
3591
    buf = NULL;
×
3592
    size = 0;
×
3593
  }
3594
  STREAM_PRINT_LOG_END_WITHID(code, lino);
242,709✔
3595
  SRpcMsg rsp = {
242,709✔
3596
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3597
  tmsgSendRsp(&rsp);
242,709✔
3598

3599
  return code;
242,709✔
3600
}
3601

3602
static int32_t setVtableInfo(SVnode* pVnode, SArray* infos, SArray* cids, int64_t uid, uint64_t gid, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo) {
41,228✔
3603
  int32_t              code = 0;
41,228✔
3604
  int32_t              lino = 0;
41,228✔
3605
  void* pTask = sStreamReaderInfo->pTask;
41,228✔
3606

3607
  VTableInfo* vTable = taosArrayReserve(infos, 1);
41,228✔
3608
  STREAM_CHECK_NULL_GOTO(vTable, terrno);
41,228✔
3609
  vTable->uid = uid;
41,228✔
3610
  vTable->gId = gid;
41,228✔
3611

3612
  ST_TASK_DLOG("vgId:%d %s put vtable uid:%"PRId64, TD_VID(pVnode), __func__, uid);
41,228✔
3613

3614
  code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(metaReader, ver, uid);
41,228✔
3615
  if (code != 0) {
41,228✔
3616
    ST_TASK_ELOG("vgId:%d %s get table entry by uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, uid, tstrerror(code));
×
3617
    goto end;
×
3618
  }
3619
  if (atomic_load_8(&sStreamReaderInfo->isVtableOnlyTs) == 1) {
41,228✔
3620
    vTable->cols.nCols = metaReader->me.colRef.nCols;
820✔
3621
    vTable->cols.version = metaReader->me.colRef.version;
820✔
3622
    vTable->cols.pColRef = taosMemoryCalloc(metaReader->me.colRef.nCols, sizeof(SColRef));
820✔
3623
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
820✔
3624
    for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
4,920✔
3625
      memcpy(vTable->cols.pColRef + j, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
4,100✔
3626
    }
3627
  } else {
3628
    vTable->cols.nCols = taosArrayGetSize(cids);
40,408✔
3629
    vTable->cols.version = metaReader->me.colRef.version;
40,408✔
3630
    vTable->cols.pColRef = taosMemoryCalloc(taosArrayGetSize(cids), sizeof(SColRef));
40,408✔
3631
    STREAM_CHECK_NULL_GOTO(vTable->cols.pColRef, terrno);
40,408✔
3632
    for (size_t i = 0; i < taosArrayGetSize(cids); i++) {
129,503✔
3633
      for (size_t j = 0; j < metaReader->me.colRef.nCols; j++) {
359,598✔
3634
        if (metaReader->me.colRef.pColRef[j].hasRef &&
318,491✔
3635
            metaReader->me.colRef.pColRef[j].id == *(col_id_t*)taosArrayGet(cids, i)) {
225,062✔
3636
          memcpy(vTable->cols.pColRef + i, &metaReader->me.colRef.pColRef[j], sizeof(SColRef));
47,988✔
3637
          break;
47,988✔
3638
        }
3639
      }
3640
    }
3641
  }
3642
  tDecoderClear(&metaReader->coder);
41,228✔
3643

3644
end:
41,228✔
3645
  return code;
41,228✔
3646
}
3647

3648
static int32_t getAllVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
26,088✔
3649
  int32_t              code = 0;
26,088✔
3650
  int32_t              lino = 0;
26,088✔
3651
  void* pTask = sStreamReaderInfo->pTask;
26,088✔
3652
  SArray*              pTableListArray = NULL;
26,088✔
3653

3654

3655
  pTableListArray = qStreamGetTableArrayList(sStreamReaderInfo);
26,088✔
3656
  STREAM_CHECK_NULL_GOTO(pTableListArray, terrno);
26,088✔
3657

3658
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(pTableListArray), sizeof(VTableInfo));
26,088✔
3659
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
26,088✔
3660

3661
  for (size_t i = 0; i < taosArrayGetSize(pTableListArray); i++) {
67,316✔
3662
    SStreamTableKeyInfo* pKeyInfo = taosArrayGetP(pTableListArray, i);
41,228✔
3663
    if (pKeyInfo == NULL || pKeyInfo->markedDeleted) {
41,228✔
3664
      continue;
×
3665
    }
3666
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, pKeyInfo->uid, pKeyInfo->groupId, ver, metaReader, sStreamReaderInfo);
41,228✔
3667
    if (code != 0) {
41,228✔
3668
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, pKeyInfo->uid, tstrerror(code));
×
3669
      code = 0;
×
3670
      continue;
×
3671
    }
3672
  }
3673

3674
end:
26,088✔
3675
  taosArrayDestroyP(pTableListArray, taosMemFree);
26,088✔
3676
  return code;
26,088✔
3677
}
3678

3679
static int32_t getSpicificVinfo(SVnode* pVnode, SStreamMsgVTableInfo* vTableInfo, SArray* uids, SArray* cids, int64_t ver, SMetaReader* metaReader, SStreamTriggerReaderInfo* sStreamReaderInfo){
×
3680
  int32_t              code = 0;
×
3681
  int32_t              lino = 0;
×
3682
  void* pTask = sStreamReaderInfo->pTask;
×
3683

3684
  vTableInfo->infos = taosArrayInit(taosArrayGetSize(uids), sizeof(VTableInfo));
×
3685
  STREAM_CHECK_NULL_GOTO(vTableInfo->infos, terrno);
×
3686

3687
  for (size_t i = 0; i < taosArrayGetSize(uids); i++) {
×
3688
    int64_t* uid = taosArrayGet(uids, i);
×
3689
    STREAM_CHECK_NULL_GOTO(uid, terrno);
×
3690

3691
    taosRLockLatch(&sStreamReaderInfo->lock);
×
3692
    uint64_t groupId = qStreamGetGroupIdFromOrigin(sStreamReaderInfo, *uid);
×
3693
    taosRUnLockLatch(&sStreamReaderInfo->lock);
×
3694
    if (groupId == -1) {
×
3695
      ST_TASK_WLOG("vgId:%d %s uid:%"PRId64" not found in stream group", TD_VID(pVnode), __func__, *uid);
×
3696
      continue;
×
3697
    }
3698
    code = setVtableInfo(pVnode, vTableInfo->infos, cids, *uid, groupId, ver, metaReader, sStreamReaderInfo);
×
3699
    if (code != 0) {
×
3700
      ST_TASK_WLOG("vgId:%d %s set vtable info uid:%"PRId64" failed, msg:%s", TD_VID(pVnode), __func__, *uid, tstrerror(code));
×
3701
      code = 0;
×
3702
      continue;
×
3703
    }
3704
  }
3705
  
3706
end:
×
3707
  return code;
×
3708
}
3709

3710
static int32_t vnodeProcessStreamVTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
26,088✔
3711
  int32_t              code = 0;
26,088✔
3712
  int32_t              lino = 0;
26,088✔
3713
  void*                buf = NULL;
26,088✔
3714
  size_t               size = 0;
26,088✔
3715
  SStreamMsgVTableInfo vTableInfo = {0};
26,088✔
3716
  SMetaReader          metaReader = {0};
26,088✔
3717

3718
  void* pTask = sStreamReaderInfo->pTask;
26,088✔
3719
  ST_TASK_DLOG("vgId:%d %s start, version:%"PRId64, TD_VID(pVnode), __func__, req->virTableInfoReq.ver);
26,088✔
3720

3721
  SArray* cids = req->virTableInfoReq.cids;
26,088✔
3722
  STREAM_CHECK_NULL_GOTO(cids, terrno);
26,088✔
3723

3724
  if (taosArrayGetSize(cids) == 1 && *(col_id_t*)taosArrayGet(cids, 0) == PRIMARYKEY_TIMESTAMP_COL_ID){
26,088✔
3725
    (void)atomic_val_compare_exchange_8(&sStreamReaderInfo->isVtableOnlyTs, 0, 1);
820✔
3726
  }
3727
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
26,088✔
3728

3729
  if (req->virTableInfoReq.fetchAllTable || req->virTableInfoReq.uids == NULL || taosArrayGetSize(req->virTableInfoReq.uids) == 0) {
26,088✔
3730
    STREAM_CHECK_RET_GOTO(getAllVinfo(pVnode, &vTableInfo, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
26,088✔
3731
  } else {
3732
    STREAM_CHECK_RET_GOTO(getSpicificVinfo(pVnode, &vTableInfo, req->virTableInfoReq.uids, cids, req->virTableInfoReq.ver, &metaReader, sStreamReaderInfo));
×
3733
  }
3734
  ST_TASK_DLOG("vgId:%d %s end, size:%"PRIzu, TD_VID(pVnode), __func__, taosArrayGetSize(vTableInfo.infos));
26,088✔
3735
  STREAM_CHECK_RET_GOTO(buildVTableInfoRsp(&vTableInfo, &buf, &size));
26,088✔
3736

3737
end:
26,088✔
3738
  tDestroySStreamMsgVTableInfo(&vTableInfo);
26,088✔
3739
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
26,088✔
3740
  STREAM_PRINT_LOG_END_WITHID(code, lino);
26,088✔
3741
  SRpcMsg rsp = {
26,088✔
3742
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3743
  tmsgSendRsp(&rsp);
26,088✔
3744
  return code;
26,088✔
3745
}
3746

3747
static int32_t vnodeProcessStreamOTableInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
30,082✔
3748
  int32_t                   code = 0;
30,082✔
3749
  int32_t                   lino = 0;
30,082✔
3750
  void*                     buf = NULL;
30,082✔
3751
  size_t                    size = 0;
30,082✔
3752
  SSTriggerOrigTableInfoRsp oTableInfo = {0};
30,082✔
3753
  SMetaReader               metaReader = {0};
30,082✔
3754
  void*                     pTask = sStreamReaderInfo->pTask;
30,082✔
3755

3756
  ST_TASK_DLOG("vgId:%d %s start, ver:%" PRId64, TD_VID(pVnode), __func__, req->origTableInfoReq.ver);
30,082✔
3757

3758
  SArray* cols = req->origTableInfoReq.cols;
30,082✔
3759
  STREAM_CHECK_NULL_GOTO(cols, terrno);
30,082✔
3760

3761
  oTableInfo.cols = taosArrayInit(taosArrayGetSize(cols), sizeof(OTableInfoRsp));
30,082✔
3762

3763
  STREAM_CHECK_NULL_GOTO(oTableInfo.cols, terrno);
30,082✔
3764

3765
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
30,082✔
3766
  for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
81,120✔
3767
    OTableInfo*    oInfo = taosArrayGet(cols, i);
51,268✔
3768
    OTableInfoRsp* vTableInfo = taosArrayReserve(oTableInfo.cols, 1);
51,268✔
3769
    STREAM_CHECK_NULL_GOTO(oInfo, terrno);
51,268✔
3770
    STREAM_CHECK_NULL_GOTO(vTableInfo, terrno);
51,268✔
3771
    code = sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionName(&metaReader, req->origTableInfoReq.ver, oInfo->refTableName);
51,268✔
3772
    if (code != 0) {
51,268✔
3773
      code = 0;
205✔
3774
      ST_TASK_ELOG("vgId:%d %s get table entry by name:%s failed, msg:%s", TD_VID(pVnode), __func__, oInfo->refTableName, tstrerror(code));
205✔
3775
      continue;
205✔
3776
    }
3777
    vTableInfo->uid = metaReader.me.uid;
51,063✔
3778
    ST_TASK_DLOG("vgId:%d %s get original uid:%"PRId64, TD_VID(pVnode), __func__, vTableInfo->uid);
51,063✔
3779

3780
    SSchemaWrapper* sSchemaWrapper = NULL;
51,063✔
3781
    if (metaReader.me.type == TD_CHILD_TABLE) {
51,063✔
3782
      int64_t suid = metaReader.me.ctbEntry.suid;
49,223✔
3783
      vTableInfo->suid = suid;
49,223✔
3784
      tDecoderClear(&metaReader.coder);
49,223✔
3785
      STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->origTableInfoReq.ver, suid));
49,223✔
3786
      sSchemaWrapper = &metaReader.me.stbEntry.schemaRow;
48,993✔
3787
    } else if (metaReader.me.type == TD_NORMAL_TABLE) {
1,840✔
3788
      vTableInfo->suid = 0;
1,840✔
3789
      sSchemaWrapper = &metaReader.me.ntbEntry.schemaRow;
1,840✔
3790
    } else {
3791
      ST_TASK_ELOG("invalid table type:%d", metaReader.me.type);
×
3792
    }
3793

3794
    for (size_t j = 0; j < sSchemaWrapper->nCols; j++) {
210,536✔
3795
      SSchema* s = sSchemaWrapper->pSchema + j;
210,766✔
3796
      if (strcmp(s->name, oInfo->refColName) == 0) {
210,766✔
3797
        vTableInfo->cid = s->colId;
51,063✔
3798
        break;
50,833✔
3799
      }
3800
    }
3801
    if (vTableInfo->cid == 0) {
50,603✔
3802
      stError("vgId:%d %s, not found col %s in table %s", TD_VID(pVnode), __func__, oInfo->refColName,
×
3803
              oInfo->refTableName);
3804
    }
3805
    tDecoderClear(&metaReader.coder);
51,063✔
3806
  }
3807

3808
  STREAM_CHECK_RET_GOTO(buildOTableInfoRsp(&oTableInfo, &buf, &size));
29,852✔
3809

3810
end:
30,082✔
3811
  tDestroySTriggerOrigTableInfoRsp(&oTableInfo);
30,082✔
3812
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
30,082✔
3813
  STREAM_PRINT_LOG_END_WITHID(code, lino);
30,082✔
3814
  SRpcMsg rsp = {
30,082✔
3815
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3816
  tmsgSendRsp(&rsp);
30,082✔
3817
  return code;
30,082✔
3818
}
3819

3820
static int32_t vnodeProcessStreamVTableTagInfoReq(SVnode* pVnode, SRpcMsg* pMsg, SSTriggerPullRequestUnion* req, SStreamTriggerReaderInfo* sStreamReaderInfo) {
110,199✔
3821
  int32_t                   code = 0;
110,199✔
3822
  int32_t                   lino = 0;
110,199✔
3823
  void*                     buf = NULL;
110,199✔
3824
  size_t                    size = 0;
110,199✔
3825
  SSDataBlock* pBlock = NULL;
110,199✔
3826

3827
  SMetaReader               metaReader = {0};
110,199✔
3828
  SMetaReader               metaReaderStable = {0};
110,199✔
3829
  int64_t streamId = req->base.streamId;
110,199✔
3830
  stsDebug("vgId:%d %s start, ver:%"PRId64, TD_VID(pVnode), __func__, req->virTablePseudoColReq.ver);
110,199✔
3831

3832
  SArray* cols = req->virTablePseudoColReq.cids;
110,199✔
3833
  STREAM_CHECK_NULL_GOTO(cols, terrno);
110,199✔
3834

3835
  sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReader, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
110,199✔
3836
  STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReader, req->virTablePseudoColReq.ver, req->virTablePseudoColReq.uid));
110,199✔
3837

3838
  STREAM_CHECK_CONDITION_GOTO(metaReader.me.type != TD_VIRTUAL_CHILD_TABLE && metaReader.me.type != TD_VIRTUAL_NORMAL_TABLE, TSDB_CODE_INVALID_PARA);
110,199✔
3839

3840
  STREAM_CHECK_RET_GOTO(createDataBlock(&pBlock));
110,199✔
3841
  if (metaReader.me.type == TD_VIRTUAL_NORMAL_TABLE) {
110,199✔
3842
    STREAM_CHECK_CONDITION_GOTO (taosArrayGetSize(cols) < 1 || *(col_id_t*)taosArrayGet(cols, 0) != -1, TSDB_CODE_INVALID_PARA);
2,076✔
3843
    SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
2,076✔
3844
    STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
2,076✔
3845
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
2,076✔
3846
    pBlock->info.rows = 1;
2,076✔
3847
    SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, 0);
2,076✔
3848
    STREAM_CHECK_NULL_GOTO(pDst, terrno);
2,076✔
3849
    STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
2,076✔
3850
  } else if (metaReader.me.type == TD_VIRTUAL_CHILD_TABLE){
108,123✔
3851
    int64_t suid = metaReader.me.ctbEntry.suid;
108,123✔
3852
    sStreamReaderInfo->storageApi.metaReaderFn.readerReleaseLock(&metaReader);
108,123✔
3853
    sStreamReaderInfo->storageApi.metaReaderFn.initReader(&metaReaderStable, pVnode, META_READER_LOCK, &sStreamReaderInfo->storageApi.metaFn);
108,123✔
3854

3855
    STREAM_CHECK_RET_GOTO(sStreamReaderInfo->storageApi.metaReaderFn.getTableEntryByVersionUid(&metaReaderStable, req->virTablePseudoColReq.ver, suid));
108,123✔
3856
    SSchemaWrapper*  sSchemaWrapper = &metaReaderStable.me.stbEntry.schemaTag;
108,123✔
3857
    for (size_t i = 0; i < taosArrayGetSize(cols); i++){
293,604✔
3858
      col_id_t* id = taosArrayGet(cols, i);
185,691✔
3859
      STREAM_CHECK_NULL_GOTO(id, terrno);
185,691✔
3860
      if (*id == -1) {
185,691✔
3861
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN, -1);
108,123✔
3862
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
108,123✔
3863
        continue;
108,123✔
3864
      }
3865
      size_t j = 0;
77,568✔
3866
      for (; j < sSchemaWrapper->nCols; j++) {
90,168✔
3867
        SSchema* s = sSchemaWrapper->pSchema + j;
90,168✔
3868
        if (s->colId == *id) {
90,168✔
3869
          SColumnInfoData idata = createColumnInfoData(s->type, s->bytes, s->colId);
77,568✔
3870
          STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
77,568✔
3871
          break;
77,568✔
3872
        }
3873
      }
3874
      if (j == sSchemaWrapper->nCols) {
77,568✔
3875
        SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, CHAR_BYTES, *id);
×
3876
        STREAM_CHECK_RET_GOTO(blockDataAppendColInfo(pBlock, &idata));
×
3877
      }
3878
    }
3879
    STREAM_CHECK_RET_GOTO(blockDataEnsureCapacity(pBlock, 1));
107,913✔
3880
    pBlock->info.rows = 1;
108,123✔
3881
    
3882
    for (size_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++){
293,814✔
3883
      SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
185,691✔
3884
      STREAM_CHECK_NULL_GOTO(pDst, terrno);
185,691✔
3885

3886
      if (pDst->info.colId == -1) {
185,691✔
3887
        STREAM_CHECK_RET_GOTO(varColSetVarData(pDst, 0, metaReader.me.name, strlen(metaReader.me.name), false));
108,123✔
3888
        continue;
108,123✔
3889
      }
3890
      if (pDst->info.type == TSDB_DATA_TYPE_NULL) {
77,568✔
3891
        STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, NULL, true));
×
3892
        continue;
×
3893
      }
3894

3895
      STagVal val = {0};
77,568✔
3896
      val.cid = pDst->info.colId;
77,568✔
3897
      const char* p = sStreamReaderInfo->storageApi.metaFn.extractTagVal(metaReader.me.ctbEntry.pTags, pDst->info.type, &val);
77,568✔
3898

3899
      char* data = NULL;
77,568✔
3900
      if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) {
77,568✔
3901
        data = tTagValToData((const STagVal*)p, false);
77,568✔
3902
      } else {
3903
        data = (char*)p;
×
3904
      }
3905

3906
      STREAM_CHECK_RET_GOTO(colDataSetVal(pDst, 0, data,
77,568✔
3907
                            (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))));
3908

3909
      if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) &&
77,568✔
3910
          (data != NULL)) {
3911
        taosMemoryFree(data);
8,400✔
3912
      }
3913
    }
3914
  } else {
3915
    stError("vgId:%d %s, invalid table type:%d", TD_VID(pVnode), __func__, metaReader.me.type);
×
3916
    code = TSDB_CODE_INVALID_PARA;
×
3917
    goto end;
×
3918
  }
3919
  
3920
  stsDebug("vgId:%d %s get result rows:%" PRId64, TD_VID(pVnode), __func__, pBlock->info.rows);
109,989✔
3921
  printDataBlock(pBlock, __func__, "", streamId);
110,199✔
3922
  STREAM_CHECK_RET_GOTO(buildRsp(pBlock, &buf, &size));
110,199✔
3923

3924
end:
110,619✔
3925
  if(size == 0){
110,199✔
3926
    code = TSDB_CODE_STREAM_NO_DATA;
×
3927
  }
3928
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReaderStable);
110,199✔
3929
  sStreamReaderInfo->storageApi.metaReaderFn.clearReader(&metaReader);
110,199✔
3930
  STREAM_PRINT_LOG_END(code, lino);
110,199✔
3931
  SRpcMsg rsp = {
110,199✔
3932
      .msgType = TDMT_STREAM_TRIGGER_PULL_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
3933
  tmsgSendRsp(&rsp);
110,199✔
3934
  blockDataDestroy(pBlock);
110,199✔
3935
  return code;
110,199✔
3936
}
3937

3938
static int32_t vnodeProcessStreamFetchMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
6,644,642✔
3939
  int32_t            code = 0;
6,644,642✔
3940
  int32_t            lino = 0;
6,644,642✔
3941
  void*              buf = NULL;
6,644,642✔
3942
  size_t             size = 0;
6,644,642✔
3943
  void*              taskAddr = NULL;
6,644,642✔
3944
  SArray*            pResList = NULL;
6,644,642✔
3945
  bool               hasNext = false;
6,644,642✔
3946

3947
  SResFetchReq req = {0};
6,644,642✔
3948
  STREAM_CHECK_CONDITION_GOTO(tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0,
6,644,642✔
3949
                              TSDB_CODE_QRY_INVALID_INPUT);
3950
  SArray* calcInfoList = (SArray*)qStreamGetReaderInfo(req.queryId, req.taskId, &taskAddr);
6,644,642✔
3951
  STREAM_CHECK_NULL_GOTO(calcInfoList, terrno);
6,644,642✔
3952

3953
  STREAM_CHECK_CONDITION_GOTO(req.execId < 0, TSDB_CODE_INVALID_PARA);
6,644,642✔
3954
  SStreamTriggerReaderCalcInfo* sStreamReaderCalcInfo = taosArrayGetP(calcInfoList, req.execId);
6,644,642✔
3955
  STREAM_CHECK_NULL_GOTO(sStreamReaderCalcInfo, terrno);
6,644,642✔
3956
  sStreamReaderCalcInfo->rtInfo.execId = req.execId;
6,644,642✔
3957

3958
  void* pTask = sStreamReaderCalcInfo->pTask;
6,644,642✔
3959
  ST_TASK_DLOG("vgId:%d %s start, execId:%d, reset:%d, pTaskInfo:%p, scan type:%d", TD_VID(pVnode), __func__, req.execId, req.reset,
6,644,642✔
3960
               sStreamReaderCalcInfo->pTaskInfo, nodeType(sStreamReaderCalcInfo->calcAst->pNode));
3961

3962
  if (req.reset) {
6,644,642✔
3963
    int64_t uid = 0;
3,295,899✔
3964
    if (req.dynTbname) {
3,295,899✔
3965
      SArray* vals = req.pStRtFuncInfo->pStreamPartColVals;
109,312✔
3966
      for (int32_t i = 0; i < taosArrayGetSize(vals); ++i) {
109,312✔
3967
        SStreamGroupValue* pValue = taosArrayGet(vals, i);
109,312✔
3968
        if (pValue != NULL && pValue->isTbname) {
109,312✔
3969
          uid = pValue->uid;
109,312✔
3970
          break;
109,312✔
3971
        }
3972
      }
3973
    }
3974
    
3975
    SReadHandle handle = {0};
3,295,899✔
3976
    handle.vnode = pVnode;
3,295,899✔
3977
    handle.pMsgCb = &pVnode->msgCb;
3,295,899✔
3978
    handle.pWorkerCb = pInfo->workerCb;
3,295,899✔
3979
    handle.uid = uid;
3,295,899✔
3980
    handle.cacheSttStatis = true;
3,295,899✔
3981

3982
    initStorageAPI(&handle.api);
3,295,899✔
3983
    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode) ||
3,295,899✔
3984
      QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(sStreamReaderCalcInfo->calcAst->pNode)){
2,573,514✔
3985
      STimeRangeNode* node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pTimeRange;
3,132,827✔
3986
      if (node != NULL) {
3,132,827✔
3987
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, false));
279,364✔
3988
      } else {
3989
        ST_TASK_DLOG("vgId:%d %s no scan time range node", TD_VID(pVnode), __func__);
2,853,463✔
3990
      }
3991

3992
      node = (STimeRangeNode*)((STableScanPhysiNode*)(sStreamReaderCalcInfo->calcAst->pNode))->pExtTimeRange;
3,132,827✔
3993
      if (node != NULL) {
3,132,827✔
3994
        STREAM_CHECK_RET_GOTO(processCalaTimeRange(sStreamReaderCalcInfo, &req, node, &handle, true));
77,000✔
3995
      } else {
3996
        ST_TASK_DLOG("vgId:%d %s no interp time range node", TD_VID(pVnode), __func__);
3,055,827✔
3997
      }      
3998
    }
3999

4000
    TSWAP(sStreamReaderCalcInfo->rtInfo.funcInfo, *req.pStRtFuncInfo);
3,295,899✔
4001
    sStreamReaderCalcInfo->rtInfo.funcInfo.hasPlaceHolder = sStreamReaderCalcInfo->hasPlaceHolder;
3,295,899✔
4002
    handle.streamRtInfo = &sStreamReaderCalcInfo->rtInfo;
3,295,899✔
4003

4004
    if (sStreamReaderCalcInfo->pTaskInfo == NULL || !qNeedReset(sStreamReaderCalcInfo->pTaskInfo)) {
3,295,899✔
4005
      qDestroyTask(sStreamReaderCalcInfo->pTaskInfo);
419,087✔
4006
      STREAM_CHECK_RET_GOTO(qCreateStreamExecTaskInfo(&sStreamReaderCalcInfo->pTaskInfo,
419,087✔
4007
                                                    sStreamReaderCalcInfo->calcScanPlan, &handle, NULL, TD_VID(pVnode),
4008
                                                    req.taskId));
4009
    } else {
4010
      STREAM_CHECK_RET_GOTO(qResetTableScan(sStreamReaderCalcInfo->pTaskInfo, &handle));
2,876,812✔
4011
    }
4012

4013
    STREAM_CHECK_RET_GOTO(qSetTaskId(sStreamReaderCalcInfo->pTaskInfo, req.taskId, req.queryId));
3,295,899✔
4014
  }
4015

4016
  if (req.pOpParam != NULL) {
6,644,642✔
4017
    qUpdateOperatorParam(sStreamReaderCalcInfo->pTaskInfo, (void*)req.pOpParam);
158,378✔
4018
  }
4019

4020
  pResList = taosArrayInit(4, POINTER_BYTES);
6,644,642✔
4021
  STREAM_CHECK_NULL_GOTO(pResList, terrno);
6,644,642✔
4022
  uint64_t ts = 0;
6,644,642✔
4023
  STREAM_CHECK_RET_GOTO(qExecTaskOpt(sStreamReaderCalcInfo->pTaskInfo, pResList, &ts, &hasNext, NULL, req.pOpParam != NULL));
6,644,642✔
4024

4025
  for(size_t i = 0; i < taosArrayGetSize(pResList); i++){
17,335,217✔
4026
    SSDataBlock* pBlock = taosArrayGetP(pResList, i);
10,691,964✔
4027
    if (pBlock == NULL) continue;
10,691,964✔
4028
    printDataBlock(pBlock, __func__, "fetch", ((SStreamTask*)pTask)->streamId);
10,691,964✔
4029
/*    
4030
    if (sStreamReaderCalcInfo->rtInfo.funcInfo.withExternalWindow) {
4031
      STREAM_CHECK_RET_GOTO(qStreamFilter(pBlock, sStreamReaderCalcInfo->pFilterInfo, NULL));
4032
      printDataBlock(pBlock, __func__, "fetch filter");
4033
    }
4034
*/    
4035
  }
4036

4037
end:
6,644,642✔
4038
  STREAM_CHECK_RET_GOTO(streamBuildFetchRsp(pResList, hasNext, &buf, &size, pVnode->config.tsdbCfg.precision));
6,644,642✔
4039
  taosArrayDestroy(pResList);
6,644,642✔
4040
  streamReleaseTask(taskAddr);
6,644,642✔
4041

4042
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST){
6,644,642✔
4043
    code = TDB_CODE_SUCCESS;
×
4044
  }
4045
  STREAM_PRINT_LOG_END(code, lino);
6,644,642✔
4046
  SRpcMsg rsp = {.msgType = TDMT_STREAM_FETCH_RSP, .info = pMsg->info, .pCont = buf, .contLen = size, .code = code};
6,644,642✔
4047
  tmsgSendRsp(&rsp);
6,643,907✔
4048
  tDestroySResFetchReq(&req);
6,642,913✔
4049
  if (TDB_CODE_SUCCESS != code) {
6,644,374✔
4050
    ST_TASK_ELOG("vgId:%d %s failed, code:%d - %s", TD_VID(pVnode), __func__,
×
4051
                 code, tstrerror(code));
4052
  }
4053
  return code;
6,644,374✔
4054
}
4055

4056
static int32_t initTableList(SStreamTriggerReaderInfo* sStreamReaderInfo, SVnode* pVnode) {
13,955,909✔
4057
  int32_t code = 0;
13,955,909✔
4058
  if (sStreamReaderInfo->tableList.pTableList != NULL) {  
13,955,909✔
4059
    return code;
13,765,859✔
4060
  }
4061
  taosWLockLatch(&sStreamReaderInfo->lock);
190,238✔
4062
  sStreamReaderInfo->pVnode = pVnode;
190,238✔
4063
  initStorageAPI(&sStreamReaderInfo->storageApi);
190,238✔
4064
  if (sStreamReaderInfo->tableList.pTableList == NULL) {
190,051✔
4065
    code = initStreamTableListInfo(&sStreamReaderInfo->tableList);
190,238✔
4066
    if (code == 0) {
190,238✔
4067
      code = generateTablistForStreamReader(pVnode, sStreamReaderInfo);
190,238✔
4068
      if (code != 0) {
190,238✔
4069
        qStreamDestroyTableInfo(&sStreamReaderInfo->tableList);
×
4070
      } else {
4071
        sStreamReaderInfo->tableList.version = pVnode->state.applied;
190,238✔
4072
        stDebug("vgId:%d %s init table list for stream reader, table num:%zu, version:%" PRId64,
190,238✔
4073
                TD_VID(pVnode), __func__, taosArrayGetSize(sStreamReaderInfo->tableList.pTableList), sStreamReaderInfo->tableList.version);
4074
      }
4075
    }
4076
  }
4077
  taosWUnLockLatch(&sStreamReaderInfo->lock);
190,051✔
4078
  return code;
190,008✔
4079
}
4080

4081
int32_t vnodeProcessStreamReaderMsg(SVnode* pVnode, SRpcMsg* pMsg, SQueueInfo *pInfo) {
20,656,473✔
4082
  int32_t                   code = 0;
20,656,473✔
4083
  int32_t                   lino = 0;
20,656,473✔
4084
  SSTriggerPullRequestUnion req = {0};
20,656,473✔
4085
  void*                     taskAddr = NULL;
20,657,574✔
4086
  bool                      sendRsp = false;
20,654,484✔
4087

4088
  vDebug("vgId:%d, msg:%p in stream reader queue is processing", pVnode->config.vgId, pMsg);
20,654,484✔
4089
  if (!syncIsReadyForRead(pVnode->sync)) {
20,655,186✔
4090
    vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
45,898✔
4091
    return 0;
45,898✔
4092
  }
4093

4094
  if (pMsg->msgType == TDMT_STREAM_FETCH) {
20,611,802✔
4095
    return vnodeProcessStreamFetchMsg(pVnode, pMsg, pInfo);
6,644,642✔
4096
  } else if (pMsg->msgType == TDMT_STREAM_TRIGGER_PULL) {
13,967,365✔
4097
    void*   pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
13,967,795✔
4098
    int32_t len = pMsg->contLen - sizeof(SMsgHead);
13,967,565✔
4099
    STREAM_CHECK_RET_GOTO(tDeserializeSTriggerPullRequest(pReq, len, &req));
13,966,875✔
4100
    stDebug("vgId:%d %s start, type:%d, streamId:%" PRIx64 ", readerTaskId:%" PRIx64 ", sessionId:%" PRIx64 ", applied:%" PRIx64,
13,965,639✔
4101
            TD_VID(pVnode), __func__, req.base.type, req.base.streamId, req.base.readerTaskId, req.base.sessionId, pVnode->state.applied);
4102
    SStreamTriggerReaderInfo* sStreamReaderInfo = qStreamGetReaderInfo(req.base.streamId, req.base.readerTaskId, &taskAddr);
13,966,256✔
4103
    STREAM_CHECK_NULL_GOTO(sStreamReaderInfo, terrno);
13,966,473✔
4104
    STREAM_CHECK_RET_GOTO(initTableList(sStreamReaderInfo, pVnode));
13,955,679✔
4105
    sendRsp = true;
13,955,407✔
4106
    switch (req.base.type) {
13,955,407✔
4107
      case STRIGGER_PULL_SET_TABLE:
30,082✔
4108
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamSetTableReq(pVnode, pMsg, &req, sStreamReaderInfo));
30,082✔
4109
        break;
30,082✔
4110
      case STRIGGER_PULL_LAST_TS:
181,009✔
4111
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamLastTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
181,009✔
4112
        break;
180,877✔
4113
      case STRIGGER_PULL_FIRST_TS:
140,964✔
4114
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamFirstTsReq(pVnode, pMsg, &req, sStreamReaderInfo));
140,964✔
4115
        break;
140,734✔
4116
      case STRIGGER_PULL_TSDB_META:
117,583✔
4117
      case STRIGGER_PULL_TSDB_META_NEXT:
4118
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbMetaReq(pVnode, pMsg, &req, sStreamReaderInfo));
117,583✔
4119
        break;
117,583✔
4120
      case STRIGGER_PULL_TSDB_TS_DATA:
166,420✔
4121
        if (sStreamReaderInfo->isVtableStream) {
166,420✔
4122
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqVTable(pVnode, pMsg, &req, sStreamReaderInfo));
×
4123
        } else {
4124
          STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTsDataReqNonVTable(pVnode, pMsg, &req, sStreamReaderInfo));
166,420✔
4125
        }
4126
        break;
166,420✔
4127
      case STRIGGER_PULL_TSDB_TRIGGER_DATA:
111,158✔
4128
      case STRIGGER_PULL_TSDB_TRIGGER_DATA_NEXT:
4129
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbTriggerDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
111,158✔
4130
        break;
55,579✔
4131
      case STRIGGER_PULL_TSDB_CALC_DATA:
5,901,224✔
4132
      case STRIGGER_PULL_TSDB_CALC_DATA_NEXT:
4133
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbCalcDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
5,901,224✔
4134
        break;
5,901,207✔
4135
      case STRIGGER_PULL_TSDB_DATA:
65,356✔
4136
      case STRIGGER_PULL_TSDB_DATA_NEXT:
4137
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamTsdbVirtalDataReq(pVnode, pMsg, &req, sStreamReaderInfo));
65,356✔
4138
        break;
65,356✔
4139
      case STRIGGER_PULL_GROUP_COL_VALUE:
242,709✔
4140
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamGroupColValueReq(pVnode, pMsg, &req, sStreamReaderInfo));
242,709✔
4141
        break;
242,709✔
4142
      case STRIGGER_PULL_VTABLE_INFO:
26,088✔
4143
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
26,088✔
4144
        break;
26,088✔
4145
      case STRIGGER_PULL_VTABLE_PSEUDO_COL:
110,199✔
4146
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamVTableTagInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
110,199✔
4147
        break;
110,199✔
4148
      case STRIGGER_PULL_OTABLE_INFO:
30,082✔
4149
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamOTableInfoReq(pVnode, pMsg, &req, sStreamReaderInfo));
30,082✔
4150
        break;
30,082✔
4151
      case STRIGGER_PULL_WAL_META_NEW:
2,862,318✔
4152
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
2,862,318✔
4153
        break;
2,862,748✔
4154
      case STRIGGER_PULL_WAL_DATA_NEW:
668,506✔
4155
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
668,506✔
4156
        break;
668,736✔
4157
      case STRIGGER_PULL_WAL_META_DATA_NEW:
3,087,727✔
4158
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalMetaDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
3,087,727✔
4159
        break;
3,087,267✔
4160
      case STRIGGER_PULL_WAL_CALC_DATA_NEW:
214,974✔
4161
        STREAM_CHECK_RET_GOTO(vnodeProcessStreamWalCalcDataNewReq(pVnode, pMsg, &req, sStreamReaderInfo));
214,974✔
4162
        break;
214,974✔
4163
      default:
×
4164
        vError("unknown inner msg type:%d in stream reader queue", req.base.type);
×
4165
        sendRsp = false;
×
4166
        STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4167
    }
4168
  } else {
4169
    vError("unknown msg type:%d in stream reader queue", pMsg->msgType);
×
4170
    STREAM_CHECK_RET_GOTO(TSDB_CODE_APP_ERROR);
×
4171
  }
4172
end:
13,958,549✔
4173

4174
  streamReleaseTask(taskAddr);
13,966,391✔
4175

4176
  tDestroySTriggerPullRequest(&req);
13,967,836✔
4177
  STREAM_PRINT_LOG_END(code, lino);
13,964,665✔
4178
  if (!sendRsp) {
13,967,410✔
4179
    SRpcMsg rsp = {
21,588✔
4180
      .code = code,
4181
      .pCont = pMsg->info.rsp,
10,794✔
4182
      .contLen = pMsg->info.rspLen,
10,794✔
4183
      .info = pMsg->info,
4184
    };
4185
    tmsgSendRsp(&rsp);
10,794✔
4186
  }
4187
  return code;
13,967,381✔
4188
}
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