cqMain.c 12.2 KB
Newer Older
J
draft  
jtao1735 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */

#define _DEFAULT_SOURCE
J
jtao1735 已提交
17

H
TD-354  
Hongze Cheng 已提交
18 19
#include <errno.h>
#include <pthread.h>
J
jtao1735 已提交
20 21
#include <stdlib.h>
#include <string.h>
H
TD-354  
Hongze Cheng 已提交
22 23

#include "taos.h"
24
#include "tsclient.h"
J
jtao1735 已提交
25
#include "taosdef.h"
J
draft  
jtao1735 已提交
26
#include "taosmsg.h"
B
Bomin Zhang 已提交
27
#include "ttimer.h"
H
TD-354  
Hongze Cheng 已提交
28 29
#include "tcq.h"
#include "tdataformat.h"
J
jtao1735 已提交
30
#include "tglobal.h"
J
jtao1735 已提交
31 32 33
#include "tlog.h"
#include "twal.h"

S
TD-1520  
Shengliang Guan 已提交
34 35 36 37 38
#define cFatal(...) { if (cqDebugFlag & DEBUG_FATAL) { taosPrintLog("CQ  FATAL ", 255, __VA_ARGS__); }}
#define cError(...) { if (cqDebugFlag & DEBUG_ERROR) { taosPrintLog("CQ  ERROR ", 255, __VA_ARGS__); }}
#define cWarn(...)  { if (cqDebugFlag & DEBUG_WARN)  { taosPrintLog("CQ  WARN ", 255, __VA_ARGS__); }}
#define cInfo(...)  { if (cqDebugFlag & DEBUG_INFO)  { taosPrintLog("CQ  ", 255, __VA_ARGS__); }}
#define cDebug(...) { if (cqDebugFlag & DEBUG_DEBUG) { taosPrintLog("CQ  ", cqDebugFlag, __VA_ARGS__); }}
S
Shengliang Guan 已提交
39
#define cTrace(...) { if (cqDebugFlag & DEBUG_TRACE) { taosPrintLog("CQ  ", cqDebugFlag, __VA_ARGS__); }}
J
jtao1735 已提交
40 41

typedef struct {
S
Shengliang Guan 已提交
42
  int32_t  vgId;
S
TD-2283  
Shengliang Guan 已提交
43 44
  int32_t  master;
  int32_t  num;      // number of continuous streams
J
jtao1735 已提交
45
  char     user[TSDB_USER_LEN];
46
  char     pass[TSDB_KEY_LEN];
B
Bomin Zhang 已提交
47
  char     db[TSDB_DB_NAME_LEN];
J
jtao1735 已提交
48 49 50
  FCqWrite cqWrite;
  struct SCqObj *pHead;
  void    *dbConn;
B
Bomin Zhang 已提交
51
  void    *tmrCtrl;
J
jtao1735 已提交
52
  pthread_mutex_t mutex;
D
fix bug  
dapan1121 已提交
53 54
  int32_t delete;
  int32_t cqObjNum;
J
jtao1735 已提交
55 56 57
} SCqContext;

typedef struct SCqObj {
B
Bomin Zhang 已提交
58
  tmr_h          tmrId;
D
fix bug  
dapan1121 已提交
59
  int64_t        rid;
B
Bomin Zhang 已提交
60 61
  uint64_t       uid;
  int32_t        tid;      // table ID
S
Shengliang Guan 已提交
62
  int32_t        rowSize;  // bytes of a row
63
  char *         dstTable;
H
TD-354  
Hongze Cheng 已提交
64 65 66 67 68 69
  char *         sqlStr;   // SQL string
  STSchema *     pSchema;  // pointer to schema array
  void *         pStream;
  struct SCqObj *prev;
  struct SCqObj *next;
  SCqContext *   pContext;
J
jtao1735 已提交
70 71 72
} SCqObj;

static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row); 
73
static void cqCreateStream(SCqContext *pContext, SCqObj *pObj);
J
jtao1735 已提交
74

D
fix bug  
dapan1121 已提交
75 76
int32_t    cqObjRef = -1;

