tq.c 13.3 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
 */

L
Liu Jicong 已提交
16
#include "tcompare.h"
L
Liu Jicong 已提交
17
#include "tqInt.h"
L
Liu Jicong 已提交
18
#include "tqMetaStore.h"
S
Shengliang Guan 已提交
19

L
Liu Jicong 已提交
20
int32_t tqInit() { return tqPushMgrInit(); }
L
Liu Jicong 已提交
21

L
Liu Jicong 已提交
22
void tqCleanUp() { tqPushMgrCleanUp(); }
L
Liu Jicong 已提交
23

L
Liu Jicong 已提交
24
STQ* tqOpen(const char* path, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac) {
L
Liu Jicong 已提交
25
  STQ* pTq = malloc(sizeof(STQ));
L
Liu Jicong 已提交
26
  if (pTq == NULL) {
L
Liu Jicong 已提交
27
    terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
L
Liu Jicong 已提交
28 29
    return NULL;
  }
H
Hongze Cheng 已提交
30
  pTq->path = strdup(path);
L
Liu Jicong 已提交
31
  pTq->tqConfig = tqConfig;
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, free, 0);
L
Liu Jicong 已提交
43
  if (pTq->tqMeta == NULL) {
L
Liu Jicong 已提交
44
    free(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 52 53 54 55 56 57
  pTq->tqPushMgr = tqPushMgrOpen();
  if (pTq->tqPushMgr == NULL) {
    // free store
    free(pTq);
    return NULL;
  }

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

L
Liu Jicong 已提交
60 61
  return pTq;
}
L
Liu Jicong 已提交
62

L
Liu Jicong 已提交
63
void tqClose(STQ* pTq) {
H
Hongze Cheng 已提交
64
  if (pTq) {
H
Hongze Cheng 已提交
65
    tfree(pTq->path);
H
Hongze Cheng 已提交
66 67
    free(pTq);
  }
L
Liu Jicong 已提交
68 69
  // TODO
}
L
Liu Jicong 已提交
70

L
Liu Jicong 已提交
71
int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) {
L
Liu Jicong 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  if (msgType != TDMT_VND_SUBMIT) return 0;
  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
      STqStreamToken* token = malloc(sizeof(STqStreamToken));
      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 已提交
92 93
  // iterate hash
  // process all msg
L
fix  
Liu Jicong 已提交
94 95
  // if waiting
  // memcpy and send msg to fetch thread
L
Liu Jicong 已提交
96 97 98 99
  // TODO: add reference
  // if handle waiting, launch query and response to consumer
  //
  // if no waiting handle, return
L
Liu Jicong 已提交
100 101 102
  return 0;
}

L
Liu Jicong 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
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 已提交
127 128 129
  /*tlen += taosEncodeFixedI64(buf, pTopic->persistedOffset);*/
  /*tlen += taosEncodeFixedI64(buf, pTopic->committedOffset);*/
  /*tlen += taosEncodeFixedI64(buf, pTopic->currentOffset);*/
L
Liu Jicong 已提交
130 131 132 133 134 135 136 137 138
  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 已提交
139 140 141
  /*buf = taosDecodeFixedI64(buf, &pTopic->persistedOffset);*/
  /*buf = taosDecodeFixedI64(buf, &pTopic->committedOffset);*/
  /*buf = taosDecodeFixedI64(buf, &pTopic->currentOffset);*/
L
Liu Jicong 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
  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);
  tlen += taosEncodeFixedI64(buf, pConsumer->epoch);
  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 已提交
159 160
}

