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

taosdata / TDengine / #4513

17 Jul 2025 02:02AM UTC coverage: 31.359% (-31.1%) from 62.446%
#4513

push

travis-ci

web-flow
Merge pull request #31914 from taosdata/fix/3.0/compare-ans-failed

fix:Convert line endings from LF to CRLF for ans file

68541 of 301034 branches covered (22.77%)

Branch coverage included in aggregate %.

117356 of 291771 relevant lines covered (40.22%)

602262.98 hits per line

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

13.6
/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
typedef struct SSsMigrateMonitor SSsMigrateMonitor;
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
  SSsMigrateMonitor   *pSsMigrateMonitor;
385
  struct {
386
    SVHashTable *ht;
387
    SArray      *arr;
388
  } *commitInfo;
389
};
390

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

593
struct SDelFile {
594
  volatile int32_t nRef;
595

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

601
struct SHeadFile {
602
  volatile int32_t nRef;
603

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

609
struct SDataFile {
610
  volatile int32_t nRef;
611

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

616
struct SSttFile {
617
  volatile int32_t nRef;
618

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

624
struct SSmaFile {
625
  volatile int32_t nRef;
626

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

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

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

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

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

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

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

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

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

702
typedef TARRAY2(SVersionRange) SVerRangeList;
703

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

960
int32_t tsdbCacheGetBlockSs(SLRUCache *pCache, STsdbFD *pFD, LRUHandle **handle);
961
int32_t tsdbCacheGetPageSs(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, LRUHandle **handle);
962
void    tsdbCacheSetPageSs(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, uint8_t *pPage);
963

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

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

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

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

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

987
  return 0;
988
}
989

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

993
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
994
  if (pIter == NULL) return NULL;
208,004!
995

996
  if (pIter->pRow) {
208,004!
997
    return pIter->pRow;
90,200✔
998
  }
999

1000
  if (pIter->backward) {
117,804!
1001
    if (pIter->pNode == pIter->pTbData->sl.pHead) {
708!
1002
      return NULL;
×
1003
    }
1004
  } else {
1005
    if (pIter->pNode == pIter->pTbData->sl.pTail) {
117,096!
1006
      return NULL;
279✔
1007
    }
1008
  }
1009

1010
  pIter->pRow = &pIter->row;
117,525✔
1011
  pIter->row = pIter->pNode->row;
117,525✔
1012

1013
  return pIter->pRow;
117,525✔
1014
}
1015

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

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

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

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

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

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

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

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

1082
void tsdbRemoveFile(const char *path);
1083

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

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

1094
#ifdef __cplusplus
1095
}
1096
#endif
1097

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