Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6bc0d176
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看板
提交
6bc0d176
编写于
4月 10, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
a0039fe2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
262 addition
and
63 deletion
+262
-63
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
+72
-50
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+177
-11
source/dnode/vnode/src/tsdb/dev/tsdbFS.h
source/dnode/vnode/src/tsdb/dev/tsdbFS.h
+2
-2
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
+9
-0
source/dnode/vnode/src/tsdb/dev/tsdbFSet.h
source/dnode/vnode/src/tsdb/dev/tsdbFSet.h
+2
-0
未找到文件。
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
浏览文件 @
6bc0d176
...
...
@@ -155,7 +155,7 @@ static int32_t commit_delete_data(SCommitter *pCommitter) {
int32_t
code
=
0
;
int32_t
lino
;
ASSERTS
(
0
,
"n
ot implemented yet"
);
// ASSERTS(0, "TODO: N
ot implemented yet");
int64_t
nDel
=
0
;
SMemTable
*
pMem
=
pCommitter
->
pTsdb
->
imem
;
...
...
@@ -284,7 +284,9 @@ static int32_t close_committer(SCommitter *pCommiter, int32_t eno) {
int32_t
code
=
0
;
int32_t
lino
;
// code = tsdbFSBegin(pCommiter->pTsdb, pCommiter->aFileOp);
code
=
tsdbFileSystemEditBegin
(
pCommiter
->
pTsdb
->
pFS
,
//
pCommiter
->
aFileOp
,
//
TSDB_FS_EDIT_COMMIT
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
...
...
@@ -329,57 +331,77 @@ int32_t tsdbCommitBegin(STsdb *pTsdb, SCommitInfo *pInfo) {
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
lino
,
tstrerror
(
code
));
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
//
TD_VID
(
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
else
{
tsdbInfo
(
"vgId:%d %s done, nRow:%"
PRId64
" nDel:%"
PRId64
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
pMem
->
nRow
,
tsdbInfo
(
"vgId:%d %s done, nRow:%"
PRId64
" nDel:%"
PRId64
,
//
TD_VID
(
pTsdb
->
pVnode
),
//
__func__
,
//
pMem
->
nRow
,
//
pMem
->
nDel
);
}
return
code
;
}
// int32_t tsdbCommitCommit(STsdb *pTsdb) {
// int32_t code = 0;
// int32_t lino = 0;
// SMemTable *pMemTable = pTsdb->imem;
// // lock
// taosThreadRwlockWrlock(&pTsdb->rwLock);
// code = tsdbFSCommit(pTsdb);
// if (code) {
// taosThreadRwlockUnlock(&pTsdb->rwLock);
// TSDB_CHECK_CODE(code, lino, _exit);
// }
// pTsdb->imem = NULL;
// // unlock
// taosThreadRwlockUnlock(&pTsdb->rwLock);
// if (pMemTable) {
// tsdbUnrefMemTable(pMemTable, NULL, true);
// }
// _exit:
// if (code) {
// tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
// } else {
// tsdbInfo("vgId:%d, tsdb finish commit", TD_VID(pTsdb->pVnode));
// }
// return code;
// }
// int32_t tsdbCommitAbort(STsdb *pTsdb) {
// int32_t code = 0;
// int32_t lino = 0;
// code = tsdbFSRollback(pTsdb);
// TSDB_CHECK_CODE(code, lino, _exit);
// _exit:
// if (code) {
// tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
// } else {
// tsdbInfo("vgId:%d, tsdb rollback commit", TD_VID(pTsdb->pVnode));
// }
// return code;
// }
\ No newline at end of file
int32_t
tsdbCommitCommit
(
STsdb
*
pTsdb
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
// lock
taosThreadRwlockWrlock
(
&
pTsdb
->
rwLock
);
code
=
tsdbFileSystemEditCommit
(
pTsdb
->
pFS
,
//
TSDB_FS_EDIT_COMMIT
);
if
(
code
)
{
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
pTsdb
->
imem
=
NULL
;
// unlock
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
if
(
pMemTable
)
{
tsdbUnrefMemTable
(
pMemTable
,
NULL
,
true
);
}
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed at line %d since %s"
,
//
TD_VID
(
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
else
{
tsdbInfo
(
"vgId:%d %s done"
,
//
TD_VID
(
pTsdb
->
pVnode
),
__func__
);
}
return
code
;
}
int32_t
tsdbCommitAbort
(
STsdb
*
pTsdb
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
code
=
tsdbFileSystemEditAbort
(
pTsdb
->
pFS
,
//
TSDB_FS_EDIT_COMMIT
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed at line %d since %s"
,
//
TD_VID
(
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
else
{
tsdbInfo
(
"vgId:%d %s done"
,
//
TD_VID
(
pTsdb
->
pVnode
),
//
__func__
);
}
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
6bc0d176
...
...
@@ -26,7 +26,7 @@ static int32_t create_file_system(STsdb *pTsdb, struct STFileSystem **ppFS) {
}
ppFS
[
0
]
->
pTsdb
=
pTsdb
;
tsem_init
(
&
ppFS
[
0
]
->
can
_e
dit
,
0
,
1
);
tsem_init
(
&
ppFS
[
0
]
->
can
E
dit
,
0
,
1
);
return
0
;
}
...
...
@@ -34,7 +34,7 @@ static int32_t create_file_system(STsdb *pTsdb, struct STFileSystem **ppFS) {
static
int32_t
destroy_file_system
(
struct
STFileSystem
**
ppFS
)
{
if
(
ppFS
[
0
])
{
taosArrayDestroy
(
ppFS
[
0
]
->
aFileSet
);
tsem_destroy
(
&
ppFS
[
0
]
->
can
_e
dit
);
tsem_destroy
(
&
ppFS
[
0
]
->
can
E
dit
);
taosMemoryFree
(
ppFS
[
0
]);
ppFS
[
0
]
=
NULL
;
}
...
...
@@ -42,27 +42,193 @@ static int32_t destroy_file_system(struct STFileSystem **ppFS) {
}
static
int32_t
get_current_json
(
STsdb
*
pTsdb
,
char
fname
[])
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
pTsdb
->
path
,
TD_DIRSEP
,
"current.json"
);
if
(
pTsdb
->
pVnode
->
pTfs
)
{
snprintf
(
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s%s%s"
,
//
tfsGetPrimaryPath
(
pTsdb
->
pVnode
->
pTfs
),
//
TD_DIRSEP
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
"current.json"
);
}
else
{
snprintf
(
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s"
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
"current.json"
);
}
return
0
;
}
static
int32_t
get_current_temp
(
STsdb
*
pTsdb
,
char
fname
[],
tsdb_fs_edit_t
etype
)
{
switch
(
etype
)
{
case
TSDB_FS_EDIT_COMMIT
:
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
pTsdb
->
path
,
TD_DIRSEP
,
"current.json.commit"
);
if
(
pTsdb
->
pVnode
->
pTfs
)
{
snprintf
(
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s%s%s"
,
//
tfsGetPrimaryPath
(
pTsdb
->
pVnode
->
pTfs
),
//
TD_DIRSEP
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
"current.json.commit"
);
}
else
{
snprintf
(
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s"
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
"current.json.commit"
);
}
break
;
default:
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
pTsdb
->
path
,
TD_DIRSEP
,
"current.json.t"
);
if
(
pTsdb
->
pVnode
->
pTfs
)
{
snprintf
(
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s%s%s"
,
//
tfsGetPrimaryPath
(
pTsdb
->
pVnode
->
pTfs
),
//
TD_DIRSEP
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
"current.json.t"
);
}
else
{
snprintf
(
fname
,
//
TSDB_FILENAME_LEN
,
//
"%s%s%s"
,
//
pTsdb
->
path
,
//
TD_DIRSEP
,
//
"current.json.t"
);
}
break
;
}
return
0
;
}
static
int32_t
save_fs_to_file
(
struct
STFileSystem
*
pFS
,
const
char
*
fname
)
{
cJSON
*
pJson
=
NULL
;
static
int32_t
fs_to_json_str
(
struct
STFileSystem
*
pFS
,
char
**
ppData
)
{
int32_t
code
=
0
;
int32_t
lino
;
cJSON
*
pJson
=
cJSON_CreateObject
();
if
(
pJson
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
/* format version */
TSDB_CHECK_NULL
(
//
cJSON_AddNumberToObject
(
pJson
,
//
"format"
,
//
1
/* TODO */
),
code
,
//
lino
,
//
_exit
,
//
TSDB_CODE_OUT_OF_MEMORY
);
/* next edit id */
TSDB_CHECK_NULL
(
//
cJSON_AddNumberToObject
(
pJson
,
//
"next edit id"
,
//
pFS
->
nextEditId
),
code
,
//
lino
,
//
_exit
,
//
TSDB_CODE_OUT_OF_MEMORY
);
/* file sets */
cJSON
*
aFileSetJson
;
TSDB_CHECK_NULL
(
//
aFileSetJson
=
cJSON_AddArrayToObject
(
pJson
,
"file sets"
),
//
code
,
//
lino
,
//
_exit
,
//
TSDB_CODE_OUT_OF_MEMORY
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pFS
->
aFileSet
);
i
++
)
{
struct
SFileSet
*
pFileSet
=
taosArrayGet
(
pFS
->
aFileSet
,
i
);
code
=
tsdbFileSetToJson
(
aFileSetJson
,
pFileSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
ppData
[
0
]
=
cJSON_Print
(
pJson
);
if
(
ppData
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
_exit:
cJSON_Delete
(
pJson
);
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
return
code
;
}
static
int32_t
fs_from_json_str
(
const
char
*
pData
,
struct
STFileSystem
*
pFS
)
{
int32_t
code
=
0
;
int32_t
lino
;
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
return
0
;
_exit:
return
code
;
}
static
int32_t
save_fs_to_file
(
struct
STFileSystem
*
pFS
,
const
char
*
fname
)
{
int32_t
code
=
0
;
int32_t
lino
;
char
*
pData
=
NULL
;
// to json string
code
=
fs_to_json_str
(
pFS
,
&
pData
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
TdFilePtr
fd
=
taosOpenFile
(
fname
,
//
TD_FILE_WRITE
//
|
TD_FILE_CREATE
//
|
TD_FILE_TRUNC
);
if
(
fd
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
int64_t
n
=
taosWriteFile
(
fd
,
pData
,
strlen
(
pData
)
+
1
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
taosCloseFile
(
&
fd
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
if
(
taosFsyncFile
(
fd
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
taosCloseFile
(
&
fd
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
taosCloseFile
(
&
fd
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
__func__
,
//
lino
,
//
tstrerror
(
code
));
}
else
{
tsdbDebug
(
"vgId:%d %s success"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
__func__
);
}
if
(
pData
)
{
taosMemoryFree
(
pData
);
}
return
code
;
}
static
int32_t
load_fs_from_file
(
const
char
*
fname
,
struct
STFileSystem
*
pFS
)
{
...
...
@@ -231,7 +397,7 @@ int32_t tsdbFileSystemEditBegin(struct STFileSystem *pFS, const SArray *aFileOp,
get_current_temp
(
pFS
->
pTsdb
,
fname
,
etype
);
tsem_wait
(
&
pFS
->
can
_e
dit
);
tsem_wait
(
&
pFS
->
can
E
dit
);
code
=
write_fs_to_file
(
pFS
,
fname
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
@@ -254,7 +420,7 @@ _exit:
int32_t
tsdbFileSystemEditCommit
(
struct
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
)
{
int32_t
code
=
commit_edit
(
pFS
,
etype
);
tsem_post
(
&
pFS
->
can
_e
dit
);
tsem_post
(
&
pFS
->
can
E
dit
);
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed since %s"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
...
...
@@ -279,6 +445,6 @@ int32_t tsdbFileSystemEditAbort(struct STFileSystem *pFS, tsdb_fs_edit_t etype)
etype
);
}
else
{
}
tsem_post
(
&
pFS
->
can
_e
dit
);
tsem_post
(
&
pFS
->
can
E
dit
);
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/dev/tsdbFS.h
浏览文件 @
6bc0d176
...
...
@@ -25,8 +25,8 @@ extern "C" {
/* Exposed Handle */
struct
STFileSystem
{
STsdb
*
pTsdb
;
tsem_t
can
_e
dit
;
int64_t
eidt_i
d
;
tsem_t
can
E
dit
;
int64_t
nextEditI
d
;
SArray
*
aFileSet
;
// SArray<struct SFileSet>
};
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
浏览文件 @
6bc0d176
...
...
@@ -14,3 +14,12 @@
*/
#include "dev.h"
int32_t
tsdbFileSetToJson
(
SJson
*
pJson
,
const
struct
SFileSet
*
pSet
)
{
int32_t
code
=
0
;
ASSERTS
(
0
,
"TODO: Not implemented yet"
);
_exit:
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/dev/tsdbFSet.h
浏览文件 @
6bc0d176
...
...
@@ -52,6 +52,8 @@ struct SFileSet {
}
lStt
[
TSDB_STT_FILE_LEVEL_MAX
];
};
int32_t
tsdbFileSetToJson
(
SJson
*
pJson
,
const
struct
SFileSet
*
pSet
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录