From e4535ab88af339e01e17420df7e0ac2f84fc7d09 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 8 Feb 2020 20:10:19 +0800 Subject: [PATCH] more --- src/vnode/cache/inc/cache.h | 6 +++-- src/vnode/common/datastructure/inc/dlist.h | 29 ++++++++++++++++++++++ src/vnode/tsdb/inc/tsdbCache.h | 14 ++++++++--- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/vnode/common/datastructure/inc/dlist.h diff --git a/src/vnode/cache/inc/cache.h b/src/vnode/cache/inc/cache.h index c90c47a621..52f357ee8f 100644 --- a/src/vnode/cache/inc/cache.h +++ b/src/vnode/cache/inc/cache.h @@ -1,12 +1,14 @@ #if !defined(_TD_CACHE_H_) #define _TD_CACHE_H_ +#define TD_MIN_CACHE_BLOCK_SIZE 1024*1024 /* 1M */ +#define TD_MAX_CACHE_BLOCK_SIZE 64*1024*1024 /* 64M */ + typedef void cache_pool_t; typedef struct SCacheBlock { - SCacheBlock *next; - SCacheBlock *prev; + int32_t blockId; char data[]; } SCacheBlock; diff --git a/src/vnode/common/datastructure/inc/dlist.h b/src/vnode/common/datastructure/inc/dlist.h new file mode 100644 index 0000000000..81a3b32ab0 --- /dev/null +++ b/src/vnode/common/datastructure/inc/dlist.h @@ -0,0 +1,29 @@ +// A doubly linked list +#if !defined(_TD_DLIST_H_) +#define _TD_DLIST_H_ + +#include + +typedef struct { + SListNode *prev; + SListNode *next; + void * data; +} SListNode; + +// Doubly linked list +typedef struct { + SListNode *head; + SListNode *tail; + int32_t length; +} SDList; + +// ----- Set operation +#define TD_GET_DLIST_LENGTH(pDList) (((SDList *)pDList)->length) +#define TD_GET_DLIST_HEAD(pDList) (((SDList *)pDList)->head) +#define TD_GET_DLIST_TAIL(pDList) (((SDList *)pDList)->tail) + +#define TD_GET_DLIST_NEXT_NODE(pDNode) (((SListNode *)pDNode)->next) +#define TD_GET_DLIST_PREV_NODE(pDNode) (((SListNode *)pDNode)->prev) +#define TD_GET_DLIST_NODE_DATA(pDNode) (((SListNode *)pDNode)->data) + +#endif // _TD_DLIST_H_ diff --git a/src/vnode/tsdb/inc/tsdbCache.h b/src/vnode/tsdb/inc/tsdbCache.h index cafb545606..d1d2551683 100644 --- a/src/vnode/tsdb/inc/tsdbCache.h +++ b/src/vnode/tsdb/inc/tsdbCache.h @@ -4,11 +4,19 @@ #include #include "cache.h" +#include "dlist.h" +typedef struct { + int64_t blockId; + SCacheBlock *pBlock +} STSDBCacheBlock; + +// Use a doublely linked list to implement this typedef struct STSDBCache { - int64_t blockId; // A block ID counter - SCacheBlock *blockList; + int64_t blockId; // A block ID counter + SDList *cacheList; } STSDBCache; +STSDBCache *tsdbCreateCache(); -#endif // _TD_TSDBCACHE_H_ +#endif // _TD_TSDBCACHE_H_ -- GitLab