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

taosdata / TDengine / #3548

04 Dec 2024 01:03PM UTC coverage: 59.846% (-0.8%) from 60.691%
#3548

push

travis-ci

web-flow
Merge pull request #29033 from taosdata/fix/calculate-vnode-memory-used

fix/calculate-vnode-memory-used

118484 of 254183 branches covered (46.61%)

Branch coverage included in aggregate %.

199691 of 277471 relevant lines covered (71.97%)

18794141.86 hits per line

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

41.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 ", 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

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

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

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

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

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

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

305
int32_t tsdbMerge(void *arg);
306

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

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

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

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

335
typedef struct {
336
  rocksdb_t                           *db;
337
  rocksdb_comparator_t                *my_comparator;
338
  rocksdb_cache_t                     *blockcache;
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
} SRocksCache;
351

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

357
typedef struct SCompMonitor SCompMonitor;
358

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

587
struct SDelFile {
588
  volatile int32_t nRef;
589

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

595
struct SHeadFile {
596
  volatile int32_t nRef;
597

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

603
struct SDataFile {
604
  volatile int32_t nRef;
605

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

610
struct SSttFile {
611
  volatile int32_t nRef;
612

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

618
struct SSmaFile {
619
  volatile int32_t nRef;
620

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

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

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

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

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

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

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

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

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

696
typedef TARRAY2(SVersionRange) SVerRangeList;
697

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

981
  return 0;
982
}
983

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

987
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
988
  if (pIter == NULL) return NULL;
2,147,483,647!
989

990
  if (pIter->pRow) {
2,147,483,647!
991
    return pIter->pRow;
1,623,348,218✔
992
  }
993

994
  if (pIter->backward) {
2,102,323,898!
995
    if (pIter->pNode == pIter->pTbData->sl.pHead) {
138,228,753!
996
      return NULL;
147,509✔
997
    }
998
  } else {
999
    if (pIter->pNode == pIter->pTbData->sl.pTail) {
1,964,095,145!
1000
      return NULL;
466,797✔
1001
    }
1002
  }
1003

1004
  pIter->pRow = &pIter->row;
2,101,709,592✔
1005
  pIter->row = pIter->pNode->row;
2,101,709,592✔
1006

1007
  return pIter->pRow;
2,101,709,592✔
1008
}
1009

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

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

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

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

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

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

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

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

1076
void tsdbRemoveFile(const char *path);
1077

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

1085
#ifdef __cplusplus
1086
}
1087
#endif
1088

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

© 2025 Coveralls, Inc