tsdbCache.h 1.6 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
TD-34  
hzcheng 已提交
20
#include "taosdef.h"
H
TD-34  
hzcheng 已提交
21
#include "tlist.h"
H
more  
Hongze Cheng 已提交
22

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

H
TD-34  
hzcheng 已提交
27
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16 * 1024 * 1024 /* 16M */
H
more  
Hongze Cheng 已提交
28 29

typedef struct {
H
TD-34  
hzcheng 已提交
30 31 32 33 34 35
  int  blockId;
  int  offset;
  int  remain;
  int  padding;
  char data[];
} STsdbCacheBlock;
H
more  
Hongze Cheng 已提交
36

H
TD-34  
hzcheng 已提交
37 38 39 40
typedef struct {
  int64_t index;
  SList * memPool;
} STsdbCachePool;
H
more  
Hongze Cheng 已提交
41

H
TD-34  
hzcheng 已提交
42 43 44 45 46 47 48
typedef struct {
  TSKEY   keyFirst;
  TSKEY   keyLast;
  int64_t numOfPoints;
  SList * list;
} SCacheMem;

H
TD-34  
hzcheng 已提交
49 50 51 52 53
typedef struct {
  int              maxBytes;
  int              cacheBlockSize;
  STsdbCachePool   pool;
  STsdbCacheBlock *curBlock;
H
TD-34  
hzcheng 已提交
54 55
  SCacheMem *      mem;
  SCacheMem *      imem;
H
hzcheng 已提交
56
} STsdbCache;
H
more  
Hongze Cheng 已提交
57

H
TD-34  
hzcheng 已提交
58 59
STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize);
void        tsdbFreeCache(STsdbCache *pCache);
H
TD-34  
hzcheng 已提交
60
void *      tsdbAllocFromCache(STsdbCache *pCache, int bytes, TSKEY key);
H
more  
Hongze Cheng 已提交
61

H
more  
hzcheng 已提交
62 63 64 65
#ifdef __cplusplus
}
#endif

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