Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7d8e5c3a
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看板
提交
7d8e5c3a
编写于
12月 22, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor tindex write
上级
0cd932e8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
118 addition
and
103 deletion
+118
-103
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+118
-103
未找到文件。
source/libs/index/src/index_tfile.c
浏览文件 @
7d8e5c3a
...
@@ -31,112 +31,21 @@ typedef struct TFileValue {
...
@@ -31,112 +31,21 @@ typedef struct TFileValue {
int32_t
offset
;
int32_t
offset
;
}
TFileValue
;
}
TFileValue
;
// static tfileGetCompareFunc(uint8_t byte) {}
static
int
tfileValueCompare
(
const
void
*
a
,
const
void
*
b
,
const
void
*
param
);
static
int
tfileValueCompare
(
const
void
*
a
,
const
void
*
b
,
const
void
*
param
)
{
static
void
tfileSerialTableIdsToBuf
(
char
*
buf
,
SArray
*
tableIds
);
__compar_fn_t
fn
=
*
(
__compar_fn_t
*
)
param
;
TFileValue
*
av
=
(
TFileValue
*
)
a
;
TFileValue
*
bv
=
(
TFileValue
*
)
b
;
return
fn
(
av
->
colVal
,
bv
->
colVal
);
}
static
void
tfileSerialTableIdsToBuf
(
char
*
buf
,
SArray
*
tableIds
)
{
int
tbSz
=
taosArrayGetSize
(
tableIds
);
SERIALIZE_VAR_TO_BUF
(
buf
,
tbSz
,
int32_t
);
for
(
size_t
i
=
0
;
i
<
tbSz
;
i
++
)
{
uint64_t
*
v
=
taosArrayGet
(
tableIds
,
i
);
SERIALIZE_VAR_TO_BUF
(
buf
,
*
v
,
uint64_t
);
}
}
static
FORCE_INLINE
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
)
{
int32_t
fstOffset
=
offset
+
sizeof
(
tw
->
header
.
fstOffset
);
tw
->
header
.
fstOffset
=
fstOffset
;
if
(
sizeof
(
fstOffset
)
!=
tw
->
ctx
->
write
(
tw
->
ctx
,
(
char
*
)
&
fstOffset
,
sizeof
(
fstOffset
)))
{
return
-
1
;
}
return
0
;
}
static
FORCE_INLINE
int
tfileWriteHeader
(
TFileWriter
*
writer
)
{
char
buf
[
TFILE_HEADER_NO_FST
]
=
{
0
};
char
*
p
=
buf
;
TFileHeader
*
header
=
&
writer
->
header
;
static
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
);
memcpy
(
buf
,
(
char
*
)
header
,
sizeof
(
buf
));
static
int
tfileWriteHeader
(
TFileWriter
*
writer
);
static
int
tfileWriteData
(
TFileWriter
*
write
,
TFileValue
*
tval
);
int
nwrite
=
writer
->
ctx
->
write
(
writer
->
ctx
,
buf
,
sizeof
(
buf
));
static
int
tfileReadLoadHeader
(
TFileReader
*
reader
);
if
(
sizeof
(
buf
)
!=
nwrite
)
{
return
-
1
;
}
writer
->
offset
=
nwrite
;
return
0
;
}
static
int
tfileWriteData
(
TFileWriter
*
write
,
TFileValue
*
tval
)
{
TFileHeader
*
header
=
&
write
->
header
;
uint8_t
colType
=
header
->
colType
;
if
(
colType
==
TSDB_DATA_TYPE_BINARY
||
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
FstSlice
key
=
fstSliceCreate
((
uint8_t
*
)(
tval
->
colVal
),
(
size_t
)
strlen
(
tval
->
colVal
));
if
(
fstBuilderInsert
(
write
->
fb
,
key
,
tval
->
offset
))
{
fstSliceDestroy
(
&
key
);
return
0
;
}
fstSliceDestroy
(
&
key
);
return
-
1
;
}
else
{
// handle other type later
}
}
static
FORCE_INLINE
int
tfileReadLoadHeader
(
TFileReader
*
reader
)
{
// TODO simple tfile header later
char
buf
[
TFILE_HEADER_SIZE
];
char
*
p
=
buf
;
int64_t
nread
=
reader
->
ctx
->
read
(
reader
->
ctx
,
buf
,
TFILE_HEADER_SIZE
);
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
);
assert
(
nread
==
TFILE_HEADER_SIZE
);
static
void
tfileDestroyFileName
(
void
*
elem
);
memcpy
(
&
reader
->
header
,
buf
,
sizeof
(
buf
));
static
int
tfileCompare
(
const
void
*
a
,
const
void
*
b
);
return
0
;
static
int
tfileParseFileName
(
const
char
*
filename
,
uint64_t
*
suid
,
int
*
colId
,
int
*
version
);
}
static
void
tfileSerialCacheKey
(
TFileCacheKey
*
key
,
char
*
buf
);
// static tfileGetCompareFunc(uint8_t byte) {}
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
DIR
*
dir
=
opendir
(
path
);
if
(
NULL
==
dir
)
{
return
-
1
;
}
struct
dirent
*
entry
;
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
size_t
len
=
strlen
(
entry
->
d_name
);
char
*
buf
=
calloc
(
1
,
len
+
1
);
memcpy
(
buf
,
entry
->
d_name
,
len
);
taosArrayPush
(
result
,
&
buf
);
}
closedir
(
dir
);
return
0
;
}
static
void
tfileDestroyFileName
(
void
*
elem
)
{
char
*
p
=
*
(
char
**
)
elem
;
free
(
p
);
}
static
int
tfileCompare
(
const
void
*
a
,
const
void
*
b
)
{
const
char
*
aName
=
*
(
char
**
)
a
;
const
char
*
bName
=
*
(
char
**
)
b
;
size_t
aLen
=
strlen
(
aName
);
size_t
bLen
=
strlen
(
bName
);
return
strncmp
(
aName
,
bName
,
aLen
>
bLen
?
aLen
:
bLen
);
}
// tfile name suid-colId-version.tindex
static
int
tfileParseFileName
(
const
char
*
filename
,
uint64_t
*
suid
,
int
*
colId
,
int
*
version
)
{
if
(
3
==
sscanf
(
filename
,
"%"
PRIu64
"-%d-%d.tindex"
,
suid
,
colId
,
version
))
{
// read suid & colid & version success
return
0
;
}
return
-
1
;
}
static
void
tfileSerialCacheKey
(
TFileCacheKey
*
key
,
char
*
buf
)
{
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
suid
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
colType
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
version
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_STR_MEM_TO_BUF
(
buf
,
key
,
colName
,
key
->
nColName
);
}
TFileCache
*
tfileCacheCreate
(
const
char
*
path
)
{
TFileCache
*
tfileCacheCreate
(
const
char
*
path
)
{
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
...
@@ -369,3 +278,109 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
...
@@ -369,3 +278,109 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
return
0
;
return
0
;
}
}
static
int
tfileValueCompare
(
const
void
*
a
,
const
void
*
b
,
const
void
*
param
)
{
__compar_fn_t
fn
=
*
(
__compar_fn_t
*
)
param
;
TFileValue
*
av
=
(
TFileValue
*
)
a
;
TFileValue
*
bv
=
(
TFileValue
*
)
b
;
return
fn
(
av
->
colVal
,
bv
->
colVal
);
}
static
void
tfileSerialTableIdsToBuf
(
char
*
buf
,
SArray
*
tableIds
)
{
int
tbSz
=
taosArrayGetSize
(
tableIds
);
SERIALIZE_VAR_TO_BUF
(
buf
,
tbSz
,
int32_t
);
for
(
size_t
i
=
0
;
i
<
tbSz
;
i
++
)
{
uint64_t
*
v
=
taosArrayGet
(
tableIds
,
i
);
SERIALIZE_VAR_TO_BUF
(
buf
,
*
v
,
uint64_t
);
}
}
static
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
)
{
int32_t
fstOffset
=
offset
+
sizeof
(
tw
->
header
.
fstOffset
);
tw
->
header
.
fstOffset
=
fstOffset
;
if
(
sizeof
(
fstOffset
)
!=
tw
->
ctx
->
write
(
tw
->
ctx
,
(
char
*
)
&
fstOffset
,
sizeof
(
fstOffset
)))
{
return
-
1
;
}
return
0
;
}
static
int
tfileWriteHeader
(
TFileWriter
*
writer
)
{
char
buf
[
TFILE_HEADER_NO_FST
]
=
{
0
};
char
*
p
=
buf
;
TFileHeader
*
header
=
&
writer
->
header
;
memcpy
(
buf
,
(
char
*
)
header
,
sizeof
(
buf
));
int
nwrite
=
writer
->
ctx
->
write
(
writer
->
ctx
,
buf
,
sizeof
(
buf
));
if
(
sizeof
(
buf
)
!=
nwrite
)
{
return
-
1
;
}
writer
->
offset
=
nwrite
;
return
0
;
}
static
int
tfileWriteData
(
TFileWriter
*
write
,
TFileValue
*
tval
)
{
TFileHeader
*
header
=
&
write
->
header
;
uint8_t
colType
=
header
->
colType
;
if
(
colType
==
TSDB_DATA_TYPE_BINARY
||
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
FstSlice
key
=
fstSliceCreate
((
uint8_t
*
)(
tval
->
colVal
),
(
size_t
)
strlen
(
tval
->
colVal
));
if
(
fstBuilderInsert
(
write
->
fb
,
key
,
tval
->
offset
))
{
fstSliceDestroy
(
&
key
);
return
0
;
}
fstSliceDestroy
(
&
key
);
return
-
1
;
}
else
{
// handle other type later
}
}
static
int
tfileReadLoadHeader
(
TFileReader
*
reader
)
{
// TODO simple tfile header later
char
buf
[
TFILE_HEADER_SIZE
]
=
{
0
};
char
*
p
=
buf
;
int64_t
nread
=
reader
->
ctx
->
read
(
reader
->
ctx
,
buf
,
sizeof
(
buf
));
assert
(
nread
==
sizeof
(
buf
));
memcpy
(
&
reader
->
header
,
buf
,
sizeof
(
buf
));
return
0
;
}
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
DIR
*
dir
=
opendir
(
path
);
if
(
NULL
==
dir
)
{
return
-
1
;
}
struct
dirent
*
entry
;
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
size_t
len
=
strlen
(
entry
->
d_name
);
char
*
buf
=
calloc
(
1
,
len
+
1
);
memcpy
(
buf
,
entry
->
d_name
,
len
);
taosArrayPush
(
result
,
&
buf
);
}
closedir
(
dir
);
return
0
;
}
static
void
tfileDestroyFileName
(
void
*
elem
)
{
char
*
p
=
*
(
char
**
)
elem
;
free
(
p
);
}
static
int
tfileCompare
(
const
void
*
a
,
const
void
*
b
)
{
const
char
*
aName
=
*
(
char
**
)
a
;
const
char
*
bName
=
*
(
char
**
)
b
;
size_t
aLen
=
strlen
(
aName
);
size_t
bLen
=
strlen
(
bName
);
return
strncmp
(
aName
,
bName
,
aLen
>
bLen
?
aLen
:
bLen
);
}
// tfile name suid-colId-version.tindex
static
int
tfileParseFileName
(
const
char
*
filename
,
uint64_t
*
suid
,
int
*
colId
,
int
*
version
)
{
if
(
3
==
sscanf
(
filename
,
"%"
PRIu64
"-%d-%d.tindex"
,
suid
,
colId
,
version
))
{
// read suid & colid & version success
return
0
;
}
return
-
1
;
}
static
void
tfileSerialCacheKey
(
TFileCacheKey
*
key
,
char
*
buf
)
{
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
suid
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
colType
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
version
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_STR_MEM_TO_BUF
(
buf
,
key
,
colName
,
key
->
nColName
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录