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

H
Hongze Cheng 已提交
16
#include "vnodeInt.h"
S
Shengliang Guan 已提交
17

L
Liu Jicong 已提交
18
int32_t tqInit() { return tqPushMgrInit(); }
L
Liu Jicong 已提交
19

L
Liu Jicong 已提交
20
void tqCleanUp() { tqPushMgrCleanUp(); }
L
Liu Jicong 已提交
21

L
Liu Jicong 已提交
22 23
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig,
            SMemAllocatorFactory* allocFac) {
wafwerar's avatar
wafwerar 已提交
24
  STQ* pTq = taosMemoryMalloc(sizeof(STQ));
L
Liu Jicong 已提交
25
  if (pTq == NULL) {
L
Liu Jicong 已提交
26
    terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
L
Liu Jicong 已提交
27 28
    return NULL;
  }
H
Hongze Cheng 已提交
29
  pTq->path = strdup(path);
L
Liu Jicong 已提交
30
  pTq->tqConfig = tqConfig;
L
Liu Jicong 已提交
31
  pTq->pVnode = pVnode;
L
Liu Jicong 已提交
32
  pTq->pWal = pWal;
L
Liu Jicong 已提交
33
  pTq->pVnodeMeta = pVnodeMeta;
L
Liu Jicong 已提交
34
#if 0
L
Liu Jicong 已提交
35
  pTq->tqMemRef.pAllocatorFactory = allocFac;
L
Liu Jicong 已提交
36 37
  pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
  if (pTq->tqMemRef.pAllocator == NULL) {
L
Liu Jicong 已提交
38
    // TODO: error code of buffer pool
L
Liu Jicong 已提交
39
  }
L
Liu Jicong 已提交
40
#endif
L
Liu Jicong 已提交
41 42
  pTq->tqMeta = tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer,
                            (FTqDelete)taosMemoryFree, 0);
L
Liu Jicong 已提交
43
  if (pTq->tqMeta == NULL) {
wafwerar's avatar
wafwerar 已提交
44
    taosMemoryFree(pTq);
L
Liu Jicong 已提交
45 46 47
#if 0
    allocFac->destroy(allocFac, pTq->tqMemRef.pAllocator);
#endif
L
Liu Jicong 已提交
48 49
    return NULL;
  }
L
Liu Jicong 已提交
50

L
Liu Jicong 已提交
51
#if 0
L
Liu Jicong 已提交
52 53 54
  pTq->tqPushMgr = tqPushMgrOpen();
  if (pTq->tqPushMgr == NULL) {
    // free store
wafwerar's avatar
wafwerar 已提交
55
    taosMemoryFree(pTq);
L
Liu Jicong 已提交
56 57
    return NULL;
  }
L
Liu Jicong 已提交
58
#endif
L
Liu Jicong 已提交
59

L
Liu Jicong 已提交
60 61
  pTq->pStreamTasks = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);

L
Liu Jicong 已提交
62 63
  return pTq;
}
L
Liu Jicong 已提交
64

L
Liu Jicong 已提交
65
void tqClose(STQ* pTq) {
H
Hongze Cheng 已提交
66
  if (pTq) {
wafwerar's avatar
wafwerar 已提交
67 68
    taosMemoryFreeClear(pTq->path);
    taosMemoryFree(pTq);
H
Hongze Cheng 已提交
69
  }
L
Liu Jicong 已提交
70 71
  // TODO
}
L
Liu Jicong 已提交
72

L
Liu Jicong 已提交
73
int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version) {
L
Liu Jicong 已提交
74
  if (msgType != TDMT_VND_SUBMIT) return 0;
wafwerar's avatar
wafwerar 已提交
75
  void* data = taosMemoryMalloc(msgLen);
L
Liu Jicong 已提交
76 77
  if (data == NULL) {
    return -1;
L
Liu Jicong 已提交
78
  }
L
Liu Jicong 已提交
79
  memcpy(data, msg, msgLen);
C
Cary Xu 已提交
80 81

  if (msgType == TDMT_VND_SUBMIT) {
82
    if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, version) != 0) {
C
Cary Xu 已提交
83 84
      return -1;
    }
C
Cary Xu 已提交
85 86
  }

L
Liu Jicong 已提交
87 88 89 90 91 92
  SRpcMsg req = {
      .msgType = TDMT_VND_STREAM_TRIGGER,
      .pCont = data,
      .contLen = msgLen,
  };
  tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &req);
L
Liu Jicong 已提交
93 94

#if 0
L
Liu Jicong 已提交
95 96 97 98 99 100
  void* pIter = taosHashIterate(pTq->tqPushMgr->pHash, NULL);
  while (pIter != NULL) {
    STqPusher* pusher = *(STqPusher**)pIter;
    if (pusher->type == TQ_PUSHER_TYPE__STREAM) {
      STqStreamPusher* streamPusher = (STqStreamPusher*)pusher;
      // repack
wafwerar's avatar
wafwerar 已提交
101
      STqStreamToken* token = taosMemoryMalloc(sizeof(STqStreamToken));
L
Liu Jicong 已提交
102 103 104 105 106 107 108 109 110 111 112 113
      if (token == NULL) {
        taosHashCancelIterate(pTq->tqPushMgr->pHash, pIter);
        terrno = TSDB_CODE_OUT_OF_MEMORY;
        return -1;
      }
      token->type = TQ_STREAM_TOKEN__DATA;
      token->data = msg;
      // set input
      // exec
    }
    // send msg to ep
  }
