• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3565

25 Dec 2024 05:34AM UTC coverage: 51.098% (-11.1%) from 62.21%
#3565

push

travis-ci

web-flow
Merge pull request #29316 from taosdata/enh/3.0/TD-33266

enh(ut):Add wal & config UT.

111558 of 284773 branches covered (39.17%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 2 files covered. (50.0%)

39015 existing lines in 102 files now uncovered.

177882 of 281666 relevant lines covered (63.15%)

15090998.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

16
#include "cos.h"
17
#include "tsdb.h"
18

19
/**
20
 * @brief max key by precision
21
 *  approximately calculation:
22
 *  ms: 3600*1000*8765*1000         // 1970 + 1000 years
23
 *  us: 3600*1000000*8765*1000      // 1970 + 1000 years
24
 *  ns: 3600*1000000000*8765*292    // 1970 + 292 years
25
 */
26
int64_t tsMaxKeyByPrecision[] = {31556995200000L, 31556995200000000L, 9214646400000000000L};
27

28
// static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg);
29

UNCOV
30
int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq2 *pMsg, SSubmitRsp2 *pRsp) {
×
31
  int32_t code;
UNCOV
32
  int32_t arrSize = 0;
×
UNCOV
33
  int32_t affectedrows = 0;
×
UNCOV
34
  int32_t numOfRows = 0;
×
35

UNCOV
36
  if (pTsdb->mem == NULL) {
×
37
    TAOS_RETURN(TSDB_CODE_INTERNAL_ERROR);
×
38
  }
39

UNCOV
40
  arrSize = taosArrayGetSize(pMsg->aSubmitTbData);
×
41

42
  // scan and convert
UNCOV
43
  if ((code = tsdbScanAndConvertSubmitMsg(pTsdb, pMsg)) < 0) {
×
44
    if (code != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
×
45
      tsdbError("vgId:%d, failed to insert data since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
×
46
    }
47
    return code;
×
48
  }
49

50
  // loop to insert
UNCOV
51
  for (int32_t i = 0; i < arrSize; ++i) {
×
UNCOV
52
    TAOS_CHECK_RETURN(tsdbInsertTableData(pTsdb, version, taosArrayGet(pMsg->aSubmitTbData, i), &affectedrows));
×
53
  }
54

55
  if (pRsp != NULL) {
56
    // pRsp->affectedRows = affectedrows;
57
    // pRsp->numOfRows = numOfRows;
58
  }
59

UNCOV
60
  return 0;
×
61
}
62

63
static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, TSKEY rowKey, TSKEY minKey, TSKEY maxKey,
64
                                          TSKEY now) {
UNCOV
65
  if (rowKey < minKey || rowKey > maxKey) {
×
66
    tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
×
67
              " maxKey %" PRId64 " row key %" PRId64,
68
              TD_VID(pTsdb->pVnode), uid, now, minKey, maxKey, rowKey);
69
    return TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
×
70
  }
71

UNCOV
72
  return 0;
×
73
}
74

UNCOV
75
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) {
×
UNCOV
76
  STsdbKeepCfg *pCfg = &pTsdb->keepCfg;
×
UNCOV
77
  TSKEY         now = taosGetTimestamp(pCfg->precision);
×
UNCOV
78
  TSKEY         minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep2;
×
UNCOV
79
  TSKEY         maxKey = tsMaxKeyByPrecision[pCfg->precision];
×
UNCOV
80
  int32_t       size = taosArrayGetSize(pMsg->aSubmitTbData);
×
81

UNCOV
82
  for (int32_t i = 0; i < size; ++i) {
×
UNCOV
83
    SSubmitTbData *pData = TARRAY_GET_ELEM(pMsg->aSubmitTbData, i);
×
UNCOV
84
    if (pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
×
85
      uint64_t  nColData = TARRAY_SIZE(pData->aCol);
×
86
      SColData *aColData = (SColData *)TARRAY_DATA(pData->aCol);
×
87
      if (nColData > 0) {
×
88
        int32_t nRows = aColData[0].nVal;
×
89
        TSKEY  *aKey = (TSKEY *)aColData[0].pData;
×
90
        for (int32_t r = 0; r < nRows; ++r) {
×
91
          TAOS_CHECK_RETURN(tsdbCheckRowRange(pTsdb, pData->uid, aKey[r], minKey, maxKey, now));
×
92
        }
93
      }
94
    } else {
UNCOV
95
      int32_t nRows = taosArrayGetSize(pData->aRowP);
×
UNCOV
96
      for (int32_t r = 0; r < nRows; ++r) {
×
UNCOV
97
        SRow *pRow = (SRow *)taosArrayGetP(pData->aRowP, r);
×
UNCOV
98
        TAOS_CHECK_RETURN(tsdbCheckRowRange(pTsdb, pData->uid, pRow->ts, minKey, maxKey, now));
×
99
      }
100
    }
101
  }
102

UNCOV
103
  return 0;
×
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc