smaTimeRange.c 15.5 KB
Newer Older
C
Cary Xu 已提交
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/>.
 */

#include "sma.h"
L
Liu Jicong 已提交
17
#include "tq.h"
C
Cary Xu 已提交
18 19 20 21 22 23
#include "tsdb.h"

#define SMA_STORAGE_MINUTES_MAX  86400
#define SMA_STORAGE_MINUTES_DAY  1440
#define SMA_STORAGE_SPLIT_FACTOR 14400  // least records in tsma file

24 25 26 27
static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg);
static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg);
static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days);

C
Cary Xu 已提交
28 29 30 31
int32_t tdProcessTSmaInsert(SSma *pSma, int64_t indexUid, const char *msg) {
  int32_t code = TSDB_CODE_SUCCESS;

  if ((code = tdProcessTSmaInsertImpl(pSma, indexUid, msg)) < 0) {
K
kailixu 已提交
32
    smaError("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
C
Cary Xu 已提交
33
  }
K
kailixu 已提交
34

C
Cary Xu 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  return code;
}

int32_t tdProcessTSmaCreate(SSma *pSma, int64_t version, const char *msg) {
  int32_t code = TSDB_CODE_SUCCESS;

  if ((code = tdProcessTSmaCreateImpl(pSma, version, msg)) < 0) {
    smaWarn("vgId:%d, create tsma failed since %s", SMA_VID(pSma), tstrerror(terrno));
  }
  return code;
}

int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) {
  int32_t code = TSDB_CODE_SUCCESS;
  if ((code = tdProcessTSmaGetDaysImpl(pCfg, pCont, contLen, days)) < 0) {
    smaWarn("vgId:%d, get tsma days failed since %s", pCfg->vgId, tstrerror(terrno));
  }
  smaDebug("vgId:%d, get tsma days %d", pCfg->vgId, *days);
  return code;
}

C
Cary Xu 已提交
56 57 58 59 60 61 62 63 64
/**
 * @brief Judge the tsma file split days
 *
 * @param pCfg
 * @param pCont
 * @param contLen
 * @param days unit is minute
 * @return int32_t
 */
65
static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) {
C
Cary Xu 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  SDecoder coder = {0};
  tDecoderInit(&coder, pCont, contLen);

  STSma tsma = {0};
  if (tDecodeSVCreateTSmaReq(&coder, &tsma) < 0) {
    terrno = TSDB_CODE_MSG_DECODE_ERROR;
    goto _err;
  }
  STsdbCfg *pTsdbCfg = &pCfg->tsdbCfg;
  int64_t   sInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_SECOND);
  if (sInterval <= 0) {
    *days = pTsdbCfg->days;
    return 0;
  }
  int64_t records = pTsdbCfg->days * 60 / sInterval;
  if (records >= SMA_STORAGE_SPLIT_FACTOR) {
    *days = pTsdbCfg->days;
  } else {
    int64_t mInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE);
    int64_t daysPerFile = mInterval * SMA_STORAGE_MINUTES_DAY * 2;

    if (daysPerFile > SMA_STORAGE_MINUTES_MAX) {
      *days = SMA_STORAGE_MINUTES_MAX;
    } else {
      *days = (int32_t)daysPerFile;
    }

    if (*days < pTsdbCfg->days) {
      *days = pTsdbCfg->days;
    }
  }
  tDecoderClear(&coder);
  return 0;
_err:
  tDecoderClear(&coder);
  return -1;
}

/**
 * @brief create tsma meta and result stable
 *
 * @param pSma
 * @param version
 * @param pMsg
 * @return int32_t
 */