L
Liu Jicong 已提交
114 115
  // iterate hash
  // process all msg
L
fix  
Liu Jicong 已提交
116 117
  // if waiting
  // memcpy and send msg to fetch thread
L
Liu Jicong 已提交
118 119 120 121
  // TODO: add reference
  // if handle waiting, launch query and response to consumer
  //
  // if no waiting handle, return
L
Liu Jicong 已提交
122
#endif
L
Liu Jicong 已提交
123 124 125
  return 0;
}

L
Liu Jicong 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
int tqCommit(STQ* pTq) { return tqStorePersist(pTq->tqMeta); }

int32_t tqGetTopicHandleSize(const STqTopic* pTopic) {
  return strlen(pTopic->topicName) + strlen(pTopic->sql) + strlen(pTopic->logicalPlan) + strlen(pTopic->physicalPlan) +
         strlen(pTopic->qmsg) + sizeof(int64_t) * 3;
}

int32_t tqGetConsumerHandleSize(const STqConsumer* pConsumer) {
  int     num = taosArrayGetSize(pConsumer->topics);
  int32_t sz = 0;
  for (int i = 0; i < num; i++) {
    STqTopic* pTopic = taosArrayGet(pConsumer->topics, i);
    sz += tqGetTopicHandleSize(pTopic);
  }
  return sz;
}

static FORCE_INLINE int32_t tEncodeSTqTopic(void** buf, const STqTopic* pTopic) {
  int32_t tlen = 0;
  tlen += taosEncodeString(buf, pTopic->topicName);
  /*tlen += taosEncodeString(buf, pTopic->sql);*/
  /*tlen += taosEncodeString(buf, pTopic->logicalPlan);*/
  /*tlen += taosEncodeString(buf, pTopic->physicalPlan);*/
  tlen += taosEncodeString(buf, pTopic->qmsg);
L
Liu Jicong 已提交
150 151 152
  /*tlen += taosEncodeFixedI64(buf, pTopic->persistedOffset);*/
  /*tlen += taosEncodeFixedI64(buf, pTopic->committedOffset);*/
  /*tlen += taosEncodeFixedI64(buf, pTopic->currentOffset);*/
L
Liu Jicong 已提交
153 154 155 156 157 158 159 160 161
  return tlen;
}

static FORCE_INLINE const void* tDecodeSTqTopic(const void* buf, STqTopic* pTopic) {
  buf = taosDecodeStringTo(buf, pTopic->topicName);
  /*buf = taosDecodeString(buf, &pTopic->sql);*/
  /*buf = taosDecodeString(buf, &pTopic->logicalPlan);*/
  /*buf = taosDecodeString(buf, &pTopic->physicalPlan);*/
  buf = taosDecodeString(buf, &pTopic->qmsg);
L
Liu Jicong 已提交
162 163 164
  /*buf = taosDecodeFixedI64(buf, &pTopic->persistedOffset);*/
  /*buf = taosDecodeFixedI64(buf, &pTopic->committedOffset);*/
  /*buf = taosDecodeFixedI64(buf, &pTopic->currentOffset);*/
L
Liu Jicong 已提交
165 166 167 168 169 170 171 172
  return buf;
}

static FORCE_INLINE int32_t tEncodeSTqConsumer(void** buf, const STqConsumer* pConsumer) {
  int32_t sz;

  int32_t tlen = 0;
  tlen += taosEncodeFixedI64(buf, pConsumer->consumerId);
L
Liu Jicong 已提交
173
  tlen += taosEncodeFixedI32(buf, pConsumer->epoch);
L
Liu Jicong 已提交
174 175 176 177 178 179 180 181
  tlen += taosEncodeString(buf, pConsumer->cgroup);
  sz = taosArrayGetSize(pConsumer->topics);
  tlen += taosEncodeFixedI32(buf, sz);
  for (int32_t i = 0; i < sz; i++) {
    STqTopic* pTopic = taosArrayGet(pConsumer->topics, i);
    tlen += tEncodeSTqTopic(buf, pTopic);
  }
  return tlen;
L
Liu Jicong 已提交
182 183
}

L
Liu Jicong 已提交
184 185 186 187
static FORCE_INLINE const void* tDecodeSTqConsumer(const void* buf, STqConsumer* pConsumer) {
  int32_t sz;

  buf = taosDecodeFixedI64(buf, &pConsumer->consumerId);
L
Liu Jicong 已提交
188
  buf = taosDecodeFixedI32(buf, &pConsumer->epoch);
L
Liu Jicong 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
  buf = taosDecodeStringTo(buf, pConsumer->cgroup);
  buf = taosDecodeFixedI32(buf, &sz);
  pConsumer->topics = taosArrayInit(sz, sizeof(STqTopic));
  if (pConsumer->topics == NULL) return NULL;
  for (int32_t i = 0; i < sz; i++) {
    STqTopic pTopic;
    buf = tDecodeSTqTopic(buf, &pTopic);
    taosArrayPush(pConsumer->topics, &pTopic);
  }
  return buf;
}

