Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2a18512e
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看板
未验证
提交
2a18512e
编写于
3月 02, 2022
作者:
wafwerar
提交者:
GitHub
3月 02, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10512 from taosdata/fix/ZhiqiangWang/TD-13756-file-system-with-lock
[TD-13756]<fix>: file system with lock.
上级
d15b1867
39062f19
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
8 deletion
+58
-8
source/os/src/osFile.c
source/os/src/osFile.c
+58
-8
未找到文件。
source/os/src/osFile.c
浏览文件 @
2a18512e
...
...
@@ -15,8 +15,6 @@
#define ALLOW_FORBID_FUNC
#include "os.h"
#define MAX_FPRINTFLINE_BUFFER_SIZE (1000)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <io.h>
...
...
@@ -46,10 +44,15 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
typedef
int32_t
FileFd
;
#define FILE_WITH_LOCK 1
typedef
struct
TdFile
{
int
refId
;
FileFd
fd
;
FILE
*
fp
;
#if FILE_WITH_LOCK
pthread_rwlock_t
rwlock
;
#endif
int
refId
;
FileFd
fd
;
FILE
*
fp
;
}
*
TdFilePtr
,
TdFile
;
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
...
...
@@ -238,6 +241,9 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
if
(
fp
!=
NULL
)
fclose
(
fp
);
return
NULL
;
}
#if FILE_WITH_LOCK
pthread_rwlock_init
(
&
(
pFile
->
rwlock
),
NULL
);
#endif
pFile
->
fd
=
fd
;
pFile
->
fp
=
fp
;
pFile
->
refId
=
0
;
...
...
@@ -249,6 +255,12 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
0
;
#else
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
)
{
return
0
;
}
#if FILE_WITH_LOCK
pthread_rwlock_wrlock
(
&
((
*
ppFile
)
->
rwlock
));
#endif
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
||
(
*
ppFile
)
->
fd
==
-
1
)
{
return
0
;
}
...
...
@@ -263,6 +275,10 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
(
*
ppFile
)
->
fd
=
-
1
;
}
(
*
ppFile
)
->
refId
=
0
;
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
((
*
ppFile
)
->
rwlock
));
pthread_rwlock_destroy
(
&
((
*
ppFile
)
->
rwlock
));
#endif
free
(
*
ppFile
);
*
ppFile
=
NULL
;
return
0
;
...
...
@@ -273,6 +289,9 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
if
(
pFile
==
NULL
)
{
return
0
;
}
#if FILE_WITH_LOCK
pthread_rwlock_rdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
int64_t
leftbytes
=
count
;
int64_t
readbytes
;
...
...
@@ -284,9 +303,15 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
if
(
errno
==
EINTR
)
{
continue
;
}
else
{
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
-
1
;
}
}
else
if
(
readbytes
==
0
)
{
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
(
int64_t
)(
count
-
leftbytes
);
}
...
...
@@ -294,6 +319,9 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
tbuf
+=
readbytes
;
}
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
count
;
}
...
...
@@ -301,14 +329,24 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
if
(
pFile
==
NULL
)
{
return
0
;
}
#if FILE_WITH_LOCK
pthread_rwlock_rdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
return
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
int64_t
ret
=
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
ret
;
}
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
)
{
if
(
pFile
==
NULL
)
{
return
0
;
}
#if FILE_WITH_LOCK
pthread_rwlock_wrlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
int64_t
nleft
=
count
;
...
...
@@ -321,12 +359,18 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
if
(
errno
==
EINTR
)
{
continue
;
}
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
-
1
;
}
nleft
-=
nwritten
;
tbuf
+=
nwritten
;
}
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
count
;
}
...
...
@@ -334,8 +378,15 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
if
(
pFile
==
NULL
)
{
return
0
;
}
#if FILE_WITH_LOCK
pthread_rwlock_rdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
return
(
int64_t
)
lseek
(
pFile
->
fd
,
(
long
)
offset
,
whence
);
int64_t
ret
=
lseek
(
pFile
->
fd
,
(
long
)
offset
,
whence
);
#if FILE_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pFile
->
rwlock
));
#endif
return
ret
;
}
int32_t
taosFStatFile
(
TdFilePtr
pFile
,
int64_t
*
size
,
int32_t
*
mtime
)
{
...
...
@@ -637,7 +688,6 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
}
assert
(
pFile
->
fp
!=
NULL
);
char
buffer
[
MAX_FPRINTFLINE_BUFFER_SIZE
]
=
{
0
};
va_list
ap
;
va_start
(
ap
,
format
);
vfprintf
(
pFile
->
fp
,
format
,
ap
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录