tsdbCache.h 1.9 KB
Newer Older
H
more  
hzcheng 已提交
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
more  
Hongze Cheng 已提交
15 16 17 18 19
#if !defined(_TD_TSDBCACHE_H_)
#define _TD_TSDBCACHE_H_

#include <stdint.h>

H
more  
hzcheng 已提交
20
// #include "cache.h"
H
more  
Hongze Cheng 已提交
21

H
more  
hzcheng 已提交
22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

H
more  
Hongze Cheng 已提交
26 27 28 29 30
#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 已提交
31
  int32_t numOfRows; // numOfRows
H
more  
Hongze Cheng 已提交
32 33
} STableCacheInfo;

H
more  
hzcheng 已提交
34 35 36 37 38
typedef struct _tsdb_cache_block {
  char *                    pData;
  STableCacheInfo *         pTableInfo;
  struct _tsdb_cache_block *prev;
  struct _tsdb_cache_block *next;
H
more  
Hongze Cheng 已提交
39 40 41
} STSDBCacheBlock;

// Use a doublely linked list to implement this
H
more  
Hongze Cheng 已提交
42
typedef struct STSDBCache {
H
more  
Hongze Cheng 已提交
43
  // Number of blocks the cache is allocated
H
more  
hzcheng 已提交
44
  int32_t          numOfBlocks;
H
more  
Hongze Cheng 已提交
45
  STSDBCacheBlock *cacheList;
H
more  
hzcheng 已提交
46
  void *           current;
H
more  
Hongze Cheng 已提交
47 48 49 50 51
} 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 已提交
52
#define TSDB_TABLE_INFO_OF_CACHE(pBlock, tableId) ((pBlock)->pTableInfo)[tableId]
H
more  
Hongze Cheng 已提交
53 54
#define TSDB_NEXT_CACHE_BLOCK(pBlock) ((pBlock)->next)
#define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev)
H
more  
Hongze Cheng 已提交
55

H
more  
Hongze Cheng 已提交
56
SCacheHandle *tsdbCreateCache(int32_t numOfBlocks);
H
more  
hzcheng 已提交
57
int32_t tsdbFreeCache(SCacheHandle *pHandle);
H
more  
Hongze Cheng 已提交
58

H
more  
hzcheng 已提交
59 60 61 62
#ifdef __cplusplus
}
#endif

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