int tqSerializeConsumer(const STqConsumer* pConsumer, STqSerializedHead** ppHead) {
  int32_t sz = tEncodeSTqConsumer(NULL, pConsumer);

L
Liu Jicong 已提交
204
  if (sz > (*ppHead)->ssize) {
wafwerar's avatar
wafwerar 已提交
205
    void* tmpPtr = taosMemoryRealloc(*ppHead, sizeof(STqSerializedHead) + sz);
L
Liu Jicong 已提交
206
    if (tmpPtr == NULL) {
wafwerar's avatar
wafwerar 已提交
207
      taosMemoryFree(*ppHead);
L
Liu Jicong 已提交
208
      terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
L
Liu Jicong 已提交
209 210 211 212 213 214 215
      return -1;
    }
    *ppHead = tmpPtr;
    (*ppHead)->ssize = sz;
  }

  void* ptr = (*ppHead)->content;
L
Liu Jicong 已提交
216 217
  void* abuf = ptr;
  tEncodeSTqConsumer(&abuf, pConsumer);
L
Liu Jicong 已提交
218

L
Liu Jicong 已提交
219 220 221
  return 0;
}

L
Liu Jicong 已提交
222 223
int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsumer** ppConsumer) {
  const void* str = pHead->content;
wafwerar's avatar
wafwerar 已提交
224
  *ppConsumer = taosMemoryCalloc(1, sizeof(STqConsumer));
L
Liu Jicong 已提交
225 226 227 228 229 230 231 232 233 234
  if (*ppConsumer == NULL) {
    terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
    return -1;
  }
  if (tDecodeSTqConsumer(str, *ppConsumer) == NULL) {
    terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
    return -1;
  }
  STqConsumer* pConsumer = *ppConsumer;
  int32_t      sz = taosArrayGetSize(pConsumer->topics);
L
Liu Jicong 已提交
235
  for (int32_t i = 0; i < sz; i++) {
L
Liu Jicong 已提交
236 237 238 239 240
    STqTopic* pTopic = taosArrayGet(pConsumer->topics, i);
    pTopic->pReadhandle = walOpenReadHandle(pTq->pWal);
    if (pTopic->pReadhandle == NULL) {
      ASSERT(false);
    }
L
Liu Jicong 已提交
241 242
    for (int j = 0; j < TQ_BUFFER_SIZE; j++) {
      pTopic->buffer.output[j].status = 0;
L
Liu Jicong 已提交
243
      STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
L
Liu Jicong 已提交
244 245 246 247
      SReadHandle    handle = {
             .reader = pReadHandle,
             .meta = pTq->pVnodeMeta,
      };
L
Liu Jicong 已提交
248 249
      pTopic->buffer.output[j].pReadHandle = pReadHandle;
      pTopic->buffer.output[j].task = qCreateStreamExecTaskInfo(pTopic->qmsg, &handle);
L
Liu Jicong 已提交
250
    }
L
Liu Jicong 已提交
251
  }
L
Liu Jicong 已提交
252 253

  return 0;
L
Liu Jicong 已提交
254
}
L
Liu Jicong 已提交
255
#if 0
L
fix  
Liu Jicong 已提交
256
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
L
Liu Jicong 已提交
257 258 259 260
  SMqPollReq* pReq = pMsg->pCont;
  int64_t     consumerId = pReq->consumerId;
  int64_t     fetchOffset;
  int64_t     blockingTime = pReq->blockingTime;
L
Liu Jicong 已提交
261
  int32_t     reqEpoch = pReq->epoch;
262

L
Liu Jicong 已提交
263 264 265 266 267 268 269 270
  if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) {
    fetchOffset = 0;
  } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) {
    fetchOffset = walGetLastVer(pTq->pWal);
  } else {
    fetchOffset = pReq->currentOffset + 1;
  }

H
Hongze Cheng 已提交
271 272
  vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch,
         pTq->pVnode->vgId, pReq->currentOffset, fetchOffset);
L
fix  
Liu Jicong 已提交
273

L
Liu Jicong 已提交
274
  SMqPollRsp rsp = {
L
Liu Jicong 已提交
275
      /*.consumerId = consumerId,*/
L
Liu Jicong 已提交
276 277 278
      .numOfTopics = 0,
      .pBlockData = NULL,
  };
279 280 281

  STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId);
  if (pConsumer == NULL) {
L
Liu Jicong 已提交
282
    vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, pTq->pVnode->vgId);
283 284 285
    pMsg->pCont = NULL;
    pMsg->contLen = 0;
    pMsg->code = -1;
S
shm  
Shengliang Guan 已提交
286
    tmsgSendRsp(pMsg);
287 288
    return 0;
  }
L
Liu Jicong 已提交
289

L
Liu Jicong 已提交
290 291 292 293 294 295
  int32_t consumerEpoch = atomic_load_32(&pConsumer->epoch);
  while (consumerEpoch < reqEpoch) {
    consumerEpoch = atomic_val_compare_exchange_32(&pConsumer->epoch, consumerEpoch, reqEpoch);
  }

  STqTopic* pTopic = NULL;