L
Liu Jicong 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
static FORCE_INLINE const void* tDecodeSTqConsumer(const void* buf, STqConsumer* pConsumer) {
  int32_t sz;

  buf = taosDecodeFixedI64(buf, &pConsumer->consumerId);
  buf = taosDecodeFixedI64(buf, &pConsumer->epoch);
  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 已提交
181
  if (sz > (*ppHead)->ssize) {
L
Liu Jicong 已提交
182
    void* tmpPtr = realloc(*ppHead, sizeof(STqSerializedHead) + sz);
L
Liu Jicong 已提交
183 184
    if (tmpPtr == NULL) {
      free(*ppHead);
L
Liu Jicong 已提交
185
      terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
L
Liu Jicong 已提交
186 187 188 189 190 191 192
      return -1;
    }
    *ppHead = tmpPtr;
    (*ppHead)->ssize = sz;
  }

  void* ptr = (*ppHead)->content;
L
Liu Jicong 已提交
193 194
  void* abuf = ptr;
  tEncodeSTqConsumer(&abuf, pConsumer);
L
Liu Jicong 已提交
195

L
Liu Jicong 已提交
196 197 198
  return 0;
}

L
Liu Jicong 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211
int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsumer** ppConsumer) {
  const void* str = pHead->content;
  *ppConsumer = calloc(1, sizeof(STqConsumer));
  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 已提交
212
  for (int32_t i = 0; i < sz; i++) {
L
Liu Jicong 已提交
213 214 215 216 217
    STqTopic* pTopic = taosArrayGet(pConsumer->topics, i);
    pTopic->pReadhandle = walOpenReadHandle(pTq->pWal);
    if (pTopic->pReadhandle == NULL) {
      ASSERT(false);
    }
L
Liu Jicong 已提交
218 219
    for (int j = 0; j < TQ_BUFFER_SIZE; j++) {
      pTopic->buffer.output[j].status = 0;
L
Liu Jicong 已提交
220
      STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
L
Liu Jicong 已提交
221 222 223 224
      SReadHandle    handle = {
             .reader = pReadHandle,
             .meta = pTq->pVnodeMeta,
      };
L
Liu Jicong 已提交
225 226
      pTopic->buffer.output[j].pReadHandle = pReadHandle;
      pTopic->buffer.output[j].task = qCreateStreamExecTaskInfo(pTopic->qmsg, &handle);
L
Liu Jicong 已提交
227
    }
L
Liu Jicong 已提交
228
  }
L
Liu Jicong 已提交
229 230

  return 0;
L
Liu Jicong 已提交
231 232
}

L
Liu Jicong 已提交
233 234 235 236 237
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
  SMqPollReq* pReq = pMsg->pCont;
  int64_t     consumerId = pReq->consumerId;
  int64_t     fetchOffset;
  int64_t     blockingTime = pReq->blockingTime;
238

L
Liu Jicong 已提交
239 240 241 242 243 244 245 246
  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;
  }

L
Liu Jicong 已提交
247
  SMqPollRsp rsp = {
L
Liu Jicong 已提交
248 249 250 251
      .consumerId = consumerId,
      .numOfTopics = 0,
      .pBlockData = NULL,
  };
252 253 254 255 256 257 258 259 260

  STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId);
  if (pConsumer == NULL) {
    pMsg->pCont = NULL;
    pMsg->contLen = 0;
    pMsg->code = -1;
    rpcSendResponse(pMsg);
    return 0;
  }
L
Liu Jicong 已提交
261

262 263 264 265 266 267
  int sz = taosArrayGetSize(pConsumer->topics);
  ASSERT(sz == 1);
  STqTopic* pTopic = taosArrayGet(pConsumer->topics, 0);
  ASSERT(strcmp(pTopic->topicName, pReq->topic) == 0);
  ASSERT(pConsumer->consumerId == consumerId);

L
Liu Jicong 已提交
268
  rsp.reqOffset = pReq->currentOffset;
