tsdbCache.h 1.1 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4 5 6 7
#if !defined(_TD_TSDBCACHE_H_)
#define _TD_TSDBCACHE_H_

#include <stdint.h>

#include "cache.h"

H
more  
Hongze Cheng 已提交
8 9 10 11 12 13 14 15
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16*1024*1024 /* 16M */

typedef struct {
  int64_t skey;     // start key
  int64_t ekey;     // end key
  int32_t numOfRows // numOfRows
} STableCacheInfo;

H
more  
Hongze Cheng 已提交
16
typedef struct {
H
more  
Hongze Cheng 已提交
17 18 19 20
  char *pData;
  STableCacheInfo *pTableInfo;
  SCacheBlock *prev;
  SCacheBlock *next;
H
more  
Hongze Cheng 已提交
21 22 23
} STSDBCacheBlock;

// Use a doublely linked list to implement this
H
more  
Hongze Cheng 已提交
24
typedef struct STSDBCache {
H
more  
Hongze Cheng 已提交
25
  // Number of blocks the cache is allocated
H
more  
Hongze Cheng 已提交
26
  int32_t numOfBlocks;
H
more  
Hongze Cheng 已提交
27
  STSDBCacheBlock *cacheList;
H
more  
Hongze Cheng 已提交
28 29 30 31 32 33 34
  void *  current;
} SCacheHandle;


// ---- Operation on STSDBCacheBlock
#define TSDB_CACHE_BLOCK_DATA(pBlock) ((pBlock)->pData)
#define TSDB_CACHE_AVAIL_SPACE(pBlock) ((char *)((pBlock)->pTableInfo) - ((pBlock)->pData))
H
more  
Hongze Cheng 已提交
35
#define TSDB_TABLE_INFO_OF_CACHE(pBlock, tableId) ((pBlock)->pTableInfo)[tableId]
H
more  
Hongze Cheng 已提交
36 37
#define TSDB_NEXT_CACHE_BLOCK(pBlock) ((pBlock)->next)
#define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev)
H
more  
Hongze Cheng 已提交
38

H
more  
Hongze Cheng 已提交
39
SCacheHandle *tsdbCreateCache(int32_t numOfBlocks);
H
more  
Hongze Cheng 已提交
40

H
more  
Hongze Cheng 已提交
41
#endif  // _TD_TSDBCACHE_H_