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

taosdata / TDengine / #3561

19 Dec 2024 03:15AM UTC coverage: 58.812% (-1.3%) from 60.124%
#3561

push

travis-ci

web-flow
Merge pull request #29213 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

130770 of 287658 branches covered (45.46%)

Branch coverage included in aggregate %.

32 of 78 new or added lines in 4 files covered. (41.03%)

7347 existing lines in 166 files now uncovered.

205356 of 283866 relevant lines covered (72.34%)

7187865.64 hits per line

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

14.17
/source/dnode/vnode/src/tq/tqOffset.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
#define _DEFAULT_SOURCE
16

17
#include "tq.h"
18

19
int32_t tqBuildFName(char** data, const char* path, char* name) {
28,769✔
20
  if (data == NULL || path == NULL || name == NULL) {
28,769!
UNCOV
21
    return TSDB_CODE_INVALID_MSG;
×
22
  }
23
  int32_t len = strlen(path) + strlen(name) + 2;
28,791✔
24
  char*   fname = taosMemoryCalloc(1, len);
28,791!
25
  if(fname == NULL) {
28,789!
UNCOV
26
    return terrno;
×
27
  }
28
  int32_t code = tsnprintf(fname, len, "%s%s%s", path, TD_DIRSEP, name);
28,789✔
29
  if (code < 0){
28,789!
UNCOV
30
    code = TAOS_SYSTEM_ERROR(errno);
×
UNCOV
31
    taosMemoryFree(fname);
×
UNCOV
32
    return code;
×
33
  }
34
  *data = fname;
28,789✔
35
  return TDB_CODE_SUCCESS;
28,789✔
36
}
37

UNCOV
38
int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
×
39
  if (pTq == NULL || name == NULL) {
×
40
    return TSDB_CODE_INVALID_MSG;
×
41
  }
42
  int32_t   code = TDB_CODE_SUCCESS;
×
UNCOV
43
  void*     pMemBuf = NULL;
×
44

45
  TdFilePtr pFile = taosOpenFile(name, TD_FILE_READ);
×
46
  if (pFile == NULL) {
×
47
    code = TDB_CODE_SUCCESS;
×
48
    goto END;
×
49
  }
50

51
  int64_t ret = 0;
×
UNCOV
52
  int32_t size = 0;
×
53
  int32_t total = 0;
×
UNCOV
54
  while (1) {
×
55
    if ((ret = taosReadFile(pFile, &size, INT_BYTES)) != INT_BYTES) {
×
56
      if (ret != 0) {
×
57
        code = TSDB_CODE_INVALID_MSG;
×
58
      }
59
      break;
×
60
    }
UNCOV
61
    total += INT_BYTES;
×
UNCOV
62
    size = htonl(size);
×
63
    if (size <= 0) {
×
64
      code = TSDB_CODE_INVALID_MSG;
×
65
      goto END;
×
66
    }
UNCOV
67
    pMemBuf = taosMemoryCalloc(1, size);
×
68
    if (pMemBuf == NULL) {
×
69
      code = terrno;
×
70
      goto END;
×
71
    }
72

73
    if (taosReadFile(pFile, pMemBuf, size) != size) {
×
74
      terrno = TSDB_CODE_INVALID_MSG;
×
UNCOV
75
      goto END;
×
76
    }
77

78
    total += size;
×
79
    STqOffset offset = {0};
×
UNCOV
80
    TQ_ERR_GO_TO_END(tqMetaDecodeOffsetInfo(&offset, pMemBuf, size));
×
UNCOV
81
    code = taosHashPut(pTq->pOffset, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset));
×
82
    if (code != TDB_CODE_SUCCESS) {
×
83
      tDeleteSTqOffset(&offset);
×
84
      goto END;
×
85
    }
86

87
    tqInfo("tq: offset restore from file to tdb, size:%d, hash size:%d subkey:%s", total, taosHashGetSize(pTq->pOffset), offset.subKey);
×
88
    taosMemoryFree(pMemBuf);
×
UNCOV
89
    pMemBuf = NULL;
×
90
  }
91

92
  void *pIter = NULL;
×
93
  while ((pIter = taosHashIterate(pTq->pOffset, pIter))) {
×
94
    STqOffset* pOffset = (STqOffset*)pIter;
×
UNCOV
95
    code = tqMetaSaveOffset(pTq, pOffset);
×
96
    if(code != 0){
×
UNCOV
97
      taosHashCancelIterate(pTq->pOffset, pIter);
×
UNCOV
98
      goto END;
×
99
    }
100
  }
101

UNCOV
102
END:
×
UNCOV
103
  taosCloseFile(&pFile);
×
UNCOV
104
  taosMemoryFree(pMemBuf);
×
105

UNCOV
106
  return code;
×
107
}
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