L
Liu Jicong 已提交
296
  int32_t   sz = taosArrayGetSize(pConsumer->topics);
L
Liu Jicong 已提交
297 298
  for (int32_t i = 0; i < sz; i++) {
    STqTopic* topic = taosArrayGet(pConsumer->topics, i);
H
Hongze Cheng 已提交
299
    // TODO race condition
L
Liu Jicong 已提交
300 301 302 303 304 305 306
    ASSERT(pConsumer->consumerId == consumerId);
    if (strcmp(topic->topicName, pReq->topic) == 0) {
      pTopic = topic;
      break;
    }
  }
  if (pTopic == NULL) {
H
Hongze Cheng 已提交
307 308
    vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic,
          pTq->pVnode->vgId);
L
Liu Jicong 已提交
309 310 311 312 313 314 315
    pMsg->pCont = NULL;
    pMsg->contLen = 0;
    pMsg->code = -1;
    tmsgSendRsp(pMsg);
    return 0;
  }

L
Liu Jicong 已提交
316 317
  vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch,
         pTq->pVnode->vgId);
318

L
Liu Jicong 已提交
319
  rsp.reqOffset = pReq->currentOffset;
320 321 322
  rsp.skipLogNum = 0;

  while (1) {
L
Liu Jicong 已提交
323
    /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/
H
Hongze Cheng 已提交
324
    // TODO
L
Liu Jicong 已提交
325
    consumerEpoch = atomic_load_32(&pConsumer->epoch);
L
Liu Jicong 已提交
326
    if (consumerEpoch > reqEpoch) {
L
Liu Jicong 已提交
327 328
      vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d",
             consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, consumerEpoch, reqEpoch);
L
Liu Jicong 已提交
329 330
      break;
    }
L
fix  
Liu Jicong 已提交
331 332
    SWalReadHead* pHead;
    if (walReadWithHandle_s(pTopic->pReadhandle, fetchOffset, &pHead) < 0) {
L
Liu Jicong 已提交
333 334
      // TODO: no more log, set timer to wait blocking time
      // if data inserted during waiting, launch query and
L
Liu Jicong 已提交
335
      // response to user
L
Liu Jicong 已提交
336 337
      vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch,
             pTq->pVnode->vgId, fetchOffset);
338 339
      break;
    }
L
Liu Jicong 已提交
340 341
    vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
           pTq->pVnode->vgId, fetchOffset, pHead->msgType);
L
fix  
Liu Jicong 已提交
342 343 344 345 346 347
    /*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/
    /*pHead = pTopic->pReadhandle->pHead;*/
    if (pHead->msgType == TDMT_VND_SUBMIT) {
      SSubmitReq* pCont = (SSubmitReq*)&pHead->body;
      qTaskInfo_t task = pTopic->buffer.output[workerId].task;
      ASSERT(task);
348
      qSetStreamInput(task, pCont, STREAM_DATA_TYPE_SUBMIT_BLOCK);
349 350
      SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
      while (1) {
L
fix  
Liu Jicong 已提交
351
        SSDataBlock* pDataBlock = NULL;
352 353 354 355 356
        uint64_t     ts;
        if (qExecTask(task, &pDataBlock, &ts) < 0) {
          ASSERT(false);
        }
        if (pDataBlock == NULL) {
L
fix  
Liu Jicong 已提交
357
          /*pos = fetchOffset % TQ_BUFFER_SIZE;*/
358 359 360 361
          break;
        }

        taosArrayPush(pRes, pDataBlock);
L
fix  
Liu Jicong 已提交
362 363 364
      }

      if (taosArrayGetSize(pRes) == 0) {
L
Liu Jicong 已提交
365 366
        vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId,
               pReq->epoch, pTq->pVnode->vgId, fetchOffset);
L
fix  
Liu Jicong 已提交
367 368 369 370 371 372 373
        fetchOffset++;
        rsp.skipLogNum++;
        taosArrayDestroy(pRes);
        continue;
      }
      rsp.schema = pTopic->buffer.output[workerId].pReadHandle->pSchemaWrapper;
      rsp.rspOffset = fetchOffset;
374

L
fix  
Liu Jicong 已提交
375 376
      rsp.numOfTopics = 1;
      rsp.pBlockData = pRes;
377

L
fix  
Liu Jicong 已提交
378 379 380 381 382 383
      int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
      void*   buf = rpcMallocCont(tlen);
      if (buf == NULL) {
        pMsg->code = -1;
        taosMemoryFree(pHead);
        return -1;
384
      }
L
fix  
Liu Jicong 已提交
385 386 387 388 389 390 391 392 393 394
      ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
      ((SMqRspHead*)buf)->epoch = pReq->epoch;
      ((SMqRspHead*)buf)->consumerId = consumerId;

      void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
      tEncodeSMqPollRsp(&abuf, &rsp);
      /*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/
      pMsg->pCont = buf;
      pMsg->contLen = tlen;
      pMsg->code = 0;
L
Liu Jicong 已提交
395 396
      vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset,
             pHead->msgType, consumerId, pReq->epoch);
L
fix  
Liu Jicong 已提交
397 398 399
      tmsgSendRsp(pMsg);
      taosMemoryFree(pHead);
      return 0;
400
    } else {
L
fix  
Liu Jicong 已提交
401
      taosMemoryFree(pHead);
402 403 404 405 406
      fetchOffset++;
      rsp.skipLogNum++;
    }
  }

L
Liu Jicong 已提交
407 408 409 410
  /*if (blockingTime != 0) {*/
  /*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/
  /*} else {*/
  int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