112
static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg) {
K
kailixu 已提交
113 114 115
  int32_t        code = 0;
  int32_t        lino = 0;
  SSmaCfg       *pCfg = (SSmaCfg *)pMsg;
K
kailixu 已提交
116
  SName          stbFullName = {0};
K
kailixu 已提交
117
  SVCreateStbReq pReq = {0};
C
Cary Xu 已提交
118 119 120 121

  if (TD_VID(pSma->pVnode) == pCfg->dstVgId) {
    // create tsma meta in dstVgId
    if (metaCreateTSma(SMA_META(pSma), version, pCfg) < 0) {
K
kailixu 已提交
122 123
      code = terrno;
      TSDB_CHECK_CODE(code, lino, _exit);
C
Cary Xu 已提交
124 125 126
    }

    // create stable to save tsma result in dstVgId
C
Cary Xu 已提交
127
    tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
128
    pReq.name = (char *)tNameGetTableName(&stbFullName);
C
Cary Xu 已提交
129 130 131 132 133
    pReq.suid = pCfg->dstTbUid;
    pReq.schemaRow = pCfg->schemaRow;
    pReq.schemaTag = pCfg->schemaTag;

    if (metaCreateSTable(SMA_META(pSma), version, &pReq) < 0) {
K
kailixu 已提交
134 135
      code = terrno;
      TSDB_CHECK_CODE(code, lino, _exit);
C
Cary Xu 已提交
136
    }
K
kailixu 已提交
137 138 139 140
  } else {
    code = terrno = TSDB_CODE_TSMA_INVALID_STAT;
    TSDB_CHECK_CODE(code, lino, _exit);
  }
C
Cary Xu 已提交
141

K
kailixu 已提交
142 143 144 145 146 147 148
_exit:
  if (code) {
    smaError("vgId:%d, failed at line %d to create sma index %s %" PRIi64 " on stb:%" PRIi64 ", dstSuid:%" PRIi64
             " dstTb:%s dstVg:%d",
             SMA_VID(pSma), lino, pCfg->indexName, pCfg->indexUid, pCfg->tableUid, pCfg->dstTbUid, pReq.name,
             pCfg->dstVgId);
  } else {
C
Cary Xu 已提交
149 150 151
    smaDebug("vgId:%d, success to create sma index %s %" PRIi64 " on stb:%" PRIi64 ", dstSuid:%" PRIi64
             " dstTb:%s dstVg:%d",
             SMA_VID(pSma), pCfg->indexName, pCfg->indexUid, pCfg->tableUid, pCfg->dstTbUid, pReq.name, pCfg->dstVgId);
C
Cary Xu 已提交
152 153
  }

K
kailixu 已提交
154
  return code;
C
Cary Xu 已提交
155 156
}

L
Liu Jicong 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *pTSchema,
                         SSchemaWrapper *pTagSchemaWrapper, bool createTb, int64_t suid, const char *stbFullName,
                         SBatchDeleteReq *pDeleteReq, void **ppData, int32_t *pLen) {
  void        *pBuf = NULL;
  int32_t      len = 0;
  SSubmitReq2 *pReq = NULL;
  SArray      *tagArray = NULL;
  SArray      *createTbArray = NULL;
  SArray      *pVals = NULL;

  int32_t sz = taosArrayGetSize(pBlocks);

  if (!(tagArray = taosArrayInit(1, sizeof(STagVal)))) {
    goto _end;
  }

  if (!(createTbArray = taosArrayInit(sz, POINTER_BYTES))) {
    goto _end;
  }

  if (!(pReq = taosMemoryCalloc(1, sizeof(SSubmitReq2)))) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    goto _end;
  }

  if (!(pReq->aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
    goto _end;
  }

  // create table req
  if (createTb) {
    for (int32_t i = 0; i < sz; ++i) {
      SSDataBlock   *pDataBlock = taosArrayGet(pBlocks, i);
      SVCreateTbReq *pCreateTbReq = NULL;
      if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
        taosArrayPush(createTbArray, &pCreateTbReq);
        continue;
      }

      if (!(pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateStbReq)))) {
        goto _end;
      };

      // don't move to the end of loop as to destroy in the end of func when error occur
      taosArrayPush(createTbArray, &pCreateTbReq);

      // set const
      pCreateTbReq->flags = 0;
      pCreateTbReq->type = TSDB_CHILD_TABLE;
      pCreateTbReq->ctb.suid = suid;

      // set super table name
      SName name = {0};
      tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
211
      pCreateTbReq->ctb.stbName = taosStrdup((char *)tNameGetTableName(&name));  // taosStrdup(stbFullName);
L
Liu Jicong 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

      // set tag content
      taosArrayClear(tagArray);
      STagVal tagVal = {
          .cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1,
          .type = TSDB_DATA_TYPE_UBIGINT,
          .i64 = (int64_t)pDataBlock->info.id.groupId,
      };
      taosArrayPush(tagArray, &tagVal);
      pCreateTbReq->ctb.tagNum = taosArrayGetSize(tagArray);

      STag *pTag = NULL;
      tTagNew(tagArray, 1, false, &pTag);
      if (pTag == NULL) {
        terrno = TSDB_CODE_OUT_OF_MEMORY;
        goto _end;
      }
      pCreateTbReq->ctb.pTag = (uint8_t *)pTag;

      // set tag name
      SArray *tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
      char    tagNameStr[TSDB_COL_NAME_LEN] = {0};
      strcpy(tagNameStr, "group_id");
      taosArrayPush(tagName, tagNameStr);
      pCreateTbReq->ctb.tagName = tagName;

      // set table name
      if (pDataBlock->info.parTbName[0]) {
240
        pCreateTbReq->name = taosStrdup(pDataBlock->info.parTbName);
L
Liu Jicong 已提交
241 242 243 244 245 246 247 248 249 250 251 252
      } else {
        pCreateTbReq->name = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
      }
    }
  }

  // SSubmitTbData req
  for (int32_t i = 0; i < sz; ++i) {
    SSDataBlock *pDataBlock = taosArrayGet(pBlocks, i);
    if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
      pDeleteReq->suid = suid;
      pDeleteReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
H
Haojun Liao 已提交
253
      tqBuildDeleteReq(stbFullName, pDataBlock, pDeleteReq, "");
L
Liu Jicong 已提交
254 255 256 257 258
      continue;
    }

    int32_t rows = pDataBlock->info.rows;

K
kailixu 已提交
259
    SSubmitTbData tbData = {0};
L
Liu Jicong 已提交
260

K
kailixu 已提交
261
    if (!(tbData.aRowP = taosArrayInit(rows, sizeof(SRow *)))) {
L
Liu Jicong 已提交
262 263
      goto _end;
    }
K
kailixu 已提交
264 265 266
    tbData.suid = suid;
    tbData.uid = 0;  // uid is assigned by vnode
    tbData.sver = pTSchema->version;
L
Liu Jicong 已提交
267 268

    if (createTb) {
K
kailixu 已提交
269 270
      tbData.pCreateTbReq = taosArrayGetP(createTbArray, i);
      if (tbData.pCreateTbReq) tbData.flags = SUBMIT_REQ_AUTO_CREATE_TABLE;
L
Liu Jicong 已提交
271 272 273
    }

    if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) {
K
kailixu 已提交
274
      taosArrayDestroy(tbData.aRowP);
L
Liu Jicong 已提交
275 276 277
      goto _end;
    }

L
Liu Jicong 已提交
278
    for (int32_t j = 0; j < rows; ++j) {
L
Liu Jicong 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
      taosArrayClear(pVals);
      for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
        const STColumn  *pCol = &pTSchema->columns[k];
        SColumnInfoData *pColData = taosArrayGet(pDataBlock->pDataBlock, k);
        if (colDataIsNull_s(pColData, j)) {
          SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
          taosArrayPush(pVals, &cv);
        } else {
          void *data = colDataGetData(pColData, j);
          if (IS_STR_DATA_TYPE(pCol->type)) {
            SValue  sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)};  // address copy, no value
            SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
            taosArrayPush(pVals, &cv);
          } else {
            SValue sv;
            memcpy(&sv.val, data, tDataTypes[pCol->type].bytes);
            SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
            taosArrayPush(pVals, &cv);
          }
        }
      }
      SRow *pRow = NULL;
      if ((terrno = tRowBuild(pVals, (STSchema *)pTSchema, &pRow)) < 0) {
302
        tDestroySubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
L
Liu Jicong 已提交
303 304
        goto _end;
      }
K
kailixu 已提交
305
      taosArrayPush(tbData.aRowP, &pRow);
L
Liu Jicong 已提交
306 307
    }

K
kailixu 已提交
308
    taosArrayPush(pReq->aSubmitTbData, &tbData);
L
Liu Jicong 已提交
309 310 311
  }

  // encode
312
  tEncodeSize(tEncodeSubmitReq, pReq, len, terrno);
