Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzh_me
TDengine
提交
d103af8f
TDengine
项目概览
lzh_me
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d103af8f
编写于
10月 31, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1872 according to the suggestion of review
上级
249e599b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
69 addition
and
19 deletion
+69
-19
src/wal/inc/walInt.h
src/wal/inc/walInt.h
+2
-1
src/wal/src/walMgmt.c
src/wal/src/walMgmt.c
+14
-7
src/wal/src/walUtil.c
src/wal/src/walUtil.c
+43
-10
src/wal/src/walWrite.c
src/wal/src/walWrite.c
+10
-1
未找到文件。
src/wal/inc/walInt.h
浏览文件 @
d103af8f
...
...
@@ -32,7 +32,7 @@ extern int32_t wDebugFlag;
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
#define WAL_PREFIX "wal"
#define WAL_PREFIX_LEN
3
#define WAL_PREFIX_LEN
2
#define WAL_REFRESH_MS 1000
#define WAL_MAX_SIZE (1024 * 1024)
#define WAL_SIGNATURE ((uint32_t)(0xFAFBFDFE))
...
...
@@ -56,6 +56,7 @@ typedef struct {
int32_t
walGetNextFile
(
SWal
*
pWal
,
int64_t
*
nextFileId
);
int32_t
walGetOldFile
(
SWal
*
pWal
,
int64_t
curFileId
,
int32_t
minDiff
,
int64_t
*
oldFileId
);
int32_t
walGetNewFile
(
SWal
*
pWal
,
int64_t
*
newFileId
);
#ifdef __cplusplus
}
...
...
src/wal/src/walMgmt.c
浏览文件 @
d103af8f
...
...
@@ -23,7 +23,6 @@
typedef
struct
{
int32_t
refId
;
int32_t
num
;
int32_t
seq
;
int8_t
stop
;
pthread_t
thread
;
...
...
@@ -85,7 +84,6 @@ void *walOpen(char *path, SWalCfg *pCfg) {
return
NULL
;
}
atomic_add_fetch_32
(
&
tsWal
.
num
,
1
);
wDebug
(
"vgId:%d, wal:%p is opened, level:%d fsyncPeriod:%d"
,
pWal
->
vgId
,
pWal
,
pWal
->
level
,
pWal
->
fsyncPeriod
);
return
pWal
;
...
...
@@ -116,19 +114,28 @@ void walClose(void *handle) {
if
(
handle
==
NULL
)
return
;
SWal
*
pWal
=
handle
;
pthread_mutex_lock
(
&
pWal
->
mutex
);
taosClose
(
pWal
->
fd
);
if
(
!
pWal
->
keep
)
{
snprintf
(
pWal
->
name
,
sizeof
(
pWal
->
name
),
"%s/%s%"
PRId64
,
pWal
->
path
,
WAL_PREFIX
,
pWal
->
fileId
);
if
(
remove
(
pWal
->
name
)
<
0
)
{
wError
(
"vgId:%d, wal:%p file:%s, failed to remove"
,
pWal
->
vgId
,
pWal
,
pWal
->
name
);
}
else
{
wDebug
(
"vgId:%d, wal:%p file:%s, it is removed"
,
pWal
->
vgId
,
pWal
,
pWal
->
name
);
int64_t
fileId
=
-
1
;
while
(
walGetNextFile
(
pWal
,
&
fileId
)
>=
0
)
{
snprintf
(
pWal
->
name
,
sizeof
(
pWal
->
name
),
"%s/%s%"
PRId64
,
pWal
->
path
,
WAL_PREFIX
,
fileId
);
if
(
fileId
==
pWal
->
fileId
)
{
wDebug
(
"vgId:%d, wal:%p file:%s, it is closed and kept"
,
pWal
->
vgId
,
pWal
,
pWal
->
name
);
}
else
if
(
remove
(
pWal
->
name
)
<
0
)
{
wError
(
"vgId:%d, wal:%p file:%s, failed to remove"
,
pWal
->
vgId
,
pWal
,
pWal
->
name
);
}
else
{
wDebug
(
"vgId:%d, wal:%p file:%s, it is removed"
,
pWal
->
vgId
,
pWal
,
pWal
->
name
);
}
}
}
else
{
wDebug
(
"vgId:%d, wal:%p file:%s, it is closed and kept"
,
pWal
->
vgId
,
pWal
,
pWal
->
name
);
}
pthread_mutex_unlock
(
&
pWal
->
mutex
);
taosRemoveRef
(
tsWal
.
refId
,
pWal
);
}
...
...
src/wal/src/walUtil.c
浏览文件 @
d103af8f
...
...
@@ -19,7 +19,7 @@
int32_t
walGetNextFile
(
SWal
*
pWal
,
int64_t
*
nextFileId
)
{
int64_t
curFileId
=
*
nextFileId
;
int64_t
near
FileId
=
INT64_MAX
;
int64_t
min
FileId
=
INT64_MAX
;
DIR
*
dir
=
opendir
(
pWal
->
path
);
if
(
dir
==
NULL
)
{
...
...
@@ -35,23 +35,23 @@ int32_t walGetNextFile(SWal *pWal, int64_t *nextFileId) {
int64_t
id
=
atoll
(
name
+
WAL_PREFIX_LEN
);
if
(
id
<=
curFileId
)
continue
;
if
(
id
<
near
FileId
)
{
near
FileId
=
id
;
if
(
id
<
min
FileId
)
{
min
FileId
=
id
;
}
}
}
closedir
(
dir
);
if
(
near
FileId
==
INT64_MAX
)
return
-
1
;
if
(
min
FileId
==
INT64_MAX
)
return
-
1
;
*
nextFileId
=
near
FileId
;
*
nextFileId
=
min
FileId
;
wTrace
(
"vgId:%d, path:%s, curFileId:%"
PRId64
" nextFileId:%"
PRId64
,
pWal
->
vgId
,
pWal
->
path
,
curFileId
,
*
nextFileId
);
return
0
;
}
int32_t
walGetOldFile
(
SWal
*
pWal
,
int64_t
curFileId
,
int32_t
minDiff
,
int64_t
*
oldFileId
)
{
int64_t
near
FileId
=
INT64_MAX
;
int64_t
min
FileId
=
INT64_MAX
;
DIR
*
dir
=
opendir
(
pWal
->
path
);
if
(
dir
==
NULL
)
{
...
...
@@ -68,18 +68,51 @@ int32_t walGetOldFile(SWal *pWal, int64_t curFileId, int32_t minDiff, int64_t *o
if
(
id
>=
curFileId
)
continue
;
minDiff
--
;
if
(
id
<
near
FileId
)
{
near
FileId
=
id
;
if
(
id
<
min
FileId
)
{
min
FileId
=
id
;
}
}
}
closedir
(
dir
);
if
(
near
FileId
==
INT64_MAX
)
return
-
1
;
if
(
min
FileId
==
INT64_MAX
)
return
-
1
;
if
(
minDiff
>
0
)
return
-
1
;
*
oldFileId
=
near
FileId
;
*
oldFileId
=
min
FileId
;
wTrace
(
"vgId:%d, path:%s, curFileId:%"
PRId64
" oldFildId:%"
PRId64
,
pWal
->
vgId
,
pWal
->
path
,
curFileId
,
*
oldFileId
);
return
0
;
}
int32_t
walGetNewFile
(
SWal
*
pWal
,
int64_t
*
newFileId
)
{
int64_t
maxFileId
=
INT64_MIN
;
DIR
*
dir
=
opendir
(
pWal
->
path
);
if
(
dir
==
NULL
)
{
wError
(
"vgId:%d, path:%s, failed to open since %s"
,
pWal
->
vgId
,
pWal
->
path
,
strerror
(
errno
));
return
-
1
;
}
struct
dirent
*
ent
;
while
((
ent
=
readdir
(
dir
))
!=
NULL
)
{
char
*
name
=
ent
->
d_name
;
if
(
strncmp
(
name
,
WAL_PREFIX
,
WAL_PREFIX_LEN
)
==
0
)
{
int64_t
id
=
atoll
(
name
+
WAL_PREFIX_LEN
);
if
(
id
>
maxFileId
)
{
maxFileId
=
id
;
}
}
}
closedir
(
dir
);
if
(
maxFileId
==
INT64_MAX
)
{
*
newFileId
=
0
;
}
else
{
*
newFileId
=
maxFileId
;
}
wTrace
(
"vgId:%d, path:%s, newFileId:%"
PRId64
,
pWal
->
vgId
,
pWal
->
path
,
*
newFileId
);
return
0
;
}
\ No newline at end of file
src/wal/src/walWrite.c
浏览文件 @
d103af8f
...
...
@@ -36,7 +36,12 @@ int32_t walRenew(void *handle) {
wDebug
(
"vgId:%d, file:%s, it is closed"
,
pWal
->
vgId
,
pWal
->
name
);
}
pWal
->
fileId
=
(
pWal
->
keep
?
0
:
taosGetTimestampUs
());
if
(
pWal
->
keep
)
{
pWal
->
fileId
=
0
;
}
else
{
if
(
walGetNewFile
(
pWal
,
&
pWal
->
fileId
)
!=
0
)
pWal
->
fileId
=
0
;
pWal
->
fileId
++
;
}
snprintf
(
pWal
->
name
,
sizeof
(
pWal
->
name
),
"%s/%s%"
PRId64
,
pWal
->
path
,
WAL_PREFIX
,
pWal
->
fileId
);
pWal
->
fd
=
open
(
pWal
->
name
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
...
...
@@ -82,6 +87,8 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pHead
,
sizeof
(
SWalHead
));
int32_t
contLen
=
pHead
->
len
+
sizeof
(
SWalHead
);
pthread_mutex_lock
(
&
pWal
->
mutex
);
if
(
taosTWrite
(
pWal
->
fd
,
pHead
,
contLen
)
!=
contLen
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%s, failed to write since %s"
,
pWal
->
vgId
,
pWal
->
name
,
strerror
(
errno
));
...
...
@@ -90,6 +97,8 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
wTrace
(
"vgId:%d, write version:%"
PRId64
", fileId:%"
PRId64
,
pWal
->
vgId
,
pWal
->
version
,
pWal
->
fileId
);
}
pthread_mutex_unlock
(
&
pWal
->
mutex
);
ASSERT
(
contLen
==
pHead
->
len
+
sizeof
(
SWalHead
));
return
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录