Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
944d6a9c
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看板
提交
944d6a9c
编写于
5月 19, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
5847774b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
71 deletion
+71
-71
include/util/tarray2.h
include/util/tarray2.h
+18
-11
source/dnode/vnode/src/tsdb/dev/inc/tsdbDef.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbDef.h
+1
-0
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
+2
-3
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+41
-48
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
+9
-9
未找到文件。
include/util/tarray2.h
浏览文件 @
944d6a9c
...
...
@@ -44,12 +44,19 @@ extern "C" {
#define TARRAY2_ELEM(a, i) ((a)->data[i])
#define TARRAY2_ELEM_PTR(a, i) (&((a)->data[i]))
static
FORCE_INLINE
int32_t
tarray2_make_room
(
int32_t
*
c
,
void
**
pp
,
int32_t
elem_size
)
{
int32_t
capacity
=
c
[
0
]
?
(
c
[
0
]
<<
1
)
:
TARRAY2_MIN_SIZE
;
void
*
p
=
taosMemoryRealloc
(
pp
[
0
],
capacity
*
elem_size
);
static
FORCE_INLINE
int32_t
tarray2_make_room
(
void
*
arg
,
// array
int32_t
es
,
// expected size
int32_t
sz
// size of element
)
{
TARRAY2
(
void
)
*
a
=
arg
;
int32_t
capacity
=
a
->
capacity
?
(
a
->
capacity
<<
1
)
:
TARRAY2_MIN_SIZE
;
while
(
capacity
<
es
)
{
capacity
<<=
1
;
}
void
*
p
=
taosMemoryRealloc
(
a
->
data
,
capacity
*
sz
);
if
(
p
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
c
[
0
]
=
capacity
;
pp
[
0
]
=
p
;
a
->
capacity
=
capacity
;
a
->
data
=
p
;
return
0
;
}
...
...
@@ -60,11 +67,11 @@ static FORCE_INLINE int32_t tarray2_make_room(int32_t *c, void **pp, int32_t ele
(a)->data = NULL; \
} while (0)
#define TARRAY2_FREE(a) \
do { \
if ((a)->data) { \
taosMemoryFree(
a
->data); \
} \
#define TARRAY2_FREE(a)
\
do {
\
if ((a)->data) {
\
taosMemoryFree(
(a)
->data); \
}
\
} while (0)
#define TARRAY2_CLEAR(a, cb) \
...
...
@@ -84,7 +91,7 @@ static FORCE_INLINE int32_t tarray2_make_room(int32_t *c, void **pp, int32_t ele
({ \
int32_t __ret = 0; \
if ((a)->size >= (a)->capacity) { \
__ret = tarray2_make_room(&(a)
->capacity, (void **)&(a)->data, sizeof(*(a)->data));
\
__ret = tarray2_make_room(&(a)
, (a)->size + 1, sizeof(*(a)->data));
\
} \
if (!__ret) { \
if ((a)->size > (idx)) { \
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbDef.h
浏览文件 @
944d6a9c
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tarray2.h"
#include "tsdb.h"
#ifndef _TD_TSDB_DEF_H_
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
浏览文件 @
944d6a9c
...
...
@@ -48,11 +48,10 @@ struct STFileSystem {
tsem_t
canEdit
;
int32_t
state
;
int64_t
neid
;
SArray
*
cstate
;
// current state, SArray<STFileSet>
// new state
EFEditT
etype
;
int64_t
eid
;
SArray
*
nstate
;
// staging state, SArray<STFileSet>
TARRAY2
(
STFileSet
*
)
cstate
;
TARRAY2
(
STFileSet
*
)
nstate
;
};
#ifdef __cplusplus
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
944d6a9c
...
...
@@ -41,27 +41,20 @@ static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) {
fs
[
0
]
=
taosMemoryCalloc
(
1
,
sizeof
(
*
fs
[
0
]));
if
(
fs
[
0
]
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
fs
[
0
]
->
cstate
=
taosArrayInit
(
16
,
sizeof
(
STFileSet
));
fs
[
0
]
->
nstate
=
taosArrayInit
(
16
,
sizeof
(
STFileSet
));
if
(
fs
[
0
]
->
cstate
==
NULL
||
fs
[
0
]
->
nstate
==
NULL
)
{
taosArrayDestroy
(
fs
[
0
]
->
nstate
);
taosArrayDestroy
(
fs
[
0
]
->
cstate
);
taosMemoryFree
(
fs
[
0
]);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
fs
[
0
]
->
pTsdb
=
pTsdb
;
fs
[
0
]
->
state
=
TSDB_FS_STATE_NONE
;
tsem_init
(
&
fs
[
0
]
->
canEdit
,
0
,
1
);
fs
[
0
]
->
state
=
TSDB_FS_STATE_NONE
;
fs
[
0
]
->
neid
=
0
;
TARRAY2_INIT
(
&
fs
[
0
]
->
cstate
);
TARRAY2_INIT
(
&
fs
[
0
]
->
nstate
);
return
0
;
}
static
int32_t
destroy_fs
(
STFileSystem
**
fs
)
{
if
(
fs
[
0
]
==
NULL
)
return
0
;
taosArrayDestroy
(
fs
[
0
]
->
n
state
);
taosArrayDestroy
(
fs
[
0
]
->
c
state
);
TARRAY2_FREE
(
&
fs
[
0
]
->
c
state
);
TARRAY2_FREE
(
&
fs
[
0
]
->
n
state
);
tsem_destroy
(
&
fs
[
0
]
->
canEdit
);
taosMemoryFree
(
fs
[
0
]);
fs
[
0
]
=
NULL
;
...
...
@@ -249,14 +242,14 @@ static bool is_same_file(const STFile *f1, const STFile f2) {
}
static
int32_t
apply_commit_add_fset
(
STFileSystem
*
fs
,
const
STFileSet
*
fset
)
{
int32_t
idx
=
taosArraySearchIdx
(
fs
->
cstate
,
fset
,
(
__compar_fn_t
)
tsdbFSetCmprFn
,
TD_GT
);
if
(
idx
<
0
)
idx
=
taosArrayGetSize
(
fs
->
cstate
);
//
int32_t idx = taosArraySearchIdx(fs->cstate, fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GT);
//
if (idx < 0) idx = taosArrayGetSize(fs->cstate);
STFileSet
*
pFileSet
=
taosArrayInsert
(
fs
->
cstate
,
idx
,
fset
);
if
(
pFileSet
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
//
STFileSet *pFileSet = taosArrayInsert(fs->cstate, idx, fset);
//
if (pFileSet == NULL) return TSDB_CODE_OUT_OF_MEMORY;
int32_t
code
=
tsdbFileSetInitEx
(
fset
,
pFileSet
);
if
(
code
)
return
code
;
//
int32_t code = tsdbFileSetInitEx(fset, pFileSet);
//
if (code) return code;
return
0
;
}
...
...
@@ -289,12 +282,12 @@ static int32_t apply_commit_upd_fset(STFileSystem *fs, STFileSet *fset_from, con
static
int32_t
apply_commit
(
STFileSystem
*
fs
)
{
int32_t
code
=
0
;
int32_t
i1
=
0
,
i2
=
0
;
int32_t
n1
=
taosArrayGetSize
(
fs
->
cstate
);
int32_t
n2
=
taosArrayGetSize
(
fs
->
nstate
);
int32_t
n1
=
TARRAY2_SIZE
(
&
fs
->
cstate
);
int32_t
n2
=
TARRAY2_SIZE
(
&
fs
->
nstate
);
while
(
i1
<
n1
||
i2
<
n2
)
{
STFileSet
*
fset1
=
i1
<
n1
?
(
STFileSet
*
)
taosArrayGet
(
fs
->
cstate
,
i1
)
:
NULL
;
STFileSet
*
fset2
=
i2
<
n2
?
(
STFileSet
*
)
taosArrayGet
(
fs
->
nstate
,
i2
)
:
NULL
;
STFileSet
*
fset1
=
i1
<
n1
?
TARRAY2_ELEM
(
&
fs
->
cstate
,
i1
)
:
NULL
;
STFileSet
*
fset2
=
i2
<
n2
?
TARRAY2_ELEM
(
&
fs
->
nstate
,
i2
)
:
NULL
;
if
(
fset1
&&
fset2
)
{
if
(
fset1
->
fid
<
fset2
->
fid
)
{
...
...
@@ -427,8 +420,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
current_fname
(
pTsdb
,
mCurrent
,
TSDB_FCURRENT_M
);
if
(
taosCheckExistFile
(
fCurrent
))
{
// current.json exists
code
=
load_fs
(
fCurrent
,
fs
->
cstate
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
//
code = load_fs(fCurrent, fs->cstate);
//
TSDB_CHECK_CODE(code, lino, _exit);
if
(
taosCheckExistFile
(
cCurrent
))
{
// current.c.json exists
...
...
@@ -438,8 +431,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
code
=
abort_edit
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
code
=
load_fs
(
cCurrent
,
fs
->
nstate
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
//
code = load_fs(cCurrent, fs->nstate);
//
TSDB_CHECK_CODE(code, lino, _exit);
code
=
commit_edit
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
@@ -454,8 +447,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
code
=
scan_and_fix_fs
(
fs
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
code
=
save_fs
(
fs
->
cstate
,
fCurrent
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
//
code = save_fs(fs->cstate, fCurrent);
//
TSDB_CHECK_CODE(code, lino, _exit);
}
_exit:
...
...
@@ -496,22 +489,22 @@ static int32_t edit_fs(STFileSystem *pFS, const SArray *aFileOp) {
struct
STFileOp
*
op
=
taosArrayGet
(
aFileOp
,
iop
);
if
(
pSet
==
NULL
||
pSet
->
fid
!=
op
->
fid
)
{
STFileSet
fset
=
{.
fid
=
op
->
fid
};
int32_t
idx
=
taosArraySearchIdx
(
pFS
->
nstate
,
&
fset
,
(
__compar_fn_t
)
tsdbFSetCmprFn
,
TD_GE
);
pSet
=
NULL
;
if
(
idx
<
0
)
{
idx
=
taosArrayGetSize
(
pFS
->
nstate
);
}
else
{
pSet
=
taosArrayGet
(
pFS
->
nstate
,
idx
);
if
(
pSet
->
fid
!=
op
->
fid
)
pSet
=
NULL
;
}
if
(
!
pSet
)
{
pSet
=
taosArrayInsert
(
pFS
->
nstate
,
idx
,
&
fset
);
if
(
!
pSet
)
TSDB_CHECK_CODE
(
code
=
TSDB_CODE_OUT_OF_MEMORY
,
lino
,
_exit
);
tsdbFileSetInit
(
pSet
,
op
->
fid
);
}
//
STFileSet fset = {.fid = op->fid};
//
int32_t idx = taosArraySearchIdx(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GE);
//
pSet = NULL;
//
if (idx < 0) {
//
idx = taosArrayGetSize(pFS->nstate);
//
} else {
//
pSet = taosArrayGet(pFS->nstate, idx);
//
if (pSet->fid != op->fid) pSet = NULL;
//
}
//
if (!pSet) {
//
pSet = taosArrayInsert(pFS->nstate, idx, &fset);
//
if (!pSet) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
//
tsdbFileSetInit(pSet, op->fid);
//
}
}
code
=
tsdbFileSetEdit
(
pSet
,
op
);
...
...
@@ -575,8 +568,8 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, int64_t eid, const SArray *aFileOp, EF
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// save fs
code
=
save_fs
(
fs
->
nstate
,
current_t
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
//
code = save_fs(fs->nstate, current_t);
//
TSDB_CHECK_CODE(code, lino, _exit);
_exit:
if
(
code
)
{
...
...
@@ -601,7 +594,7 @@ int32_t tsdbFSEditAbort(STFileSystem *fs) {
}
int32_t
tsdbFSGetFSet
(
STFileSystem
*
fs
,
int32_t
fid
,
const
STFileSet
**
ppFSet
)
{
STFileSet
fset
=
{.
fid
=
fid
};
ppFSet
[
0
]
=
taosArraySearch
(
fs
->
cstate
,
&
fset
,
(
__compar_fn_t
)
tsdbFSetCmprFn
,
TD_EQ
);
//
STFileSet fset = {.fid = fid};
//
ppFSet[0] = taosArraySearch(fs->cstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_EQ);
return
0
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
浏览文件 @
944d6a9c
...
...
@@ -94,15 +94,15 @@ int32_t tsdbMerge(STsdb *pTsdb) {
code
=
tsdbOpenMerger
(
pTsdb
,
&
pMerger
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pTsdb
->
pFS
->
cstate
);
i
++
)
{
struct
STFileSet
*
pFileSet
=
taosArrayGet
(
pTsdb
->
pFS
->
cstate
,
i
);
if
(
!
tsdbFileSetShouldMerge
(
pFileSet
))
{
continue
;
}
code
=
tsdbFileSetMerge
(
pFileSet
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
//
for (int32_t i = 0; i < taosArrayGetSize(pTsdb->pFS->cstate); i++) {
//
struct STFileSet *pFileSet = taosArrayGet(pTsdb->pFS->cstate, i);
//
if (!tsdbFileSetShouldMerge(pFileSet)) {
//
continue;
//
}
//
code = tsdbFileSetMerge(pFileSet);
//
TSDB_CHECK_CODE(code, lino, _exit);
//
}
code
=
tsdbCloseMerger
(
&
pMerger
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录