Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
023281ae
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看板
提交
023281ae
编写于
5月 09, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
faadf5d3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
93 addition
and
81 deletion
+93
-81
cmake/cmake.options
cmake/cmake.options
+0
-1
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
+9
-7
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
+9
-9
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+72
-61
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
+3
-3
未找到文件。
cmake/cmake.options
浏览文件 @
023281ae
...
...
@@ -178,7 +178,6 @@ option(
"If use dev code"
ON
)
if (${USE_DEV_CODE})
add_definitions(-DUSE_DEV_CODE)
endif(USE_DEV_CODE)
\ No newline at end of file
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
浏览文件 @
023281ae
...
...
@@ -26,26 +26,28 @@ extern "C" {
typedef
struct
STFileSystem
STFileSystem
;
typedef
enum
{
TSDB_F
S_
EDIT_COMMIT
=
1
,
//
TSDB_F
S_
EDIT_MERGE
}
tsdb_fs_edit_t
;
TSDB_FEDIT_COMMIT
=
1
,
//
TSDB_FEDIT_MERGE
}
EFEditT
;
/* Exposed APIs */
// open/close
int32_t
tsdbOpenFileSystem
(
STsdb
*
pTsdb
,
STFileSystem
**
ppFS
,
int8_t
rollback
);
int32_t
tsdbCloseFileSystem
(
STFileSystem
**
ppFS
);
// txn
int32_t
tsdbF
ileSystemEditBegin
(
STFileSystem
*
pFS
,
const
SArray
*
aFileOp
,
tsdb_fs_edit_t
etype
);
int32_t
tsdbF
ileSystemEditCommit
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
);
int32_t
tsdbF
ileSystemEditAbort
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
);
int32_t
tsdbF
SEditBegin
(
STFileSystem
*
pFS
,
const
SArray
*
aFileOp
,
EFEditT
etype
);
int32_t
tsdbF
SEditCommit
(
STFileSystem
*
pFS
,
EFEditT
etype
);
int32_t
tsdbF
SEditAbort
(
STFileSystem
*
pFS
,
EFEditT
etype
);
/* Exposed Structs */
struct
STFileSystem
{
STsdb
*
pTsdb
;
int32_t
state
;
tsem_t
canEdit
;
int64_t
ne
xtEditI
d
;
int64_t
ne
i
d
;
SArray
*
cstate
;
// current state, SArray<STFileSet>
EFEditT
etype
;
int64_t
eid
;
SArray
*
nstate
;
// next state, SArray<STFileSet>
};
...
...
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
浏览文件 @
023281ae
...
...
@@ -357,11 +357,11 @@ static int32_t close_committer(SCommitter *pCommiter, int32_t eno) {
int32_t
lino
;
if
(
eno
==
0
)
{
TSDB_CHECK_CODE
(
//
code
=
tsdbF
ileSystemEditBegin
(
//
pCommiter
->
pTsdb
->
pFS
,
//
pCommiter
->
aFileOp
,
//
TSDB_F
S_
EDIT_COMMIT
),
TSDB_CHECK_CODE
(
//
code
=
tsdbF
SEditBegin
(
//
pCommiter
->
pTsdb
->
pFS
,
//
pCommiter
->
aFileOp
,
//
TSDB_FEDIT_COMMIT
),
lino
,
//
_exit
);
}
else
{
...
...
@@ -448,8 +448,8 @@ int32_t tsdbCommitCommit(STsdb *pTsdb) {
// lock
taosThreadRwlockWrlock
(
&
pTsdb
->
rwLock
);
code
=
tsdbF
ileSystem
EditCommit
(
pTsdb
->
pFS
,
//
TSDB_FS_
EDIT_COMMIT
);
code
=
tsdbF
S
EditCommit
(
pTsdb
->
pFS
,
//
TSDB_F
EDIT_COMMIT
);
if
(
code
)
{
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
@@ -481,8 +481,8 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) {
int32_t
code
=
0
;
int32_t
lino
=
0
;
code
=
tsdbF
ileSystem
EditAbort
(
pTsdb
->
pFS
,
//
TSDB_FS_
EDIT_COMMIT
);
code
=
tsdbF
S
EditAbort
(
pTsdb
->
pFS
,
//
TSDB_F
EDIT_COMMIT
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
023281ae
...
...
@@ -15,8 +15,8 @@
#include "inc/tsdbFS.h"
#define TSDB_FS_EDIT_MIN TSDB_F
S_
EDIT_COMMIT
#define TSDB_FS_EDIT_MAX (TSDB_F
S_
EDIT_MERGE + 1)
#define TSDB_FS_EDIT_MIN TSDB_FEDIT_COMMIT
#define TSDB_FS_EDIT_MAX (TSDB_FEDIT_MERGE + 1)
enum
{
TSDB_FS_STATE_NONE
=
0
,
...
...
@@ -33,8 +33,8 @@ typedef enum {
static
const
char
*
gCurrentFname
[]
=
{
[
TSDB_FCURRENT
]
=
"current.json"
,
[
TSDB_FCURRENT_C
]
=
"current.
json.0
"
,
[
TSDB_FCURRENT_M
]
=
"current.
json.1
"
,
[
TSDB_FCURRENT_C
]
=
"current.
c.json
"
,
[
TSDB_FCURRENT_M
]
=
"current.
m.json
"
,
};
static
int32_t
create_fs
(
STsdb
*
pTsdb
,
STFileSystem
**
ppFS
)
{
...
...
@@ -55,7 +55,7 @@ static int32_t create_fs(STsdb *pTsdb, STFileSystem **ppFS) {
ppFS
[
0
]
->
pTsdb
=
pTsdb
;
ppFS
[
0
]
->
state
=
TSDB_FS_STATE_NONE
;
tsem_init
(
&
ppFS
[
0
]
->
canEdit
,
0
,
1
);
ppFS
[
0
]
->
ne
xtEditI
d
=
0
;
ppFS
[
0
]
->
ne
i
d
=
0
;
return
0
;
}
...
...
@@ -194,17 +194,17 @@ static int32_t save_fs(int64_t eid, SArray *aTFileSet, const char *fname) {
}
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
aTFileSet
);
i
++
)
{
STFileSet
*
pFileSet
=
(
STFileSet
*
)
taosArrayGet
(
aTFileSet
,
i
);
cJSON
*
item
;
cJSON
*
tjson
=
cJSON_CreateObject
();
if
(
tjson
==
NULL
)
{
if
((
item
=
cJSON_CreateObject
())
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
code
=
tsdbFileSetToJson
(
pFileSet
,
tjson
);
code
=
tsdbFileSetToJson
(
pFileSet
,
item
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
cJSON_AddItemToArray
(
ajson
,
tjson
);
cJSON_AddItemToArray
(
ajson
,
item
);
}
code
=
save_json
(
json
,
fname
);
...
...
@@ -237,8 +237,7 @@ static int32_t load_fs(const char *fname, SArray *aTFileSet, int64_t *eid) {
if
(
cJSON_IsNumber
(
item
))
{
ASSERT
(
item
->
valuedouble
==
1
);
}
else
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_FILE_CORRUPTED
,
lino
,
_exit
)
}
/* eid */
...
...
@@ -246,8 +245,7 @@ static int32_t load_fs(const char *fname, SArray *aTFileSet, int64_t *eid) {
if
(
cJSON_IsNumber
(
item
))
{
eid
[
0
]
=
item
->
valuedouble
;
}
else
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_FILE_CORRUPTED
,
lino
,
_exit
)
}
/* fset */
...
...
@@ -255,18 +253,16 @@ static int32_t load_fs(const char *fname, SArray *aTFileSet, int64_t *eid) {
if
(
cJSON_IsArray
(
item
))
{
const
cJSON
*
titem
;
cJSON_ArrayForEach
(
titem
,
item
)
{
STFileSet
*
pFileSet
=
taosArrayReserve
(
aTFileSet
,
1
);
if
(
pFileSet
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
STFileSet
*
pFileSet
;
if
((
pFileSet
=
taosArrayReserve
(
aTFileSet
,
1
))
==
NULL
)
{
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_OUT_OF_MEMORY
,
lino
,
_exit
);
}
code
=
tsdbFileSetFromJson
(
titem
,
pFileSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
}
}
else
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_FILE_CORRUPTED
,
lino
,
_exit
)
}
_exit:
...
...
@@ -277,44 +273,55 @@ _exit:
return
code
;
}
static
int32_t
commit_edit
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
)
{
int32_t
code
;
char
ofname
[
TSDB_FILENAME_LEN
];
char
nfname
[
TSDB_FILENAME_LEN
];
current_fname
(
pFS
->
pTsdb
,
nfname
,
TSDB_FCURRENT
);
current_fname
(
pFS
->
pTsdb
,
ofname
,
etype
==
TSDB_FS_EDIT_COMMIT
?
TSDB_FCURRENT_C
:
TSDB_FCURRENT_M
);
static
int32_t
commit_edit
(
STFileSystem
*
pFS
)
{
char
current
[
TSDB_FILENAME_LEN
];
char
current_t
[
TSDB_FILENAME_LEN
];
code
=
taosRenameFile
(
ofname
,
nfname
);
if
(
code
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
return
code
;
current_fname
(
pFS
->
pTsdb
,
current
,
TSDB_FCURRENT
);
if
(
pFS
->
etype
==
TSDB_FEDIT_COMMIT
)
{
current_fname
(
pFS
->
pTsdb
,
current
,
TSDB_FCURRENT_C
);
}
else
if
(
pFS
->
etype
==
TSDB_FEDIT_MERGE
)
{
current_fname
(
pFS
->
pTsdb
,
current
,
TSDB_FCURRENT_M
);
}
else
{
ASSERT
(
0
);
}
ASSERTS
(
0
,
"TODO: Do changes to pFS"
);
int32_t
code
;
int32_t
lino
;
if
((
code
=
taosRenameFile
(
current_t
,
current
)))
{
TSDB_CHECK_CODE
(
code
=
TAOS_SYSTEM_ERROR
(
code
),
lino
,
_exit
)
}
return
0
;
_exit:
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
abort_edit
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
)
{
int32_t
code
;
char
fname
[
TSDB_FILENAME_LEN
];
static
int32_t
abort_edit
(
STFileSystem
*
pFS
)
{
char
fname
[
TSDB_FILENAME_LEN
];
current_fname
(
pFS
->
pTsdb
,
fname
,
etype
==
TSDB_FS_EDIT_COMMIT
?
TSDB_FCURRENT_C
:
TSDB_FCURRENT_M
);
if
(
pFS
->
etype
==
TSDB_FEDIT_COMMIT
)
{
current_fname
(
pFS
->
pTsdb
,
fname
,
TSDB_FCURRENT_C
);
}
else
if
(
pFS
->
etype
==
TSDB_FEDIT_MERGE
)
{
current_fname
(
pFS
->
pTsdb
,
fname
,
TSDB_FCURRENT_M
);
}
else
{
ASSERT
(
0
);
}
code
=
taosRemoveFile
(
fname
);
int32_t
code
=
taosRemoveFile
(
fname
);
if
(
code
)
code
=
TAOS_SYSTEM_ERROR
(
code
);
return
code
;
}
static
int32_t
scan_file_system
(
STFileSystem
*
pFS
)
{
//
ASSERTS(0, "TODO: Not implemented yet");
//
TODO
return
0
;
}
static
int32_t
scan_and_schedule_merge
(
STFileSystem
*
pFS
)
{
//
ASSERTS(0, "TODO: Not implemented yet");
//
TODO
return
0
;
}
...
...
@@ -323,12 +330,12 @@ static int32_t update_fs_if_needed(STFileSystem *pFS) {
return
0
;
}
static
int32_t
open_fs
(
STFileSystem
*
pFS
,
int8_t
rollback
)
{
static
int32_t
open_fs
(
STFileSystem
*
fs
,
int8_t
rollback
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
STsdb
*
pTsdb
=
pFS
->
pTsdb
;
STsdb
*
pTsdb
=
fs
->
pTsdb
;
code
=
update_fs_if_needed
(
pFS
);
code
=
update_fs_if_needed
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
char
fCurrent
[
TSDB_FILENAME_LEN
];
...
...
@@ -340,33 +347,37 @@ static int32_t open_fs(STFileSystem *pFS, int8_t rollback) {
current_fname
(
pTsdb
,
mCurrent
,
TSDB_FCURRENT_M
);
if
(
taosCheckExistFile
(
fCurrent
))
{
// current.json exists
code
=
load_fs
(
fCurrent
,
pFS
->
cstate
,
&
pFS
->
nextEditI
d
);
code
=
load_fs
(
fCurrent
,
fs
->
cstate
,
&
fs
->
nei
d
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// check current.json.commit existence
if
(
taosCheckExistFile
(
cCurrent
))
{
// current.c.json exists
fs
->
etype
=
TSDB_FEDIT_COMMIT
;
if
(
rollback
)
{
code
=
commit_edit
(
pFS
,
TSDB_FS_EDIT_COMMIT
);
code
=
abort_edit
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
code
=
abort_edit
(
pFS
,
TSDB_FS_EDIT_COMMIT
);
code
=
load_fs
(
cCurrent
,
fs
->
nstate
,
&
fs
->
eid
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
code
=
commit_edit
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
// check current.json.t existence
if
(
taosCheckExistFile
(
mCurrent
))
{
code
=
abort_edit
(
pFS
,
TSDB_FS_EDIT_MERGE
);
}
else
if
(
taosCheckExistFile
(
mCurrent
))
{
// current.m.json exists
fs
->
etype
=
TSDB_FEDIT_MERGE
;
code
=
abort_edit
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
code
=
scan_file_system
(
pFS
);
code
=
scan_file_system
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
scan_and_schedule_merge
(
pFS
);
code
=
scan_and_schedule_merge
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
code
=
save_fs
(
0
,
pFS
->
nstate
,
fCurrent
);
code
=
save_fs
(
0
,
fs
->
nstate
,
fCurrent
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
...
...
@@ -479,12 +490,12 @@ int32_t tsdbCloseFileSystem(STFileSystem **ppFS) {
return
0
;
}
int32_t
tsdbF
ileSystemEditBegin
(
STFileSystem
*
pFS
,
const
SArray
*
aFileOp
,
tsdb_fs_edit_t
etype
)
{
int32_t
tsdbF
SEditBegin
(
STFileSystem
*
pFS
,
const
SArray
*
aFileOp
,
EFEditT
etype
)
{
int32_t
code
=
0
;
int32_t
lino
;
char
fname
[
TSDB_FILENAME_LEN
];
// current_fname(pFS->pTsdb, fname, etype == TSDB_F
S_
EDIT_COMMIT ? TSDB_FCURRENT_C : TSDB_FCURRENT_M);
// current_fname(pFS->pTsdb, fname, etype == TSDB_FEDIT_COMMIT ? TSDB_FCURRENT_C : TSDB_FCURRENT_M);
// tsem_wait(&pFS->canEdit);
...
...
@@ -514,8 +525,8 @@ _exit:
return
code
;
}
int32_t
tsdbF
ileSystemEditCommit
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
)
{
int32_t
code
=
commit_edit
(
pFS
,
etype
);
int32_t
tsdbF
SEditCommit
(
STFileSystem
*
pFS
,
EFEditT
etype
)
{
int32_t
code
=
commit_edit
(
pFS
);
tsem_post
(
&
pFS
->
canEdit
);
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed since %s"
,
//
...
...
@@ -531,8 +542,8 @@ int32_t tsdbFileSystemEditCommit(STFileSystem *pFS, tsdb_fs_edit_t etype) {
return
code
;
}
int32_t
tsdbF
ileSystemEditAbort
(
STFileSystem
*
pFS
,
tsdb_fs_edit_t
etype
)
{
int32_t
code
=
abort_edit
(
pFS
,
etype
);
int32_t
tsdbF
SEditAbort
(
STFileSystem
*
pFS
,
EFEditT
etype
)
{
int32_t
code
=
abort_edit
(
pFS
);
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed since %s, etype:%d"
,
//
TD_VID
(
pFS
->
pTsdb
->
pVnode
),
//
...
...
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
浏览文件 @
023281ae
...
...
@@ -69,14 +69,14 @@ static int32_t tsdbCloseMerger(SMerger *pMerger) {
STsdb
*
pTsdb
=
pMerger
->
pTsdb
;
code
=
tsdbF
ileSystemEditBegin
(
pTsdb
->
pFS
,
pMerger
->
aFileOp
,
TSDB_FS_
EDIT_MERGE
);
code
=
tsdbF
SEditBegin
(
pTsdb
->
pFS
,
pMerger
->
aFileOp
,
TSDB_F
EDIT_MERGE
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
_exit:
if
(
code
)
{
tsdbF
ileSystemEditAbort
(
pTsdb
->
pFS
,
TSDB_FS_
EDIT_MERGE
);
tsdbF
SEditAbort
(
pTsdb
->
pFS
,
TSDB_F
EDIT_MERGE
);
}
else
{
tsdbF
ileSystemEditCommit
(
pTsdb
->
pFS
,
TSDB_FS_
EDIT_MERGE
);
tsdbF
SEditCommit
(
pTsdb
->
pFS
,
TSDB_F
EDIT_MERGE
);
}
tsdbDestroyMerger
(
pMerger
);
return
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录