L
Liu Jicong 已提交
313 314
  if (TSDB_CODE_SUCCESS == terrno) {
    SEncoder encoder;
315
    len += sizeof(SSubmitReq2Msg);
L
Liu Jicong 已提交
316 317 318 319
    pBuf = rpcMallocCont(len);
    if (NULL == pBuf) {
      goto _end;
    }
320 321 322 323
    ((SSubmitReq2Msg *)pBuf)->header.vgId = TD_VID(pVnode);
    ((SSubmitReq2Msg *)pBuf)->header.contLen = htonl(len);
    ((SSubmitReq2Msg *)pBuf)->version = htobe64(1);
    tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
324
    if (tEncodeSubmitReq(&encoder, pReq) < 0) {
L
Liu Jicong 已提交
325
      terrno = TSDB_CODE_OUT_OF_MEMORY;
L
Liu Jicong 已提交
326
      /*vError("failed to encode submit req since %s", terrstr());*/
L
Liu Jicong 已提交
327 328 329 330
    }
    tEncoderClear(&encoder);
  }
_end:
K
kailixu 已提交
331
  taosArrayDestroy(createTbArray);
L
Liu Jicong 已提交
332 333
  taosArrayDestroy(tagArray);
  taosArrayDestroy(pVals);
K
kailixu 已提交
334
  if (pReq) {
335
    tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
K
kailixu 已提交
336 337
    taosMemoryFree(pReq);
  }
L
Liu Jicong 已提交
338 339 340 341 342 343 344 345 346 347 348

  if (terrno != 0) {
    rpcFreeCont(pBuf);
    taosArrayDestroy(pDeleteReq->deleteReqs);
    return TSDB_CODE_FAILED;
  }
  if (ppData) *ppData = pBuf;
  if (pLen) *pLen = len;
  return TSDB_CODE_SUCCESS;
}

K
kailixu 已提交
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq *pDelReq) {
  int32_t code = 0;
  int32_t lino = 0;

  if (taosArrayGetSize(pDelReq->deleteReqs) > 0) {
    int32_t len = 0;
    tEncodeSize(tEncodeSBatchDeleteReq, pDelReq, len, code);
    TSDB_CHECK_CODE(code, lino, _exit);

    void *pBuf = rpcMallocCont(len + sizeof(SMsgHead));
    if (!pBuf) {
      code = terrno;
      TSDB_CHECK_CODE(code, lino, _exit);
    }

    SEncoder encoder;
    tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len);
    tEncodeSBatchDeleteReq(&encoder, pDelReq);
    tEncoderClear(&encoder);

    ((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode);

    SRpcMsg delMsg = {.msgType = TDMT_VND_BATCH_DEL, .pCont = pBuf, .contLen = len + sizeof(SMsgHead)};
    code = tmsgPutToQueue(&pSma->pVnode->msgCb, WRITE_QUEUE, &delMsg);
    TSDB_CHECK_CODE(code, lino, _exit);
  }

_exit:
  taosArrayDestroy(pDelReq->deleteReqs);
  if (code) {
K
kailixu 已提交
379 380
    smaError("vgId:%d, failed at line %d to process delete req for smaIndex %" PRIi64 " since %s", SMA_VID(pSma), lino,
             indexUid, tstrerror(code));
K
kailixu 已提交
381 382 383 384 385
  }

  return code;
}

C
Cary Xu 已提交
386 387 388 389 390 391 392
/**
 * @brief Insert/Update Time-range-wise SMA data.
 *
 * @param pSma
 * @param msg
 * @return int32_t
 */
393
static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
C
Cary Xu 已提交
394 395 396 397
  const SArray *pDataBlocks = (const SArray *)msg;
  if (!pDataBlocks) {
    terrno = TSDB_CODE_TSMA_INVALID_PTR;
    smaWarn("vgId:%d, insert tsma data failed since pDataBlocks is NULL", SMA_VID(pSma));
C
Cary Xu 已提交
398
    return TSDB_CODE_FAILED;
C
Cary Xu 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411
  }

  if (taosArrayGetSize(pDataBlocks) <= 0) {
    terrno = TSDB_CODE_TSMA_INVALID_PARA;
    smaWarn("vgId:%d, insert tsma data failed since pDataBlocks is empty", SMA_VID(pSma));
    return TSDB_CODE_FAILED;
  }

  if (tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_TIME_RANGE) != 0) {
    terrno = TSDB_CODE_TSMA_INIT_FAILED;
    return TSDB_CODE_FAILED;
  }