269 270 271 272
  rsp.skipLogNum = 0;

  SWalHead* pHead;
  while (1) {
L
Liu Jicong 已提交
273
    /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/
274
    if (walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {
L
Liu Jicong 已提交
275 276
      // TODO: no more log, set timer to wait blocking time
      // if data inserted during waiting, launch query and
L
Liu Jicong 已提交
277
      // response to user
278 279
      break;
    }
L
Liu Jicong 已提交
280
    int8_t pos = fetchOffset % TQ_BUFFER_SIZE;
281 282
    pHead = pTopic->pReadhandle->pHead;
    if (pHead->head.msgType == TDMT_VND_SUBMIT) {
S
Shengliang Guan 已提交
283
      SSubmitReq* pCont = (SSubmitReq*)&pHead->head.body;
284 285 286 287 288 289 290 291 292 293 294
      qTaskInfo_t task = pTopic->buffer.output[pos].task;
      qSetStreamInput(task, pCont);
      SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
      while (1) {
        SSDataBlock* pDataBlock;
        uint64_t     ts;
        if (qExecTask(task, &pDataBlock, &ts) < 0) {
          ASSERT(false);
        }
        if (pDataBlock == NULL) {
          fetchOffset++;
L
Liu Jicong 已提交
295
          pos = fetchOffset % TQ_BUFFER_SIZE;
296 297 298 299 300 301 302 303 304 305 306
          rsp.skipLogNum++;
          break;
        }

        taosArrayPush(pRes, pDataBlock);
        rsp.schemas = pTopic->buffer.output[pos].pReadHandle->pSchemaWrapper;
        rsp.rspOffset = fetchOffset;

        rsp.numOfTopics = 1;
        rsp.pBlockData = pRes;

L
Liu Jicong 已提交
307
        int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
308 309 310 311 312
        void*   buf = rpcMallocCont(tlen);
        if (buf == NULL) {
          pMsg->code = -1;
          return -1;
        }
L
fix  
Liu Jicong 已提交
313 314
        ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
        ((SMqRspHead*)buf)->epoch = pReq->epoch;
315

L
fix  
Liu Jicong 已提交
316
        void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
L
Liu Jicong 已提交
317
        tEncodeSMqPollRsp(&abuf, &rsp);
318 319 320 321 322 323 324 325 326 327 328 329 330
        taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);
        pMsg->pCont = buf;
        pMsg->contLen = tlen;
        pMsg->code = 0;
        rpcSendResponse(pMsg);
        return 0;
      }
    } else {
      fetchOffset++;
      rsp.skipLogNum++;
    }
  }

L
Liu Jicong 已提交
331 332 333 334
  /*if (blockingTime != 0) {*/
  /*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/
  /*} else {*/
  int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
335 336 337 338 339
  void*   buf = rpcMallocCont(tlen);
  if (buf == NULL) {
    pMsg->code = -1;
    return -1;
  }
L
Liu Jicong 已提交
340 341
  ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
  ((SMqRspHead*)buf)->epoch = pReq->epoch;
342

L
Liu Jicong 已提交
343
  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
L
Liu Jicong 已提交
344
  tEncodeSMqPollRsp(&abuf, &rsp);
345 346 347 348 349
  rsp.pBlockData = NULL;
  pMsg->pCont = buf;
  pMsg->contLen = tlen;
  pMsg->code = 0;
  rpcSendResponse(pMsg);
L
Liu Jicong 已提交
350 351
  /*}*/

352 353 354
  return 0;
}

L
Liu Jicong 已提交
355 356 357 358
int32_t tqProcessRebReq(STQ* pTq, char* msg) {
  SMqMVRebReq req = {0};
  tDecodeSMqMVRebReq(msg, &req);

L
Liu Jicong 已提交
359
  STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, req.oldConsumerId);
L
Liu Jicong 已提交
360
  ASSERT(pConsumer);
L
Liu Jicong 已提交
361
  pConsumer->consumerId = req.newConsumerId;
L
Liu Jicong 已提交
362 363 364 365 366 367 368
  tqHandleMovePut(pTq->tqMeta, req.newConsumerId, pConsumer);
  tqHandleCommit(pTq->tqMeta, req.newConsumerId);
  tqHandlePurge(pTq->tqMeta, req.oldConsumerId);
  terrno = TSDB_CODE_SUCCESS;
  return 0;
}

