tsdb.h 15.1 KB
Newer Older
L
Liu Jicong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
H
Hongze Cheng 已提交
15 16 17 18

#ifndef _TD_VNODE_TSDB_H_
#define _TD_VNODE_TSDB_H_

H
Hongze Cheng 已提交
19 20
#include "vnodeInt.h"

H
Hongze Cheng 已提交
21 22 23 24
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
25 26 27 28 29 30 31 32 33
// tsdbDebug ================
// clang-format off
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}     while(0)
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}     while(0)
#define tsdbWarn(...)  do { if (tsdbDebugFlag & DEBUG_WARN)  { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}       while(0)
#define tsdbInfo(...)  do { if (tsdbDebugFlag & DEBUG_INFO)  { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }}            while(0)
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
H
Hongze Cheng 已提交
34

H
Hongze Cheng 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
typedef struct TSDBROW        TSDBROW;
typedef struct TABLEID        TABLEID;
typedef struct TSDBKEY        TSDBKEY;
typedef struct KEYINFO        KEYINFO;
typedef struct SDelData       SDelData;
typedef struct SDelIdx        SDelIdx;
typedef struct STbData        STbData;
typedef struct SMemTable      SMemTable;
typedef struct STbDataIter    STbDataIter;
typedef struct SMergeInfo     SMergeInfo;
typedef struct STable         STable;
typedef struct SMapData       SMapData;
typedef struct SBlockSMA      SBlockSMA;
typedef struct SBlockIdx      SBlockIdx;
typedef struct SBlock         SBlock;
typedef struct SBlockStatis   SBlockStatis;
typedef struct SAggrBlkCol    SAggrBlkCol;
typedef struct SColData       SColData;
typedef struct SBlockDataHdr  SBlockDataHdr;
typedef struct SBlockData     SBlockData;
H
Hongze Cheng 已提交
55 56
typedef struct SDelFile       SDelFile;
typedef struct STsdbCacheFile STsdbCacheFile;
H
Hongze Cheng 已提交
57 58 59 60
typedef struct SHeadFile      SHeadFile;
typedef struct SDataFile      SDataFile;
typedef struct SLastFile      SLastFile;
typedef struct SSmaFile       SSmaFile;
H
Hongze Cheng 已提交
61
typedef struct SDFileSet      SDFileSet;
H
Hongze Cheng 已提交
62 63 64 65
typedef struct SDataFWriter   SDataFWriter;
typedef struct SDataFReader   SDataFReader;
typedef struct SDelFWriter    SDelFWriter;
typedef struct SDelFReader    SDelFReader;
H
Hongze Cheng 已提交
66 67
typedef struct SRowIter       SRowIter;
typedef struct STsdbFS        STsdbFS;
H
Hongze Cheng 已提交
68

H
Hongze Cheng 已提交
69
#define TSDB_MAX_SUBBLOCKS 8
H
refact  
Hongze Cheng 已提交
70

H
Hongze Cheng 已提交
71 72 73
#define HAS_NONE  ((int8_t)0x1)
#define HAS_NULL  ((int8_t)0x2)
#define HAS_VALUE ((int8_t)0x4)
H
Hongze Cheng 已提交
74
// tsdbUtil.c ==============================================================================================
H
Hongze Cheng 已提交
75
// TSDBROW
H
Hongze Cheng 已提交
76
#define TSDBROW_SVERSION(ROW)                 TD_ROW_SVER((ROW)->pTSRow)
H
Hongze Cheng 已提交
77 78
#define tsdbRowFromTSRow(VERSION, TSROW)      ((TSDBROW){.type = 0, .version = (VERSION), .pTSRow = (TSROW)});
#define tsdbRowFromBlockData(BLOCKDATA, IROW) ((TSDBROW){.type = 1, .pBlockData = (BLOCKDATA), .pTSRow = (IROW)});
H
Hongze Cheng 已提交
79
TSDBKEY tsdbRowKey(TSDBROW *pRow);
H
Hongze Cheng 已提交
80 81 82
void    tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow);
H
Hongze Cheng 已提交
83 84 85
// SRowIter
#define tRowIterInit(ROW, SCHEMA) ((SRowIter){.pRow = (ROW), .pSchema = (SCHEMA)})
SColVal *tRowIterNext(SRowIter *pIter);
H
Hongze Cheng 已提交
86
// TABLEID
H
Hongze Cheng 已提交
87
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
H
Hongze Cheng 已提交
88
// TSDBKEY
H
Hongze Cheng 已提交
89
int32_t tsdbKeyCmprFn(const void *p1, const void *p2);
H
Hongze Cheng 已提交
90
// KEYINFO
H
Hongze Cheng 已提交
91 92 93 94 95
#define tKEYINFOInit()                                          \
  ((KEYINFO){.maxKey = {.ts = TSKEY_MIN, .version = -1},        \
             .minKey = {.ts = TSKEY_MAX, .version = INT64_MAX}, \
             .minVerion = INT64_MAX,                            \
             .maxVersion = -1})
