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

taosdata / TDengine / #4936

23 Jan 2026 09:40AM UTC coverage: 66.746% (+0.04%) from 66.708%
#4936

push

travis-ci

web-flow
fix: case failuer caused by the modification of the error description (#34391)

204023 of 305671 relevant lines covered (66.75%)

124768167.97 hits per line

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

93.75
/source/dnode/vnode/src/inc/tsdb.h
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
#ifndef _TD_VNODE_TSDB_H_
17
#define _TD_VNODE_TSDB_H_
18

19
// #include "../tsdb/tsdbFile2.h"
20
// #include "../tsdb/tsdbMerge.h"
21
// #include "../tsdb/tsdbSttFileRW.h"
22
#include "tsimplehash.h"
23
#include "vnodeInt.h"
24

25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28

29
// tsdbDebug ================
30
// clang-format off
31
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSD FATAL ", DEBUG_FATAL, 255,           __VA_ARGS__); }} while(0)
32
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSD ERROR ", DEBUG_ERROR, 255,           __VA_ARGS__); }} while(0)
33
#define tsdbWarn(...)  do { if (tsdbDebugFlag & DEBUG_WARN)  { taosPrintLog("TSD WARN  ", DEBUG_WARN,  255,           __VA_ARGS__); }} while(0)
34
#define tsdbInfo(...)  do { if (tsdbDebugFlag & DEBUG_INFO)  { taosPrintLog("TSD INFO  ", DEBUG_INFO,  255,           __VA_ARGS__); }} while(0)
35
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSD DEBUG ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
36
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSD TRACE ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
37
// clang-format on
38

39
typedef struct TSDBROW          TSDBROW;
40
typedef struct TABLEID          TABLEID;
41
typedef struct TSDBKEY          TSDBKEY;
42
typedef struct SDelData         SDelData;
43
typedef struct SDelIdx          SDelIdx;
44
typedef struct STbData          STbData;
45
typedef struct SMemTable        SMemTable;
46
typedef struct STbDataIter      STbDataIter;
47
typedef struct SMapData         SMapData;
48
typedef struct SBlockIdx        SBlockIdx;
49
typedef struct SDataBlk         SDataBlk;
50
typedef struct SSttBlk          SSttBlk;
51
typedef struct SDiskDataHdr     SDiskDataHdr;
52
typedef struct SBlockData       SBlockData;
53
typedef struct SDelFile         SDelFile;
54
typedef struct SHeadFile        SHeadFile;
55
typedef struct SDataFile        SDataFile;
56
typedef struct SSttFile         SSttFile;
57
typedef struct SSmaFile         SSmaFile;
58
typedef struct SDFileSet        SDFileSet;
59
typedef struct SDataFWriter     SDataFWriter;
60
typedef struct SDataFReader     SDataFReader;
61
typedef struct SDelFWriter      SDelFWriter;
62
typedef struct SDelFReader      SDelFReader;
63
typedef struct STSDBRowIter     STSDBRowIter;
64
typedef struct STsdbFS          STsdbFS;
65
typedef struct SRowMerger       SRowMerger;
66
typedef struct STsdbReadSnap    STsdbReadSnap;
67
typedef struct SBlockInfo       SBlockInfo;
68
typedef struct SSmaInfo         SSmaInfo;
69
typedef struct SBlockCol        SBlockCol;
70
typedef struct SLDataIter       SLDataIter;
71
typedef struct SDiskCol         SDiskCol;
72
typedef struct SDiskData        SDiskData;
73
typedef struct SDiskDataBuilder SDiskDataBuilder;
74
typedef struct SBlkInfo         SBlkInfo;
75
typedef struct STsdbDataIter2   STsdbDataIter2;
76
typedef struct STsdbFilterInfo  STsdbFilterInfo;
77
typedef struct STFileSystem     STFileSystem;
78
typedef struct STsdbRowKey      STsdbRowKey;
79

80
#define TSDBROW_ROW_FMT ((int8_t)0x0)
81
#define TSDBROW_COL_FMT ((int8_t)0x1)
82

83
#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F)
84
#define TSDB_FHDR_SIZE 512
85

86
#define VERSION_MIN 0
87
#define VERSION_MAX INT64_MAX
88

89
#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN})
90
#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX})
91

92
#define TABLE_SAME_SCHEMA(SUID1, UID1, SUID2, UID2) ((SUID1) ? (SUID1) == (SUID2) : (UID1) == (UID2))
93

94
#define PAGE_CONTENT_SIZE(PAGE) ((PAGE) - sizeof(TSCKSUM))
95
#define LOGIC_TO_FILE_OFFSET(LOFFSET, PAGE) \
96
  ((LOFFSET) / PAGE_CONTENT_SIZE(PAGE) * (PAGE) + (LOFFSET) % PAGE_CONTENT_SIZE(PAGE))
97
#define FILE_TO_LOGIC_OFFSET(OFFSET, PAGE) ((OFFSET) / (PAGE)*PAGE_CONTENT_SIZE(PAGE) + (OFFSET) % (PAGE))
98
#define PAGE_OFFSET(PGNO, PAGE)            (((PGNO)-1) * (PAGE))
99
#define OFFSET_PGNO(OFFSET, PAGE)          ((OFFSET) / (PAGE) + 1)
100

101
static FORCE_INLINE int64_t tsdbLogicToFileSize(int64_t lSize, int32_t szPage) {
102
  int64_t fOffSet = LOGIC_TO_FILE_OFFSET(lSize, szPage);
66,746✔
103
  int64_t pgno = OFFSET_PGNO(fOffSet, szPage);
66,746✔
104

105
  if (fOffSet % szPage == 0) {
66,746✔
106
    pgno--;
×
107
  }
108

109
  return pgno * szPage;
66,746✔
110
}
111

112
// tsdbUtil.c ==============================================================================================
113
// TSDBROW
114
#define TSDBROW_TS(ROW) (((ROW)->type == TSDBROW_ROW_FMT) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
115
#define TSDBROW_VERSION(ROW) \
116
  (((ROW)->type == TSDBROW_ROW_FMT) ? (ROW)->version : (ROW)->pBlockData->aVersion[(ROW)->iRow])
117
#define TSDBROW_SVERSION(ROW)            ((ROW)->type == TSDBROW_ROW_FMT ? (ROW)->pTSRow->sver : -1)
118
#define TSDBROW_KEY(ROW)                 ((TSDBKEY){.version = TSDBROW_VERSION(ROW), .ts = TSDBROW_TS(ROW)})
119
#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = TSDBROW_ROW_FMT, .version = (VERSION), .pTSRow = (TSROW)})
120
#define tsdbRowFromBlockData(BLOCKDATA, IROW) \
121
  ((TSDBROW){.type = TSDBROW_COL_FMT, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
122

123
#define TSDBROW_INIT_KEY(_ROW, _KEY)                             \
124
  {                                                              \
125
    if ((_ROW)->type == TSDBROW_ROW_FMT) {                       \
126
      _KEY.version = (_ROW)->version;                            \
127
      _KEY.ts = (_ROW)->pTSRow->ts;                              \
128
    } else {                                                     \
129
      _KEY.version = (_ROW)->pBlockData->aVersion[(_ROW)->iRow]; \
130
      _KEY.ts = (_ROW)->pBlockData->aTSKEY[(_ROW)->iRow];        \
131
    }                                                            \
132
  }
133

134
#define tColRowGetKey(_pBlock, _irow, _key)             \
135
  {                                                     \
136
    (_key)->ts = (_pBlock)->aTSKEY[(_irow)];            \
137
    (_key)->numOfPKs = 0;                               \
138
    if ((_pBlock)->nColData > 0) {                      \
139
      tColRowGetPrimaryKey((_pBlock), (_irow), (_key)); \
140
    }                                                   \
141
  }
142

143
void    tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
144
int32_t tsdbRowCompare(const void *p1, const void *p2);
145
int32_t tsdbRowCompareWithoutVersion(const void *p1, const void *p2);
146
int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2);
147
void    tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key);
148
void    tColRowGetPrimaryKey(SBlockData *pBlock, int32_t irow, SRowKey *key);
149

150
// STSDBRowIter
151
int32_t  tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
152
void     tsdbRowClose(STSDBRowIter *pIter);
153
SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
154

155
// SRowMerger
156
int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pSchema);
157
int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
158
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
159
void    tsdbRowMergerClear(SRowMerger *pMerger);
160
void    tsdbRowMergerCleanup(SRowMerger *pMerger);
161

