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
TD-34  
hzcheng 已提交
22
#include "tsdb.h"
H
more  
Hongze Cheng 已提交
23

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

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

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

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

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

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

H
TD-34  
hzcheng 已提交
61
STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize, tsdb_repo_t *pRepo);
H
TD-34  
hzcheng 已提交
62
void        tsdbFreeCache(STsdbCache *pCache);
H
TD-34  
hzcheng 已提交
63
void *      tsdbAllocFromCache(STsdbCache *pCache, int bytes, TSKEY key);
H
more  
Hongze Cheng 已提交
64

H
more  
hzcheng 已提交
65 66 67 68
#ifdef __cplusplus
}
#endif

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