Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d5e4fc32
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d5e4fc32
编写于
3月 20, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-34
上级
e865255b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
156 addition
and
69 deletion
+156
-69
src/util/inc/tlist.h
src/util/inc/tlist.h
+3
-4
src/util/src/tlist.c
src/util/src/tlist.c
+37
-24
src/vnode/tsdb/inc/tsdbCache.h
src/vnode/tsdb/inc/tsdbCache.h
+22
-28
src/vnode/tsdb/src/tsdbCache.c
src/vnode/tsdb/src/tsdbCache.c
+92
-11
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+2
-2
未找到文件。
src/util/inc/tlist.h
浏览文件 @
d5e4fc32
...
...
@@ -19,10 +19,7 @@
extern
"C"
{
#endif
typedef
enum
{
TD_LIST_FORWARD
,
TD_LIST_BACKWARD
}
TD_LIST_DIRECTION_T
;
typedef
enum
{
TD_LIST_FORWARD
,
TD_LIST_BACKWARD
}
TD_LIST_DIRECTION_T
;
typedef
struct
_list_node
{
struct
_list_node
*
next
;
...
...
@@ -52,6 +49,8 @@ typedef struct {
SList
*
tdListNew
(
int
eleSize
);
void
tdListFree
(
SList
*
list
);
void
tdListEmpty
(
SList
*
list
);
void
tdListPrependNode
(
SList
*
list
,
SListNode
*
node
);
void
tdListAppendNode
(
SList
*
list
,
SListNode
*
node
);
int
tdListPrepend
(
SList
*
list
,
void
*
data
);
int
tdListAppend
(
SList
*
list
,
void
*
data
);
SListNode
*
tdListPopHead
(
SList
*
list
);
...
...
src/util/src/tlist.c
浏览文件 @
d5e4fc32
...
...
@@ -43,10 +43,7 @@ void tdListFree(SList *list) {
free
(
list
);
}
int
tdListPrepend
(
SList
*
list
,
void
*
data
)
{
SListNode
*
node
=
(
SListNode
*
)
malloc
(
sizeof
(
SListNode
)
+
list
->
eleSize
);
if
(
node
==
NULL
)
return
-
1
;
void
tdListPrependNode
(
SList
*
list
,
SListNode
*
node
)
{
if
(
list
->
head
==
NULL
)
{
list
->
head
=
node
;
list
->
tail
=
node
;
...
...
@@ -57,12 +54,9 @@ int tdListPrepend(SList *list, void *data) {
list
->
head
=
node
;
}
list
->
numOfEles
++
;
return
0
;
}
int
tdListAppend
(
SList
*
list
,
void
*
data
)
{
SListNode
*
node
=
(
SListNode
*
)
malloc
(
sizeof
(
SListNode
)
+
list
->
eleSize
);
if
(
node
==
NULL
)
return
-
1
;
void
tdListAppendNode
(
SList
*
list
,
SListNode
*
node
)
{
if
(
list
->
head
==
NULL
)
{
list
->
head
=
node
;
list
->
tail
=
node
;
...
...
@@ -74,6 +68,25 @@ int tdListAppend(SList *list, void *data) {
}
list
->
numOfEles
++
;
}
int
tdListPrepend
(
SList
*
list
,
void
*
data
)
{
SListNode
*
node
=
(
SListNode
*
)
malloc
(
sizeof
(
SListNode
)
+
list
->
eleSize
);
if
(
node
==
NULL
)
return
-
1
;
memcpy
((
void
*
)(
node
->
data
),
data
,
list
->
eleSize
);
tdListPrependNode
(
list
,
node
);
return
0
;
}
int
tdListAppend
(
SList
*
list
,
void
*
data
)
{
SListNode
*
node
=
(
SListNode
*
)
malloc
(
sizeof
(
SListNode
)
+
list
->
eleSize
);
if
(
node
==
NULL
)
return
-
1
;
memcpy
((
void
*
)(
node
->
data
),
data
,
list
->
eleSize
);
tdListAppendNode
(
list
,
node
);
return
0
;
}
...
...
@@ -104,22 +117,22 @@ SListNode *tdListPopTail(SList *list) {
}
SListNode
*
tdListPopNode
(
SList
*
list
,
SListNode
*
node
)
{
if
(
list
->
head
==
node
)
{
list
->
head
=
node
->
next
;
}
if
(
list
->
tail
==
node
)
{
list
->
tail
=
node
->
prev
;
}
if
(
node
->
prev
!=
NULL
)
{
node
->
prev
->
next
=
node
->
next
;
}
if
(
node
->
next
!=
NULL
)
{
node
->
next
->
prev
=
node
->
prev
;
}
list
->
numOfEles
--
;
return
node
;
if
(
list
->
head
==
node
)
{
list
->
head
=
node
->
next
;
}
if
(
list
->
tail
==
node
)
{
list
->
tail
=
node
->
prev
;
}
if
(
node
->
prev
!=
NULL
)
{
node
->
prev
->
next
=
node
->
next
;
}
if
(
node
->
next
!=
NULL
)
{
node
->
next
->
prev
=
node
->
prev
;
}
list
->
numOfEles
--
;
return
node
;
}
void
tdListNodeGetData
(
SList
*
list
,
SListNode
*
node
,
void
*
target
)
{
memcpy
(
node
->
data
,
target
,
list
->
eleSize
);
}
...
...
src/vnode/tsdb/inc/tsdbCache.h
浏览文件 @
d5e4fc32
...
...
@@ -17,45 +17,39 @@
#include <stdint.h>
// #include "cache
.h"
#include "tlist
.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
*1024*
1024
/* 16M */
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
* 1024 *
1024
/* 16M */
typedef
struct
{
int64_t
skey
;
// start key
int64_t
ekey
;
// end key
int32_t
numOfRows
;
// numOfRows
}
STableCacheInfo
;
int
blockId
;
int
offset
;
int
remain
;
int
padding
;
char
data
[];
}
STsdbCacheBlock
;
typedef
struct
_tsdb_cache_block
{
char
*
pData
;
STableCacheInfo
*
pTableInfo
;
struct
_tsdb_cache_block
*
prev
;
struct
_tsdb_cache_block
*
next
;
}
STSDBCacheBlock
;
typedef
struct
{
int64_t
index
;
SList
*
memPool
;
}
STsdbCachePool
;
// Use a doublely linked list to implement this
typedef
struct
STSDBCache
{
// Number of blocks the cache is allocated
int32_t
numOfBlocks
;
STSDBCacheBlock
*
cacheList
;
void
*
current
;
typedef
struct
{
int
maxBytes
;
int
cacheBlockSize
;
STsdbCachePool
pool
;
STsdbCacheBlock
*
curBlock
;
SList
*
mem
;
SList
*
imem
;
}
STsdbCache
;
// ---- Operation on STSDBCacheBlock
#define TSDB_CACHE_BLOCK_DATA(pBlock) ((pBlock)->pData)
#define TSDB_CACHE_AVAIL_SPACE(pBlock) ((char *)((pBlock)->pTableInfo) - ((pBlock)->pData))
#define TSDB_TABLE_INFO_OF_CACHE(pBlock, tableId) ((pBlock)->pTableInfo)[tableId]
#define TSDB_NEXT_CACHE_BLOCK(pBlock) ((pBlock)->next)
#define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev)
STsdbCache
*
tsdbInitCache
(
int64_t
maxSize
);
int32_t
tsdbFreeCache
(
STsdbCache
*
pCache
);
void
*
tsdbAllocFromCache
(
STsdbCache
*
pCache
,
int64_t
bytes
);
STsdbCache
*
tsdbInitCache
(
int
maxBytes
,
int
cacheBlockSize
);
void
tsdbFreeCache
(
STsdbCache
*
pCache
);
void
*
tsdbAllocFromCache
(
STsdbCache
*
pCache
,
int
bytes
);
#ifdef __cplusplus
}
...
...
src/vnode/tsdb/src/tsdbCache.c
浏览文件 @
d5e4fc32
...
...
@@ -16,22 +16,103 @@
#include "tsdbCache.h"
STsdbCache
*
tsdbInitCache
(
int64_t
maxSize
)
{
STsdbCache
*
pCacheHandle
=
(
STsdbCache
*
)
malloc
(
sizeof
(
STsdbCache
));
if
(
pCacheHandle
==
NULL
)
{
// TODO : deal with the error
return
NULL
;
static
int
tsdbAllocBlockFromPool
(
STsdbCache
*
pCache
);
static
void
tsdbFreeBlockList
(
SList
*
list
);
STsdbCache
*
tsdbInitCache
(
int
maxBytes
,
int
cacheBlockSize
)
{
STsdbCache
*
pCache
=
(
STsdbCache
*
)
calloc
(
1
,
sizeof
(
STsdbCache
));
if
(
pCache
==
NULL
)
return
NULL
;
pCache
->
maxBytes
=
maxBytes
;
pCache
->
cacheBlockSize
=
cacheBlockSize
;
int
nBlocks
=
maxBytes
/
cacheBlockSize
+
1
;
if
(
nBlocks
<=
1
)
nBlocks
=
2
;
STsdbCachePool
*
pPool
=
&
(
pCache
->
pool
);
pPool
->
index
=
0
;
pPool
->
memPool
=
tdListNew
(
sizeof
(
STsdbCacheBlock
*
));
if
(
pPool
->
memPool
==
NULL
)
goto
_err
;
for
(
int
i
=
0
;
i
<
nBlocks
;
i
++
)
{
STsdbCacheBlock
*
pBlock
=
(
STsdbCacheBlock
*
)
malloc
(
sizeof
(
STsdbCacheBlock
)
+
cacheBlockSize
);
if
(
pBlock
==
NULL
)
{
goto
_err
;
}
pBlock
->
offset
=
0
;
pBlock
->
remain
=
cacheBlockSize
;
tdListAppend
(
pPool
->
memPool
,
(
void
*
)(
&
pBlock
));
}
return
pCacheHandle
;
pCache
->
mem
=
tdListNew
(
sizeof
(
STsdbCacheBlock
*
));
if
(
pCache
->
mem
==
NULL
)
goto
_err
;
pCache
->
imem
=
tdListNew
(
sizeof
(
STsdbCacheBlock
*
));
if
(
pCache
->
imem
==
NULL
)
goto
_err
;
return
pCache
;
_err:
tsdbFreeCache
(
pCache
);
return
NULL
;
}
int32_t
tsdbFreeCache
(
STsdbCache
*
pHandle
)
{
return
0
;
}
void
tsdbFreeCache
(
STsdbCache
*
pCache
)
{
tsdbFreeBlockList
(
pCache
->
imem
);
tsdbFreeBlockList
(
pCache
->
mem
);
tsdbFreeBlockList
(
pCache
->
pool
.
memPool
);
free
(
pCache
);
}
void
*
tsdbAllocFromCache
(
STsdbCache
*
pCache
,
int64_t
bytes
)
{
// TODO: implement here
void
*
ptr
=
malloc
(
bytes
);
if
(
ptr
==
NULL
)
return
NULL
;
void
*
tsdbAllocFromCache
(
STsdbCache
*
pCache
,
int
bytes
)
{
if
(
pCache
==
NULL
)
return
NULL
;
if
(
bytes
>
pCache
->
cacheBlockSize
)
return
NULL
;
if
(
isListEmpty
(
pCache
->
imem
))
{
if
(
tsdbAllocBlockFromPool
(
pCache
)
<
0
)
{
// TODO: deal with the error
}
}
if
(
pCache
->
curBlock
->
remain
<
bytes
)
{
if
(
tsdbAllocBlockFromPool
(
pCache
)
<
0
)
{
// TODO: deal with the error
}
}
void
*
ptr
=
(
void
*
)(
pCache
->
curBlock
->
data
+
pCache
->
curBlock
->
offset
);
pCache
->
curBlock
->
offset
+=
bytes
;
pCache
->
curBlock
->
remain
-=
bytes
;
return
ptr
;
}
static
void
tsdbFreeBlockList
(
SList
*
list
)
{
if
(
list
==
NULL
)
return
;
SListNode
*
node
=
NULL
;
STsdbCacheBlock
*
pBlock
=
NULL
;
while
((
node
=
tdListPopHead
(
list
))
!=
NULL
)
{
tdListNodeGetData
(
list
,
node
,
(
void
*
)(
&
pBlock
));
free
(
pBlock
);
listNodeFree
(
node
);
}
tdListFree
(
list
);
}
static
int
tsdbAllocBlockFromPool
(
STsdbCache
*
pCache
)
{
STsdbCachePool
*
pPool
=
&
(
pCache
->
pool
);
if
(
listNEles
(
pPool
->
memPool
)
==
0
)
return
-
1
;
SListNode
*
node
=
tdListPopHead
(
pPool
->
memPool
);
STsdbCacheBlock
*
pBlock
=
NULL
;
tdListNodeGetData
(
pPool
->
memPool
,
node
,
(
void
*
)(
&
pBlock
));
pBlock
->
blockId
=
pPool
->
index
++
;
pBlock
->
offset
=
0
;
pBlock
->
remain
=
pCache
->
cacheBlockSize
;
tdListAppendNode
(
pPool
->
memPool
,
node
);
pCache
->
curBlock
=
pBlock
;
return
0
;
}
\ No newline at end of file
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
d5e4fc32
...
...
@@ -163,7 +163,7 @@ tsdb_repo_t *tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO
pRepo
->
tsdbMeta
=
pMeta
;
// Initialize cache
STsdbCache
*
pCache
=
tsdbInitCache
(
pCfg
->
maxCacheSize
);
STsdbCache
*
pCache
=
tsdbInitCache
(
pCfg
->
maxCacheSize
,
-
1
);
if
(
pCache
==
NULL
)
{
free
(
pRepo
->
rootDir
);
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
...
...
@@ -244,7 +244,7 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
return
NULL
;
}
pRepo
->
tsdbCache
=
tsdbInitCache
(
pRepo
->
config
.
maxCacheSize
);
pRepo
->
tsdbCache
=
tsdbInitCache
(
pRepo
->
config
.
maxCacheSize
,
-
1
);
if
(
pRepo
->
tsdbCache
==
NULL
)
{
tsdbFreeMeta
(
pRepo
->
tsdbMeta
);
free
(
pRepo
->
rootDir
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录