H
Hongze Cheng 已提交
96 97
int32_t tPutKEYINFO(uint8_t *p, KEYINFO *pKeyInfo);
int32_t tGetKEYINFO(uint8_t *p, KEYINFO *pKeyInfo);
H
Hongze Cheng 已提交
98 99 100
// SBlockCol
int32_t tPutBlockCol(uint8_t *p, void *ph);
int32_t tGetBlockCol(uint8_t *p, void *ph);
H
Hongze Cheng 已提交
101
// SBlock
H
Hongze Cheng 已提交
102 103 104
#define tBlockInit() ((SBlock){.info = tKEYINFOInit()})
void    tBlockReset(SBlock *pBlock);
void    tBlockClear(SBlock *pBlock);
H
Hongze Cheng 已提交
105 106
int32_t tPutBlock(uint8_t *p, void *ph);
int32_t tGetBlock(uint8_t *p, void *ph);
H
Hongze Cheng 已提交
107
int32_t tBlockCmprFn(const void *p1, const void *p2);
H
Hongze Cheng 已提交
108
// SBlockIdx
H
Hongze Cheng 已提交
109
#define tBlockIdxInit(SUID, UID) ((SBlockIdx){.suid = (SUID), .uid = (UID), .info = tKEYINFOInit()})
H
Hongze Cheng 已提交
110 111 112 113 114
int32_t tPutBlockIdx(uint8_t *p, void *ph);
int32_t tGetBlockIdx(uint8_t *p, void *ph);
// SColdata
#define tColDataInit() ((SColData){0})
void    tColDataReset(SColData *pColData);
H
Hongze Cheng 已提交
115
void    tColDataClear(void *ph);
H
Hongze Cheng 已提交
116
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
H
Hongze Cheng 已提交
117
int32_t tColDataCmprFn(const void *p1, const void *p2);
H
Hongze Cheng 已提交
118
// SBlockData
H
Hongze Cheng 已提交
119
int32_t tBlockDataInit(SBlockData *pBlockData);
H
Hongze Cheng 已提交
120 121 122
void    tBlockDataReset(SBlockData *pBlockData);
void    tBlockDataClear(SBlockData *pBlockData);
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema);
H
Hongze Cheng 已提交
123
// SDelIdx
H
Hongze Cheng 已提交
124 125
int32_t tPutDelIdx(uint8_t *p, void *ph);
int32_t tGetDelIdx(uint8_t *p, void *ph);
H
Hongze Cheng 已提交
126
// SDelData
H
Hongze Cheng 已提交
127 128
int32_t tPutDelData(uint8_t *p, void *ph);
int32_t tGetDelData(uint8_t *p, void *ph);
H
Hongze Cheng 已提交
129 130 131 132
// memory
int32_t tsdbRealloc(uint8_t **ppBuf, int64_t size);
void    tsdbFree(uint8_t *pBuf);
// SMapData
H
Hongze Cheng 已提交
133
#define tMapDataInit() ((SMapData){0})
H
Hongze Cheng 已提交
134 135 136 137 138 139 140 141 142 143
void    tMapDataReset(SMapData *pMapData);
void    tMapDataClear(SMapData *pMapData);
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *));
int32_t tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *));
int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
int32_t tGetMapData(uint8_t *p, SMapData *pMapData);
// other
int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision);
void    tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey);
int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline);
H
Hongze Cheng 已提交
144 145
int32_t tPutDelFileHdr(uint8_t *p, SDelFile *pDelFile);
int32_t tGetDelFileHdr(uint8_t *p, SDelFile *pDelFile);
H
Hongze Cheng 已提交
146 147 148 149 150 151 152 153 154 155 156 157
// tsdbMemTable ==============================================================================================
// SMemTable
int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable);
void    tsdbMemTableDestroy(SMemTable *pMemTable);
void    tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData);
// STbDataIter
int32_t  tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter);
void    *tsdbTbDataIterDestroy(STbDataIter *pIter);
void     tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter);
TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter);
bool     tsdbTbDataIterNext(STbDataIter *pIter);
// tsdbFile.c ==============================================================================================
H
Hongze Cheng 已提交
158 159 160 161 162 163 164 165 166
// SDataFSet
// SHeadFile
void tsdbHeadFileName(STsdb *pTsdb, SHeadFile *pFile, char fname[]);
// SDataFile
void tsdbDataFileName(STsdb *pTsdb, SDataFile *pFile, char fname[]);
// SLastFile
void tsdbLastFileName(STsdb *pTsdb, SLastFile *pFile, char fname[]);
// SSmaFile
void tsdbSmaFileName(STsdb *pTsdb, SSmaFile *pFile, char fname[]);
H
Hongze Cheng 已提交
167
// SDelFile
H
Hongze Cheng 已提交
168 169 170
#define tsdbDelFileCreate() \
  ((SDelFile){              \
      .maxKey = TSKEY_MIN, .minKey = TSKEY_MAX, .maxVersion = -1, .minVersion = INT64_MAX, .size = 0, .offset = 0})