D
fix bug  
dapan1121 已提交
77 78
void cqRmFromList(SCqObj *pObj) {
  //LOCK in caller
D
fix bug  
dapan1121 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91

  SCqContext *pContext = pObj->pContext;

  if (pObj->prev) {
    pObj->prev->next = pObj->next;
  } else {
    pContext->pHead = pObj->next;
  }

  if (pObj->next) {
    pObj->next->prev = pObj->prev;
  }

D
fix bug  
dapan1121 已提交
92 93 94 95 96
}

void cqFree(void *handle) {
  if (tsEnableStream == 0) {
    return;
D
fix bug  
dapan1121 已提交
97
  }
D
fix bug  
dapan1121 已提交
98 99 100
  SCqObj *pObj = handle;
  SCqContext *pContext = pObj->pContext;
  int32_t delete = 0;
D
fix bug  
dapan1121 已提交
101

D
fix bug  
dapan1121 已提交
102 103
  pthread_mutex_lock(&pContext->mutex);
  
D
fix bug  
dapan1121 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  // free the resources associated
  if (pObj->pStream) {
    taos_close_stream(pObj->pStream);
    pObj->pStream = NULL;
  } else {
    taosTmrStop(pObj->tmrId);
    pObj->tmrId = 0;
  }

  cInfo("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr); 
  tdFreeSchema(pObj->pSchema);
  free(pObj->dstTable);
  free(pObj->sqlStr);
  free(pObj);

D
fix bug  
dapan1121 已提交
119 120 121 122 123 124
  pContext->cqObjNum--;

  if (pContext->cqObjNum <= 0 && pContext->delete) {
    delete = 1;
  }

D
fix bug  
dapan1121 已提交
125 126
  pthread_mutex_unlock(&pContext->mutex);

D
fix bug  
dapan1121 已提交
127
  if (delete) {
D
fix bug  
dapan1121 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    pthread_mutex_unlock(&pContext->mutex);
    
    pthread_mutex_destroy(&pContext->mutex);
    
    taosTmrCleanUp(pContext->tmrCtrl);
    pContext->tmrCtrl = NULL;
    
    cDebug("vgId:%d, CQ is closed", pContext->vgId);
    free(pContext);
  }
}


void cqCreateRef() {
  int32_t ref = atomic_load_32(&cqObjRef);
  if (ref == -1) {
    ref = taosOpenRef(4096, cqFree);

    if (atomic_val_compare_exchange_32(&cqObjRef, -1, ref) != -1) {
      taosCloseRef(ref);
    }  
  }
}


J
jtao1735 已提交
153
void *cqOpen(void *ahandle, const SCqCfg *pCfg) {
154 155 156
  if (tsEnableStream == 0) {
    return NULL;
  }
J
jtao1735 已提交
157
  SCqContext *pContext = calloc(sizeof(SCqContext), 1);
158 159 160 161
  if (pContext == NULL) {
    terrno = TAOS_SYSTEM_ERROR(errno);
    return NULL;
  }
J
jtao1735 已提交
162

D
fix bug  
dapan1121 已提交
163 164
  cqCreateRef();

B
Bomin Zhang 已提交
165 166
  pContext->tmrCtrl = taosTmrInit(0, 0, 0, "CQ");

B
Bomin Zhang 已提交
167 168
  tstrncpy(pContext->user, pCfg->user, sizeof(pContext->user));
  tstrncpy(pContext->pass, pCfg->pass, sizeof(pContext->pass));
B
Bomin Zhang 已提交
169 170 171 172 173 174 175
  const char* db = pCfg->db;
  for (const char* p = db; *p != 0; p++) {
    if (*p == '.') {
      db = p + 1;
      break;
    }
  }
B
Bomin Zhang 已提交
176
  tstrncpy(pContext->db, db, sizeof(pContext->db));
J
jtao1735 已提交
177 178
  pContext->vgId = pCfg->vgId;
  pContext->cqWrite = pCfg->cqWrite;
179
  tscEmbedded = 1;
J
jtao1735 已提交
180 181

  pthread_mutex_init(&pContext->mutex, NULL);
J
draft  
jtao1735 已提交
182

D
fix bug  
dapan1121 已提交
183

Z
zyyang 已提交
184
  cDebug("vgId:%d, CQ is opened", pContext->vgId);
J
draft  
jtao1735 已提交
185

J
jtao1735 已提交
186 187
  return pContext;
}
J
draft  
jtao1735 已提交
188

J
jtao1735 已提交
189
void cqClose(void *handle) {
190 191 192
  if (tsEnableStream == 0) {
    return;
  }
J
jtao1735 已提交
193
  SCqContext *pContext = handle;
194
  if (handle == NULL) return;
J
draft  
jtao1735 已提交
195

D
fix bug  
dapan1121 已提交
196 197
  pContext->delete = 1;
  
J
jtao1735 已提交
198 199
  // stop all CQs
  cqStop(pContext);
J
draft  
jtao1735 已提交
200

D
fix bug  
dapan1121 已提交
201
  int64_t rid = 0;
202

D
fix bug  
dapan1121 已提交
203 204 205 206 207 208
  while (1) {
    pthread_mutex_lock(&pContext->mutex);

    SCqObj *pObj = pContext->pHead;
    if (pObj) {
      cqRmFromList(pObj);
J
jtao1735 已提交
209

D
fix bug  
dapan1121 已提交
210 211 212 213 214 215 216 217
      rid = pObj->rid;
    } else {      
      pthread_mutex_unlock(&pContext->mutex);
      break;
    }
    
    pthread_mutex_unlock(&pContext->mutex);
    
D
fix bug  
dapan1121 已提交
218
    taosRemoveRef(cqObjRef, rid);
D
fix bug  
dapan1121 已提交
219
  }
H
haojun Liao 已提交
220 221
  
  tfree(pContext);
J
draft  
jtao1735 已提交
222 223
}

J
jtao1735 已提交
224
void cqStart(void *handle) {
225 226 227
  if (tsEnableStream == 0) {
    return;
  }
J
jtao1735 已提交
228
  SCqContext *pContext = handle;
229
  if (pContext->dbConn || pContext->master) return;
J
jtao1735 已提交
230

Z
zyyang 已提交
231
  cDebug("vgId:%d, start all CQs", pContext->vgId);
J
jtao1735 已提交
232 233
  pthread_mutex_lock(&pContext->mutex);

234
  pContext->master = 1;
J
jtao1735 已提交
235 236 237

  SCqObj *pObj = pContext->pHead;
  while (pObj) {
238
    cqCreateStream(pContext, pObj);
J
jtao1735 已提交
239
    pObj = pObj->next;
J
draft  
jtao1735 已提交
240
  }
J
jtao1735 已提交
241 242

  pthread_mutex_unlock(&pContext->mutex);
J
draft  
jtao1735 已提交
243 244
}

J
jtao1735 已提交
245
void cqStop(void *handle) {
246 247 248
  if (tsEnableStream == 0) {
    return;
  }
J
jtao1735 已提交
249
  SCqContext *pContext = handle;
S
TD-2321  
Shengliang Guan 已提交
250
  cDebug("vgId:%d, stop all CQs", pContext->vgId);
251
  if (pContext->dbConn == NULL || pContext->master == 0) return;
J
draft  
jtao1735 已提交
252

J
jtao1735 已提交
253
  pthread_mutex_lock(&pContext->mutex);
J
draft  
jtao1735 已提交
254

255
  pContext->master = 0;
J
jtao1735 已提交
256 257
  SCqObj *pObj = pContext->pHead;
  while (pObj) {
J
jtao1735 已提交
258 259 260
    if (pObj->pStream) {
      taos_close_stream(pObj->pStream);
      pObj->pStream = NULL;
S
TD-1520  
Shengliang Guan 已提交
261
      cInfo("vgId:%d, id:%d CQ:%s is closed", pContext->vgId, pObj->tid, pObj->sqlStr);
B
Bomin Zhang 已提交
262 263 264
    } else {
      taosTmrStop(pObj->tmrId);
      pObj->tmrId = 0;
J
jtao1735 已提交
265
    }
J
jtao1735 已提交
266
    pObj = pObj->next;
J
draft  
jtao1735 已提交
267
  }
J
jtao1735 已提交
268 269 270 271 272

  if (pContext->dbConn) taos_close(pContext->dbConn);
  pContext->dbConn = NULL;

  pthread_mutex_unlock(&pContext->mutex);
J
draft  
jtao1735 已提交
273 274
}

275
void *cqCreate(void *handle, uint64_t uid, int32_t sid, const char* dstTable, char *sqlStr, STSchema *pSchema) {
276 277 278
  if (tsEnableStream == 0) {
    return NULL;
  }
J
jtao1735 已提交
279
  SCqContext *pContext = handle;
D
fix bug  
dapan1121 已提交
280 281
  int64_t rid = 0;
  
J
jtao1735 已提交
282
  SCqObj *pObj = calloc(sizeof(SCqObj), 1);
J
jtao1735 已提交
283
  if (pObj == NULL) return NULL;
J
draft  
jtao1735 已提交
284

B
Bomin Zhang 已提交
285
  pObj->uid = uid;
286 287 288 289 290
  pObj->tid = sid;
  if (dstTable != NULL) {
    pObj->dstTable = strdup(dstTable);
  }
  pObj->sqlStr = strdup(sqlStr);
J
draft  
jtao1735 已提交
291

H
TD-354  
Hongze Cheng 已提交
292
  pObj->pSchema = tdDupSchema(pSchema);
B
Bomin Zhang 已提交
293
  pObj->rowSize = schemaTLen(pSchema);
J
draft  
jtao1735 已提交
294

S
TD-1520  
Shengliang Guan 已提交
295
  cInfo("vgId:%d, id:%d CQ:%s is created", pContext->vgId, pObj->tid, pObj->sqlStr);
J
draft  
jtao1735 已提交
296

J
jtao1735 已提交
297
  pthread_mutex_lock(&pContext->mutex);
J
draft  
jtao1735 已提交
298

J
jtao1735 已提交
299
  pObj->next = pContext->pHead;
J
jtao1735 已提交
300
  if (pContext->pHead) pContext->pHead->prev = pObj;
J
jtao1735 已提交
301
  pContext->pHead = pObj;
J
draft  
jtao1735 已提交
302

D
fix bug  
dapan1121 已提交
303 304
  pContext->cqObjNum++;

D
fix bug  
dapan1121 已提交
305 306
  pObj->rid = taosAddRef(cqObjRef, pObj);

307
  cqCreateStream(pContext, pObj);
J
draft  
jtao1735 已提交
308

D
fix bug  
dapan1121 已提交
309 310
  rid = pObj->rid;

J
jtao1735 已提交
311
  pthread_mutex_unlock(&pContext->mutex);
J
jtao1735 已提交
312

D
fix bug  
dapan1121 已提交
313

D
fix bug  
dapan1121 已提交
314
  return (void *)rid;
J
jtao1735 已提交
315 316
}

J
jtao1735 已提交
317
void cqDrop(void *handle) {
318 319 320
  if (tsEnableStream == 0) {
    return;
  }
J
jtao1735 已提交
321

D
fix bug  
dapan1121 已提交
322 323 324 325 326 327 328
  SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)handle);
  if (pObj == NULL) {
    return;
  }
  
  SCqContext *pContext = pObj->pContext;
  