162
// TABLEID
163
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
164
// TSDBKEY
165
#define MIN_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) < 0) ? (KEY1) : (KEY2))
166
#define MAX_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) > 0) ? (KEY1) : (KEY2))
167
// SBlockCol
168
int32_t tPutBlockCol(SBuffer *buffer, const SBlockCol *pBlockCol, int32_t ver, uint32_t cmprAlg);
169
int32_t tGetBlockCol(SBufferReader *br, SBlockCol *pBlockCol, int32_t ver, uint32_t cmprAlg);
170
int32_t tBlockColCmprFn(const void *p1, const void *p2);
171
// SDataBlk
172
void    tDataBlkReset(SDataBlk *pBlock);
173
int32_t tPutDataBlk(uint8_t *p, void *ph);
174
int32_t tGetDataBlk(uint8_t *p, void *ph);
175
int32_t tDataBlkCmprFn(const void *p1, const void *p2);
176
bool    tDataBlkHasSma(SDataBlk *pDataBlk);
177
// SSttBlk
178
int32_t tPutSttBlk(uint8_t *p, void *ph);
179
int32_t tGetSttBlk(uint8_t *p, void *ph);
180
// SBlockIdx
181
int32_t tPutBlockIdx(uint8_t *p, void *ph);
182
int32_t tGetBlockIdx(uint8_t *p, void *ph);
183
int32_t tCmprBlockIdx(void const *lhs, void const *rhs);
184
int32_t tCmprBlockL(void const *lhs, void const *rhs);
185
// SBlockData
186
#define tBlockDataFirstRow(PBLOCKDATA)             tsdbRowFromBlockData(PBLOCKDATA, 0)
187
#define tBlockDataLastRow(PBLOCKDATA)              tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
188
#define tBlockDataFirstKey(PBLOCKDATA)             TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
189
#define tBlockDataLastKey(PBLOCKDATA)              TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
190
#define tBlockDataGetColDataByIdx(PBLOCKDATA, IDX) (&(PBLOCKDATA)->aColData[IDX])
191

192
int32_t tBlockDataCreate(SBlockData *pBlockData);
193
void    tBlockDataDestroy(SBlockData *pBlockData);
194
int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid);
195
void    tBlockDataReset(SBlockData *pBlockData);
196
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
197
int32_t tBlockDataUpdateRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema);
198
int32_t tBlockDataTryUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, int64_t uid);
199
int32_t tBlockDataUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
200
void    tBlockDataClear(SBlockData *pBlockData);
201
int32_t tBlockDataCompress(SBlockData *bData, void *pCmprInfo, SBuffer *buffers, SBuffer *assist);
202
int32_t tBlockDataDecompress(SBufferReader *br, SBlockData *blockData, SBuffer *assist);
203
int32_t tBlockDataDecompressKeyPart(const SDiskDataHdr *hdr, SBufferReader *br, SBlockData *blockData, SBuffer *assist);
204
int32_t tBlockDataDecompressColData(const SDiskDataHdr *hdr, const SBlockCol *blockCol, SBufferReader *br,
205
                                    SBlockData *blockData, SBuffer *assist);