H
Hongze Cheng 已提交
171
void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]);
H
Hongze Cheng 已提交
172
// tsdbFS.c ==============================================================================================
H
Hongze Cheng 已提交
173 174
int32_t tsdbFSOpen(STsdb *pTsdb, STsdbFS **ppFS);
int32_t tsdbFSClose(STsdbFS *pFS);
H
Hongze Cheng 已提交
175 176 177
int32_t tsdbFSBegin(STsdbFS *pFS);
int32_t tsdbFSCommit(STsdbFS *pFS);
int32_t tsdbFSRollback(STsdbFS *pFS);
H
Hongze Cheng 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
// tsdbReaderWriter.c ==============================================================================================
// SDataFWriter
int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pSet);
int32_t tsdbDataFWriterClose(SDataFWriter *pWriter, int8_t sync);
int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter, uint8_t **ppBuf);
int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SMapData *pMapData, uint8_t **ppBuf);
int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, uint8_t **ppBuf, SBlockIdx *pBlockIdx);
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_t **ppBuf1, uint8_t **ppBuf2,
                           SBlockIdx *pBlockIdx, SBlock *pBlock);
int32_t tsdbWriteBlockSMA(SDataFWriter *pWriter, SBlockSMA *pBlockSMA, int64_t *rOffset, int64_t *rSize);
// SDataFReader
int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet);
int32_t tsdbDataFReaderClose(SDataFReader *pReader);
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SMapData *pMapData, uint8_t **ppBuf);
int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *pMapData, uint8_t **ppBuf);
int32_t tsdbReadBlockData(SDataFReader *pReader, SBlockIdx *pBlockIdx, SBlock *pBlock, SBlockData *pBlockData,
                          int16_t *aColId, int32_t nCol, uint8_t **ppBuf1, uint8_t **ppBuf2);
