tsdbCache.h 1.4 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 "tlist.h"
H
more  
Hongze Cheng 已提交
21

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

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

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

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

H
TD-34  
hzcheng 已提交
41 42 43 44 45 46 47
typedef struct {
  int              maxBytes;
  int              cacheBlockSize;
  STsdbCachePool   pool;
  STsdbCacheBlock *curBlock;
  SList *          mem;
  SList *          imem;
H
hzcheng 已提交
48
} STsdbCache;
H
more  
Hongze Cheng 已提交
49

H
TD-34  
hzcheng 已提交
50 51 52
STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize);
void        tsdbFreeCache(STsdbCache *pCache);
void *      tsdbAllocFromCache(STsdbCache *pCache, int bytes);
H
more  
Hongze Cheng 已提交
53

H
more  
hzcheng 已提交
54 55 56 57
#ifdef __cplusplus
}
#endif

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