tsdbWrite.c 2.0 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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 "tsdbDef.h"

C
Cary Xu 已提交
18 19 20 21 22 23 24 25
/**
 * @brief insert TS data
 *
 * @param pTsdb
 * @param pMsg
 * @param pRsp
 * @return int
 */
S
Shengliang Guan 已提交
26
int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp) {
H
Hongze Cheng 已提交
27 28
  // Check if mem is there. If not, create one.
  if (pTsdb->mem == NULL) {
H
more  
Hongze Cheng 已提交
29 30 31 32
    pTsdb->mem = tsdbNewMemTable(pTsdb);
    if (pTsdb->mem == NULL) {
      return -1;
    }
H
Hongze Cheng 已提交
33
  }
H
Hongze Cheng 已提交
34
  return tsdbMemTableInsert(pTsdb, pTsdb->mem, pMsg, NULL);
C
Cary Xu 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
}

/**
 * @brief Insert/Update tSma(Time-range-wise SMA) data from stream computing engine
 * 
 * @param pTsdb 
 * @param param 
 * @param pData 
 * @return int32_t 
 * TODO: Who is responsible for resource allocate and release?
 */
int32_t tsdbInsertTSmaData(STsdb *pTsdb, STSma *param, STSmaData *pData) {
  int32_t code = TSDB_CODE_SUCCESS;
  if ((code = tsdbInsertTSmaDataImpl(pTsdb, param, pData)) < 0) {
    tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
  }
  return code;
}

/**
 * @brief Insert Time-range-wise Rollup Sma(RSma) data
 *
 * @param pTsdb
 * @param param
 * @param pData
 * @return int32_t
 */
int32_t tsdbInsertRSmaData(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
  int32_t code = TSDB_CODE_SUCCESS;
  if ((code = tsdbInsertRSmaDataImpl(pTsdb, param, pData)) < 0) {
    tsdbWarn("vgId:%d insert rSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
  }
  return code;
H
Hongze Cheng 已提交
68
}