411 412 413 414 415
  void*   buf = rpcMallocCont(tlen);
  if (buf == NULL) {
    pMsg->code = -1;
    return -1;
  }
L
Liu Jicong 已提交
416 417
  ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
  ((SMqRspHead*)buf)->epoch = pReq->epoch;
L
temp  
Liu Jicong 已提交
418
  rsp.rspOffset = fetchOffset - 1;
419

L
Liu Jicong 已提交
420
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
L
Liu Jicong 已提交
421
  tEncodeSMqPollRsp(&abuf, &rsp);
422 423 424 425
  rsp.pBlockData = NULL;
  pMsg->pCont = buf;
  pMsg->contLen = tlen;
  pMsg->code = 0;
S
shm  
Shengliang Guan 已提交
426
  tmsgSendRsp(pMsg);
L
Liu Jicong 已提交
427 428
  vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId,
         pReq->epoch);
L
Liu Jicong 已提交
429 430
  /*}*/

431 432
  return 0;
}
L
Liu Jicong 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
#endif

int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
  SMqPollReq* pReq = pMsg->pCont;
  int64_t     consumerId = pReq->consumerId;
  int64_t     fetchOffset;
  int64_t     blockingTime = pReq->blockingTime;
  int32_t     reqEpoch = pReq->epoch;

  if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) {
    fetchOffset = 0;
  } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) {
    fetchOffset = walGetLastVer(pTq->pWal);
  } else {
    fetchOffset = pReq->currentOffset + 1;
  }

  vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch,
         pTq->pVnode->vgId, pReq->currentOffset, fetchOffset);

  SMqPollRspV2 rspV2 = {0};
  rspV2.dataLen = 0;

  STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId);
  if (pConsumer == NULL) {
    vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, pTq->pVnode->vgId);
    pMsg->pCont = NULL;
    pMsg->contLen = 0;
    pMsg->code = -1;
    tmsgSendRsp(pMsg);
    return 0;
  }

  int32_t consumerEpoch = atomic_load_32(&pConsumer->epoch);
  while (consumerEpoch < reqEpoch) {
    consumerEpoch = atomic_val_compare_exchange_32(&pConsumer->epoch, consumerEpoch, reqEpoch);
  }

  STqTopic* pTopic = NULL;
  int32_t   topicSz = taosArrayGetSize(pConsumer->topics);
  for (int32_t i = 0; i < topicSz; i++) {
    STqTopic* topic = taosArrayGet(pConsumer->topics, i);
    // TODO race condition
    ASSERT(pConsumer->consumerId == consumerId);
    if (strcmp(topic->topicName, pReq->topic) == 0) {
      pTopic = topic;
      break;
    }
  }
  if (pTopic == NULL) {
    vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic,
          pTq->pVnode->vgId);
    pMsg->pCont = NULL;
    pMsg->contLen = 0;
    pMsg->code = -1;
    tmsgSendRsp(pMsg);
    return 0;
  }

  vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch,
         pTq->pVnode->vgId);

  rspV2.reqOffset = pReq->currentOffset;
  rspV2.skipLogNum = 0;

  while (1) {
    /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/
    // TODO
    consumerEpoch = atomic_load_32(&pConsumer->epoch);
    if (consumerEpoch > reqEpoch) {
      vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d",
             consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, consumerEpoch, reqEpoch);
      break;
    }
    SWalReadHead* pHead;
    if (walReadWithHandle_s(pTopic->pReadhandle, fetchOffset, &pHead) < 0) {
      // TODO: no more log, set timer to wait blocking time
      // if data inserted during waiting, launch query and
      // response to user
      vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch,
             pTq->pVnode->vgId, fetchOffset);
      break;
    }
    vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
           pTq->pVnode->vgId, fetchOffset, pHead->msgType);
    /*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/
    /*pHead = pTopic->pReadhandle->pHead;*/
    if (pHead->msgType == TDMT_VND_SUBMIT) {
      SSubmitReq* pCont = (SSubmitReq*)&pHead->body;
      qTaskInfo_t task = pTopic->buffer.output[workerId].task;
      ASSERT(task);
      qSetStreamInput(task, pCont, STREAM_DATA_TYPE_SUBMIT_BLOCK);
      SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
      while (1) {
        SSDataBlock* pDataBlock = NULL;
        uint64_t     ts;
        if (qExecTask(task, &pDataBlock, &ts) < 0) {
          ASSERT(false);
        }
        if (pDataBlock == NULL) {
          /*pos = fetchOffset % TQ_BUFFER_SIZE;*/
          break;
        }

        taosArrayPush(pRes, pDataBlock);
      }

      if (taosArrayGetSize(pRes) == 0) {
        vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId,
               pReq->epoch, pTq->pVnode->vgId, fetchOffset);
        fetchOffset++;
        rspV2.skipLogNum++;
        taosArrayDestroy(pRes);
        continue;
      }
      rspV2.rspOffset = fetchOffset;

      int32_t blockSz = taosArrayGetSize(pRes);