J
jtao1735 已提交
329 330
  pthread_mutex_lock(&pContext->mutex);

D
fix bug  
dapan1121 已提交
331 332
  cqRmFromList(pObj);
  
J
jtao1735 已提交
333
  // free the resources associated
B
Bomin Zhang 已提交
334 335 336 337 338 339 340
  if (pObj->pStream) {
    taos_close_stream(pObj->pStream);
    pObj->pStream = NULL;
  } else {
    taosTmrStop(pObj->tmrId);
    pObj->tmrId = 0;
  }
J
draft  
jtao1735 已提交
341

B
Bomin Zhang 已提交
342
  pthread_mutex_unlock(&pContext->mutex);
D
fix bug  
dapan1121 已提交
343

D
fix bug  
dapan1121 已提交
344 345
  taosRemoveRef(cqObjRef, (int64_t)handle);
  taosReleaseRef(cqObjRef, (int64_t)handle);
J
draft  
jtao1735 已提交
346 347
}

S
Shengliang Guan 已提交
348
static void doCreateStream(void *param, TAOS_RES *result, int32_t code) {
D
fix bug  
dapan1121 已提交
349 350 351 352 353
  SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)param);
  if (pObj == NULL) {
    return;
  }
  
354 355
  SCqContext* pContext = pObj->pContext;
  SSqlObj* pSql = (SSqlObj*)result;
