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

#include <stdint.h>

H
more  
hzcheng 已提交
6
// #include "cache.h"
H
more  
Hongze Cheng 已提交
7

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

typedef struct {
  int64_t skey;     // start key
  int64_t ekey;     // end key
H
more  
hzcheng 已提交
13
  int32_t numOfRows; // numOfRows
H
more  
Hongze Cheng 已提交
14 15
} STableCacheInfo;

H
more  
hzcheng 已提交
16 17 18 19 20
typedef struct _tsdb_cache_block {
  char *                    pData;
  STableCacheInfo *         pTableInfo;
  struct _tsdb_cache_block *prev;
  struct _tsdb_cache_block *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  
hzcheng 已提交
26
  int32_t          numOfBlocks;
H
more  
Hongze Cheng 已提交
27
  STSDBCacheBlock *cacheList;
H
more  
hzcheng 已提交
28
  void *           current;
H
more  
Hongze Cheng 已提交
29 30 31 32 33
} 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 已提交
34
#define TSDB_TABLE_INFO_OF_CACHE(pBlock, tableId) ((pBlock)->pTableInfo)[tableId]
H
more  
Hongze Cheng 已提交
35 36
#define TSDB_NEXT_CACHE_BLOCK(pBlock) ((pBlock)->next)
#define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev)
H
more  
Hongze Cheng 已提交
37

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

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