206

207
SColData *tBlockDataGetColData(SBlockData *pBlockData, int16_t cid);
208
int32_t   tBlockDataAddColData(SBlockData *pBlockData, int16_t cid, int8_t type, int8_t cflag, SColData **ppColData);
209
// SDiskDataHdr
210
int32_t tPutDiskDataHdr(SBuffer *buffer, const SDiskDataHdr *pHdr);
211
int32_t tGetDiskDataHdr(SBufferReader *br, SDiskDataHdr *pHdr);
212
// SDelIdx
213
int32_t tPutDelIdx(uint8_t *p, void *ph);
214
int32_t tGetDelIdx(uint8_t *p, void *ph);
215
int32_t tCmprDelIdx(void const *lhs, void const *rhs);
216
// SDelData
217
int32_t tPutDelData(uint8_t *p, void *ph);
218
int32_t tGetDelData(uint8_t *p, void *ph);
219
// SMapData
220
#define tMapDataInit() ((SMapData){0})
221
void    tMapDataReset(SMapData *pMapData);
222
void    tMapDataClear(SMapData *pMapData);
223
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *));
224
int32_t tMapDataCopy(SMapData *pFrom, SMapData *pTo);
225
void    tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *));
226
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
227
                       int32_t (*tItemCmprFn)(const void *, const void *), void *pItem);
228
int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
229
int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize);
230
int32_t tMapDataToArray(SMapData *pMapData, int32_t itemSize, int32_t (*tGetItemFn)(uint8_t *, void *),
231
                        SArray **ppArray);
232
// other
233
int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision);
234
void    tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey);
235
int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t nowSec);
236
int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline);
237
int32_t tPutColumnDataAgg(SBuffer *buffer, SColumnDataAgg *pColAgg);
238
int32_t tGetColumnDataAgg(SBufferReader *br, SColumnDataAgg *pColAgg);
239
int32_t tRowInfoCmprFn(const void *p1, const void *p2);
240
// tsdbMemTable ==============================================================================================
241
// SMemTable
242
int32_t  tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable);
243
void     tsdbMemTableDestroy(SMemTable *pMemTable, bool proactive);
244
STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid);
245
int32_t  tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode);
246
void     tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive);
247
// STbDataIter
248
int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter);
249
void   *tsdbTbDataIterDestroy(STbDataIter *pIter);
250
void    tsdbTbDataIterOpen(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter *pIter);
251
bool    tsdbTbDataIterNext(STbDataIter *pIter);
252
void    tsdbMemTableCountRows(SMemTable *pMemTable, SSHashObj *pTableMap, int64_t *rowsNum);
253
int32_t tsdbMemTableSaveToCache(SMemTable *pMemTable, void *func);
254

255
// STbData
256
int32_t tsdbGetNRowsInTbData(STbData *pTbData);
257
// tsdbFile.c ==============================================================================================
258
typedef enum { TSDB_HEAD_FILE = 0, TSDB_DATA_FILE, TSDB_LAST_FILE, TSDB_SMA_FILE } EDataFileT;
259

260
bool    tsdbDelFileIsSame(SDelFile *pDelFile1, SDelFile *pDelFile2);
261
int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile);
262
int32_t tPutDataFile(uint8_t *p, SDataFile *pDataFile);
263
int32_t tPutSttFile(uint8_t *p, SSttFile *pSttFile);
264
int32_t tPutSmaFile(uint8_t *p, SSmaFile *pSmaFile);
265
int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile);
266
int32_t tGetDelFile(uint8_t *p, SDelFile *pDelFile);
267
int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet);
268
int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet);
269

270
void tsdbHeadFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SHeadFile *pHeadF, char fname[]);
271
void tsdbDataFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SDataFile *pDataF, char fname[]);
272
void tsdbSttFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSttFile *pSttF, char fname[]);
273
void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, char fname[]);
274

275
// SDelFile
276
void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]);
277
// tsdbFS.c ==============================================================================================
278
int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback);
279
int32_t tsdbFSClose(STsdb *pTsdb);
280
void    tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t);
281
// tsdbReaderWriter.c ==============================================================================================
282
// SDataFReader
283
int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet);
284
void    tsdbDataFReaderClose(SDataFReader **ppReader);
285
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
286
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk);
287
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
288
// SDelFReader
289
int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb);
290
void    tsdbDelFReaderClose(SDelFReader **ppReader);
291
int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer);
292
int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData);
293
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx);
294

295
// tsdbRead.c ==============================================================================================
296
int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap, const char *id);
297
void    tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive);
298
int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid,
299
                           SSchemaWrapper **pSchemaWrapper);
300

301
// tsdbMerge.c ==============================================================================================
302
typedef struct {
303
  STsdb  *tsdb;
304
  int32_t fid;
305
} SMergeArg;
306

307
int32_t tsdbMerge(void *arg);
308

309
// tsdbDataIter.c ==============================================================================================
310
#define TSDB_MEM_TABLE_DATA_ITER 0
311
#define TSDB_DATA_FILE_DATA_ITER 1
312
#define TSDB_STT_FILE_DATA_ITER  2
313
#define TSDB_TOMB_FILE_DATA_ITER 3
314

315
#define TSDB_FILTER_FLAG_BY_VERSION           0x1
316
#define TSDB_FILTER_FLAG_BY_TABLEID           0x2
317
#define TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE 0x4
318

