Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ef247cdb
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
提交
ef247cdb
编写于
8月 10, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support reopen stream state
上级
a20b299f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
58 deletion
+58
-58
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+5
-5
source/dnode/vnode/src/tq/tqStreamStateSnap.c
source/dnode/vnode/src/tq/tqStreamStateSnap.c
+2
-2
source/libs/stream/src/streamBackendRocksdb.c
source/libs/stream/src/streamBackendRocksdb.c
+42
-42
source/libs/stream/src/streamMeta.c
source/libs/stream/src/streamMeta.c
+9
-9
未找到文件。
include/libs/stream/tstream.h
浏览文件 @
ef247cdb
...
...
@@ -369,11 +369,11 @@ typedef struct SStreamMeta {
int32_t
chkptNotReadyTasks
;
int64_t
ch
eckpoint
Id
;
SArray
*
ch
eckpoint
Saved
;
SArray
*
ch
eckpoint
InUse
;
int32_t
ch
eckpoint
Cap
;
SRWLatch
ch
eckpoint
DirLock
;
int64_t
ch
kp
Id
;
SArray
*
ch
kp
Saved
;
SArray
*
ch
kp
InUse
;
int32_t
ch
kp
Cap
;
SRWLatch
ch
kp
DirLock
;
}
SStreamMeta
;
int32_t
tEncodeStreamEpInfo
(
SEncoder
*
pEncoder
,
const
SStreamChildEpInfo
*
pInfo
);
...
...
source/dnode/vnode/src/tq/tqStreamStateSnap.c
浏览文件 @
ef247cdb
...
...
@@ -47,11 +47,11 @@ int32_t streamStateSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamS
pReader
->
sver
=
sver
;
pReader
->
ever
=
ever
;
int64_t
ch
eckpointId
=
meta
?
meta
->
checkpoint
Id
:
0
;
int64_t
ch
kpId
=
meta
?
meta
->
chkp
Id
:
0
;
SStreamSnapReader
*
pSnapReader
=
NULL
;
if
(
streamSnapReaderOpen
(
pTq
,
sver
,
ch
eckpoint
Id
,
pTq
->
path
,
&
pSnapReader
)
==
0
)
{
if
(
streamSnapReaderOpen
(
pTq
,
sver
,
ch
kp
Id
,
pTq
->
path
,
&
pSnapReader
)
==
0
)
{
pReader
->
complete
=
1
;
}
else
{
code
=
-
1
;
...
...
source/libs/stream/src/streamBackendRocksdb.c
浏览文件 @
ef247cdb
...
...
@@ -372,8 +372,8 @@ int32_t copyFiles(const char* src, const char* dst) {
// opt later, just hard link
int32_t
sLen
=
strlen
(
src
);
int32_t
dLen
=
strlen
(
dst
);
char
*
absSrcPath
=
taosMemoryCalloc
(
1
,
sLen
+
64
);
char
*
absDstPath
=
taosMemoryCalloc
(
1
,
dLen
+
64
);
char
*
srcName
=
taosMemoryCalloc
(
1
,
sLen
+
64
);
char
*
dstName
=
taosMemoryCalloc
(
1
,
dLen
+
64
);
TdDirPtr
pDir
=
taosOpenDir
(
src
);
if
(
pDir
==
NULL
)
return
0
;
...
...
@@ -383,22 +383,22 @@ int32_t copyFiles(const char* src, const char* dst) {
char
*
name
=
taosGetDirEntryName
(
de
);
if
(
strcmp
(
name
,
"."
)
==
0
||
strcmp
(
name
,
".."
)
==
0
)
continue
;
sprintf
(
absSrcPath
,
"%s%s%s"
,
src
,
TD_DIRSEP
,
name
);
sprintf
(
absDstPath
,
"%s%s%s"
,
dst
,
TD_DIRSEP
,
name
);
sprintf
(
srcName
,
"%s%s%s"
,
src
,
TD_DIRSEP
,
name
);
sprintf
(
dstName
,
"%s%s%s"
,
dst
,
TD_DIRSEP
,
name
);
if
(
!
taosDirEntryIsDir
(
de
))
{
code
=
taosCopyFile
(
absSrcPath
,
absDstPath
);
code
=
taosCopyFile
(
srcName
,
dstName
);
if
(
code
==
-
1
)
{
goto
_err
;
}
}
memset
(
absSrcPath
,
0
,
sLen
+
64
);
memset
(
absDstPath
,
0
,
dLen
+
64
);
memset
(
srcName
,
0
,
sLen
+
64
);
memset
(
dstName
,
0
,
dLen
+
64
);
}
_err:
taosMemoryFreeClear
(
absSrcPath
);
taosMemoryFreeClear
(
absDstPath
);
taosMemoryFreeClear
(
srcName
);
taosMemoryFreeClear
(
dstName
);
taosCloseDir
(
&
pDir
);
return
code
>=
0
?
0
:
-
1
;
}
...
...
@@ -626,75 +626,75 @@ void streamBackendHandleCleanup(void* arg) {
int32_t
getLatestCheckpoint
(
void
*
arg
,
int64_t
*
checkpoint
)
{
SStreamMeta
*
pMeta
=
arg
;
taosWLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosWLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
int64_t
tc
=
0
;
int32_t
sz
=
taosArrayGetSize
(
pMeta
->
ch
eckpoint
Saved
);
int32_t
sz
=
taosArrayGetSize
(
pMeta
->
ch
kp
Saved
);
if
(
sz
<=
0
)
{
taosWUnLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosWUnLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
return
-
1
;
}
else
{
tc
=
*
(
int64_t
*
)
taosArrayGetLast
(
pMeta
->
ch
eckpoint
Saved
);
tc
=
*
(
int64_t
*
)
taosArrayGetLast
(
pMeta
->
ch
kp
Saved
);
}
taosArrayPush
(
pMeta
->
ch
eckpoint
InUse
,
&
tc
);
taosArrayPush
(
pMeta
->
ch
kp
InUse
,
&
tc
);
*
checkpoint
=
tc
;
taosWUnLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosWUnLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
return
0
;
}
/*
* checkpointSave |--cp1--|--cp2--|--cp3--|--cp4--|--cp5--|
* ch
eckpoint
InUse: |--cp2--|--cp4--|
* ch
eckpoint
InUse is doing translation, cannot del until
* ch
kp
InUse: |--cp2--|--cp4--|
* ch
kp
InUse is doing translation, cannot del until
* replication is finished
*/
int32_t
delObsoleteCheckpoint
(
void
*
arg
,
const
char
*
path
)
{
SStreamMeta
*
pMeta
=
arg
;
taosWLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosWLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
SArray
*
ch
eckpoint
Del
=
taosArrayInit
(
10
,
sizeof
(
int64_t
));
SArray
*
ch
eckpoint
Dup
=
taosArrayInit
(
10
,
sizeof
(
int64_t
));
SArray
*
ch
kp
Del
=
taosArrayInit
(
10
,
sizeof
(
int64_t
));
SArray
*
ch
kp
Dup
=
taosArrayInit
(
10
,
sizeof
(
int64_t
));
int64_t
minId
=
0
;
if
(
taosArrayGetSize
(
pMeta
->
ch
eckpoint
InUse
)
>=
1
)
{
minId
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
eckpoint
InUse
,
0
);
if
(
taosArrayGetSize
(
pMeta
->
ch
kp
InUse
)
>=
1
)
{
minId
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
kp
InUse
,
0
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pMeta
->
ch
eckpoint
Saved
);
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
eckpoint
Saved
,
i
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pMeta
->
ch
kp
Saved
);
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
kp
Saved
,
i
);
if
(
id
>=
minId
)
{
taosArrayPush
(
ch
eckpoint
Dup
,
&
id
);
taosArrayPush
(
ch
kp
Dup
,
&
id
);
}
else
{
taosArrayPush
(
ch
eckpoint
Del
,
&
id
);
taosArrayPush
(
ch
kp
Del
,
&
id
);
}
}
}
else
{
int32_t
sz
=
taosArrayGetSize
(
pMeta
->
ch
eckpoint
Saved
);
int32_t
dsz
=
sz
-
pMeta
->
ch
eckpoint
Cap
;
// del size
int32_t
sz
=
taosArrayGetSize
(
pMeta
->
ch
kp
Saved
);
int32_t
dsz
=
sz
-
pMeta
->
ch
kp
Cap
;
// del size
for
(
int
i
=
0
;
i
<
dsz
;
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
eckpoint
Saved
,
i
);
taosArrayPush
(
ch
eckpoint
Del
,
&
id
);
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
kp
Saved
,
i
);
taosArrayPush
(
ch
kp
Del
,
&
id
);
}
for
(
int
i
=
dsz
<
0
?
0
:
dsz
;
i
<
sz
;
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
eckpoint
Saved
,
i
);
taosArrayPush
(
ch
eckpoint
Dup
,
&
id
);
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
pMeta
->
ch
kp
Saved
,
i
);
taosArrayPush
(
ch
kp
Dup
,
&
id
);
}
}
taosArrayDestroy
(
pMeta
->
ch
eckpoint
Saved
);
pMeta
->
ch
eckpointSaved
=
checkpoint
Dup
;
taosArrayDestroy
(
pMeta
->
ch
kp
Saved
);
pMeta
->
ch
kpSaved
=
chkp
Dup
;
taosWUnLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosWUnLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
ch
eckpoint
Del
);
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
ch
eckpoint
Del
,
i
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
ch
kp
Del
);
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
ch
kp
Del
,
i
);
char
tbuf
[
256
]
=
{
0
};
sprintf
(
tbuf
,
"%s%scheckpoint%"
PRId64
""
,
path
,
TD_DIRSEP
,
id
);
if
(
taosIsDir
(
tbuf
))
{
taosRemoveDir
(
tbuf
);
}
}
taosArrayDestroy
(
ch
eckpoint
Del
);
taosArrayDestroy
(
ch
kp
Del
);
return
0
;
}
...
...
@@ -742,7 +742,7 @@ int32_t streamBackendLoadCheckpointInfo(void* arg) {
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
suffix
);
i
++
)
{
int64_t
id
=
*
(
int64_t
*
)
taosArrayGet
(
suffix
,
i
);
taosArrayPush
(
pMeta
->
ch
eckpoint
Saved
,
&
id
);
taosArrayPush
(
pMeta
->
ch
kp
Saved
,
&
id
);
}
taosArrayDestroy
(
suffix
);
...
...
@@ -794,9 +794,9 @@ int32_t streamBackendDoCheckpoint(void* arg, uint64_t checkpointId) {
}
rocksdb_checkpoint_object_destroy
(
cp
);
}
taosWLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosArrayPush
(
pMeta
->
ch
eckpoint
Saved
,
&
checkpointId
);
taosWUnLockLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
taosWLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
taosArrayPush
(
pMeta
->
ch
kp
Saved
,
&
checkpointId
);
taosWUnLockLatch
(
&
pMeta
->
ch
kp
DirLock
);
delObsoleteCheckpoint
(
arg
,
path
);
...
...
source/libs/stream/src/streamMeta.c
浏览文件 @
ef247cdb
...
...
@@ -91,12 +91,13 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
pMeta
->
pTaskBackendUnique
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_ENTRY_LOCK
);
pMeta
->
ch
eckpoint
Saved
=
taosArrayInit
(
4
,
sizeof
(
int64_t
));
pMeta
->
ch
eckpoint
InUse
=
taosArrayInit
(
4
,
sizeof
(
int64_t
));
pMeta
->
ch
eckpoint
Cap
=
8
;
taosInitRWLatch
(
&
pMeta
->
ch
eckpoint
DirLock
);
pMeta
->
ch
kp
Saved
=
taosArrayInit
(
4
,
sizeof
(
int64_t
));
pMeta
->
ch
kp
InUse
=
taosArrayInit
(
4
,
sizeof
(
int64_t
));
pMeta
->
ch
kp
Cap
=
8
;
taosInitRWLatch
(
&
pMeta
->
ch
kp
DirLock
);
int64_t
chkpId
=
streamGetLatestCheckpointId
(
pMeta
);
pMeta
->
chkpId
=
chkpId
;
pMeta
->
streamBackend
=
streamBackendInit
(
pMeta
->
path
,
chkpId
);
if
(
pMeta
->
streamBackend
==
NULL
)
{
...
...
@@ -109,7 +110,6 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_err
;
}
taosInitRWLatch
(
&
pMeta
->
lock
);
taosThreadMutexInit
(
&
pMeta
->
backendMutex
,
NULL
);
...
...
@@ -182,9 +182,9 @@ int32_t streamMetaReopen(SStreamMeta* pMeta, int64_t chkpId) {
taosHashClear
(
pMeta
->
pTaskBackendUnique
);
taosArrayClear
(
pMeta
->
ch
eckpoint
Saved
);
taosArrayClear
(
pMeta
->
ch
kp
Saved
);
taosArrayClear
(
pMeta
->
ch
eckpoint
InUse
);
taosArrayClear
(
pMeta
->
ch
kp
InUse
);
return
0
;
}
...
...
@@ -222,8 +222,8 @@ void streamMetaClose(SStreamMeta* pMeta) {
taosThreadMutexDestroy
(
&
pMeta
->
backendMutex
);
taosHashCleanup
(
pMeta
->
pTaskBackendUnique
);
taosArrayDestroy
(
pMeta
->
ch
eckpoint
Saved
);
taosArrayDestroy
(
pMeta
->
ch
eckpoint
InUse
);
taosArrayDestroy
(
pMeta
->
ch
kp
Saved
);
taosArrayDestroy
(
pMeta
->
ch
kp
InUse
);
taosMemoryFree
(
pMeta
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录