int32_t tsdbReadBlockSMA(SDataFReader *pReader, SBlockSMA *pBlkSMA);
// SDelFWriter
int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb);
int32_t tsdbDelFWriterClose(SDelFWriter *pWriter, int8_t sync);
int32_t tsdbWriteDelData(SDelFWriter *pWriter, SMapData *pDelDataMap, uint8_t **ppBuf, SDelIdx *pDelIdx);
int32_t tsdbWriteDelIdx(SDelFWriter *pWriter, SMapData *pDelIdxMap, uint8_t **ppBuf);
int32_t tsdbUpdateDelFileHdr(SDelFWriter *pWriter, uint8_t **ppBuf);
// SDelFReader
int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb, uint8_t **ppBuf);
int32_t tsdbDelFReaderClose(SDelFReader *pReader);
int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SMapData *pDelDataMap, uint8_t **ppBuf);
int32_t tsdbReadDelIdx(SDelFReader *pReader, SMapData *pDelIdxMap, uint8_t **ppBuf);
H
Hongze Cheng 已提交
207

208 209
// tsdbCache
int32_t tsdbOpenCache(STsdb *pTsdb);
H
Hongze Cheng 已提交
210
void    tsdbCloseCache(SLRUCache *pCache);
211 212 213 214
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, tb_uid_t uid, STSRow *row);
int32_t tsdbCacheGetLastrow(SLRUCache *pCache, tb_uid_t uid, STSRow **ppRow);
int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid);

H
Hongze Cheng 已提交
215
// structs =======================
H
Hongze Cheng 已提交
216 217 218 219 220 221 222
typedef struct {
  int   minFid;
  int   midFid;
  int   maxFid;
  TSKEY minKey;
} SRtn;

C
Cary Xu 已提交
223
#define TSDB_DATA_DIR_LEN 6  // adapt accordingly
H
Hongze Cheng 已提交
224
struct STsdb {
H
refact  
Hongze Cheng 已提交
225 226 227 228 229 230 231 232 233 234
  char         *path;
  SVnode       *pVnode;
  TdThreadMutex mutex;
  char          dir[TSDB_DATA_DIR_LEN];
  bool          repoLocked;
  STsdbKeepCfg  keepCfg;
  SMemTable    *mem;
  SMemTable    *imem;
  SRtn          rtn;
  STsdbFS      *fs;
235
  SLRUCache    *lruCache;
H
Hongze Cheng 已提交
236 237
};

H
Hongze Cheng 已提交
238
struct STable {
H
Hongze Cheng 已提交
239
  uint64_t  suid;
H
Hongze Cheng 已提交
240
  uint64_t  uid;
241 242
  STSchema *pSchema;       // latest schema
  STSchema *pCacheSchema;  // cached cache
H
Hongze Cheng 已提交
243
};
H
Hongze Cheng 已提交
244

H
refact  
Hongze Cheng 已提交
245 246 247 248 249
struct TSDBKEY {
  int64_t version;
  TSKEY   ts;
};

H
Hongze Cheng 已提交
250 251 252 253 254 255 256
struct KEYINFO {
  TSDBKEY minKey;
  TSDBKEY maxKey;
  int64_t minVerion;
  int64_t maxVersion;
};

H
Hongze Cheng 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270
typedef struct SMemSkipListNode SMemSkipListNode;
struct SMemSkipListNode {
  int8_t            level;
  SMemSkipListNode *forwards[0];
};
typedef struct SMemSkipList {
  uint32_t          seed;
  int64_t           size;
  int8_t            maxLevel;
  int8_t            level;
  SMemSkipListNode *pHead;
  SMemSkipListNode *pTail;
} SMemSkipList;

H
Hongze Cheng 已提交
271 272 273 274 275
struct SDelDataInfo {
  tb_uid_t suid;
  tb_uid_t uid;
};

H
Hongze Cheng 已提交
276
struct STbData {
H
Hongze Cheng 已提交
277 278
  tb_uid_t     suid;
  tb_uid_t     uid;
H
Hongze Cheng 已提交
279
  KEYINFO      info;
H
Hongze Cheng 已提交
280 281
  SDelData    *pHead;
  SDelData    *pTail;
H
Hongze Cheng 已提交
282
  SMemSkipList sl;
H
Hongze Cheng 已提交
283
};
H
Hongze Cheng 已提交
284

