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

taosdata / TDengine / #4488

12 Jul 2025 07:47AM UTC coverage: 62.207% (-0.7%) from 62.948%
#4488

push

travis-ci

web-flow
docs: update stream docs (#31822)

157961 of 324087 branches covered (48.74%)

Branch coverage included in aggregate %.

244465 of 322830 relevant lines covered (75.73%)

6561668.76 hits per line

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

39.2
/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);
×
103
  int64_t pgno = OFFSET_PGNO(fOffSet, szPage);
×
104

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

109
  return pgno * szPage;
×
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

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

390
struct TSDBKEY {
391
  int64_t version;
392
  TSKEY   ts;
393
};
394

395
typedef struct SMemSkipListNode SMemSkipListNode;
396
typedef struct SMemSkipList {
397
  int64_t           size;
398
  uint32_t          seed;
399
  int8_t            maxLevel;
400
  int8_t            level;
401
  SMemSkipListNode *pHead;
402
  SMemSkipListNode *pTail;
403
} SMemSkipList;
404

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

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

435
struct TSDBROW {
436
  int8_t type;  // TSDBROW_ROW_FMT for row from tsRow, TSDBROW_COL_FMT for row from block data
437
  union {
438
    struct {
439
      int64_t version;
440
      SRow   *pTSRow;
441
    };
442
    struct {
443
      SBlockData *pBlockData;
444
      int32_t     iRow;
445
    };
446
  };
447
};
448

449
struct SMemSkipListNode {
450
  int8_t            level;
451
  TSDBROW           row;
452
  SMemSkipListNode *forwards[0];
453
};
454

455
struct STsdbRowKey {
456
  SRowKey key;
457
  int64_t version;
458
};
459

460
struct SBlockIdx {
461
  int64_t suid;
462
  int64_t uid;
463
  int64_t offset;
464
  int64_t size;
465
};
466

467
struct SMapData {
468
  int32_t  nItem;
469
  int32_t  nData;
470
  int32_t *aOffset;
471
  uint8_t *pData;
472
};
473

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

487
struct SBlockInfo {
488
  int64_t offset;  // block data offset
489
  int32_t szBlock;
490
  int32_t szKey;
491
};
492

493
struct SSmaInfo {
494
  int64_t offset;
495
  int32_t size;
496
};
497

498
struct SBlkInfo {
499
  int64_t minUid;
500
  int64_t maxUid;
501
  TSKEY   minKey;
502
  TSKEY   maxKey;
503
  int64_t minVer;
504
  int64_t maxVer;
505
  TSDBKEY minTKey;
506
  TSDBKEY maxTKey;
507
};
508

509
struct SDataBlk {
510
  TSDBKEY    minKey;
511
  TSDBKEY    maxKey;
512
  int64_t    minVer;
513
  int64_t    maxVer;
514
  int32_t    nRow;
515
  int8_t     hasDup;
516
  int8_t     nSubBlock;
517
  SBlockInfo aSubBlock[1];
518
  SSmaInfo   smaInfo;
519
};
520

521
struct SSttBlk {
522
  int64_t    suid;
523
  int64_t    minUid;
524
  int64_t    maxUid;
525
  TSKEY      minKey;
526
  TSKEY      maxKey;
527
  int64_t    minVer;
528
  int64_t    maxVer;
529
  int32_t    nRow;
530
  SBlockInfo bInfo;
531
};
532

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

548
struct TABLEID {
549
  tb_uid_t suid;
550
  tb_uid_t uid;
551
};
552

553
struct STbDataIter {
554
  STbData          *pTbData;
555
  int8_t            backward;
556
  SMemSkipListNode *pNode;
557
  TSDBROW          *pRow;
558
  TSDBROW           row;
559
};
560

561
struct SDelData {
562
  int64_t   version;
563
  TSKEY     sKey;
564
  TSKEY     eKey;
565
  SDelData *pNext;
566
};
567

568
struct SDelIdx {
569
  tb_uid_t suid;
570
  tb_uid_t uid;
571
  int64_t  offset;
572
  int64_t  size;
573
};
574

575
struct SDiskDataHdr {
576
  uint32_t delimiter;
577
  uint32_t fmtVer;
578
  int64_t  suid;
579
  int64_t  uid;
580
  int32_t  szUid;
581
  int32_t  szVer;
582
  int32_t  szKey;
583
  int32_t  szBlkCol;
584
  int32_t  nRow;
585
  uint32_t cmprAlg;
586

587
  // fmtVer == 1
588
  int8_t    numOfPKs;
589
  SBlockCol primaryBlockCols[TD_MAX_PK_COLS];
590
};
591