319
#define TSDB_RBTN_TO_DATA_ITER(pNode) ((STsdbDataIter2 *)(((char *)pNode) - offsetof(STsdbDataIter2, rbtn)))
320
/* open */
321
int32_t tsdbOpenDataFileDataIter(SDataFReader *pReader, STsdbDataIter2 **ppIter);
322
int32_t tsdbOpenSttFileDataIter(SDataFReader *pReader, int32_t iStt, STsdbDataIter2 **ppIter);
323
int32_t tsdbOpenTombFileDataIter(SDelFReader *pReader, STsdbDataIter2 **ppIter);
324
/* close */
325
void tsdbCloseDataIter2(STsdbDataIter2 *pIter);
326
/* cmpr */
327
int32_t tsdbDataIterCmprFn(const SRBTreeNode *pNode1, const SRBTreeNode *pNode2);
328
/* next */
329
int32_t tsdbDataIterNext2(STsdbDataIter2 *pIter, STsdbFilterInfo *pFilterInfo);
330

331
// structs =======================
332
struct STsdbFS {
333
  SDelFile *pDelFile;
334
  SArray   *aDFileSet;  // SArray<SDFileSet>
335
};
336

337
typedef struct {
338
#ifdef USE_ROCKSDB
339
  rocksdb_t                           *db;
340
  rocksdb_comparator_t                *my_comparator;
341
  rocksdb_block_based_table_options_t *tableoptions;
342
  rocksdb_options_t                   *options;
343
  rocksdb_flushoptions_t              *flushoptions;
344
  rocksdb_writeoptions_t              *writeoptions;
345
  rocksdb_readoptions_t               *readoptions;
346
  rocksdb_writebatch_t                *writebatch;
347
  TdThreadMutex                        writeBatchMutex;
348
#endif
349
  int32_t                              sver;
350
  tb_uid_t                             suid;
351
  tb_uid_t                             uid;
352
  STSchema                            *pTSchema;
353
  SArray                              *ctxArray;
354
} SRocksCache;
355

356
typedef struct {
357
  STsdb *pTsdb;
358
  int    flush_count;
359
} SCacheFlushState;
360

361
typedef struct SCompMonitor SCompMonitor;
362
typedef struct SRetentionMonitor SRetentionMonitor;
363
typedef struct SSsMigrateMonitor SSsMigrateMonitor;
364
struct STsdb {
365
  char                *path;
366
  SVnode              *pVnode;
367
  char                 name[VNODE_TSDB_NAME_LEN];
368
  STsdbKeepCfg         keepCfg;
369
  TdThreadMutex        mutex;
370
  bool                 bgTaskDisabled;
371
  SMemTable           *mem;
372
  SMemTable           *imem;
373
  STsdbFS              fs;  // old
374
  SLRUCache           *lruCache;
375
  TdThreadMutex        lruMutex;
376
  SLRUCache           *biCache;
377
  TdThreadMutex        biMutex;
378
  SLRUCache           *bCache;
379
  TdThreadMutex        bMutex;
380
  SLRUCache           *pgCache;
381
  TdThreadMutex        pgMutex;
382
  struct STFileSystem *pFS;  // new
383
  SRocksCache          rCache;
384
  SCompMonitor        *pCompMonitor;
385
  SRetentionMonitor   *pRetentionMonitor;
386
  SSsMigrateMonitor   *pSsMigrateMonitor;
387
  struct {
388
    SVHashTable *ht;
389
    SArray      *arr;
390
  } *commitInfo;
391
  struct SScanMonitor *pScanMonitor;
392
};
393

394
struct TSDBKEY {
395
  int64_t version;
396
  TSKEY   ts;
397
};
398

399
typedef struct SMemSkipListNode SMemSkipListNode;
400
typedef struct SMemSkipList {
401
  int64_t           size;
402
  uint32_t          seed;
403
  int8_t            maxLevel;
404
  int8_t            level;
405
  SMemSkipListNode *pHead;
406
  SMemSkipListNode *pTail;
407
} SMemSkipList;
408

409
struct STbData {
410
  tb_uid_t     suid;
411
  tb_uid_t     uid;
412
  TSKEY        minKey;
413
  TSKEY        maxKey;
414
  SRWLatch     lock;
415
  SDelData    *pHead;
416
  SDelData    *pTail;
417
  SMemSkipList sl;
418
  STbData     *next;
419
  SRBTreeNode  rbtn[1];
420
};
421

422
struct SMemTable {
423
  SRWLatch         latch;
424
  STsdb           *pTsdb;
425
  SVBufPool       *pPool;
426
  volatile int32_t nRef;
427
  int64_t          minVer;
428
  int64_t          maxVer;
429
  TSKEY            minKey;
430
  TSKEY            maxKey;
431
  int64_t          nRow;
432
  int64_t          nDel;
433
  int32_t          nTbData;
434
  int32_t          nBucket;
435
  STbData        **aBucket;
436
  SRBTree          tbDataTree[1];
437
};
438

439
struct TSDBROW {
440
  int8_t type;  // TSDBROW_ROW_FMT for row from tsRow, TSDBROW_COL_FMT for row from block data
441
  union {
442
    struct {
443
      int64_t version;
444
      SRow   *pTSRow;
445
    };
446
    struct {
447
      SBlockData *pBlockData;
448
      int32_t     iRow;
449
    };
450
  };
451
  void *arg;
452
};
453

454
struct SMemSkipListNode {
455
  int8_t            level;
456
  TSDBROW           row;
457
  SMemSkipListNode *forwards[0];
458
};
459

460
struct STsdbRowKey {
461
  SRowKey key;
462
  int64_t version;
463
};
464

465
struct SBlockIdx {
466
  int64_t suid;
467
  int64_t uid;
468
  int64_t offset;
469
  int64_t size;
470
};
471

