Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
59646be2
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看板
提交
59646be2
编写于
7月 26, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'feature/stream' into fix/wal
上级
9d5acf18
dd18eeb6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
46 deletion
+46
-46
include/libs/wal/wal.h
include/libs/wal/wal.h
+2
-2
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+7
-7
source/libs/wal/src/walSeek.c
source/libs/wal/src/walSeek.c
+12
-12
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+25
-25
未找到文件。
include/libs/wal/wal.h
浏览文件 @
59646be2
...
...
@@ -103,8 +103,8 @@ typedef struct SWal {
int32_t
fsyncSeq
;
// meta
SWalVer
vers
;
TdFilePtr
p
WriteLogT
File
;
TdFilePtr
p
WriteIdxT
File
;
TdFilePtr
p
Log
File
;
TdFilePtr
p
Idx
File
;
int32_t
writeCur
;
SArray
*
fileInfoSet
;
// SArray<SWalFileInfo>
// status
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
59646be2
...
...
@@ -101,8 +101,8 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
// open meta
walResetVer
(
&
pWal
->
vers
);
pWal
->
p
WriteLogT
File
=
NULL
;
pWal
->
p
WriteIdxT
File
=
NULL
;
pWal
->
p
Log
File
=
NULL
;
pWal
->
p
Idx
File
=
NULL
;
pWal
->
writeCur
=
-
1
;
pWal
->
fileInfoSet
=
taosArrayInit
(
8
,
sizeof
(
SWalFileInfo
));
if
(
pWal
->
fileInfoSet
==
NULL
)
{
...
...
@@ -179,10 +179,10 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
void
walClose
(
SWal
*
pWal
)
{
taosThreadMutexLock
(
&
pWal
->
mutex
);
taosCloseFile
(
&
pWal
->
p
WriteLogT
File
);
pWal
->
p
WriteLogT
File
=
NULL
;
taosCloseFile
(
&
pWal
->
p
WriteIdxT
File
);
pWal
->
p
WriteIdxT
File
=
NULL
;
taosCloseFile
(
&
pWal
->
p
Log
File
);
pWal
->
p
Log
File
=
NULL
;
taosCloseFile
(
&
pWal
->
p
Idx
File
);
pWal
->
p
Idx
File
=
NULL
;
walSaveMeta
(
pWal
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
pWal
->
fileInfoSet
=
NULL
;
...
...
@@ -223,7 +223,7 @@ static void walFsyncAll() {
if
(
walNeedFsync
(
pWal
))
{
wTrace
(
"vgId:%d, do fsync, level:%d seq:%d rseq:%d"
,
pWal
->
cfg
.
vgId
,
pWal
->
cfg
.
level
,
pWal
->
fsyncSeq
,
atomic_load_32
(
&
tsWal
.
seq
));
int32_t
code
=
taosFsyncFile
(
pWal
->
p
WriteLogT
File
);
int32_t
code
=
taosFsyncFile
(
pWal
->
p
Log
File
);
if
(
code
!=
0
)
{
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to fsync since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
code
));
...
...
source/libs/wal/src/walSeek.c
浏览文件 @
59646be2
...
...
@@ -22,8 +22,8 @@
static
int64_t
walSeekWritePos
(
SWal
*
pWal
,
int64_t
ver
)
{
int64_t
code
=
0
;
TdFilePtr
pIdxTFile
=
pWal
->
p
WriteIdxT
File
;
TdFilePtr
pLogTFile
=
pWal
->
p
WriteLogT
File
;
TdFilePtr
pIdxTFile
=
pWal
->
p
Idx
File
;
TdFilePtr
pLogTFile
=
pWal
->
p
Log
File
;
// seek position
int64_t
idxOff
=
walGetVerIdxOffset
(
pWal
,
ver
);
...
...
@@ -68,8 +68,8 @@ int walInitWriteFile(SWal* pWal) {
return
-
1
;
}
// switch file
pWal
->
p
WriteIdxT
File
=
pIdxTFile
;
pWal
->
p
WriteLogT
File
=
pLogTFile
;
pWal
->
p
Idx
File
=
pIdxTFile
;
pWal
->
p
Log
File
=
pLogTFile
;
pWal
->
writeCur
=
taosArrayGetSize
(
pWal
->
fileInfoSet
)
-
1
;
return
0
;
}
...
...
@@ -78,15 +78,15 @@ int walChangeWrite(SWal* pWal, int64_t ver) {
int
code
;
TdFilePtr
pIdxTFile
,
pLogTFile
;
char
fnameStr
[
WAL_FILE_LEN
];
if
(
pWal
->
p
WriteLogT
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
WriteLogT
File
);
if
(
pWal
->
p
Log
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
Log
File
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
}
if
(
pWal
->
p
WriteIdxT
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
WriteIdxT
File
);
if
(
pWal
->
p
Idx
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
Idx
File
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
...
...
@@ -106,7 +106,7 @@ int walChangeWrite(SWal* pWal, int64_t ver) {
pIdxTFile
=
taosOpenFile
(
fnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
if
(
pIdxTFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
pWal
->
p
WriteIdxT
File
=
NULL
;
pWal
->
p
Idx
File
=
NULL
;
return
-
1
;
}
walBuildLogName
(
pWal
,
fileFirstVer
,
fnameStr
);
...
...
@@ -114,12 +114,12 @@ int walChangeWrite(SWal* pWal, int64_t ver) {
if
(
pLogTFile
==
NULL
)
{
taosCloseFile
(
&
pIdxTFile
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
pWal
->
p
WriteLogT
File
=
NULL
;
pWal
->
p
Log
File
=
NULL
;
return
-
1
;
}
pWal
->
p
WriteLogT
File
=
pLogTFile
;
pWal
->
p
WriteIdxT
File
=
pIdxTFile
;
pWal
->
p
Log
File
=
pLogTFile
;
pWal
->
p
Idx
File
=
pIdxTFile
;
pWal
->
writeCur
=
idx
;
return
fileFirstVer
;
}
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
59646be2
...
...
@@ -32,8 +32,8 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
}
}
taosCloseFile
(
&
pWal
->
p
WriteLogT
File
);
taosCloseFile
(
&
pWal
->
p
WriteIdxT
File
);
taosCloseFile
(
&
pWal
->
p
Log
File
);
taosCloseFile
(
&
pWal
->
p
Idx
File
);
if
(
pWal
->
vers
.
firstVer
!=
-
1
)
{
int32_t
fileSetSize
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
...
...
@@ -324,34 +324,34 @@ END:
int32_t
walRollImpl
(
SWal
*
pWal
)
{
int32_t
code
=
0
;
if
(
pWal
->
p
WriteIdxT
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
WriteIdxT
File
);
if
(
pWal
->
p
Idx
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
Idx
File
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
END
;
}
}
if
(
pWal
->
p
WriteLogT
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
WriteLogT
File
);
if
(
pWal
->
p
Log
File
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
p
Log
File
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
END
;
}
}
TdFilePtr
pIdx
TFile
,
pLogT
File
;
TdFilePtr
pIdx
File
,
pLog
File
;
// create new file
int64_t
newFileFirstVer
sion
=
pWal
->
vers
.
lastVer
+
1
;
int64_t
newFileFirstVer
=
pWal
->
vers
.
lastVer
+
1
;
char
fnameStr
[
WAL_FILE_LEN
];
walBuildIdxName
(
pWal
,
newFileFirstVer
sion
,
fnameStr
);
pIdx
T
File
=
taosOpenFile
(
fnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
if
(
pIdx
T
File
==
NULL
)
{
walBuildIdxName
(
pWal
,
newFileFirstVer
,
fnameStr
);
pIdxFile
=
taosOpenFile
(
fnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
if
(
pIdxFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
code
=
-
1
;
goto
END
;
}
walBuildLogName
(
pWal
,
newFileFirstVer
sion
,
fnameStr
);
pLog
T
File
=
taosOpenFile
(
fnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
if
(
pLog
T
File
==
NULL
)
{
walBuildLogName
(
pWal
,
newFileFirstVer
,
fnameStr
);
pLogFile
=
taosOpenFile
(
fnameStr
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
if
(
pLogFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
code
=
-
1
;
goto
END
;
...
...
@@ -363,8 +363,8 @@ int32_t walRollImpl(SWal *pWal) {
}
// switch file
pWal
->
p
WriteIdxTFile
=
pIdxT
File
;
pWal
->
p
WriteLogTFile
=
pLogT
File
;
pWal
->
p
IdxFile
=
pIdx
File
;
pWal
->
p
LogFile
=
pLog
File
;
pWal
->
writeCur
=
taosArrayGetSize
(
pWal
->
fileInfoSet
)
-
1
;
ASSERT
(
pWal
->
writeCur
>=
0
);
...
...
@@ -378,10 +378,10 @@ END:
static
int32_t
walWriteIndex
(
SWal
*
pWal
,
int64_t
ver
,
int64_t
offset
)
{
SWalIdxEntry
entry
=
{.
ver
=
ver
,
.
offset
=
offset
};
int64_t
idxOffset
=
taosLSeekFile
(
pWal
->
p
WriteIdxT
File
,
0
,
SEEK_END
);
int64_t
idxOffset
=
taosLSeekFile
(
pWal
->
p
Idx
File
,
0
,
SEEK_END
);
wDebug
(
"vgId:%d, write index, index:%"
PRId64
", offset:%"
PRId64
", at %"
PRId64
,
pWal
->
cfg
.
vgId
,
ver
,
offset
,
idxOffset
);
int64_t
size
=
taosWriteFile
(
pWal
->
p
WriteIdxT
File
,
&
entry
,
sizeof
(
SWalIdxEntry
));
int64_t
size
=
taosWriteFile
(
pWal
->
p
Idx
File
,
&
entry
,
sizeof
(
SWalIdxEntry
));
if
(
size
!=
sizeof
(
SWalIdxEntry
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
// TODO truncate
...
...
@@ -407,7 +407,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
pWal
->
writeHead
.
cksumHead
=
walCalcHeadCksum
(
&
pWal
->
writeHead
);
pWal
->
writeHead
.
cksumBody
=
walCalcBodyCksum
(
body
,
bodyLen
);
if
(
taosWriteFile
(
pWal
->
p
WriteLogT
File
,
&
pWal
->
writeHead
,
sizeof
(
SWalCkHead
))
!=
sizeof
(
SWalCkHead
))
{
if
(
taosWriteFile
(
pWal
->
p
Log
File
,
&
pWal
->
writeHead
,
sizeof
(
SWalCkHead
))
!=
sizeof
(
SWalCkHead
))
{
// TODO ftruncate
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
...
...
@@ -416,7 +416,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
goto
END
;
}
if
(
taosWriteFile
(
pWal
->
p
WriteLogT
File
,
(
char
*
)
body
,
bodyLen
)
!=
bodyLen
)
{
if
(
taosWriteFile
(
pWal
->
p
Log
File
,
(
char
*
)
body
,
bodyLen
)
!=
bodyLen
)
{
// TODO ftruncate
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
...
...
@@ -456,14 +456,14 @@ int64_t walAppendLog(SWal *pWal, tmsg_t msgType, SWalSyncInfo syncMeta, const vo
return
-
1
;
}
if
(
pWal
->
p
WriteIdxTFile
==
NULL
||
pWal
->
pWriteIdxT
File
==
NULL
||
pWal
->
writeCur
<
0
)
{
if
(
pWal
->
p
IdxFile
==
NULL
||
pWal
->
pIdx
File
==
NULL
||
pWal
->
writeCur
<
0
)
{
if
(
walInitWriteFile
(
pWal
)
<
0
)
{
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
return
-
1
;
}
}
ASSERT
(
pWal
->
p
WriteIdxTFile
!=
NULL
&&
pWal
->
pWriteLogT
File
!=
NULL
&&
pWal
->
writeCur
>=
0
);
ASSERT
(
pWal
->
p
IdxFile
!=
NULL
&&
pWal
->
pLog
File
!=
NULL
&&
pWal
->
writeCur
>=
0
);
if
(
walWriteImpl
(
pWal
,
index
,
msgType
,
syncMeta
,
body
,
bodyLen
)
<
0
)
{
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
...
...
@@ -494,14 +494,14 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SWalSync
return
-
1
;
}
if
(
pWal
->
p
WriteIdxTFile
==
NULL
||
pWal
->
pWriteIdxT
File
==
NULL
||
pWal
->
writeCur
<
0
)
{
if
(
pWal
->
p
IdxFile
==
NULL
||
pWal
->
pIdx
File
==
NULL
||
pWal
->
writeCur
<
0
)
{
if
(
walInitWriteFile
(
pWal
)
<
0
)
{
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
return
-
1
;
}
}
ASSERT
(
pWal
->
p
WriteIdxTFile
!=
NULL
&&
pWal
->
pWriteLogT
File
!=
NULL
&&
pWal
->
writeCur
>=
0
);
ASSERT
(
pWal
->
p
IdxFile
!=
NULL
&&
pWal
->
pLog
File
!=
NULL
&&
pWal
->
writeCur
>=
0
);
if
(
walWriteImpl
(
pWal
,
index
,
msgType
,
syncMeta
,
body
,
bodyLen
)
<
0
)
{
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
...
...
@@ -524,7 +524,7 @@ int32_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
void
walFsync
(
SWal
*
pWal
,
bool
forceFsync
)
{
if
(
forceFsync
||
(
pWal
->
cfg
.
level
==
TAOS_WAL_FSYNC
&&
pWal
->
cfg
.
fsyncPeriod
==
0
))
{
wTrace
(
"vgId:%d, fileId:%"
PRId64
".log, do fsync"
,
pWal
->
cfg
.
vgId
,
walGetCurFileFirstVer
(
pWal
));
if
(
taosFsyncFile
(
pWal
->
p
WriteLogT
File
)
<
0
)
{
if
(
taosFsyncFile
(
pWal
->
p
Log
File
)
<
0
)
{
wError
(
"vgId:%d, file:%"
PRId64
".log, fsync failed since %s"
,
pWal
->
cfg
.
vgId
,
walGetCurFileFirstVer
(
pWal
),
strerror
(
errno
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录