Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d9e9155f
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d9e9155f
编写于
6月 07, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
32d95b8f
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
84 addition
and
74 deletion
+84
-74
include/util/talgo.h
include/util/talgo.h
+3
-4
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+30
-13
source/util/src/talgo.c
source/util/src/talgo.c
+43
-57
source/util/test/CMakeLists.txt
source/util/test/CMakeLists.txt
+8
-0
未找到文件。
include/util/talgo.h
浏览文件 @
d9e9155f
...
...
@@ -65,7 +65,7 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __
* @param flags
* @return
*/
void
*
taosbsearch
(
const
void
*
key
,
const
void
*
base
,
int
64_t
nmemb
,
int64_t
size
,
__compar_fn_t
fn
,
int32_t
flags
);
void
*
taosbsearch
(
const
void
*
key
,
const
void
*
base
,
int
32_t
nmemb
,
int32_t
size
,
__compar_fn_t
compar
,
int32_t
flags
);
/**
* adjust heap
...
...
@@ -82,7 +82,7 @@ void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size
* @return
*/
void
taosheapadjust
(
void
*
base
,
int32_t
size
,
int32_t
start
,
int32_t
end
,
const
void
*
parcompar
,
__ext_compar_fn_t
compar
,
char
*
buf
,
bool
maxroot
);
__ext_compar_fn_t
compar
,
char
*
buf
,
bool
maxroot
);
/**
* sort heap to make sure it is a max/min root heap
...
...
@@ -97,8 +97,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
* @param maxroot: if heap is max root heap
* @return
*/
void
taosheapsort
(
void
*
base
,
int32_t
size
,
int32_t
len
,
const
void
*
parcompar
,
__ext_compar_fn_t
compar
,
bool
maxroot
);
void
taosheapsort
(
void
*
base
,
int32_t
size
,
int32_t
len
,
const
void
*
parcompar
,
__ext_compar_fn_t
compar
,
bool
maxroot
);
#ifdef __cplusplus
}
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
d9e9155f
...
...
@@ -61,8 +61,9 @@ typedef struct {
static
int32_t
tsdbCommitData
(
SCommitH
*
pCommith
);
static
int32_t
tsdbCommitDel
(
SCommitH
*
pCommith
);
static
int32_t
tsdbCommitCache
(
SCommitH
*
pCommith
);
static
void
tsdbStartCommit
(
STsdb
*
pRepo
);
static
void
tsdbEndCommit
(
STsdb
*
pTsdb
,
int
eno
);
static
int32_t
tsdbStartCommit
(
STsdb
*
pTsdb
,
SCommitH
*
pCHandle
);
static
int32_t
tsdbEndCommit
(
SCommitH
*
pCHandle
,
int
eno
);
static
int
tsdbInitCommitH
(
SCommitH
*
pCommith
,
STsdb
*
pRepo
);
static
void
tsdbSeekCommitIter
(
SCommitH
*
pCommith
,
TSKEY
key
);
static
int
tsdbNextCommitFid
(
SCommitH
*
pCommith
);
...
...
@@ -115,9 +116,9 @@ int32_t tsdbCommit(STsdb *pTsdb) {
pTsdb
->
mem
=
NULL
;
// start commit
tsdbStartCommit
(
pTsdb
);
if
(
tsdbInitCommitH
(
&
commith
,
pTsdb
)
<
0
)
{
return
-
1
;
code
=
tsdbStartCommit
(
pTsdb
,
&
commith
);
if
(
code
)
{
goto
_err
;
}
// commit impl
...
...
@@ -137,18 +138,21 @@ int32_t tsdbCommit(STsdb *pTsdb) {
}
// end commit
tsdbDestroyCommitH
(
&
commith
);
tsdbEndCommit
(
pTsdb
,
TSDB_CODE_SUCCESS
);
code
=
tsdbEndCommit
(
&
commith
,
0
);
if
(
code
)
{
goto
_err
;
}
return
code
;
_err:
tsdbError
(
"vgId:%d failed to commit since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
static
int32_t
tsdbCommitData
(
SCommitH
*
pCommith
)
{
int32_t
fid
;
SDFileSet
*
pSet
;
SDFileSet
*
pSet
=
NULL
;
int32_t
code
=
0
;
STsdb
*
pTsdb
=
TSDB_COMMIT_REPO
(
pCommith
);
...
...
@@ -276,19 +280,32 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) {
pRtn
->
minFid
,
pRtn
->
midFid
,
pRtn
->
maxFid
);
}
static
void
tsdbStartCommit
(
STsdb
*
pRepo
)
{
SMemTable
*
pMem
=
pRepo
->
imem
;
static
int32_t
tsdbStartCommit
(
STsdb
*
pTsdb
,
SCommitH
*
pCHandle
)
{
int32_t
code
=
0
;
tsdbInfo
(
"vgId:%d, start to commit"
,
REPO_ID
(
p
Repo
));
tsdbInfo
(
"vgId:%d, start to commit"
,
REPO_ID
(
p
Tsdb
));
tsdbStartFSTxn
(
pRepo
,
0
,
0
);
if
(
tsdbInitCommitH
(
pCHandle
,
pTsdb
)
<
0
)
{
return
-
1
;
}
tsdbStartFSTxn
(
pTsdb
,
0
,
0
);
return
code
;
}
static
void
tsdbEndCommit
(
STsdb
*
pTsdb
,
int
eno
)
{
static
int32_t
tsdbEndCommit
(
SCommitH
*
pCHandle
,
int
eno
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
TSDB_COMMIT_REPO
(
pCHandle
);
tsdbDestroyCommitH
(
pCHandle
);
tsdbEndFSTxn
(
pTsdb
);
tsdbMemTableDestroy
(
pTsdb
->
imem
);
pTsdb
->
imem
=
NULL
;
tsdbInfo
(
"vgId:%d, commit over, %s"
,
REPO_ID
(
pTsdb
),
(
eno
==
TSDB_CODE_SUCCESS
)
?
"succeed"
:
"failed"
);
return
code
;
}
static
int
tsdbInitCommitH
(
SCommitH
*
pCommith
,
STsdb
*
pRepo
)
{
...
...
source/util/src/talgo.c
浏览文件 @
d9e9155f
...
...
@@ -158,82 +158,68 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __
taosMemoryFreeClear
(
buf
);
}
void
*
taosbsearch
(
const
void
*
key
,
const
void
*
base
,
int
64_t
nmemb
,
int64
_t
size
,
__compar_fn_t
compar
,
int32_t
flags
)
{
// TODO: need to check the correctness of this function
int32_t
l
=
0
;
int32_t
r
=
(
int32_t
)
nmemb
;
int32_t
idx
=
0
;
int32_t
comparison
;
void
*
taosbsearch
(
const
void
*
key
,
const
void
*
base
,
int
32_t
nmemb
,
int32
_t
size
,
__compar_fn_t
compar
,
int32_t
flags
)
{
uint8_t
*
p
;
int32_t
lidx
;
int32_t
ridx
;
int32_t
midx
;
int32_t
c
;
if
(
flags
==
TD_EQ
)
{
return
bsearch
(
key
,
base
,
nmemb
,
size
,
compar
);
}
else
if
(
flags
==
TD_GE
)
{
if
(
nmemb
<=
0
)
return
NULL
;
if
((
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
0
))
<=
0
)
return
elePtrAt
(
base
,
size
,
0
);
if
((
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
nmemb
-
1
))
>
0
)
return
NULL
;
while
(
l
<
r
)
{
idx
=
(
l
+
r
)
/
2
;
comparison
=
(
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
idx
));
if
(
comparison
<
0
)
{
r
=
idx
;
}
else
if
(
comparison
>
0
)
{
l
=
idx
+
1
;
lidx
=
0
;
ridx
=
nmemb
-
1
;
while
(
lidx
<=
ridx
)
{
midx
=
(
lidx
+
ridx
)
/
2
;
p
=
(
uint8_t
*
)
base
+
size
*
midx
;
c
=
compar
(
key
,
p
);
if
(
c
==
0
)
{
break
;
}
else
if
(
c
<
0
)
{
ridx
=
midx
-
1
;
}
else
{
return
elePtrAt
(
base
,
size
,
idx
)
;
lidx
=
midx
+
1
;
}
}
if
((
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
idx
))
<
0
)
{
return
elePtrAt
(
base
,
size
,
idx
);
if
(
flags
==
TD_EQ
)
{
if
(
c
==
0
)
{
return
p
;
}
else
{
if
(
idx
+
1
>
nmemb
-
1
)
{
return
NULL
;
}
}
else
if
(
flags
==
TD_GE
)
{
if
(
c
<=
0
)
{
return
p
;
}
else
{
return
elePtrAt
(
base
,
size
,
idx
+
1
);
if
(
midx
+
1
<
nmemb
)
{
return
p
+
size
;
}
else
{
return
NULL
;
}
}
}
else
if
(
flags
==
TD_LE
)
{
if
(
nmemb
<=
0
)
return
NULL
;
if
((
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
nmemb
-
1
))
>=
0
)
return
elePtrAt
(
base
,
size
,
nmemb
-
1
);
if
((
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
0
))
<
0
)
return
NULL
;
while
(
l
<
r
)
{
idx
=
(
l
+
r
)
/
2
;
comparison
=
(
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
idx
));
if
(
comparison
<
0
)
{
r
=
idx
;
}
else
if
(
comparison
>
0
)
{
l
=
idx
+
1
;
if
(
c
>=
0
)
{
return
p
;
}
else
{
return
elePtrAt
(
base
,
size
,
idx
);
}
}
if
((
*
compar
)(
key
,
elePtrAt
(
base
,
size
,
idx
))
>
0
)
{
return
elePtrAt
(
base
,
size
,
idx
);
if
(
midx
>
0
)
{
return
p
-
size
;
}
else
{
if
(
idx
==
0
)
{
return
NULL
;
}
else
{
return
elePtrAt
(
base
,
size
,
idx
-
1
);
}
}
}
else
{
assert
(
0
);
return
NULL
;
ASSERT
(
0
);
}
return
NULL
;
}
void
taosheapadjust
(
void
*
base
,
int32_t
size
,
int32_t
start
,
int32_t
end
,
const
void
*
parcompar
,
__ext_compar_fn_t
compar
,
char
*
buf
,
bool
maxroot
)
{
__ext_compar_fn_t
compar
,
char
*
buf
,
bool
maxroot
)
{
int32_t
parent
;
int32_t
child
;
char
*
tmp
=
NULL
;
char
*
tmp
=
NULL
;
if
(
buf
==
NULL
)
{
tmp
=
taosMemoryMalloc
(
size
);
}
else
{
...
...
@@ -288,7 +274,7 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar,
bool
maxroot
)
{
int32_t
i
;
char
*
buf
=
taosMemoryCalloc
(
1
,
size
);
char
*
buf
=
taosMemoryCalloc
(
1
,
size
);
if
(
buf
==
NULL
)
{
return
;
}
...
...
source/util/test/CMakeLists.txt
浏览文件 @
d9e9155f
...
...
@@ -68,3 +68,11 @@ add_test(
NAME bloomFilterTest
COMMAND bloomFilterTest
)
# taosbsearchTest
add_executable
(
taosbsearchTest
"taosbsearchTest.cpp"
)
target_link_libraries
(
taosbsearchTest os util gtest_main
)
add_test
(
NAME taosbsearchTest
COMMAND taosbsearchTest
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录