472
struct SMapData {
473
  int32_t  nItem;
474
  int32_t  nData;
475
  int32_t *aOffset;
476
  uint8_t *pData;
477
};
478

479
struct SBlockCol {
480
  int16_t  cid;
481
  int8_t   type;
482
  int8_t   cflag;
483
  int8_t   flag;      // HAS_NONE|HAS_NULL|HAS_VALUE
484
  int32_t  szOrigin;  // original column value size (only save for variant data type)
485
  int32_t  szBitmap;  // bitmap size, 0 only for flag == HAS_VAL
486
  int32_t  szOffset;  // offset size, 0 only for non-variant-length type
487
  int32_t  szValue;   // value size, 0 when flag == (HAS_NULL | HAS_NONE)
488
  int32_t  offset;
489
  uint32_t alg;
490
};
491

492
struct SBlockInfo {
493
  int64_t offset;  // block data offset
494
  int32_t szBlock;
495
  int32_t szKey;
496
};
497

498
struct SSmaInfo {
499
  int64_t offset;
500
  int32_t size;
501
};
502

503
struct SBlkInfo {
504
  int64_t minUid;
505
  int64_t maxUid;
506
  TSKEY   minKey;
507
  TSKEY   maxKey;
508
  int64_t minVer;
509
  int64_t maxVer;
510
  TSDBKEY minTKey;
511
  TSDBKEY maxTKey;
512
};
513

514
struct SDataBlk {
515
  TSDBKEY    minKey;
516
  TSDBKEY    maxKey;
517
  int64_t    minVer;
518
  int64_t    maxVer;
519
  int32_t    nRow;
520
  int8_t     hasDup;
521
  int8_t     nSubBlock;
522
  SBlockInfo aSubBlock[1];
523
  SSmaInfo   smaInfo;
524
};
525

526
struct SSttBlk {
527
  int64_t    suid;
528
  int64_t    minUid;
529
  int64_t    maxUid;
530
  TSKEY      minKey;
531
  TSKEY      maxKey;
532
  int64_t    minVer;
533
  int64_t    maxVer;
534
  int32_t    nRow;
535
  SBlockInfo bInfo;
536
};
537

538
// (SBlockData){.suid = 0, .uid = 0}: block data not initialized
539
// (SBlockData){.suid = suid, .uid = uid}: block data for ONE child table int .data file
540
// (SBlockData){.suid = suid, .uid = 0}: block data for N child tables int .last file
541
// (SBlockData){.suid = 0, .uid = uid}: block data for 1 normal table int .last/.data file
542
struct SBlockData {
543
  int64_t   suid;      // 0 means normal table block data, otherwise child table block data
544
  int64_t   uid;       // 0 means block data in .last file, otherwise in .data file
545
  int32_t   nRow;      // number of rows
546
  int64_t  *aUid;      // uids of each row, only exist in block data in .last file (uid == 0)
547
  int64_t  *aVersion;  // versions of each row
548
  TSKEY    *aTSKEY;    // timestamp of each row
549
  int32_t   nColData;
550
  SColData *aColData;
551
};
552

553
struct TABLEID {
554
  tb_uid_t suid;
555
  tb_uid_t uid;
556
};
557

558
struct STbDataIter {
559
  STbData          *pTbData;
560
  int8_t            backward;
561
  SMemSkipListNode *pNode;
562
  TSDBROW          *pRow;
563
  TSDBROW           row;
564
};
565

566
struct SDelData {
567
  int64_t   version;
568
  TSKEY     sKey;
569
  TSKEY     eKey;
570
  SDelData *pNext;
571
};
572

573
struct SDelIdx {
574
  tb_uid_t suid;
575
  tb_uid_t uid;
576
  int64_t  offset;
577
  int64_t  size;
578
};
579

580
struct SDiskDataHdr {
581
  uint32_t delimiter;
582
  uint32_t fmtVer;
583
  int64_t  suid;
584
  int64_t  uid;
585
  int32_t  szUid;
586
  int32_t  szVer;
587
  int32_t  szKey;
588
  int32_t  szBlkCol;
589
  int32_t  nRow;
590
  uint32_t cmprAlg;
591

592
  // fmtVer == 1
593
  int8_t    numOfPKs;
594
  SBlockCol primaryBlockCols[TD_MAX_PK_COLS];
595
};
596

597
struct SDelFile {
598
  volatile int32_t nRef;
599

600
  int64_t commitID;
601
  int64_t size;
602
  int64_t offset;
603
};
604

605
struct SHeadFile {
606
  volatile int32_t nRef;
607

608
  int64_t commitID;
609
  int64_t size;
610
  int64_t offset;
611
};
612

613
struct SDataFile {
614
  volatile int32_t nRef;
615

616
  int64_t commitID;
617
  int64_t size;
618
};
619

620
struct SSttFile {
621
  volatile int32_t nRef;
622

623
  int64_t commitID;
624
  int64_t size;
625
  int64_t offset;
626
};
627

628
struct SSmaFile {
629
  volatile int32_t nRef;
630

631
  int64_t commitID;
632
  int64_t size;
633
};
634

635
struct SDFileSet {
636
  SDiskID    diskId;
637
  int32_t    fid;
638
  SHeadFile *pHeadF;
639
  SDataFile *pDataF;
640
  SSmaFile  *pSmaF;
641
  uint8_t    nSttF;
642
  SSttFile  *aSttF[TSDB_STT_TRIGGER_ARRAY_SIZE];
643
};
644

