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

#include <stdint.h>

#include "cache.h"
H
more  
Hongze Cheng 已提交
7
#include "dlist.h"
H
more  
Hongze Cheng 已提交
8

H
more  
Hongze Cheng 已提交
9 10 11 12 13 14 15 16
#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 已提交
17
typedef struct {
H
more  
Hongze Cheng 已提交
18 19 20 21
  char *pData;
  STableCacheInfo *pTableInfo;
  SCacheBlock *prev;
  SCacheBlock *next;
H
more  
Hongze Cheng 已提交
22 23 24
} STSDBCacheBlock;

// Use a doublely linked list to implement this
H
more  
Hongze Cheng 已提交
25
typedef struct STSDBCache {
H
more  
Hongze Cheng 已提交
26
  int32_t numOfBlocks;
H
more  
Hongze Cheng 已提交
27
  SDList *cacheList;
H
more  
Hongze Cheng 已提交
28 29 30 31 32 33 34 35 36 37
  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))
#define TSDB_TABLE_KEY_RANGE_AT_CACHE(pBlock, tableId) ((pBlock)->pTableInfo)[tableId]
#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
STSDBCache *tsdbCreateCache();
H
more  
Hongze Cheng 已提交
40

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