592
struct SDelFile {
593
  volatile int32_t nRef;
594

595
  int64_t commitID;
596
  int64_t size;
597
  int64_t offset;
598
};
599

600
struct SHeadFile {
601
  volatile int32_t nRef;
602

603
  int64_t commitID;
604
  int64_t size;
605
  int64_t offset;
606
};
607

608
struct SDataFile {
609
  volatile int32_t nRef;
610

611
  int64_t commitID;
612
  int64_t size;
613
};
614

615
struct SSttFile {
616
  volatile int32_t nRef;
617

618
  int64_t commitID;
619
  int64_t size;
620
  int64_t offset;
621
};
622

623
struct SSmaFile {
624
  volatile int32_t nRef;
625

626
  int64_t commitID;
627
  int64_t size;
628
};
629

630
struct SDFileSet {
631
  SDiskID    diskId;
632
  int32_t    fid;
633
  SHeadFile *pHeadF;
634
  SDataFile *pDataF;
635
  SSmaFile  *pSmaF;
636
  uint8_t    nSttF;
637
  SSttFile  *aSttF[TSDB_STT_TRIGGER_ARRAY_SIZE];
638
};
639

640
struct STSDBRowIter {
641
  TSDBROW *pRow;
642
  union {
643
    SRowIter *pIter;
644
    struct {
645
      int32_t iColData;
646
      SColVal cv;
647
    };
648
  };
649
};
650
struct SRowMerger {
651
  STSchema *pTSchema;
652
  int64_t   version;
653
  SArray   *pArray;  // SArray<SColVal>
654
};
655

656
typedef struct {
657
  char       *path;
658
  int32_t     szPage;
659
  int32_t     flag;
660
  TdFilePtr   pFD;
661
  int64_t     pgno;
662
  uint8_t    *pBuf;
663
  int64_t     szFile;
664
  STsdb      *pTsdb;
665
  const char *objName;
666
  uint8_t     s3File;
667
  int32_t     lcn;
668
  int32_t     fid;
669
  int64_t     cid;
670
  int64_t     blkno;
671
} STsdbFD;
672

673
struct SDelFWriter {
674
  STsdb   *pTsdb;
675
  SDelFile fDel;
676
  STsdbFD *pWriteH;
677
  uint8_t *aBuf[1];
678
};
679

680
#include "tarray2.h"
681
typedef struct STFileSet STFileSet;
682
typedef TARRAY2(STFileSet *) TFileSetArray;
683

684
// fset range
685
typedef struct STFileSetRange STFileSetRange;
686
typedef TARRAY2(STFileSetRange *) TFileSetRangeArray;  // disjoint ranges
687

688
void tsdbTFileSetRangeClear(STFileSetRange **fsr);
689
void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr);
690

691
// fset partition
692
enum {
693
  TSDB_FSET_RANGE_TYP_HEAD = 0,
694
  TSDB_FSET_RANGE_TYP_DATA,
695
  TSDB_FSET_RANGE_TYP_SMA,
696
  TSDB_FSET_RANGE_TYP_TOMB,
697
  TSDB_FSET_RANGE_TYP_STT,
698
  TSDB_FSET_RANGE_TYP_MAX,
699
};
700

701
typedef TARRAY2(SVersionRange) SVerRangeList;
702

703
struct STsdbFSetPartition {
704
  int64_t       fid;
705
  int8_t        stat;
706
  SVerRangeList verRanges[TSDB_FSET_RANGE_TYP_MAX];
707
};
708

709
typedef struct STsdbFSetPartition STsdbFSetPartition;
710
typedef TARRAY2(STsdbFSetPartition *) STsdbFSetPartList;
711

712
STsdbFSetPartList *tsdbFSetPartListCreate();
713
void               tsdbFSetPartListDestroy(STsdbFSetPartList **ppList);
714
int32_t            tDeserializeTsdbFSetPartList(void *buf, int32_t bufLen, STsdbFSetPartList *pList);
715
int32_t            tsdbFSetPartListToRangeDiff(STsdbFSetPartList *pList, TFileSetRangeArray **ppRanges);
716

717
// snap rep format
718
typedef enum ETsdbRepFmt {
719
  TSDB_SNAP_REP_FMT_DEFAULT = 0,
720
  TSDB_SNAP_REP_FMT_RAW,
721
  TSDB_SNAP_REP_FMT_HYBRID,
722
} ETsdbRepFmt;
723

724
typedef struct STsdbRepOpts {
725
  ETsdbRepFmt format;
726
} STsdbRepOpts;
727

