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

taosdata / TDengine / #3562

20 Dec 2024 09:57AM UTC coverage: 26.655% (-32.2%) from 58.812%
#3562

push

travis-ci

web-flow
Merge pull request #29229 from taosdata/enh/TS-5749-3.0

enh: seperate tsdb async tasks to different thread pools

21498 of 109421 branches covered (19.65%)

Branch coverage included in aggregate %.

66 of 96 new or added lines in 7 files covered. (68.75%)

39441 existing lines in 157 files now uncovered.

35007 of 102566 relevant lines covered (34.13%)

53922.97 hits per line

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

18.4
/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 ", DEBUG_INFO, 255, __VA_ARGS__); }}            while(0)
35
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSD ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
36
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSD ", 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
  rocksdb_t                           *db;
338
  rocksdb_comparator_t                *my_comparator;
339
  rocksdb_block_based_table_options_t *tableoptions;
340
  rocksdb_options_t                   *options;
341
  rocksdb_flushoptions_t              *flushoptions;
342
  rocksdb_writeoptions_t              *writeoptions;
343
  rocksdb_readoptions_t               *readoptions;
344
  rocksdb_writebatch_t                *writebatch;
345
  TdThreadMutex                        writeBatchMutex;
346
  int32_t                              sver;
347
  tb_uid_t                             suid;
348
  tb_uid_t                             uid;
349
  STSchema                            *pTSchema;
350
  SArray                              *ctxArray;
351
} SRocksCache;
352

353
typedef struct {
354
  STsdb *pTsdb;
355
  int    flush_count;
356
} SCacheFlushState;
357

358
typedef struct SCompMonitor SCompMonitor;
359

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

386
struct TSDBKEY {
387
  int64_t version;
388
  TSKEY   ts;
389
};
390

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

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

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

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

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

451
struct STsdbRowKey {
452
  SRowKey key;
453
  int64_t version;
454
};
455

456
struct SBlockIdx {
457
  int64_t suid;
458
  int64_t uid;
459
  int64_t offset;
460
  int64_t size;
461
};
462

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

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

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

489
struct SSmaInfo {
490
  int64_t offset;
491
  int32_t size;
492
};
493

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

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

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

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

544
struct TABLEID {
545
  tb_uid_t suid;
546
  tb_uid_t uid;
547
};
548

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

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

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

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

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

588
struct SDelFile {
589
  volatile int32_t nRef;
590

591
  int64_t commitID;
592
  int64_t size;
593
  int64_t offset;
594
};
595

596
struct SHeadFile {
597
  volatile int32_t nRef;
598

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

604
struct SDataFile {
605
  volatile int32_t nRef;
606

607
  int64_t commitID;
608
  int64_t size;
609
};
610

611
struct SSttFile {
612
  volatile int32_t nRef;
613

614
  int64_t commitID;
615
  int64_t size;
616
  int64_t offset;
617
};
618

619
struct SSmaFile {
620
  volatile int32_t nRef;
621

622
  int64_t commitID;
623
  int64_t size;
624
};
625

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

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

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

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

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

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

684
void tsdbTFileSetRangeClear(STFileSetRange **fsr);
685
void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr);
686

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

697
typedef TARRAY2(SVersionRange) SVerRangeList;
698

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

705
typedef struct STsdbFSetPartition STsdbFSetPartition;
706
typedef TARRAY2(STsdbFSetPartition *) STsdbFSetPartList;
707

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

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

720
typedef struct STsdbRepOpts {
721
  ETsdbRepFmt format;
722
} STsdbRepOpts;
723

724
int32_t tSerializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
725
int32_t tDeserializeTsdbRepOpts(void *buf, int32_t bufLen, STsdbRepOpts *pInfo);
726

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

736
struct SDataFWriter {
737
  STsdb    *pTsdb;
738
  SDFileSet wSet;
739

740
  STsdbFD *pHeadFD;
741
  STsdbFD *pDataFD;
742
  STsdbFD *pSmaFD;
743
  STsdbFD *pSttFD;
744

745
  SHeadFile fHead;
746
  SDataFile fData;
747
  SSmaFile  fSma;
748
  SSttFile  fStt[TSDB_STT_TRIGGER_ARRAY_SIZE];
749

750
  uint8_t *aBuf[4];
751
};
752

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

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

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

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

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

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

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

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

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

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

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

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

871
#define tMergeTreeGetRow(_t) (&((_t)->pIter->rInfo.row))
872

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

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

897
typedef struct SSttDataInfoForTable {
898
  SArray *pKeyRangeList;
899
  int64_t numOfRows;
900
} SSttDataInfoForTable;
901

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

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

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

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

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

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

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

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

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

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

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

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

963
int32_t tsdbGetS3Size(STsdb *tsdb, int64_t *size);
964

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

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

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

982
  return 0;
983
}
984

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

988
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
989
  if (pIter == NULL) return NULL;
3,606,483!
990

991
  if (pIter->pRow) {
3,606,483!
992
    return pIter->pRow;
1,963,033✔
993
  }
994

995
  if (pIter->backward) {
1,643,450!
996
    if (pIter->pNode == pIter->pTbData->sl.pHead) {
23,556!
UNCOV
997
      return NULL;
×
998
    }
999
  } else {
1000
    if (pIter->pNode == pIter->pTbData->sl.pTail) {
1,619,894!
1001
      return NULL;
556✔
1002
    }
1003
  }
1004

1005
  pIter->pRow = &pIter->row;
1,642,894✔
1006
  pIter->row = pIter->pNode->row;
1,642,894✔
1007

1008
  return pIter->pRow;
1,642,894✔
1009
}
1010

1011
typedef struct {
1012
  int64_t  suid;
1013
  int64_t  uid;
1014
  SDelData delData;
1015
} SDelInfo;
1016

1017
struct STsdbDataIter2 {
1018
  STsdbDataIter2 *next;
1019
  SRBTreeNode     rbtn;
1020

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

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

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

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

1068
typedef enum {
1069
  TSDB_FS_STATE_NORMAL = 0,
1070
  TSDB_FS_STATE_INCOMPLETE,
1071
} ETsdbFsState;
1072

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

1077
void tsdbRemoveFile(const char *path);
1078

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

1086
#ifdef __cplusplus
1087
}
1088
#endif
1089

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