L
Liu Jicong 已提交
369
int32_t tqProcessSetConnReq(STQ* pTq, char* msg) {
L
Liu Jicong 已提交
370
  SMqSetCVgReq req = {0};
L
Liu Jicong 已提交
371
  tDecodeSMqSetCVgReq(msg, &req);
L
Liu Jicong 已提交
372

373
  /*printf("vg %d set to consumer from %ld to %ld\n", req.vgId, req.oldConsumerId, req.newConsumerId);*/
L
Liu Jicong 已提交
374
  STqConsumer* pConsumer = calloc(1, sizeof(STqConsumer));
L
Liu Jicong 已提交
375
  if (pConsumer == NULL) {
L
Liu Jicong 已提交
376 377
    terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
    return -1;
L
Liu Jicong 已提交
378
  }
L
Liu Jicong 已提交
379

L
Liu Jicong 已提交
380
  strcpy(pConsumer->cgroup, req.cgroup);
L
Liu Jicong 已提交
381
  pConsumer->topics = taosArrayInit(0, sizeof(STqTopic));
L
Liu Jicong 已提交
382
  pConsumer->consumerId = req.consumerId;
L
Liu Jicong 已提交
383
  pConsumer->epoch = 0;
L
Liu Jicong 已提交
384

L
Liu Jicong 已提交
385
  STqTopic* pTopic = calloc(1, sizeof(STqTopic));
L
Liu Jicong 已提交
386
  if (pTopic == NULL) {
L
Liu Jicong 已提交
387
    taosArrayDestroy(pConsumer->topics);
L
Liu Jicong 已提交
388 389 390
    free(pConsumer);
    return -1;
  }
L
Liu Jicong 已提交
391
  strcpy(pTopic->topicName, req.topicName);
L
Liu Jicong 已提交
392 393 394
  pTopic->sql = req.sql;
  pTopic->logicalPlan = req.logicalPlan;
  pTopic->physicalPlan = req.physicalPlan;
L
Liu Jicong 已提交
395
  pTopic->qmsg = req.qmsg;
L
Liu Jicong 已提交
396 397
  /*pTopic->committedOffset = -1;*/
  /*pTopic->currentOffset = -1;*/
398

L
Liu Jicong 已提交
399 400
  pTopic->buffer.firstOffset = -1;
  pTopic->buffer.lastOffset = -1;
L
Liu Jicong 已提交
401 402
  pTopic->pReadhandle = walOpenReadHandle(pTq->pWal);
  if (pTopic->pReadhandle == NULL) {
L
Liu Jicong 已提交
403
    ASSERT(false);
L
Liu Jicong 已提交
404
  }
L
Liu Jicong 已提交
405 406
  for (int i = 0; i < TQ_BUFFER_SIZE; i++) {
    pTopic->buffer.output[i].status = 0;
L
Liu Jicong 已提交
407
    STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
L
Liu Jicong 已提交
408 409 410 411
    SReadHandle    handle = {
           .reader = pReadHandle,
           .meta = pTq->pVnodeMeta,
    };
L
Liu Jicong 已提交
412
    pTopic->buffer.output[i].pReadHandle = pReadHandle;
L
Liu Jicong 已提交
413
    pTopic->buffer.output[i].task = qCreateStreamExecTaskInfo(req.qmsg, &handle);
L
Liu Jicong 已提交
414
  }
L
Liu Jicong 已提交
415
  taosArrayPush(pConsumer->topics, pTopic);
L
Liu Jicong 已提交
416 417
  tqHandleMovePut(pTq->tqMeta, req.consumerId, pConsumer);
  tqHandleCommit(pTq->tqMeta, req.consumerId);
L
Liu Jicong 已提交
418
  terrno = TSDB_CODE_SUCCESS;
L
Liu Jicong 已提交
419 420
  return 0;
}
L
Liu Jicong 已提交
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435

int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
  SStreamTask* pTask = malloc(sizeof(SStreamTask));
  if (pTask == NULL) {
    return -1;
  }
  SCoder decoder;
  tCoderInit(&decoder, TD_LITTLE_ENDIAN, (uint8_t*)msg, msgLen, TD_DECODER);
  tDecodeSStreamTask(&decoder, pTask);
  tCoderClear(&decoder);

  taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask));

  return 0;
}