L
Liu Jicong 已提交
551
      int32_t dataBlockStrLen = 0;
L
Liu Jicong 已提交
552 553
      for (int32_t i = 0; i < blockSz; i++) {
        SSDataBlock* pBlock = taosArrayGet(pRes, i);
L
Liu Jicong 已提交
554
        dataBlockStrLen += sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
L
Liu Jicong 已提交
555 556
      }

L
Liu Jicong 已提交
557 558
      void* dataBlockBuf = taosMemoryMalloc(dataBlockStrLen);
      if (dataBlockBuf == NULL) {
L
Liu Jicong 已提交
559 560 561 562
        pMsg->code = -1;
        taosMemoryFree(pHead);
      }

L
Liu Jicong 已提交
563
      rspV2.blockData = dataBlockBuf;
L
Liu Jicong 已提交
564 565

      int32_t pos;
L
Liu Jicong 已提交
566
      rspV2.blockPos = taosArrayInit(blockSz, sizeof(int32_t));
L
Liu Jicong 已提交
567 568
      for (int32_t i = 0; i < blockSz; i++) {
        pos = 0;
L
Liu Jicong 已提交
569 570 571 572 573 574 575 576
        SSDataBlock*       pBlock = taosArrayGet(pRes, i);
        SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)dataBlockBuf;
        pRetrieve->useconds = 0;
        pRetrieve->precision = 0;
        pRetrieve->compressed = 0;
        pRetrieve->completed = 1;
        pRetrieve->numOfRows = htonl(pBlock->info.rows);
        blockCompressEncode(pBlock, pRetrieve->data, &pos, pBlock->info.numOfCols, false);
L
Liu Jicong 已提交
577
        taosArrayPush(rspV2.blockPos, &rspV2.dataLen);
L
Liu Jicong 已提交
578 579 580 581 582

        int32_t totLen = sizeof(SRetrieveTableRsp) + pos;
        pRetrieve->compLen = htonl(totLen);
        rspV2.dataLen += totLen;
        dataBlockBuf = POINTER_SHIFT(dataBlockBuf, totLen);
L
Liu Jicong 已提交
583
      }
L
Liu Jicong 已提交
584
      ASSERT(POINTER_DISTANCE(dataBlockBuf, rspV2.blockData) <= dataBlockStrLen);
L
Liu Jicong 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599

      int32_t msgLen = sizeof(SMqRspHead) + tEncodeSMqPollRspV2(NULL, &rspV2);
      void*   buf = rpcMallocCont(msgLen);

      ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
      ((SMqRspHead*)buf)->epoch = pReq->epoch;
      ((SMqRspHead*)buf)->consumerId = consumerId;

      void* msgBodyBuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
      tEncodeSMqPollRspV2(&msgBodyBuf, &rspV2);

      /*rsp.pBlockData = pRes;*/

      /*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/
      pMsg->pCont = buf;
L
Liu Jicong 已提交
600
      pMsg->contLen = msgLen;
L
Liu Jicong 已提交
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
      pMsg->code = 0;
      vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset,
             pHead->msgType, consumerId, pReq->epoch);
      tmsgSendRsp(pMsg);
      taosMemoryFree(pHead);
      return 0;
    } else {
      taosMemoryFree(pHead);
      fetchOffset++;
      rspV2.skipLogNum++;
    }
  }

  /*if (blockingTime != 0) {*/
  /*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/
  /*} else {*/

  rspV2.rspOffset = fetchOffset - 1;

  int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRspV2(NULL, &rspV2);
  void*   buf = rpcMallocCont(tlen);
  if (buf == NULL) {
    pMsg->code = -1;
    return -1;
  }
  ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
  ((SMqRspHead*)buf)->epoch = pReq->epoch;
  ((SMqRspHead*)buf)->consumerId = consumerId;

  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
  tEncodeSMqPollRspV2(&abuf, &rspV2);
  pMsg->pCont = buf;
  pMsg->contLen = tlen;
  pMsg->code = 0;
  tmsgSendRsp(pMsg);
  vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId,
         pReq->epoch);
  /*}*/

  return 0;
}
642

L
Liu Jicong 已提交
643 644
int32_t tqProcessRebReq(STQ* pTq, char* msg) {
  SMqMVRebReq req = {0};
L
Liu Jicong 已提交
645
  terrno = TSDB_CODE_SUCCESS;
L
Liu Jicong 已提交
646 647
  tDecodeSMqMVRebReq(msg, &req);

L
Liu Jicong 已提交
648
  vDebug("vg %d set from consumer %ld to consumer %ld", req.vgId, req.oldConsumerId, req.newConsumerId);
L
Liu Jicong 已提交
649
  STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, req.oldConsumerId);
L
Liu Jicong 已提交
650
  ASSERT(pConsumer);
