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

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

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

9.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

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

306
int32_t tsdbMerge(void *arg);
307

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

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

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

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

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

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

360
typedef struct SCompMonitor SCompMonitor;
361

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

388
struct TSDBKEY {
389
  int64_t version;
390
  TSKEY   ts;
391
};
392

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

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

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

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

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

453
struct STsdbRowKey {
454
  SRowKey key;
455
  int64_t version;
456
};
457

458
struct SBlockIdx {
459
  int64_t suid;
460
  int64_t uid;
461
  int64_t offset;
462
  int64_t size;
463
};
464

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

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

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

491
struct SSmaInfo {
492
  int64_t offset;
493
  int32_t size;
494
};
495

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

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

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

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

546
struct TABLEID {
547
  tb_uid_t suid;
548
  tb_uid_t uid;
549
};
550

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

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

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

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

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

590
struct SDelFile {
591
  volatile int32_t nRef;
592

593
  int64_t commitID;
594
  int64_t size;
595
  int64_t offset;
596
};
597

598
struct SHeadFile {
599
  volatile int32_t nRef;
600

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

606
struct SDataFile {
607
  volatile int32_t nRef;
608

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

613
struct SSttFile {
614
  volatile int32_t nRef;
615

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

621
struct SSmaFile {
622
  volatile int32_t nRef;
623

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

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

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

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

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

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

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

686
void tsdbTFileSetRangeClear(STFileSetRange **fsr);
687
void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr);
688

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

699
typedef TARRAY2(SVersionRange) SVerRangeList;
700

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

707
typedef struct STsdbFSetPartition STsdbFSetPartition;
708
typedef TARRAY2(STsdbFSetPartition *) STsdbFSetPartList;
709

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

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

722
typedef struct STsdbRepOpts {
723
  ETsdbRepFmt format;
724
} STsdbRepOpts;
725

726
int32_t tSerializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
727
int32_t tDeserializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
728

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

738
struct SDataFWriter {
739
  STsdb    *pTsdb;
740
  SDFileSet wSet;
741

742
  STsdbFD *pHeadFD;
743
  STsdbFD *pDataFD;
744
  STsdbFD *pSmaFD;
745
  STsdbFD *pSttFD;
746

747
  SHeadFile fHead;
748
  SDataFile fData;
749
  SSmaFile  fSma;
750
  SSttFile  fStt[TSDB_STT_TRIGGER_ARRAY_SIZE];
751

752
  uint8_t *aBuf[4];
753
};
754

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

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

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

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

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

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

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

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

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

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

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

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

873
#define tMergeTreeGetRow(_t) (&((_t)->pIter->rInfo.row))
874

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

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

899
typedef struct SSttDataInfoForTable {
900
  SArray *pKeyRangeList;
901
  int64_t numOfRows;
902
} SSttDataInfoForTable;
903

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

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

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

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

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

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

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

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

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

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

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

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

965
int32_t tsdbGetFsSize(STsdb *tsdb, SDbSizeStatisInfo *pInfo);
966

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

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

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

984
  return 0;
985
}
986

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

990
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
991
  if (pIter == NULL) return NULL;
1,278!
992

993
  if (pIter->pRow) {
1,278!
994
    return pIter->pRow;
629✔
995
  }
996

997
  if (pIter->backward) {
649!
998
    if (pIter->pNode == pIter->pTbData->sl.pHead) {
×
999
      return NULL;
×
1000
    }
1001
  } else {
1002
    if (pIter->pNode == pIter->pTbData->sl.pTail) {
649!
1003
      return NULL;
2✔
1004
    }
1005
  }
1006

1007
  pIter->pRow = &pIter->row;
647✔
1008
  pIter->row = pIter->pNode->row;
647✔
1009

1010
  return pIter->pRow;
647✔
1011
}
1012

1013
typedef struct {
1014
  int64_t  suid;
1015
  int64_t  uid;
1016
  SDelData delData;
1017
} SDelInfo;
1018

1019
struct STsdbDataIter2 {
1020
  STsdbDataIter2 *next;
1021
  SRBTreeNode     rbtn;
1022

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

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

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

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

1070
typedef enum {
1071
  TSDB_FS_STATE_NORMAL = 0,
1072
  TSDB_FS_STATE_INCOMPLETE,
1073
} ETsdbFsState;
1074

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

1079
void tsdbRemoveFile(const char *path);
1080

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

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

1091
#ifdef __cplusplus
1092
}
1093
#endif
1094

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