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

taosdata / TDengine / #4869

26 Nov 2025 05:46AM UTC coverage: 64.539% (-0.09%) from 64.629%
#4869

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

771 of 945 new or added lines in 33 files covered. (81.59%)

3214 existing lines in 124 files now uncovered.

158203 of 245129 relevant lines covered (64.54%)

113224023.06 hits per line

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

43.48
/source/dnode/vnode/src/bse/bseUtil.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
#include "bseUtil.h"
16
#include "bseInc.h"
17
#include "bseTable.h"
18
#include "tcompression.h"
19
// compress func set
20
typedef int32_t (*compressFunc)(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
21
typedef int32_t (*decompressFunc)(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
22

23
// plain compress
24
static int32_t plainCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
25
static int32_t plainDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
26
// lz4 func
27
static int32_t lz4Compress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
28
static int32_t lz4Decompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
29

30
static int32_t zlibCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
31
static int32_t zlibDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
32

33
static int32_t zstdCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
34
static int32_t zstdDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
35

36
static int32_t xzCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
37
static int32_t xzDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
38

39
typedef struct {
40
  char           name[8];
41
  compressFunc   compress;
42
  decompressFunc decompress;
43
} SCompressFuncSet;
44

45
static SCompressFuncSet bseCompressFuncSet[] = {
46
    {"plain", plainCompress, plainDecompress}, {"lz4", lz4Compress, lz4Decompress},
47
    {"zlib", zlibCompress, zlibDecompress},    {"zstd", zstdCompress, zstdDecompress},
48
    {"xz", xzCompress, xzDecompress},
49
};
50

51
int32_t plainCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
52
  int32_t size = *dstSize;
×
53
  if (size < srcSize) {
×
54
    return -1;
×
55
  }
56
  memcpy(dst, src, srcSize);
×
57
  return srcSize;
×
58
}
59

60
int32_t plainDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
61
  int32_t size = *dstSize;
×
62
  if (size < srcSize) {
×
63
    return -1;
×
64
  }
65
  memcpy(dst, src, srcSize);
×
66
  return 0;
×
67
}
68
int32_t lz4Compress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
3,116✔
69
  return lz4CompressImpl(src, srcSize, dst, dstSize);
3,116✔
70
}
UNCOV
71
int32_t lz4Decompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
UNCOV
72
  return lz4DecompressImpl(src, srcSize, dst, dstSize);
×
73
}
74

75
int32_t zlibCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
76
  return zlibCompressImpl(src, srcSize, dst, dstSize);
×
77
}
78
int32_t zlibDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
79
  return zlibDecompressImpl(src, srcSize, dst, dstSize);
×
80
}
81

82
int32_t zstdCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
83
  return zstdCompressImpl(src, srcSize, dst, dstSize);
×
84
}
85
int32_t zstdDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
86
  return zstdDecompressImpl(src, srcSize, dst, dstSize);
×
87
}
88

89
int32_t xzCompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
90
  return xzCompressImpl(src, srcSize, dst, dstSize);
×
91
}
92
int32_t xzDecompress(void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
93
  return xzDecompressImpl(src, srcSize, dst, dstSize);
×
94
}
95

96
int32_t bseCompressData(int8_t type, void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
3,116✔
97
  int32_t code = 0;
3,116✔
98
  if (type < 0 || type >= sizeof(bseCompressFuncSet) / sizeof(bseCompressFuncSet[0])) {
3,116✔
99
    return TSDB_CODE_INVALID_CFG;
×
100
  }
101
  bseDebug("compress %s ,srcSize %d, dstSize %d", bseCompressFuncSet[type].name, srcSize, *dstSize);
3,116✔
102
  return bseCompressFuncSet[type].compress(src, srcSize, dst, dstSize);
3,116✔
103
}
104

UNCOV
105
int32_t bseDecompressData(int8_t type, void *src, int32_t srcSize, void *dst, int32_t *dstSize) {
×
UNCOV
106
  int32_t code = 0;
×
UNCOV
107
  if (type < 0 || type >= sizeof(bseCompressFuncSet) / sizeof(bseCompressFuncSet[0])) {
×
108
    return TSDB_CODE_INVALID_CFG;
×
109
  }
110

UNCOV
111
  bseDebug("decompress %s, srcSize %d, dstSize %d", bseCompressFuncSet[type].name, srcSize, *dstSize);
×
UNCOV
112
  return bseCompressFuncSet[type].decompress(src, srcSize, dst, dstSize);
×
113
}
114