C
Cary Xu 已提交
412 413 414
  SSmaEnv   *pEnv = SMA_TSMA_ENV(pSma);
  SSmaStat  *pStat = NULL;
  STSmaStat *pTsmaStat = NULL;
C
Cary Xu 已提交
415 416

  if (!pEnv || !(pStat = SMA_ENV_STAT(pEnv))) {
K
kailixu 已提交
417
    terrno = TSDB_CODE_TSMA_INVALID_ENV;
C
Cary Xu 已提交
418 419 420
    return TSDB_CODE_FAILED;
  }

C
Cary Xu 已提交
421
  pTsmaStat = SMA_STAT_TSMA(pStat);
C
Cary Xu 已提交
422

C
Cary Xu 已提交
423
  if (!pTsmaStat->pTSma) {
C
Cary Xu 已提交
424 425
    STSma *pTSma = metaGetSmaInfoByIndex(SMA_META(pSma), indexUid);
    if (!pTSma) {
C
Cary Xu 已提交
426 427 428 429 430
      smaError("vgId:%d, failed to get STSma while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
               indexUid, tstrerror(terrno));
      goto _err;
    }
    pTsmaStat->pTSma = pTSma;
431
    pTsmaStat->pTSchema = metaGetTbTSchema(SMA_META(pSma), pTSma->dstTbUid, -1, 1);
C
Cary Xu 已提交
432 433 434 435
    if (!pTsmaStat->pTSchema) {
      smaError("vgId:%d, failed to get STSchema while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
               indexUid, tstrerror(terrno));
      goto _err;
C
Cary Xu 已提交
436 437 438
    }
  }

C
Cary Xu 已提交
439
  if (pTsmaStat->pTSma->indexUid != indexUid) {
440
    terrno = TSDB_CODE_APP_ERROR;
C
Cary Xu 已提交
441 442 443 444
    smaError("vgId:%d, tsma insert for smaIndex %" PRIi64 "(!=%" PRIi64 ") failed since %s", SMA_VID(pSma), indexUid,
             pTsmaStat->pTSma->indexUid, tstrerror(terrno));
    goto _err;
  }
C
Cary Xu 已提交
445

K
kailixu 已提交
446
  SBatchDeleteReq deleteReq = {0};
K
kailixu 已提交
447 448
  void           *pSubmitReq = NULL;
  int32_t         contLen = 0;
C
Cary Xu 已提交
449

L
Liu Jicong 已提交
450 451 452
  if (smaBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
                       pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq, &pSubmitReq,
                       &contLen) < 0) {
K
kailixu 已提交
453
    smaError("vgId:%d, failed to gen submit msg while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
C
Cary Xu 已提交
454 455 456
             indexUid, tstrerror(terrno));
    goto _err;
  }
457

K
kailixu 已提交
458 459 460 461
  if ((terrno = tsmaProcessDelReq(pSma, indexUid, &deleteReq)) != 0) {
    goto _err;
  }

C
Cary Xu 已提交
462
#if 0
K
kailixu 已提交
463 464 465 466 467 468
  if (!strncasecmp("td.tsma.rst.tb", pTsmaStat->pTSma->dstTbName, 14)) {
    terrno = TSDB_CODE_APP_ERROR;
    smaError("vgId:%d, tsma insert for smaIndex %" PRIi64 " failed since %s, %s", SMA_VID(pSma), indexUid,
             pTsmaStat->pTSma->indexUid, tstrerror(terrno), pTsmaStat->pTSma->dstTbName);
    goto _err;
  }
C
Cary Xu 已提交
469
#endif
C
Cary Xu 已提交
470 471 472 473

  SRpcMsg submitReqMsg = {
      .msgType = TDMT_VND_SUBMIT,
      .pCont = pSubmitReq,
474
      .contLen = contLen,
C
Cary Xu 已提交
475 476
  };

C
Cary Xu 已提交
477 478 479 480 481
  if (tmsgPutToQueue(&pSma->pVnode->msgCb, WRITE_QUEUE, &submitReqMsg) < 0) {
    smaError("vgId:%d, failed to put SubmitReq msg while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
             indexUid, tstrerror(terrno));
    goto _err;
  }
C
Cary Xu 已提交
482 483

  return TSDB_CODE_SUCCESS;
C
Cary Xu 已提交
484 485
_err:
  return TSDB_CODE_FAILED;
486
}