L
Liu Jicong 已提交
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
  ASSERT(pConsumer->consumerId == req.oldConsumerId);
  int32_t numOfTopics = taosArrayGetSize(pConsumer->topics);
  if (numOfTopics == 1) {
    STqTopic* pTopic = taosArrayGet(pConsumer->topics, 0);
    ASSERT(strcmp(pTopic->topicName, req.topic) == 0);
    STqConsumer* pNewConsumer = tqHandleGet(pTq->tqMeta, req.newConsumerId);
    if (pNewConsumer == NULL) {
      pConsumer->consumerId = req.newConsumerId;
      tqHandleMovePut(pTq->tqMeta, req.newConsumerId, pConsumer);
      tqHandleCommit(pTq->tqMeta, req.newConsumerId);
      tqHandlePurge(pTq->tqMeta, req.oldConsumerId);
      return 0;
    } else {
      taosArrayPush(pNewConsumer->topics, pTopic);
    }
  } else {
    for (int32_t i = 0; i < numOfTopics; i++) {
      STqTopic* pTopic = taosArrayGet(pConsumer->topics, i);
      if (strcmp(pTopic->topicName, req.topic) == 0) {
        STqConsumer* pNewConsumer = tqHandleGet(pTq->tqMeta, req.newConsumerId);
        if (pNewConsumer == NULL) {
          pNewConsumer = taosMemoryCalloc(1, sizeof(STqConsumer));
          if (pNewConsumer == NULL) {
            terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
            return -1;
          }
          strcpy(pNewConsumer->cgroup, pConsumer->cgroup);
          pNewConsumer->topics = taosArrayInit(0, sizeof(STqTopic));
          pNewConsumer->consumerId = req.newConsumerId;
          pNewConsumer->epoch = 0;

          taosArrayPush(pNewConsumer->topics, pTopic);
          tqHandleMovePut(pTq->tqMeta, req.newConsumerId, pConsumer);
          tqHandleCommit(pTq->tqMeta, req.newConsumerId);
          return 0;
        }
        ASSERT(pNewConsumer->consumerId == req.newConsumerId);
        taosArrayPush(pNewConsumer->topics, pTopic);
        break;
      }
    }
    //
  }
L
Liu Jicong 已提交
694 695 696
  return 0;
}

L
Liu Jicong 已提交
697
int32_t tqProcessSetConnReq(STQ* pTq, char* msg) {
L
Liu Jicong 已提交
698
  SMqSetCVgReq req = {0};
L
Liu Jicong 已提交
699
  tDecodeSMqSetCVgReq(msg, &req);
L
Liu Jicong 已提交
700
  bool create = false;
L
Liu Jicong 已提交
701

L
Liu Jicong 已提交
702 703
  vDebug("vg %d set to consumer %ld", req.vgId, req.consumerId);
  STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, req.consumerId);
L
Liu Jicong 已提交
704
  if (pConsumer == NULL) {
L
Liu Jicong 已提交
705 706 707 708 709 710 711 712 713
    pConsumer = taosMemoryCalloc(1, sizeof(STqConsumer));
    if (pConsumer == NULL) {
      terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
      return -1;
    }
    strcpy(pConsumer->cgroup, req.cgroup);
    pConsumer->topics = taosArrayInit(0, sizeof(STqTopic));
    pConsumer->consumerId = req.consumerId;
    pConsumer->epoch = 0;
L
Liu Jicong 已提交
714
    create = true;
L
Liu Jicong 已提交
715
  }
L
Liu Jicong 已提交
716

wafwerar's avatar
wafwerar 已提交
717
  STqTopic* pTopic = taosMemoryCalloc(1, sizeof(STqTopic));
L
Liu Jicong 已提交
718
  if (pTopic == NULL) {
L
Liu Jicong 已提交
719
    taosArrayDestroy(pConsumer->topics);
wafwerar's avatar
wafwerar 已提交
720
    taosMemoryFree(pConsumer);
L
Liu Jicong 已提交
721 722
    return -1;
  }
L
Liu Jicong 已提交
723
  strcpy(pTopic->topicName, req.topicName);
L
Liu Jicong 已提交
724 725 726
  pTopic->sql = req.sql;
  pTopic->logicalPlan = req.logicalPlan;
  pTopic->physicalPlan = req.physicalPlan;
L
Liu Jicong 已提交
727
  pTopic->qmsg = req.qmsg;
L
Liu Jicong 已提交
728 729
  /*pTopic->committedOffset = -1;*/
  /*pTopic->currentOffset = -1;*/
730

L
Liu Jicong 已提交
731 732
  pTopic->buffer.firstOffset = -1;
  pTopic->buffer.lastOffset = -1;
L
Liu Jicong 已提交
733 734
  pTopic->pReadhandle = walOpenReadHandle(pTq->pWal);
  if (pTopic->pReadhandle == NULL) {
L
Liu Jicong 已提交
735
    ASSERT(false);
L
Liu Jicong 已提交
736
  }
