Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2e3441d1
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2e3441d1
编写于
6月 18, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-353
上级
6eba0ff9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
34 deletion
+41
-34
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+1
-0
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+3
-1
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+37
-33
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
2e3441d1
...
...
@@ -318,6 +318,7 @@ int tsdbRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable);
int
tsdbUnRefMemTable
(
STsdbRepo
*
pRepo
,
SMemTable
*
pMemTable
);
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMemTable
**
pMem
,
SMemTable
**
pIMem
);
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
);
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
);
// ------------------ tsdbFile.c
#define TSDB_KEY_FILEID(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
2e3441d1
...
...
@@ -135,12 +135,14 @@ _err:
return
NULL
;
}
// Note: all working thread and query thread must stopped when calling this function
void
tsdbCloseRepo
(
TSDB_REPO_T
*
repo
,
int
toCommit
)
{
if
(
repo
==
NULL
)
return
;
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
repo
;
// TODO: wait for commit over
tsdbAsyncCommit
(
pRepo
);
if
(
pRepo
->
commit
)
pthread_join
(
pRepo
->
commitThread
,
NULL
);
tsdbCloseFileH
(
pRepo
);
tsdbCloseBufPool
(
pRepo
);
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
2e3441d1
...
...
@@ -173,42 +173,10 @@ int tsdbTakeMemSnapshot(STsdbRepo *pRepo, SMemTable **pMem, SMemTable **pIMem) {
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
)
{
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
STsdbBufBlock
*
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
int
code
=
0
;
if
(
pBufBlock
!=
NULL
&&
pBufBlock
->
remain
<
bytes
)
{
if
(
listNEles
(
pRepo
->
mem
->
bufBlockList
)
>=
pCfg
->
totalBlocks
/
2
)
{
// need to commit mem
if
(
pRepo
->
imem
)
{
code
=
pthread_join
(
pRepo
->
commitThread
,
NULL
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to thread join since %s"
,
REPO_ID
(
pRepo
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
}
if
(
tsdbUnRefMemTable
(
pRepo
,
pRepo
->
imem
)
<
0
)
{
tsdbError
(
"vgId:%d failed to unref memtable since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
))
return
NULL
;
}
}
ASSERT
(
pRepo
->
commit
==
0
);
SMemTable
*
pImem
=
pRepo
->
imem
;
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_START
);
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
NULL
;
pRepo
->
imem
=
pRepo
->
mem
;
pRepo
->
mem
=
NULL
;
pRepo
->
commit
=
1
;
code
=
pthread_create
(
&
pRepo
->
commitThread
,
NULL
,
tsdbCommitData
,
(
void
*
)
pRepo
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to create commit thread since %s"
,
REPO_ID
(
pRepo
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
tsdbUnlockRepo
(
pRepo
);
return
NULL
;
}
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
NULL
;
if
(
pImem
&&
tsdbUnRefMemTable
(
pRepo
,
pImem
)
<
0
)
return
NULL
;
if
(
tsdbAsyncCommit
(
pRepo
)
<
0
)
return
NULL
;
}
else
{
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
NULL
;
SListNode
*
pNode
=
tsdbAllocBufBlockFromPool
(
pRepo
);
...
...
@@ -242,6 +210,42 @@ void *tsdbAllocBytes(STsdbRepo *pRepo, int bytes) {
return
ptr
;
}
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
)
{
SMemTable
*
pIMem
=
pRepo
->
imem
;
int
code
=
0
;
if
(
pIMem
!=
NULL
)
{
ASSERT
(
pRepo
->
commit
);
code
=
pthread_join
(
pRepo
->
commitThread
,
NULL
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to thread join since %s"
,
REPO_ID
(
pRepo
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
}
ASSERT
(
pRepo
->
commit
==
0
);
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_START
);
if
(
pRepo
->
mem
!=
NULL
)
{
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
-
1
;
pRepo
->
imem
=
pRepo
->
mem
;
pRepo
->
mem
=
NULL
;
pRepo
->
commit
=
1
;
code
=
pthread_create
(
&
pRepo
->
commitThread
,
NULL
,
tsdbCommitData
,
(
void
*
)
pRepo
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to create commit thread since %s"
,
REPO_ID
(
pRepo
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
tsdbUnlockRepo
(
pRepo
);
return
-
1
;
}
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
-
1
;
}
if
(
pIMem
&&
tsdbUnRefMemTable
(
pRepo
,
pIMem
)
<
0
)
return
-
1
;
return
0
;
}
// ---------------- LOCAL FUNCTIONS ----------------
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
ASSERT
(
pRepo
!=
NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录