645
struct STSDBRowIter {
646
  TSDBROW *pRow;
647
  union {
648
    SRowIter *pIter;
649
    struct {
650
      int32_t iColData;
651
      SColVal cv;
652
    };
653
  };
654
};
655
struct SRowMerger {
656
  STSchema *pTSchema;
657
  int64_t   version;
658
  SArray   *pArray;  // SArray<SColVal>
659
  void     *arg;
660
};
661

662
typedef struct {
663
  char       *path;
664
  int32_t     szPage;
665
  int32_t     flag;
666
  TdFilePtr   pFD;
667
  int64_t     pgno;
668
  uint8_t    *pBuf;
669
  int64_t     szFile;
670
  STsdb      *pTsdb;
671
  const char *objName;
672
  uint8_t     ssFile;
673
  int32_t     lcn;
674
  int32_t     fid;
675
  int64_t     cid;
676
  int64_t     blkno;
677
} STsdbFD;
678

679
struct SDelFWriter {
680
  STsdb   *pTsdb;
681
  SDelFile fDel;
682
  STsdbFD *pWriteH;
683
  uint8_t *aBuf[1];
684
};
685

686
#include "tarray2.h"
687
typedef struct STFileSet STFileSet;
688
typedef TARRAY2(STFileSet *) TFileSetArray;
689

690
// fset range
691
typedef struct STFileSetRange STFileSetRange;
692
typedef TARRAY2(STFileSetRange *) TFileSetRangeArray;  // disjoint ranges
693

694
void tsdbTFileSetRangeClear(STFileSetRange **fsr);
695
void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr);
696

697
// fset partition
698
enum {
699
  TSDB_FSET_RANGE_TYP_HEAD = 0,
700
  TSDB_FSET_RANGE_TYP_DATA,
701
  TSDB_FSET_RANGE_TYP_SMA,
702
  TSDB_FSET_RANGE_TYP_TOMB,
703
  TSDB_FSET_RANGE_TYP_STT,
704
  TSDB_FSET_RANGE_TYP_MAX,
705
};
706

707
typedef TARRAY2(SVersionRange) SVerRangeList;
708

709
struct STsdbFSetPartition {
710
  int64_t       fid;
711
  int8_t        stat;
712
  SVerRangeList verRanges[TSDB_FSET_RANGE_TYP_MAX];
713
};
714

715
typedef struct STsdbFSetPartition STsdbFSetPartition;
716
typedef TARRAY2(STsdbFSetPartition *) STsdbFSetPartList;
717

718
STsdbFSetPartList *tsdbFSetPartListCreate();
719
void               tsdbFSetPartListDestroy(STsdbFSetPartList **ppList);
720
int32_t            tDeserializeTsdbFSetPartList(void *buf, int32_t bufLen, STsdbFSetPartList *pList);
721
int32_t            tsdbFSetPartListToRangeDiff(STsdbFSetPartList *pList, TFileSetRangeArray **ppRanges);
722

723
// snap rep format
724
typedef enum ETsdbRepFmt {
725
  TSDB_SNAP_REP_FMT_DEFAULT = 0,
726
  TSDB_SNAP_REP_FMT_RAW,
727
  TSDB_SNAP_REP_FMT_HYBRID,
728
} ETsdbRepFmt;
729

730
typedef struct STsdbRepOpts {
731
  ETsdbRepFmt format;
732
} STsdbRepOpts;
733

734
int32_t tSerializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
735
int32_t tDeserializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
736

737
// snap read
738
struct STsdbReadSnap {
739
  SMemTable     *pMem;
740
  SQueryNode    *pNode;
741
  SMemTable     *pIMem;
742
  SQueryNode    *pINode;
743
  TFileSetArray *pfSetArray;
744
};
745

746
struct SDataFWriter {
747
  STsdb    *pTsdb;
748
  SDFileSet wSet;
749

750
  STsdbFD *pHeadFD;
751
  STsdbFD *pDataFD;
752
  STsdbFD *pSmaFD;
753
  STsdbFD *pSttFD;
754

755
  SHeadFile fHead;
756
  SDataFile fData;
757
  SSmaFile  fSma;
758
  SSttFile  fStt[TSDB_STT_TRIGGER_ARRAY_SIZE];
759

760
  uint8_t *aBuf[4];
761
};
762

763
struct SDataFReader {
764
  STsdb     *pTsdb;
765
  SDFileSet *pSet;
766
  STsdbFD   *pHeadFD;
767
  STsdbFD   *pDataFD;
768
  STsdbFD   *pSmaFD;
769
  STsdbFD   *aSttFD[TSDB_STT_TRIGGER_ARRAY_SIZE];
770
  uint8_t   *aBuf[3];
771
};
772

773
// NOTE: do NOT change the order of the fields
774
typedef struct {
775
  int64_t suid;
776
  int64_t uid;
777
  TSDBROW row;
778
} SRowInfo;
779

780
typedef struct SSttBlockLoadCostInfo {
781
  int64_t loadBlocks;
782
  int64_t loadStatisBlocks;
783
  double  blockElapsedTime;
784
  double  statisElapsedTime;
785
} SSttBlockLoadCostInfo;
786

787
typedef struct SBlockDataInfo {
788
  SBlockData data;
789
  bool       pin;
790
  int32_t    sttBlockIndex;
791
} SBlockDataInfo;
792

793
// todo: move away
794
typedef struct {
795
  int32_t memSize;
796
  SArray *pUid;
797
  SArray *pFirstTs;
798
  SArray *pLastTs;
799
  SArray *pCount;
800
  SArray *pFirstKey;
801
  SArray *pLastKey;
802
} SSttTableRowsInfo;
803

