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

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

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

0.0
/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) {
×
20
  int32_t   code = 0;
×
21
  int32_t   lino = 0;
×
22
  char*     fname = NULL;
×
23
  TSDB_CHECK_NULL(data, code, lino, END, TSDB_CODE_INVALID_MSG);
×
24
  TSDB_CHECK_NULL(path, code, lino, END, TSDB_CODE_INVALID_MSG);
×
25
  TSDB_CHECK_NULL(name, code, lino, END, TSDB_CODE_INVALID_MSG);
×
26
  int32_t len = strlen(path) + strlen(name) + 2;
×
27
  fname = taosMemoryCalloc(1, len);
×
28
  TSDB_CHECK_NULL(fname, code, lino, END, terrno);
×
29
  (void)tsnprintf(fname, len, "%s%s%s", path, TD_DIRSEP, name);
×
30

31
  *data = fname;
×
32
  fname = NULL;
×
33

34
END:
×
35
  if (code != 0){
×
36
    tqError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
37
  }
38
  taosMemoryFree(fname);
×
39
  return code;
×
40
}
41

42
int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
×
43
  int32_t    code = TDB_CODE_SUCCESS;
×
44
  int32_t    lino = 0;
×
45
  void*      pMemBuf = NULL;
×
46
  TdFilePtr  pFile = NULL;
×
47
  STqOffset *pOffset = NULL;
×
48
  void      *pIter = NULL;
×
49

50
  TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_MSG);
×
51
  TSDB_CHECK_NULL(name, code, lino, END, TSDB_CODE_INVALID_MSG);
×
52

53
  pFile = taosOpenFile(name, TD_FILE_READ);
×
54
  TSDB_CHECK_NULL(pFile, code, lino, END, TDB_CODE_SUCCESS);
×
55

56
  int64_t ret = 0;
×
57
  int32_t size = 0;
×
58
  int32_t total = 0;
×
59
  while (1) {
×
60
    if ((ret = taosReadFile(pFile, &size, INT_BYTES)) != INT_BYTES) {
×
61
      if (ret != 0) {
×
62
        code = TSDB_CODE_INVALID_MSG;
×
63
      }
64
      break;
×
65
    }
66
    total += INT_BYTES;
×
67
    size = htonl(size);
×
68
    TSDB_CHECK_CONDITION(size > 0, code, lino, END, TSDB_CODE_INVALID_MSG);
×
69

70
    pMemBuf = taosMemoryCalloc(1, size);
×
71
    TSDB_CHECK_NULL(pMemBuf, code, lino, END, terrno);
×
72
    TSDB_CHECK_CONDITION(taosReadFile(pFile, pMemBuf, size) == size, code, lino, END, TSDB_CODE_INVALID_MSG);
×
73

74
    total += size;
×
75
    STqOffset offset = {0};
×
76
    code = tqMetaDecodeOffsetInfo(&offset, pMemBuf, size);
×
77
    TSDB_CHECK_CODE(code, lino, END);
×
78
    pOffset = &offset;
×
79
    code = taosHashPut(pTq->pOffset, pOffset->subKey, strlen(pOffset->subKey), pOffset, sizeof(STqOffset));
×
80
    TSDB_CHECK_CODE(code, lino, END);
×
81
    pOffset = NULL;
×
82

83
    tqInfo("tq: offset restore from file to tdb, size:%d, hash size:%d subkey:%s", total, taosHashGetSize(pTq->pOffset), offset.subKey);
×
84
    taosMemoryFree(pMemBuf);
×
85
    pMemBuf = NULL;
×
86
  }
87

88
  while ((pIter = taosHashIterate(pTq->pOffset, pIter))) {
×
89
    STqOffset* offset = (STqOffset*)pIter;
×
90
    code = tqMetaSaveOffset(pTq, offset);
×
91
    TSDB_CHECK_CODE(code, lino, END);
×
92
  }
93

94
END:
×
95
  if (code != 0){
×
96
    tqError("%s failed at %d since %s", __func__, lino, tstrerror(code));
×
97
  }
98
  (void)taosCloseFile(&pFile);
×
99
  taosMemoryFree(pMemBuf);
×
100

101
  tDeleteSTqOffset(pOffset);
×
102
  taosHashCancelIterate(pTq->pOffset, pIter);
×
103

104
  return code;
×
105
}
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