356 357 358 359
  if (atomic_val_compare_exchange_ptr(&(pContext->dbConn), NULL, pSql->pTscObj) != NULL) {
    taos_close(pSql->pTscObj);
  }
  pthread_mutex_lock(&pContext->mutex);
360
  cqCreateStream(pContext, pObj);
361
  pthread_mutex_unlock(&pContext->mutex);
D
fix bug  
dapan1121 已提交
362 363

  taosReleaseRef(cqObjRef, (int64_t)param);
364 365
}

B
Bomin Zhang 已提交
366
static void cqProcessCreateTimer(void *param, void *tmrId) {
D
fix bug  
dapan1121 已提交
367 368 369 370 371
  SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)param);
  if (pObj == NULL) {
    return;
  }
  
B
Bomin Zhang 已提交
372 373
  SCqContext* pContext = pObj->pContext;

374
  if (pContext->dbConn == NULL) {
S
TD-1520  
Shengliang Guan 已提交
375
    cDebug("vgId:%d, try connect to TDengine", pContext->vgId);
376 377
    taos_connect_a(NULL, pContext->user, pContext->pass, pContext->db, 0, doCreateStream, param, NULL);
  } else {
378
    pthread_mutex_lock(&pContext->mutex);
379
    cqCreateStream(pContext, pObj);
380
    pthread_mutex_unlock(&pContext->mutex);
381
  }
D
fix bug  
dapan1121 已提交
382 383

  taosReleaseRef(cqObjRef, (int64_t)param);
B
Bomin Zhang 已提交
384
}
385

B
Bomin Zhang 已提交
386
static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
B
Bomin Zhang 已提交
387
  pObj->pContext = pContext;
B
Bomin Zhang 已提交
388 389

  if (pContext->dbConn == NULL) {
S
TD-1520  
Shengliang Guan 已提交
390
    cDebug("vgId:%d, create dbConn after 1000 ms", pContext->vgId);
D
fix bug  
dapan1121 已提交
391
    pObj->tmrId = taosTmrStart(cqProcessCreateTimer, 1000, (void *)pObj->rid, pContext->tmrCtrl);
B
Bomin Zhang 已提交
392 393 394 395
    return;
  }
  pObj->tmrId = 0;

396
  if (pObj->pStream == NULL) {
D
fix bug  
dapan1121 已提交
397
    pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, (void *)pObj->rid, NULL);
398 399

    // TODO the pObj->pStream may be released if error happens
400
    if (pObj->pStream) {
401
      tscSetStreamDestTable(pObj->pStream, pObj->dstTable);
402
      pContext->num++;
S
TD-1843  
Shengliang Guan 已提交
403
      cDebug("vgId:%d, id:%d CQ:%s is opened", pContext->vgId, pObj->tid, pObj->sqlStr);
404 405 406
    } else {
      cError("vgId:%d, id:%d CQ:%s, failed to open", pContext->vgId, pObj->tid, pObj->sqlStr);
    }
407 408 409
  }
}

J
jtao1735 已提交
410
static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
D
fix bug  
dapan1121 已提交
411 412 413 414 415
  SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)param);
  if (pObj == NULL) {
    return;
  }
  
B
Bomin Zhang 已提交
416
  if (tres == NULL && row == NULL) {
417 418
    taos_close_stream(pObj->pStream);

B
Bomin Zhang 已提交
419
    pObj->pStream = NULL;
D
fix bug  
dapan1121 已提交
420 421 422

    taosReleaseRef(cqObjRef, (int64_t)param);

B
Bomin Zhang 已提交
423 424
    return;
  }