L
Liu Jicong 已提交
737 738
  for (int i = 0; i < TQ_BUFFER_SIZE; i++) {
    pTopic->buffer.output[i].status = 0;
L
Liu Jicong 已提交
739
    STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
L
Liu Jicong 已提交
740 741 742 743
    SReadHandle    handle = {
           .reader = pReadHandle,
           .meta = pTq->pVnodeMeta,
    };
L
Liu Jicong 已提交
744
    pTopic->buffer.output[i].pReadHandle = pReadHandle;
L
Liu Jicong 已提交
745
    pTopic->buffer.output[i].task = qCreateStreamExecTaskInfo(req.qmsg, &handle);
L
fix  
Liu Jicong 已提交
746
    ASSERT(pTopic->buffer.output[i].task);
L
Liu Jicong 已提交
747
  }
L
Liu Jicong 已提交
748
  vDebug("set topic %s to consumer %ld on vg %d", pTopic->topicName, req.consumerId, pTq->pVnode->vgId);
L
Liu Jicong 已提交
749
  taosArrayPush(pConsumer->topics, pTopic);
L
Liu Jicong 已提交
750 751 752 753
  if (create) {
    tqHandleMovePut(pTq->tqMeta, req.consumerId, pConsumer);
    tqHandleCommit(pTq->tqMeta, req.consumerId);
  }
L
Liu Jicong 已提交
754
  terrno = TSDB_CODE_SUCCESS;
L
Liu Jicong 已提交
755 756
  return 0;
}
L
Liu Jicong 已提交
757

L
Liu Jicong 已提交
758 759 760 761 762
int32_t tqProcessCancelConnReq(STQ* pTq, char* msg) {
  terrno = TSDB_CODE_SUCCESS;
  return 0;
}

L
Liu Jicong 已提交
763
int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) {
L
Liu Jicong 已提交
764 765 766
  if (pTask->execType == TASK_EXEC__NONE) return 0;

  pTask->exec.numOfRunners = parallel;
L
Liu Jicong 已提交
767
  pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner));
L
Liu Jicong 已提交
768 769 770
  if (pTask->exec.runners == NULL) {
    return -1;
  }
L
Liu Jicong 已提交
771 772 773 774 775 776
  for (int32_t i = 0; i < parallel; i++) {
    STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
    SReadHandle    handle = {
           .reader = pReadHandle,
           .meta = pTq->pVnodeMeta,
    };
L
Liu Jicong 已提交
777 778
    pTask->exec.runners[i].inputHandle = pReadHandle;
    pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
L
Liu Jicong 已提交
779
    ASSERT(pTask->exec.runners[i].executor);
L
Liu Jicong 已提交
780 781 782 783
  }
  return 0;
}

L
Liu Jicong 已提交
784
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
wafwerar's avatar
wafwerar 已提交
785
  SStreamTask* pTask = taosMemoryMalloc(sizeof(SStreamTask));
L
Liu Jicong 已提交
786 787 788 789 790
  if (pTask == NULL) {
    return -1;
  }
  SCoder decoder;
  tCoderInit(&decoder, TD_LITTLE_ENDIAN, (uint8_t*)msg, msgLen, TD_DECODER);
L
Liu Jicong 已提交
791 792 793
  if (tDecodeSStreamTask(&decoder, pTask) < 0) {
    ASSERT(0);
  }
L
Liu Jicong 已提交
794 795
  tCoderClear(&decoder);

L
Liu Jicong 已提交
796
  // exec
L
Liu Jicong 已提交
797 798 799
  if (tqExpandTask(pTq, pTask, 4) < 0) {
    ASSERT(0);
  }
L
Liu Jicong 已提交
800 801

  // sink
L
Liu Jicong 已提交
802
  pTask->ahandle = pTq->pVnode;
L
Liu Jicong 已提交
803 804 805
  if (pTask->sinkType == TASK_SINK__SMA) {
    pTask->smaSink.smaHandle = smaHandleRes;
  }
L
Liu Jicong 已提交
806

L
Liu Jicong 已提交
807 808 809 810
  taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask));

  return 0;
}
L
Liu Jicong 已提交
811

L
Liu Jicong 已提交
812
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId) {
L
Liu Jicong 已提交
813 814 815 816 817 818 819
  void* pIter = NULL;

  while (1) {
    pIter = taosHashIterate(pTq->pStreamTasks, pIter);
    if (pIter == NULL) break;
    SStreamTask* pTask = (SStreamTask*)pIter;

L
Liu Jicong 已提交
820
    if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, workerId) < 0) {
L
Liu Jicong 已提交
821
      // TODO
L
Liu Jicong 已提交
822 823 824 825 826
    }
  }
  return 0;
}

L
Liu Jicong 已提交
827
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId) {
L
Liu Jicong 已提交
828
  SStreamTaskExecReq req;
L
Liu Jicong 已提交
829
  tDecodeSStreamTaskExecReq(msg, &req);
L
Liu Jicong 已提交
830

L
Liu Jicong 已提交
831 832 833
  int32_t taskId = req.taskId;
  ASSERT(taskId);

L
Liu Jicong 已提交
834
  SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
L
Liu Jicong 已提交
835
  ASSERT(pTask);
L
Liu Jicong 已提交
836

L
Liu Jicong 已提交
837
  if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, workerId) < 0) {
L
Liu Jicong 已提交
838
    // TODO
L
Liu Jicong 已提交
839
  }
L
Liu Jicong 已提交
840 841
  return 0;
}