804
typedef struct SSttBlockLoadInfo {
805
  SBlockDataInfo        blockData[2];  // buffered block data
806
  SArray               *aSttBlk;
807
  int32_t               currentLoadBlockIndex;
808
  STSchema             *pSchema;
809
  int16_t              *colIds;
810
  int32_t               numOfCols;
811
  bool                  checkRemainingRow;  // todo: no assign value?
812
  bool                  isLast;
813
  bool                  sttBlockLoaded;
814
  SSttTableRowsInfo     info;
815
  SSttBlockLoadCostInfo cost;
816
} SSttBlockLoadInfo;
817

818
typedef struct SMergeTree {
819
  int8_t      backward;
820
  SRBTree     rbt;
821
  SLDataIter *pIter;
822
  SLDataIter *pPinnedBlockIter;
823
  const char *idStr;
824
  bool        ignoreEarlierTs;
825
} SMergeTree;
826

827
typedef struct {
828
  int64_t   suid;
829
  int64_t   uid;
830
  STSchema *pTSchema;
831
} SSkmInfo;
832

833
struct SDiskCol {
834
  SBlockCol      bCol;
835
  const uint8_t *pBit;
836
  const uint8_t *pOff;
837
  const uint8_t *pVal;
838
  SColumnDataAgg agg;
839
};
840

841
struct SDiskData {
842
  SDiskDataHdr   hdr;
843
  const uint8_t *pUid;
844
  const uint8_t *pVer;
845
  const uint8_t *pKey;
846
  SArray        *aDiskCol;  // SArray<SDiskCol>
847
};
848

849
struct SDiskDataBuilder {
850
  int64_t      suid;
851
  int64_t      uid;
852
  int32_t      nRow;
853
  uint8_t      cmprAlg;
854
  uint8_t      calcSma;
855
  SCompressor *pUidC;
856
  SCompressor *pVerC;
857
  SCompressor *pKeyC;
858
  int32_t      nBuilder;
859
  SArray      *aBuilder;  // SArray<SDiskColBuilder>
860
  uint8_t     *aBuf[2];
861
  SDiskData    dd;
862
  SBlkInfo     bi;
863
};
864

865
struct SLDataIter {
866
  SRBTreeNode            node;
867
  SSttBlk               *pSttBlk;
868
  int64_t                cid;  // for debug purpose
869
  int8_t                 backward;
870
  int32_t                iSttBlk;
871
  int32_t                iRow;
872
  SRowInfo               rInfo;
873
  uint64_t               uid;
874
  STimeWindow            timeWindow;
875
  SVersionRange          verRange;
876
  SSttBlockLoadInfo     *pBlockLoadInfo;
877
  SRowKey               *pStartRowKey;  // current row key
878
  bool                   ignoreEarlierTs;
879
  struct SSttFileReader *pReader;
880
};
881

882
#define tMergeTreeGetRow(_t) (&((_t)->pIter->rInfo.row))
883

884
struct SSttFileReader;
885
typedef int32_t (*_load_tomb_fn)(STsdbReader *pReader, struct SSttFileReader *pSttFileReader,
886
                                 SSttBlockLoadInfo *pLoadInfo);
887

888
typedef struct SMergeTreeConf {
889
  int8_t        backward;
890
  STsdb        *pTsdb;
891
  uint64_t      suid;
892
  uint64_t      uid;
893
  STimeWindow   timewindow;
894
  SVersionRange verRange;
895
  bool          strictTimeRange;
896
  bool          cacheStatis;    // cache the stt statis file info in cache
897
  SArray       *pSttFileBlockIterArray;
898
  void         *pCurrentFileset;
899
  STSchema     *pSchema;
900
  int16_t      *pCols;
901
  int32_t       numOfCols;
902
  SRowKey      *pCurRowKey;
903
  _load_tomb_fn loadTombFn;
904
  void         *pReader;
905
  void         *idstr;
906
  bool          rspRows;  // response the rows in stt-file, if possible
907
} SMergeTreeConf;
908

909
typedef struct SSttDataInfoForTable {
910
  SArray *pKeyRangeList;
911
  int64_t numOfRows;
912
} SSttDataInfoForTable;
913

914
int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoForTable *pTableInfo);
915
void    tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
916
int32_t tMergeTreeNext(SMergeTree *pMTree, bool *pHasNext);
917
void    tMergeTreePinSttBlock(SMergeTree *pMTree);
918
void    tMergeTreeUnpinSttBlock(SMergeTree *pMTree);
919
bool    tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree);
920
void    tMergeTreeClose(SMergeTree *pMTree);
921

922
int32_t tCreateSttBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t numOfCols, SSttBlockLoadInfo **pInfo);
923
void    destroySttBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo);
924
void    destroySttBlockReader(SArray *pLDataIterArray, SSttBlockLoadCostInfo *pLoadCost);
925

926
// tsdbCache ==============================================================================================
927
typedef enum {
928
  READER_EXEC_DATA = 0x1,
929
  READER_EXEC_ROWS = 0x2,
930
} EExecMode;
931

932
#define LAST_COL_VERSION_1 (0x1)  // add primary key, version
933
#define LAST_COL_VERSION_2 (0x2)  // add cache status
934
#define LAST_COL_VERSION   LAST_COL_VERSION_2
935

936
typedef enum {
937
  TSDB_LAST_CACHE_VALID = 0,  // last_cache has valid data
938
  TSDB_LAST_CACHE_NO_CACHE,   // last_cache has no data, but tsdb may have data
939
} ELastCacheStatus;
940

941
typedef struct {
942
  SRowKey          rowKey;
943
  int8_t           dirty;
944
  SColVal          colVal;
945
  ELastCacheStatus cacheStatus;
946
} SLastCol;
947

948
typedef struct {
949
  int8_t      lflag;
950
  STsdbRowKey tsdbRowKey;
951
  SColVal     colVal;
952
} SLastUpdateCtx;
953