425

J
jtao1735 已提交
426
  SCqContext *pContext = pObj->pContext;
B
Bomin Zhang 已提交
427
  STSchema   *pSchema = pObj->pSchema;
D
fix bug  
dapan1121 已提交
428 429 430 431 432
  if (pObj->pStream == NULL) {    
    taosReleaseRef(cqObjRef, (int64_t)param);
    return;
  }
  
S
TD-1520  
Shengliang Guan 已提交
433
  cDebug("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr);
J
jtao1735 已提交
434

S
Shengliang Guan 已提交
435
  int32_t size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + pObj->rowSize;
J
jtao1735 已提交
436 437 438
  char *buffer = calloc(size, 1);

  SWalHead   *pHead = (SWalHead *)buffer;
B
Bomin Zhang 已提交
439 440
  SSubmitMsg *pMsg = (SSubmitMsg *) (buffer + sizeof(SWalHead));
  SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg));
J
draft  
jtao1735 已提交
441

B
Bomin Zhang 已提交
442
  SDataRow trow = (SDataRow)pBlk->data;
443
  tdInitDataRow(trow, pSchema);
J
jtao1735 已提交
444

B
Bomin Zhang 已提交
445
  for (int32_t i = 0; i < pSchema->numOfCols; i++) {
446
    STColumn *c = pSchema->columns + i;
447 448 449
    void* val = row[i];
    if (val == NULL) {
      val = getNullValue(c->type);
B
Bomin Zhang 已提交
450
    } else if (c->type == TSDB_DATA_TYPE_BINARY) {
451
      val = ((char*)val) - sizeof(VarDataLenT);
B
Bomin Zhang 已提交
452 453
    } else if (c->type == TSDB_DATA_TYPE_NCHAR) {
      char buf[TSDB_MAX_NCHAR_LEN];
454
      int32_t len = taos_fetch_lengths(tres)[i];
B
Bomin Zhang 已提交
455
      taosMbsToUcs4(val, len, buf, sizeof(buf), &len);
S
TD-1207  
Shengliang Guan 已提交
456
      memcpy((char *)val + sizeof(VarDataLenT), buf, len);
B
Bomin Zhang 已提交
457
      varDataLen(val) = len;
458 459
    }
    tdAppendColVal(trow, val, c->type, c->bytes, c->offset);
B
Bomin Zhang 已提交
460
  }
H
Haojun Liao 已提交
461 462
  pBlk->dataLen = htonl(dataRowLen(trow));
  pBlk->schemaLen = 0;
B
Bomin Zhang 已提交
463 464 465 466 467 468 469

  pBlk->uid = htobe64(pObj->uid);
  pBlk->tid = htonl(pObj->tid);
  pBlk->numOfRows = htons(1);
  pBlk->sversion = htonl(pSchema->version);
  pBlk->padding = 0;

B
Bomin Zhang 已提交
470 471
  pHead->len = sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + dataRowLen(trow);

B
Bomin Zhang 已提交
472
  pMsg->header.vgId = htonl(pContext->vgId);
B
Bomin Zhang 已提交
473
  pMsg->header.contLen = htonl(pHead->len);
B
Bomin Zhang 已提交
474 475 476 477 478
  pMsg->length = pMsg->header.contLen;
  pMsg->numOfBlocks = htonl(1);

  pHead->msgType = TSDB_MSG_TYPE_SUBMIT;
  pHead->version = 0;
J
jtao1735 已提交
479 480

  // write into vnode write queue
S
TD-2283  
Shengliang Guan 已提交
481
  pContext->cqWrite(pContext->vgId, pHead, TAOS_QTYPE_CQ, NULL);
B
Bomin Zhang 已提交
482
  free(buffer);
D
fix bug  
dapan1121 已提交
483 484
  
  taosReleaseRef(cqObjRef, (int64_t)param);
J
jtao1735 已提交
485 486
}