728
int32_t tSerializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
729
int32_t tDeserializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
730

731
// snap read
732
struct STsdbReadSnap {
733
  SMemTable     *pMem;
734
  SQueryNode    *pNode;
735
  SMemTable     *pIMem;
736
  SQueryNode    *pINode;
737
  TFileSetArray *pfSetArray;
738
};
739

740
struct SDataFWriter {
741
  STsdb    *pTsdb;
742
  SDFileSet wSet;
743

744
  STsdbFD *pHeadFD;
745
  STsdbFD *pDataFD;
746
  STsdbFD *pSmaFD;
747
  STsdbFD *pSttFD;
748

749
  SHeadFile fHead;
750
  SDataFile fData;
751
  SSmaFile  fSma;
752
  SSttFile  fStt[TSDB_STT_TRIGGER_ARRAY_SIZE];
753

754
  uint8_t *aBuf[4];
755
};
756

757
struct SDataFReader {
758
  STsdb     *pTsdb;
759
  SDFileSet *pSet;
760
  STsdbFD   *pHeadFD;
761
  STsdbFD   *pDataFD;
762
  STsdbFD   *pSmaFD;
763
  STsdbFD   *aSttFD[TSDB_STT_TRIGGER_ARRAY_SIZE];
764
  uint8_t   *aBuf[3];
765
};
766

767
// NOTE: do NOT change the order of the fields
768
typedef struct {
769
  int64_t suid;
770
  int64_t uid;
771
  TSDBROW row;
772
} SRowInfo;
773

774
typedef struct SSttBlockLoadCostInfo {
775
  int64_t loadBlocks;
776
  int64_t loadStatisBlocks;
777
  double  blockElapsedTime;
778
  double  statisElapsedTime;
779
} SSttBlockLoadCostInfo;
780

781
typedef struct SBlockDataInfo {
782
  SBlockData data;
783
  bool       pin;
784
  int32_t    sttBlockIndex;
785
} SBlockDataInfo;
786

787
// todo: move away
788
typedef struct {
789
  SArray *pUid;
790
  SArray *pFirstTs;
791
  SArray *pLastTs;
792
  SArray *pCount;
793
  SArray *pFirstKey;
794
  SArray *pLastKey;
795
} SSttTableRowsInfo;
796

797
typedef struct SSttBlockLoadInfo {
798
  SBlockDataInfo        blockData[2];  // buffered block data
799
  SArray               *aSttBlk;
800
  int32_t               currentLoadBlockIndex;
801
  STSchema             *pSchema;
802
  int16_t              *colIds;
803
  int32_t               numOfCols;
804
  bool                  checkRemainingRow;  // todo: no assign value?
805
  bool                  isLast;
806
  bool                  sttBlockLoaded;
807
  SSttTableRowsInfo     info;
808
  SSttBlockLoadCostInfo cost;
809
} SSttBlockLoadInfo;
810

811
typedef struct SMergeTree {
812
  int8_t      backward;
813
  SRBTree     rbt;
814
  SLDataIter *pIter;
815
  SLDataIter *pPinnedBlockIter;
816
  const char *idStr;
817
  bool        ignoreEarlierTs;
818
} SMergeTree;
819

820
typedef struct {
821
  int64_t   suid;
822
  int64_t   uid;
823
  STSchema *pTSchema;
824
} SSkmInfo;
825

826
struct SDiskCol {
827
  SBlockCol      bCol;
828
  const uint8_t *pBit;
829
  const uint8_t *pOff;
830
  const uint8_t *pVal;
831
  SColumnDataAgg agg;
832
};
833

834
struct SDiskData {
835
  SDiskDataHdr   hdr;
836
  const uint8_t *pUid;
837
  const uint8_t *pVer;
838
  const uint8_t *pKey;
839
  SArray        *aDiskCol;  // SArray<SDiskCol>
840
};
841

842
struct SDiskDataBuilder {
843
  int64_t      suid;
844
  int64_t      uid;
845
  int32_t      nRow;
846
  uint8_t      cmprAlg;
847
  uint8_t      calcSma;
848
  SCompressor *pUidC;
849
  SCompressor *pVerC;
850
  SCompressor *pKeyC;
851
  int32_t      nBuilder;
852
  SArray      *aBuilder;  // SArray<SDiskColBuilder>
853
  uint8_t     *aBuf[2];
854
  SDiskData    dd;
855
  SBlkInfo     bi;
856
};
857