H
refact  
Hongze Cheng 已提交
285
struct SMemTable {
H
Hongze Cheng 已提交
286 287 288
  SRWLatch latch;
  STsdb   *pTsdb;
  int32_t  nRef;
H
Hongze Cheng 已提交
289
  KEYINFO  info;
H
Hongze Cheng 已提交
290
  int64_t  nRow;
H
Hongze Cheng 已提交
291
  int64_t  nDel;
H
Hongze Cheng 已提交
292
  SArray  *aTbData;  // SArray<STbData*>
H
Hongze Cheng 已提交
293
};
H
Hongze Cheng 已提交
294 295 296 297

int tsdbLockRepo(STsdb *pTsdb);
int tsdbUnlockRepo(STsdb *pTsdb);

H
Hongze Cheng 已提交
298
struct TSDBROW {
H
Hongze Cheng 已提交
299
  int8_t type;  // 0 for row from tsRow, 1 for row from block data
H
Hongze Cheng 已提交
300 301 302 303 304 305
  union {
    struct {
      int64_t version;
      STSRow *pTSRow;
    };
    struct {
H
Hongze Cheng 已提交
306 307
      SBlockData *pBlockData;
      int32_t     iRow;
H
Hongze Cheng 已提交
308 309
    };
  };
H
Hongze Cheng 已提交
310 311
};

H
Hongze Cheng 已提交
312
struct SBlockIdx {
H
Hongze Cheng 已提交
313 314
  int64_t suid;
  int64_t uid;
H
Hongze Cheng 已提交
315
  KEYINFO info;
H
Hongze Cheng 已提交
316 317 318 319
  int64_t offset;
  int64_t size;
};

H
Hongze Cheng 已提交
320 321 322 323 324 325 326 327 328
struct SMapData {
  int32_t  nItem;
  uint8_t  flag;
  uint8_t *pOfst;
  uint32_t nData;
  uint8_t *pData;
  uint8_t *pBuf;
};

H
Hongze Cheng 已提交
329
typedef struct {
H
Hongze Cheng 已提交
330 331 332
  int16_t cid;
  int8_t  type;
  int8_t  flag;
H
Hongze Cheng 已提交
333 334
  int64_t offset;
  int64_t size;
H
Hongze Cheng 已提交
335 336 337 338 339 340 341
} SBlockCol;

typedef struct {
  int64_t  offset;
  int64_t  ksize;
  int64_t  bsize;
  SMapData mBlockCol;  // SMapData<SBlockCol>
H
Hongze Cheng 已提交
342 343
} SSubBlock;

H
Hongze Cheng 已提交
344
struct SBlock {
H
Hongze Cheng 已提交
345 346
  KEYINFO   info;
  int32_t   nRow;
H
Hongze Cheng 已提交
347 348
  int8_t    last;
  int8_t    hasDup;
H
Hongze Cheng 已提交
349
  int8_t    cmprAlg;
H
Hongze Cheng 已提交
350
  int8_t    nSubBlock;
H
Hongze Cheng 已提交
351
  SSubBlock aSubBlock[TSDB_MAX_SUBBLOCKS];
H
refact  
Hongze Cheng 已提交
352
};
H
Hongze Cheng 已提交
353

H
refact  
Hongze Cheng 已提交
354
struct SAggrBlkCol {
H
Hongze Cheng 已提交
355 356 357 358 359 360 361
  int16_t colId;
  int16_t maxIndex;
  int16_t minIndex;
  int16_t numOfNull;
  int64_t sum;
  int64_t max;
  int64_t min;
H
refact  
Hongze Cheng 已提交
362
};
H
Hongze Cheng 已提交
363

H
Hongze Cheng 已提交
364 365 366 367 368 369
struct SColData {
  int16_t  cid;
  int8_t   type;
  int32_t  bytes;
  uint8_t  flags;
  uint8_t *pBitMap;
H
Hongze Cheng 已提交
370
  int32_t *pOfst;
H
Hongze Cheng 已提交
371 372
  uint32_t nData;
  uint8_t *pData;
H
refact  
Hongze Cheng 已提交
373
};
H
Hongze Cheng 已提交
374

