Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1c5346b1
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
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看板
提交
1c5346b1
编写于
8月 19, 2023
作者:
Y
yihaoDeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor checkpoint
上级
52788aca
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
100 addition
and
59 deletion
+100
-59
source/libs/stream/src/streamBackendRocksdb.c
source/libs/stream/src/streamBackendRocksdb.c
+100
-59
未找到文件。
source/libs/stream/src/streamBackendRocksdb.c
浏览文件 @
1c5346b1
...
@@ -420,7 +420,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) {
...
@@ -420,7 +420,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) {
/*param@1: checkpointId dir
/*param@1: checkpointId dir
param@2: state
param@2: state
copy
checkpointd
ir's file to state dir
copy
pChkpIdD
ir's file to state dir
opt to set hard link to previous file
opt to set hard link to previous file
*/
*/
char
*
state
=
taosMemoryCalloc
(
1
,
strlen
(
path
)
+
32
);
char
*
state
=
taosMemoryCalloc
(
1
,
strlen
(
path
)
+
32
);
...
@@ -770,8 +770,9 @@ int32_t streamBackendLoadCheckpointInfo(void* arg) {
...
@@ -770,8 +770,9 @@ int32_t streamBackendLoadCheckpointInfo(void* arg) {
return
0
;
return
0
;
}
}
int32_t
streamBackendGetAllCfHandle
(
SStreamMeta
*
pMeta
,
SArray
*
pHandle
,
SArray
*
refs
)
{
int32_t
chkpGetAllDbCfHandle
(
SStreamMeta
*
pMeta
,
rocksdb_column_family_handle_t
***
ppHandle
,
SArray
*
refs
)
{
void
*
pIter
=
taosHashIterate
(
pMeta
->
pTaskBackendUnique
,
NULL
);
SArray
*
pHandle
=
taosArrayInit
(
16
,
POINTER_BYTES
);
void
*
pIter
=
taosHashIterate
(
pMeta
->
pTaskBackendUnique
,
NULL
);
while
(
pIter
)
{
while
(
pIter
)
{
int64_t
id
=
*
(
int64_t
*
)
pIter
;
int64_t
id
=
*
(
int64_t
*
)
pIter
;
...
@@ -790,6 +791,77 @@ int32_t streamBackendGetAllCfHandle(SStreamMeta* pMeta, SArray* pHandle, SArray*
...
@@ -790,6 +791,77 @@ int32_t streamBackendGetAllCfHandle(SStreamMeta* pMeta, SArray* pHandle, SArray*
taosArrayPush
(
refs
,
&
id
);
taosArrayPush
(
refs
,
&
id
);
pIter
=
taosHashIterate
(
pMeta
->
pTaskBackendUnique
,
pIter
);
pIter
=
taosHashIterate
(
pMeta
->
pTaskBackendUnique
,
pIter
);
}
}
int32_t
nCf
=
taosArrayGetSize
(
pHandle
);
rocksdb_column_family_handle_t
**
ppCf
=
taosMemoryCalloc
(
nCf
,
sizeof
(
rocksdb_column_family_handle_t
*
));
for
(
int
i
=
0
;
i
<
nCf
;
i
++
)
{
ppCf
[
i
]
=
taosArrayGetP
(
pHandle
,
i
);
}
taosArrayDestroy
(
pHandle
);
*
ppHandle
=
ppCf
;
return
nCf
;
}
int32_t
chkpDoDbCheckpoint
(
rocksdb_t
*
db
,
char
*
path
)
{
int32_t
code
=
-
1
;
char
*
err
=
NULL
;
rocksdb_checkpoint_t
*
cp
=
rocksdb_checkpoint_object_create
(
db
,
&
err
);
if
(
cp
==
NULL
||
err
!=
NULL
)
{
qError
(
"failed to do checkpoint at:%s, reason:%s"
,
path
,
err
);
taosMemoryFreeClear
(
err
);
goto
_ERROR
;
}
rocksdb_checkpoint_create
(
cp
,
path
,
64
<<
20
,
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"failed to do checkpoint at:%s, reason:%s"
,
path
,
err
);
taosMemoryFreeClear
(
err
);
}
else
{
code
=
0
;
}
_ERROR:
rocksdb_checkpoint_object_destroy
(
cp
);
return
code
;
}
int32_t
chkpPreFlushDb
(
rocksdb_t
*
db
,
rocksdb_column_family_handle_t
**
cf
,
int32_t
nCf
)
{
int
code
=
-
1
;
char
*
err
=
NULL
;
rocksdb_flushoptions_t
*
flushOpt
=
rocksdb_flushoptions_create
();
rocksdb_flushoptions_set_wait
(
flushOpt
,
1
);
rocksdb_flush_cfs
(
db
,
flushOpt
,
cf
,
nCf
,
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"failed to flush db before streamBackend clean up, reason:%s"
,
err
);
taosMemoryFree
(
err
);
}
code
=
0
;
rocksdb_flushoptions_destroy
(
flushOpt
);
return
code
;
}
int32_t
chkpPreCheckDir
(
char
*
path
,
int64_t
chkpId
,
char
**
chkpDir
,
char
**
chkpIdDir
)
{
int32_t
code
=
0
;
char
*
pChkpDir
=
taosMemoryCalloc
(
1
,
256
);
char
*
pChkpIdDir
=
taosMemoryCalloc
(
1
,
256
);
sprintf
(
pChkpDir
,
"%s%s%s"
,
path
,
TD_DIRSEP
,
"checkpoints"
);
code
=
taosMulModeMkDir
(
pChkpDir
,
0755
);
if
(
code
!=
0
)
{
qError
(
"failed to prepare checkpoint dir, path:%s, reason:%s"
,
path
,
tstrerror
(
code
));
taosMemoryFree
(
pChkpDir
);
taosMemoryFree
(
pChkpIdDir
);
code
=
-
1
;
return
code
;
}
sprintf
(
pChkpIdDir
,
"%s%scheckpoint%"
PRId64
,
pChkpDir
,
TD_DIRSEP
,
chkpId
);
if
(
taosIsDir
(
pChkpIdDir
))
{
qInfo
(
"stream rm exist checkpoint%s"
,
pChkpIdDir
);
taosRemoveFile
(
pChkpIdDir
);
}
*
chkpDir
=
pChkpDir
;
*
chkpIdDir
=
pChkpIdDir
;
return
0
;
return
0
;
}
}
int32_t
streamBackendDoCheckpoint
(
void
*
arg
,
uint64_t
checkpointId
)
{
int32_t
streamBackendDoCheckpoint
(
void
*
arg
,
uint64_t
checkpointId
)
{
...
@@ -801,66 +873,33 @@ int32_t streamBackendDoCheckpoint(void* arg, uint64_t checkpointId) {
...
@@ -801,66 +873,33 @@ int32_t streamBackendDoCheckpoint(void* arg, uint64_t checkpointId) {
SArray
*
refs
=
taosArrayInit
(
16
,
sizeof
(
int64_t
));
SArray
*
refs
=
taosArrayInit
(
16
,
sizeof
(
int64_t
));
SArray
*
pCf
=
taosArrayInit
(
16
,
POINTER_BYTES
);
SArray
*
pCf
=
taosArrayInit
(
16
,
POINTER_BYTES
);
char
path
[
256
]
=
{
0
};
rocksdb_column_family_handle_t
**
ppCf
=
NULL
;
sprintf
(
path
,
"%s%s%s"
,
pMeta
->
path
,
TD_DIRSEP
,
"checkpoints"
);
code
=
taosMulModeMkDir
(
path
,
0755
);
if
(
code
!=
0
)
{
qError
(
"failed to prepare checkpoint dir, path:%s, reason:%s"
,
path
,
tstrerror
(
code
));
return
code
;
}
char
checkpointDir
[
256
]
=
{
0
};
snprintf
(
checkpointDir
,
tListLen
(
checkpointDir
),
"%s%scheckpoint%"
PRId64
,
path
,
TD_DIRSEP
,
checkpointId
);
SBackendWrapper
*
pHandle
=
taosAcquireRef
(
streamBackendId
,
backendRid
);
char
*
pChkpDir
=
NULL
;
if
(
pHandle
==
NULL
)
{
char
*
pChkpIdDir
=
NULL
;
return
-
1
;
if
(
chkpPreCheckDir
(
pMeta
->
path
,
checkpointId
,
&
pChkpDir
,
&
pChkpIdDir
)
!=
0
)
{
}
goto
_ERROR
;
streamBackendGetAllCfHandle
(
pMeta
,
pCf
,
refs
);
int32_t
nCf
=
taosArrayGetSize
(
pCf
);
rocksdb_column_family_handle_t
**
ppCf
=
taosMemoryCalloc
(
nCf
,
sizeof
(
rocksdb_column_family_handle_t
*
));
for
(
int
i
=
0
;
i
<
nCf
;
i
++
)
{
ppCf
[
i
]
=
taosArrayGetP
(
pCf
,
i
);
}
}
qDebug
(
"stream backend:%p start to do checkpoint at:%s, %d "
,
pHandle
,
checkpointDir
,
nCf
);
SBackendWrapper
*
pHandle
=
taosAcquireRef
(
streamBackendId
,
backendRid
);
if
(
taosIsDir
(
checkpointDir
))
{
if
(
pHandle
==
NULL
||
pHandle
->
db
==
NULL
)
{
qInfo
(
"stream rm exist checkpoint%s"
,
checkpointDir
);
goto
_ERROR
;
taosRemoveFile
(
checkpointDir
);
}
}
i
f
(
pHandle
->
db
!=
NULL
)
{
i
nt32_t
nCf
=
chkpGetAllDbCfHandle
(
pMeta
,
&
ppCf
,
refs
);
char
*
err
=
NULL
;
qDebug
(
"stream backend:%p start to do checkpoint at:%s, cf num: %d "
,
pHandle
,
pChkpIdDir
,
nCf
)
;
rocksdb_flushoptions_t
*
flushOpt
=
rocksdb_flushoptions_create
();
code
=
chkpPreFlushDb
(
pHandle
->
db
,
ppCf
,
nCf
);
rocksdb_flushoptions_set_wait
(
flushOpt
,
1
);
if
(
code
==
0
)
{
code
=
chkpDoDbCheckpoint
(
pHandle
->
db
,
pChkpIdDir
);
rocksdb_flush_cfs
(
pHandle
->
db
,
flushOpt
,
ppCf
,
nCf
,
&
err
);
if
(
code
!=
0
)
{
if
(
err
!=
NULL
)
{
qError
(
"stream backend:%p failed to do checkpoint at:%s"
,
pHandle
,
pChkpIdDir
);
qError
(
"failed to flush db before streamBackend clean up, reason:%s"
,
err
);
taosMemoryFree
(
err
);
}
rocksdb_flushoptions_destroy
(
flushOpt
);
rocksdb_checkpoint_t
*
cp
=
rocksdb_checkpoint_object_create
(
pHandle
->
db
,
&
err
);
if
(
cp
==
NULL
||
err
!=
NULL
)
{
qError
(
"stream backend:%p failed to do checkpoint at:%s, reason:%s"
,
pHandle
,
checkpointDir
,
err
);
taosMemoryFreeClear
(
err
);
code
=
-
1
;
goto
_ERROR
;
}
rocksdb_checkpoint_create
(
cp
,
checkpointDir
,
64
<<
20
,
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"stream backend:%p failed to do checkpoint at:%s, reason:%s"
,
pHandle
,
checkpointDir
,
err
);
taosMemoryFreeClear
(
err
);
}
else
{
}
else
{
code
=
0
;
qDebug
(
"stream backend:%p end to do checkpoint at:%s, time cost:%"
PRId64
"ms"
,
pHandle
,
pChkpIdDir
,
qDebug
(
"stream backend:%p end to do checkpoint at:%s, time cost:%"
PRId64
"ms"
,
pHandle
,
checkpointDir
,
taosGetTimestampMs
()
-
st
);
taosGetTimestampMs
()
-
st
);
}
}
rocksdb_checkpoint_object_destroy
(
cp
);
}
else
{
qError
(
"stream backend:%p failed to flush db at:%s"
,
pHandle
,
pChkpIdDir
);
}
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
refs
);
i
++
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
refs
);
i
++
)
{
...
@@ -871,15 +910,17 @@ int32_t streamBackendDoCheckpoint(void* arg, uint64_t checkpointId) {
...
@@ -871,15 +910,17 @@ int32_t streamBackendDoCheckpoint(void* arg, uint64_t checkpointId) {
taosWLockLatch
(
&
pMeta
->
chkpDirLock
);
taosWLockLatch
(
&
pMeta
->
chkpDirLock
);
taosArrayPush
(
pMeta
->
chkpSaved
,
&
checkpointId
);
taosArrayPush
(
pMeta
->
chkpSaved
,
&
checkpointId
);
taosWUnLockLatch
(
&
pMeta
->
chkpDirLock
);
taosWUnLockLatch
(
&
pMeta
->
chkpDirLock
);
}
taosArrayDestroy
(
refs
);
taosMemoryFree
(
ppCf
);
delObsoleteCheckpoint
(
arg
,
path
);
// delete obsolte checkpoint
delObsoleteCheckpoint
(
arg
,
pChkpDir
);
}
_ERROR:
_ERROR:
taosReleaseRef
(
streamBackendId
,
backendRid
);
taosReleaseRef
(
streamBackendId
,
backendRid
);
taosArrayDestroy
(
refs
);
taosMemoryFree
(
ppCf
);
taosMemoryFree
(
pChkpDir
);
taosMemoryFree
(
pChkpIdDir
);
return
code
;
return
code
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录