954
int32_t tsdbOpenCache(STsdb *pTsdb);
955
void    tsdbCloseCache(STsdb *pTsdb);
956
int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int64_t version, int32_t nRow, SRow **aRow);
957
int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlockData *pBlockData);
958
int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
959

960
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, TSDBROW *row, STsdb *pTsdb);
961
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, TSDBROW *row, bool dup);
962
void    tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h);
963

964
int32_t tsdbCacheGetBlockIdx(SLRUCache *pCache, SDataFReader *pFileReader, LRUHandle **handle);
965
int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h);
966

967
int32_t tsdbCacheGetBlockSs(SLRUCache *pCache, STsdbFD *pFD, LRUHandle **handle);
968
int32_t tsdbCacheGetPageSs(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, LRUHandle **handle);
969
void    tsdbCacheSetPageSs(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, uint8_t *pPage);
970

971
int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
972
int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
973
int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
974

975
int32_t tsdbGetFsSize(STsdb *tsdb, SDbSizeStatisInfo *pInfo);
976

977
// ========== inline functions ==========
978
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
979
  TSDBKEY *pKey1 = (TSDBKEY *)p1;
980
  TSDBKEY *pKey2 = (TSDBKEY *)p2;
981

982
  if (pKey1->ts < pKey2->ts) {
983
    return -1;
984
  } else if (pKey1->ts > pKey2->ts) {
985
    return 1;
986
  }
987

988
  if (pKey1->version < pKey2->version) {
989
    return -1;
990
  } else if (pKey1->version > pKey2->version) {
991
    return 1;
992
  }
993

994
  return 0;
995
}
996

997
// #define SL_NODE_FORWARD(n, l)  ((n)->forwards[l])
998
// #define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
999

1000
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
1001
  if (pIter == NULL) return NULL;
2,147,483,647✔
1002

1003
  if (pIter->pRow) {
2,147,483,647✔
1004
    return pIter->pRow;
2,147,483,647✔
1005
  }
1006

1007
  if (pIter->backward) {
2,147,483,647✔
1008
    if (pIter->pNode == pIter->pTbData->sl.pHead) {
2,147,483,647✔
1009
      return NULL;
378,756✔
1010
    }
1011
  } else {
1012
    if (pIter->pNode == pIter->pTbData->sl.pTail) {
2,147,483,647✔
1013
      return NULL;
114,165,288✔
1014
    }
1015
  }
1016

1017
  pIter->pRow = &pIter->row;
2,147,483,647✔
1018
  pIter->row = pIter->pNode->row;
2,147,483,647✔
1019

1020
  return pIter->pRow;
2,147,483,647✔
1021
}
1022

1023
typedef struct {
1024
  int64_t  suid;
1025
  int64_t  uid;
1026
  SDelData delData;
1027
} SDelInfo;
1028

1029
struct STsdbDataIter2 {
1030
  STsdbDataIter2 *next;
1031
  SRBTreeNode     rbtn;
1032

1033
  int32_t  type;
1034
  SRowInfo rowInfo;
1035
  SDelInfo delInfo;
1036
  union {
1037
    // TSDB_MEM_TABLE_DATA_ITER
1038
    struct {
1039
      SMemTable *pMemTable;
1040
    } mIter;
1041

1042
    // TSDB_DATA_FILE_DATA_ITER
1043
    struct {
1044
      SDataFReader *pReader;
1045
      SArray       *aBlockIdx;  // SArray<SBlockIdx>
1046
      SMapData      mDataBlk;
1047
      SBlockData    bData;
1048
      int32_t       iBlockIdx;
1049
      int32_t       iDataBlk;
1050
      int32_t       iRow;
1051
    } dIter;
1052

1053
    // TSDB_STT_FILE_DATA_ITER
1054
    struct {
1055
      SDataFReader *pReader;
1056
      int32_t       iStt;
1057
      SArray       *aSttBlk;
1058
      SBlockData    bData;
1059
      int32_t       iSttBlk;
1060
      int32_t       iRow;
1061
    } sIter;
1062
    // TSDB_TOMB_FILE_DATA_ITER
1063
    struct {
1064
      SDelFReader *pReader;
1065
      SArray      *aDelIdx;
1066
      SArray      *aDelData;
1067
      int32_t      iDelIdx;
1068
      int32_t      iDelData;
1069
    } tIter;
1070
  };
1071
};
1072

1073
struct STsdbFilterInfo {
1074
  int32_t flag;
1075
  int64_t sver;
1076
  int64_t ever;
1077
  TABLEID tbid;
1078
};
1079

1080
typedef enum {
1081
  TSDB_FS_STATE_NORMAL = 0,
1082
  TSDB_FS_STATE_INCOMPLETE,
1083
} ETsdbFsState;
1084

1085
// utils
1086
ETsdbFsState tsdbSnapGetFsState(SVnode *pVnode);
1087
int32_t      tsdbSnapPrepDescription(SVnode *pVnode, SSnapshot *pSnap);
1088

1089
void tsdbRemoveFile(const char *path);
1090

1091
#define taosCloseFileWithLog(fd)         \
1092
  do {                                   \
1093
    if (taosCloseFile(fd) < 0) {         \
1094
      tsdbTrace("failed to close file"); \
1095
    }                                    \
1096
  } while (0)
1097

1098
int32_t tsdbAllocateDisk(STsdb *tsdb, const char *label, int32_t expLevel, SDiskID *diskId);
1099
int32_t tsdbAllocateDiskAtLevel(STsdb *tsdb, int32_t level, const char *label, SDiskID *diskId);
1100

1101
#ifdef __cplusplus
1102
}
1103
#endif
1104

1105
#endif /*_TD_VNODE_TSDB_H_*/
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