H
Hongze Cheng 已提交
375
struct SBlockData {
H
Hongze Cheng 已提交
376 377 378 379 380 381
  int32_t  maxRow;
  int32_t  nRow;
  int64_t *aVersion;
  TSKEY   *aTSKEY;
  SArray  *apColData;
  SArray  *aColData;
H
Hongze Cheng 已提交
382
};
H
Hongze Cheng 已提交
383 384 385 386

// ================== TSDB global config
extern bool tsdbForceKeepFile;

H
Hongze Cheng 已提交
387
#define TSDB_FS_ITER_FORWARD  TSDB_ORDER_ASC
H
Hongze Cheng 已提交
388 389
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC

H
Hongze Cheng 已提交
390 391 392 393 394
struct TABLEID {
  tb_uid_t suid;
  tb_uid_t uid;
};

H
Hongze Cheng 已提交
395 396 397 398
struct STbDataIter {
  STbData          *pTbData;
  int8_t            backward;
  SMemSkipListNode *pNode;
H
Hongze Cheng 已提交
399 400
  TSDBROW          *pRow;
  TSDBROW           row;
H
Hongze Cheng 已提交
401 402
};

H
Hongze Cheng 已提交
403
struct SDelData {
H
Hongze Cheng 已提交
404 405 406 407
  int64_t   version;
  TSKEY     sKey;
  TSKEY     eKey;
  SDelData *pNext;
H
Hongze Cheng 已提交
408
};
H
Hongze Cheng 已提交
409

H
Hongze Cheng 已提交
410
struct SDelIdx {
H
Hongze Cheng 已提交
411 412 413 414 415
  tb_uid_t suid;
  tb_uid_t uid;
  TSKEY    minKey;
  TSKEY    maxKey;
  int64_t  minVersion;
H
Hongze Cheng 已提交
416
  int64_t  maxVersion;
H
Hongze Cheng 已提交
417 418
  int64_t  offset;
  int64_t  size;
H
Hongze Cheng 已提交
419
};
H
Hongze Cheng 已提交
420

H
Hongze Cheng 已提交
421
struct SDelFile {
H
Hongze Cheng 已提交
422 423 424 425
  TSKEY   minKey;
  TSKEY   maxKey;
  int64_t minVersion;
  int64_t maxVersion;
H
Hongze Cheng 已提交
426 427 428
  int64_t size;
  int64_t offset;
};
H
Hongze Cheng 已提交
429

H
Hongze Cheng 已提交
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
typedef struct {
  int16_t colId;
  int16_t maxIndex;
  int16_t minIndex;
  int16_t numOfNull;
  int64_t sum;
  int64_t max;
  int64_t min;
} SColSMA;

struct SBlockSMA {
  int32_t  nCol;
  SColSMA *aColSMA;
};

H
Hongze Cheng 已提交
445
struct SBlockDataHdr {
H
more  
Hongze Cheng 已提交
446 447 448
  uint32_t delimiter;
  int64_t  suid;
  int64_t  uid;
H
Hongze Cheng 已提交
449 450
};

H
Hongze Cheng 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
struct SHeadFile {
  int64_t size;
  int64_t offset;
  int32_t nRef;
};

struct SDataFile {
  int64_t size;
  int32_t nRef;
};

struct SLastFile {
  int64_t size;
  int32_t nRef;
};

struct SSmaFile {
  int64_t size;
  int32_t nRef;
};

struct SDFileSet {
H
Hongze Cheng 已提交
473
  SDiskID    diskId;
H
Hongze Cheng 已提交
474
  int32_t    fid;
H
Hongze Cheng 已提交
475 476 477 478
  SHeadFile *pHeadFile;
  SDataFile *pDataFile;
  SLastFile *pLastFile;
  SSmaFile  *pSmaFile;
H
Hongze Cheng 已提交
479 480 481 482 483 484 485 486
  int32_t    nRef;
};

struct SRowIter {
  TSDBROW  *pRow;
  STSchema *pSchema;
  SColVal   colVal;
  int32_t   i;
H
Hongze Cheng 已提交
487 488
};

H
Hongze Cheng 已提交
489 490 491 492
#ifdef __cplusplus
}
#endif

493
#endif /*_TD_VNODE_TSDB_H_*/