858
struct SLDataIter {
859
  SRBTreeNode            node;
860
  SSttBlk               *pSttBlk;
861
  int64_t                cid;  // for debug purpose
862
  int8_t                 backward;
863
  int32_t                iSttBlk;
864
  int32_t                iRow;
865
  SRowInfo               rInfo;
866
  uint64_t               uid;
867
  STimeWindow            timeWindow;
868
  SVersionRange          verRange;
869
  SSttBlockLoadInfo     *pBlockLoadInfo;
870
  SRowKey               *pStartRowKey;  // current row key
871
  bool                   ignoreEarlierTs;
872
  struct SSttFileReader *pReader;
873
};
874

875
#define tMergeTreeGetRow(_t) (&((_t)->pIter->rInfo.row))
876

877
struct SSttFileReader;
878
typedef int32_t (*_load_tomb_fn)(STsdbReader *pReader, struct SSttFileReader *pSttFileReader,
879
                                 SSttBlockLoadInfo *pLoadInfo);
880

881
typedef struct SMergeTreeConf {
882
  int8_t        backward;
883
  STsdb        *pTsdb;
884
  uint64_t      suid;
885
  uint64_t      uid;
886
  STimeWindow   timewindow;
887
  SVersionRange verRange;
888
  bool          strictTimeRange;
889
  SArray       *pSttFileBlockIterArray;
890
  void         *pCurrentFileset;
891
  STSchema     *pSchema;
892
  int16_t      *pCols;
893
  int32_t       numOfCols;
894
  SRowKey      *pCurRowKey;
895
  _load_tomb_fn loadTombFn;
896
  void         *pReader;
897
  void         *idstr;
898
  bool          rspRows;  // response the rows in stt-file, if possible
899
} SMergeTreeConf;
900

901
typedef struct SSttDataInfoForTable {
902
  SArray *pKeyRangeList;
903
  int64_t numOfRows;
904
} SSttDataInfoForTable;
905

906
int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoForTable *pTableInfo);
907
void    tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
908
int32_t tMergeTreeNext(SMergeTree *pMTree, bool *pHasNext);
909
void    tMergeTreePinSttBlock(SMergeTree *pMTree);
910
void    tMergeTreeUnpinSttBlock(SMergeTree *pMTree);
911
bool    tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree);
912
void    tMergeTreeClose(SMergeTree *pMTree);
913

914
int32_t tCreateSttBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t numOfCols, SSttBlockLoadInfo **pInfo);
915
void    destroySttBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo);
916
void    destroySttBlockReader(SArray *pLDataIterArray, SSttBlockLoadCostInfo *pLoadCost);
917

918
// tsdbCache ==============================================================================================
919
typedef enum {
920
  READER_EXEC_DATA = 0x1,
921
  READER_EXEC_ROWS = 0x2,
922
} EExecMode;
923

924
#define LAST_COL_VERSION_1 (0x1)  // add primary key, version
925
#define LAST_COL_VERSION_2 (0x2)  // add cache status
926
#define LAST_COL_VERSION   LAST_COL_VERSION_2
927

928
typedef enum {
929
  TSDB_LAST_CACHE_VALID = 0,  // last_cache has valid data
930
  TSDB_LAST_CACHE_NO_CACHE,   // last_cache has no data, but tsdb may have data
931
} ELastCacheStatus;
932

933
typedef struct {
934
  SRowKey          rowKey;
935
  int8_t           dirty;
936
  SColVal          colVal;
937
  ELastCacheStatus cacheStatus;
938
} SLastCol;
939

940
typedef struct {
941
  int8_t      lflag;
942
  STsdbRowKey tsdbRowKey;
943
  SColVal     colVal;
944
} SLastUpdateCtx;
945

946
int32_t tsdbOpenCache(STsdb *pTsdb);
947
void    tsdbCloseCache(STsdb *pTsdb);
948
int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int64_t version, int32_t nRow, SRow **aRow);
949
int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlockData *pBlockData);
950
int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
951

952
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, TSDBROW *row, STsdb *pTsdb);
953
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, TSDBROW *row, bool dup);
954
void    tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h);
955

956
int32_t tsdbCacheGetBlockIdx(SLRUCache *pCache, SDataFReader *pFileReader, LRUHandle **handle);
957
int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h);
958

959
int32_t tsdbCacheGetBlockS3(SLRUCache *pCache, STsdbFD *pFD, LRUHandle **handle);
960
int32_t tsdbCacheGetPageS3(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, LRUHandle **handle);
961
void    tsdbCacheSetPageS3(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, uint8_t *pPage);
962

963
int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
964
int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
965
int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
966

967
int32_t tsdbGetFsSize(STsdb *tsdb, SDbSizeStatisInfo *pInfo);
968

