Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cee5a2ec
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看板
提交
cee5a2ec
编写于
1月 04, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize tfile
上级
4bdac1fd
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
36 addition
and
3 deletion
+36
-3
include/util/tfile.h
include/util/tfile.h
+1
-1
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+5
-0
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+19
-1
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+1
-1
source/util/src/tfile.c
source/util/src/tfile.c
+10
-0
未找到文件。
include/util/tfile.h
浏览文件 @
cee5a2ec
...
@@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd);
...
@@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd);
bool
tfValid
(
int64_t
tfd
);
bool
tfValid
(
int64_t
tfd
);
int64_t
tfLseek
(
int64_t
tfd
,
int64_t
offset
,
int32_t
whence
);
int64_t
tfLseek
(
int64_t
tfd
,
int64_t
offset
,
int32_t
whence
);
int32_t
tfFtruncate
(
int64_t
tfd
,
int64_t
length
);
int32_t
tfFtruncate
(
int64_t
tfd
,
int64_t
length
);
void
*
tfMmapReadOnly
(
int64_t
tfd
,
int64_t
length
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
cee5a2ec
...
@@ -22,6 +22,8 @@ extern "C" {
...
@@ -22,6 +22,8 @@ extern "C" {
#include "tfile.h"
#include "tfile.h"
//#define USE_MMAP 1
#define DefaultMem 1024 * 1024
#define DefaultMem 1024 * 1024
static
char
tmpFile
[]
=
"./index"
;
static
char
tmpFile
[]
=
"./index"
;
...
@@ -39,6 +41,9 @@ typedef struct WriterCtx {
...
@@ -39,6 +41,9 @@ typedef struct WriterCtx {
bool
readOnly
;
bool
readOnly
;
char
buf
[
256
];
char
buf
[
256
];
int
size
;
int
size
;
#ifdef USE_MMAP
char
*
ptr
;
#endif
}
file
;
}
file
;
struct
{
struct
{
int32_t
capa
;
int32_t
capa
;
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
cee5a2ec
...
@@ -31,7 +31,12 @@ static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) {
...
@@ -31,7 +31,12 @@ static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) {
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
int
nRead
=
0
;
int
nRead
=
0
;
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
#ifdef USE_MMAP
nRead
=
len
<
ctx
->
file
.
size
?
len
:
ctx
->
file
.
size
;
memcpy
(
buf
,
ctx
->
file
.
ptr
,
nRead
);
#else
nRead
=
tfRead
(
ctx
->
file
.
fd
,
buf
,
len
);
nRead
=
tfRead
(
ctx
->
file
.
fd
,
buf
,
len
);
#endif
}
else
{
}
else
{
memcpy
(
buf
,
ctx
->
mem
.
buf
+
ctx
->
offset
,
len
);
memcpy
(
buf
,
ctx
->
mem
.
buf
+
ctx
->
offset
,
len
);
}
}
...
@@ -43,7 +48,13 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
...
@@ -43,7 +48,13 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
int
nRead
=
0
;
int
nRead
=
0
;
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
// tfLseek(ctx->file.fd, offset, 0);
// tfLseek(ctx->file.fd, offset, 0);
#ifdef USE_MMAP
int32_t
last
=
ctx
->
file
.
size
-
offset
;
nRead
=
last
>=
len
?
len
:
last
;
memcpy
(
buf
,
ctx
->
file
.
ptr
+
offset
,
nRead
);
#else
nRead
=
tfPread
(
ctx
->
file
.
fd
,
buf
,
len
,
offset
);
nRead
=
tfPread
(
ctx
->
file
.
fd
,
buf
,
len
,
offset
);
#endif
}
else
{
}
else
{
// refactor later
// refactor later
assert
(
0
);
assert
(
0
);
...
@@ -83,6 +94,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
...
@@ -83,6 +94,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
struct
stat
fstat
;
struct
stat
fstat
;
stat
(
path
,
&
fstat
);
stat
(
path
,
&
fstat
);
ctx
->
file
.
size
=
fstat
.
st_size
;
ctx
->
file
.
size
=
fstat
.
st_size
;
#ifdef USE_MMAP
ctx
->
file
.
ptr
=
(
char
*
)
tfMmapReadOnly
(
ctx
->
file
.
fd
,
ctx
->
file
.
size
);
#endif
}
}
memcpy
(
ctx
->
file
.
buf
,
path
,
strlen
(
path
));
memcpy
(
ctx
->
file
.
buf
,
path
,
strlen
(
path
));
if
(
ctx
->
file
.
fd
<
0
)
{
if
(
ctx
->
file
.
fd
<
0
)
{
...
@@ -111,8 +125,12 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
...
@@ -111,8 +125,12 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
if
(
ctx
->
type
==
TMemory
)
{
if
(
ctx
->
type
==
TMemory
)
{
free
(
ctx
->
mem
.
buf
);
free
(
ctx
->
mem
.
buf
);
}
else
{
}
else
{
// ctx->flush(ctx);
tfClose
(
ctx
->
file
.
fd
);
tfClose
(
ctx
->
file
.
fd
);
if
(
ctx
->
file
.
readOnly
)
{
#ifdef USE_MMAP
munmap
(
ctx
->
file
.
ptr
,
ctx
->
file
.
size
);
#endif
}
if
(
remove
)
{
unlink
(
ctx
->
file
.
buf
);
}
if
(
remove
)
{
unlink
(
ctx
->
file
.
buf
);
}
}
}
free
(
ctx
);
free
(
ctx
);
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
cee5a2ec
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#include "tutil.h"
#include "tutil.h"
using
namespace
std
;
using
namespace
std
;
#define NUM_OF_THREAD
10
#define NUM_OF_THREAD
5
class
DebugInfo
{
class
DebugInfo
{
public:
public:
...
...
source/util/src/tfile.c
浏览文件 @
cee5a2ec
...
@@ -158,3 +158,13 @@ int32_t tfFtruncate(int64_t tfd, int64_t length) {
...
@@ -158,3 +158,13 @@ int32_t tfFtruncate(int64_t tfd, int64_t length) {
taosReleaseRef
(
tsFileRsetId
,
tfd
);
taosReleaseRef
(
tsFileRsetId
,
tfd
);
return
code
;
return
code
;
}
}
void
*
tfMmapReadOnly
(
int64_t
tfd
,
int64_t
length
)
{
void
*
p
=
taosAcquireRef
(
tsFileRsetId
,
tfd
);
if
(
p
==
NULL
)
return
NULL
;
int32_t
fd
=
(
int32_t
)(
uintptr_t
)
p
;
void
*
ptr
=
mmap
(
NULL
,
length
,
PROT_READ
,
MAP_SHARED
,
fd
,
0
);
taosReleaseRef
(
tsFileRsetId
,
tfd
);
return
ptr
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录