115
// build file path func
116
void bseBuildDataFullName(SBse *pBse, char *name, char *buf) {
×
117
  // build data file name
118
  // snprintf(name, strlen(name), "%s/%s020"."BSE_DATA_SUFFIX, ver, pBse->path);
119
  // sprintf(name, strlen(name), "%s/%020"."BSE_DATA_SUFFIX, ver, pBse->path);
120
  TAOS_UNUSED(snprintf(buf, BSE_FILE_FULL_LEN, "%s/%s.%s", pBse->path, name, BSE_DATA_SUFFIX));
×
121
}
×
122

123
void bseBuildIndexFullName(SBse *pBse, int64_t ver, char *buf) {
×
124
  // build index file name
125
  TAOS_UNUSED(snprintf(buf, BSE_FILE_FULL_LEN, "%s/%020" PRId64 "." BSE_INDEX_SUFFIX, pBse->path, ver));
×
126
}
×
127
void bseBuildLogFullName(SBse *pBse, int64_t ver, char *buf) {
×
128
  TAOS_UNUSED(snprintf(buf, BSE_FILE_FULL_LEN, "%s/%020" PRId64 "." BSE_LOG_SUFFIX, pBse->path, ver));
×
129
}
×
130

131
void bseBuildCurrentFullName(SBse *pBse, char *name) {
4,089,194✔
132
  snprintf(name, BSE_FILE_FULL_LEN, "%s%sCURRENT", pBse->path, TD_DIRSEP);
4,089,194✔
133
}
4,093,962✔
134

135
void bseBuildTempCurrentFullName(SBse *pBse, char *name) {
6,232✔
136
  snprintf(name, BSE_FILE_FULL_LEN, "%s%sCURRENT-temp", pBse->path, TD_DIRSEP);
6,232✔
137
}
6,232✔
138

139
void bseBuildFullMetaName(SBse *pBse, char *name, char *path) {
×
140
  snprintf(path, BSE_FILE_FULL_LEN, "%s%s%s.%s", pBse->path, TD_DIRSEP, name, BSE_META_SUFFIX);
×
141
}
×
142
void bseBuildFullTempMetaName(SBse *pBse, char *name, char *path) {
×
143
  snprintf(path, BSE_FILE_FULL_LEN, "%s%s%s.%s-temp", pBse->path, TD_DIRSEP, name, BSE_META_SUFFIX);
×
144
}
×
145

146
void bseBuildMetaName(int64_t ts, char *name) {
3,116✔
147
  // refactor later
148
  snprintf(name, BSE_FILE_FULL_LEN, "%" PRId64 ".%s", ts, BSE_META_SUFFIX);
3,116✔
149
}
3,116✔
150
void bseBuildTempMetaName(int64_t ts, char *name) {
2,337✔
151
  // refactor later
152
  snprintf(name, BSE_FILE_FULL_LEN, "%" PRId64 ".%s-temp", ts, BSE_META_SUFFIX);
2,337✔
153
}
2,337✔
154

155
void bseBuildFullName(SBse *pBse, char *name, char *fullname) {
17,138✔
156
  snprintf(fullname, BSE_FILE_FULL_LEN, "%s%s%s", pBse->path, TD_DIRSEP, name);
17,138✔
157
}
17,138✔
158

159
void bseBuildDataName(int64_t ts, char *name) {
4,674✔
160
  snprintf(name, BSE_FILE_FULL_LEN, "%" PRId64 ".%s", ts, BSE_DATA_SUFFIX);
4,674✔
161
}
4,674✔
162

163
int32_t bseGetTableIdBySeq(SBse *pBse, int64_t seq, int64_t *timestamp) {
21,812✔
164
  int32_t code = 0;
21,812✔
165
  int32_t lino = 0;
21,812✔
166

167
  int64_t tts = 0;
21,812✔
168
  if (pBse == NULL) {
21,812✔
169
    return TSDB_CODE_INVALID_CFG;
×
170
  }
171

172
  (void)taosThreadMutexLock(&pBse->mutex);
21,812✔
173
  if (pBse->commitInfo.pFileList == NULL) {
21,812✔
174
    TAOS_CHECK_GOTO(TSDB_CODE_INVALID_CFG, &lino, _error);
×
175
  }
176

177
  SBseCommitInfo *pCommitInfo = &pBse->commitInfo;
21,812✔
178
  for (int32_t i = 0; i < taosArrayGetSize(pCommitInfo->pFileList); i++) {
35,834✔
179
    SBseLiveFileInfo *pInfo = taosArrayGet(pCommitInfo->pFileList, i);
14,022✔
180
    if (seqRangeContains(&pInfo->range, seq)) {
14,022✔
181
      tts = pInfo->timestamp;
×
182
      break;
×
183
    }
184
  }
185

186
  *timestamp = tts;
21,812✔
187
_error:
21,812✔
188
  (void)taosThreadMutexUnlock(&pBse->mutex);
21,812✔
189
  return code;
21,812✔
190
}
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