969
// ========== inline functions ==========
970
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
971
  TSDBKEY *pKey1 = (TSDBKEY *)p1;
972
  TSDBKEY *pKey2 = (TSDBKEY *)p2;
973

974
  if (pKey1->ts < pKey2->ts) {
975
    return -1;
976
  } else if (pKey1->ts > pKey2->ts) {
977
    return 1;
978
  }
979

980
  if (pKey1->version < pKey2->version) {
981
    return -1;
982
  } else if (pKey1->version > pKey2->version) {
983
    return 1;
984
  }
985

986
  return 0;
987
}
988

989
// #define SL_NODE_FORWARD(n, l)  ((n)->forwards[l])
990
// #define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
991

992
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
993
  if (pIter == NULL) return NULL;
1,355,766,485!
994

995
  if (pIter->pRow) {
1,355,766,485!
996
    return pIter->pRow;
656,025,920✔
997
  }
998

999
  if (pIter->backward) {
699,740,565!
1000
    if (pIter->pNode == pIter->pTbData->sl.pHead) {
58,442,770!
1001
      return NULL;
1,249✔
1002
    }
1003
  } else {
1004
    if (pIter->pNode == pIter->pTbData->sl.pTail) {
641,297,795!
1005
      return NULL;
1,045,007✔
1006
    }
1007
  }
1008

1009
  pIter->pRow = &pIter->row;
698,694,309✔
1010
  pIter->row = pIter->pNode->row;
698,694,309✔
1011

1012
  return pIter->pRow;
698,694,309✔
1013
}
1014

1015
typedef struct {
1016
  int64_t  suid;
1017
  int64_t  uid;
1018
  SDelData delData;
1019
} SDelInfo;
1020

1021
struct STsdbDataIter2 {
1022
  STsdbDataIter2 *next;
1023
  SRBTreeNode     rbtn;
1024

1025
  int32_t  type;
1026
  SRowInfo rowInfo;
1027
  SDelInfo delInfo;
1028
  union {
1029
    // TSDB_MEM_TABLE_DATA_ITER
1030
    struct {
1031
      SMemTable *pMemTable;
1032
    } mIter;
1033

1034
    // TSDB_DATA_FILE_DATA_ITER
1035
    struct {
1036
      SDataFReader *pReader;
1037
      SArray       *aBlockIdx;  // SArray<SBlockIdx>
1038
      SMapData      mDataBlk;
1039
      SBlockData    bData;
1040
      int32_t       iBlockIdx;
1041
      int32_t       iDataBlk;
1042
      int32_t       iRow;
1043
    } dIter;
1044

1045
    // TSDB_STT_FILE_DATA_ITER
1046
    struct {
1047
      SDataFReader *pReader;
1048
      int32_t       iStt;
1049
      SArray       *aSttBlk;
1050
      SBlockData    bData;
1051
      int32_t       iSttBlk;
1052
      int32_t       iRow;
1053
    } sIter;
1054
    // TSDB_TOMB_FILE_DATA_ITER
1055
    struct {
1056
      SDelFReader *pReader;
1057
      SArray      *aDelIdx;
1058
      SArray      *aDelData;
1059
      int32_t      iDelIdx;
1060
      int32_t      iDelData;
1061
    } tIter;
1062
  };
1063
};
1064

1065
struct STsdbFilterInfo {
1066
  int32_t flag;
1067
  int64_t sver;
1068
  int64_t ever;
1069
  TABLEID tbid;
1070
};
1071

1072
typedef enum {
1073
  TSDB_FS_STATE_NORMAL = 0,
1074
  TSDB_FS_STATE_INCOMPLETE,
1075
} ETsdbFsState;
1076

1077
// utils
1078
ETsdbFsState tsdbSnapGetFsState(SVnode *pVnode);
1079
int32_t      tsdbSnapPrepDescription(SVnode *pVnode, SSnapshot *pSnap);
1080

1081
void tsdbRemoveFile(const char *path);
1082

1083
#define taosCloseFileWithLog(fd)         \
1084
  do {                                   \
1085
    if (taosCloseFile(fd) < 0) {         \
1086
      tsdbTrace("failed to close file"); \
1087
    }                                    \
1088
  } while (0)
1089

1090
int32_t tsdbAllocateDisk(STsdb *tsdb, const char *label, int32_t expLevel, SDiskID *diskId);
1091
int32_t tsdbAllocateDiskAtLevel(STsdb *tsdb, int32_t level, const char *label, SDiskID *diskId);
1092

1093
#ifdef __cplusplus
1094
}
1095
#endif
1096

1097
#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