Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6a4424b5
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看板
未验证
提交
6a4424b5
编写于
12月 23, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
12月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9296 from taosdata/feature/index_cache
update tindex reader
上级
59383e1c
6e7df831
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
69 addition
and
37 deletion
+69
-37
source/libs/index/inc/index_tfile.h
source/libs/index/inc/index_tfile.h
+1
-1
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+68
-36
未找到文件。
source/libs/index/inc/index_tfile.h
浏览文件 @
6a4424b5
...
...
@@ -47,7 +47,6 @@ typedef struct TFileHeader {
typedef
struct
TFileCacheKey
{
uint64_t
suid
;
uint8_t
colType
;
int32_t
version
;
char
*
colName
;
int32_t
nColName
;
}
TFileCacheKey
;
...
...
@@ -67,6 +66,7 @@ typedef struct TFileWriter {
uint32_t
offset
;
}
TFileWriter
;
// multi reader and single write
typedef
struct
TFileReader
{
T_REF_DECLARE
()
Fst
*
fst
;
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
6a4424b5
...
...
@@ -41,8 +41,11 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval);
static
int
tfileReadLoadHeader
(
TFileReader
*
reader
);
static
int
tfileReadLoadFst
(
TFileReader
*
reader
);
static
int
tfileReadLoadTableIds
(
TFileReader
*
reader
,
int32_t
offset
,
SArray
*
result
);
static
void
tfileReadRef
(
TFileReader
*
reader
);
static
void
tfileReadUnRef
(
TFileReader
*
reader
);
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
);
static
int
tfileRmExpireFile
(
SArray
*
result
);
static
void
tfileDestroyFileName
(
void
*
elem
);
static
int
tfileCompare
(
const
void
*
a
,
const
void
*
b
);
static
int
tfileParseFileName
(
const
char
*
filename
,
uint64_t
*
suid
,
int
*
colId
,
int
*
version
);
...
...
@@ -58,6 +61,8 @@ TFileCache* tfileCacheCreate(const char* path) {
SArray
*
files
=
taosArrayInit
(
4
,
sizeof
(
void
*
));
tfileGetFileList
(
path
,
files
);
taosArraySort
(
files
,
tfileCompare
);
tfileRmExpireFile
(
files
);
uint64_t
suid
;
int32_t
colId
,
version
;
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
files
);
i
++
)
{
...
...
@@ -66,29 +71,29 @@ TFileCache* tfileCacheCreate(const char* path) {
indexInfo
(
"try parse invalid file: %s, skip it"
,
file
);
continue
;
}
WriterCtx
*
wc
=
writerCtxCreate
(
TFile
,
file
,
true
,
1024
*
64
);
if
(
wc
==
NULL
)
{
indexError
(
"failed to open index: %s"
,
file
);
goto
End
;
}
TFileReader
*
reader
=
tfileReaderCreate
(
wc
);
if
(
0
!=
tfileReadLoadHeader
(
reader
))
{
tfileReaderDestroy
(
reader
);
indexError
(
"failed to load index header, index file: %s"
,
file
);
goto
End
;
}
if
(
0
!=
tfileReadLoadFst
(
reader
))
{
tfileReaderDestroy
(
reader
);
indexError
(
"failed to load index fst, index file: %s"
,
file
);
goto
End
;
}
tfileReadRef
(
reader
);
// loader fst and validate it
TFileHeader
*
header
=
&
reader
->
header
;
TFileCacheKey
key
=
{.
suid
=
header
->
suid
,
.
version
=
header
->
version
,
.
colName
=
header
->
colName
,
.
nColName
=
strlen
(
header
->
colName
),
.
colType
=
header
->
colType
};
TFileCacheKey
key
=
{.
suid
=
header
->
suid
,
.
colName
=
header
->
colName
,
.
nColName
=
strlen
(
header
->
colName
),
.
colType
=
header
->
colType
};
char
buf
[
128
]
=
{
0
};
tfileSerialCacheKey
(
&
key
,
buf
);
...
...
@@ -110,7 +115,7 @@ void tfileCacheDestroy(TFileCache* tcache) {
TFileReader
*
p
=
*
reader
;
indexInfo
(
"drop table cache suid: %"
PRIu64
", colName: %s, colType: %d"
,
p
->
header
.
suid
,
p
->
header
.
colName
,
p
->
header
.
colType
);
tfileRead
erDestroy
(
p
);
tfileRead
UnRef
(
p
);
reader
=
taosHashIterate
(
tcache
->
tableCache
,
reader
);
}
taosHashCleanup
(
tcache
->
tableCache
);
...
...
@@ -120,12 +125,24 @@ void tfileCacheDestroy(TFileCache* tcache) {
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
)
{
char
buf
[
128
]
=
{
0
};
tfileSerialCacheKey
(
key
,
buf
);
TFileReader
*
reader
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
tfileReadRef
(
reader
);
return
reader
;
}
void
tfileCachePut
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
,
TFileReader
*
reader
)
{
char
buf
[
128
]
=
{
0
};
tfileSerialCacheKey
(
key
,
buf
);
// remove last version index reader
TFileReader
**
p
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
if
(
*
p
!=
NULL
)
{
TFileReader
*
oldReader
=
*
p
;
taosHashRemove
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
tfileReadUnRef
(
oldReader
);
}
tfileReadRef
(
reader
);
taosHashPut
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
),
&
reader
,
sizeof
(
void
*
));
return
;
}
...
...
@@ -148,24 +165,28 @@ void tfileReaderDestroy(TFileReader* reader) {
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
int
ret
=
-
1
;
// refactor to callback later
if
(
q
uery
->
qT
ype
==
QUERY_TERM
)
{
if
(
q
t
ype
==
QUERY_TERM
)
{
uint64_t
offset
;
FstSlice
key
=
fstSliceCreate
(
term
->
colVal
,
term
->
nColVal
);
if
(
fstGet
(
reader
->
fst
,
&
key
,
&
offset
))
{
return
tfileReadLoadTableIds
(
reader
,
offset
,
result
);
indexInfo
(
"index: %"
PRIu64
", col: %s, colVal: %s, found table info in tindex"
,
term
->
suid
,
term
->
colName
,
term
->
colVal
);
ret
=
tfileReadLoadTableIds
(
reader
,
offset
,
result
);
}
else
{
indexInfo
(
"index: %"
PRIu64
", col: %s, colVal: %s, not found in tindex"
,
term
->
suid
,
term
->
colName
,
term
->
colVal
);
indexInfo
(
"index: %"
PRIu64
", col: %s, colVal: %s, not found
table info
in tindex"
,
term
->
suid
,
term
->
colName
,
term
->
colVal
);
}
return
0
;
}
else
if
(
q
uery
->
qT
ype
==
QUERY_PREFIX
)
{
fstSliceDestroy
(
&
key
)
;
}
else
if
(
q
t
ype
==
QUERY_PREFIX
)
{
// handle later
//
}
else
{
// handle later
}
return
0
;
tfileReadUnRef
(
reader
);
return
ret
;
}
TFileWriter
*
tfileWriterCreate
(
WriterCtx
*
ctx
,
TFileHeader
*
header
)
{
...
...
@@ -209,7 +230,6 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
int32_t
tbsz
=
taosArrayGetSize
(
v
->
tableId
);
fstOffset
+=
TF_TABLE_TATOAL_SIZE
(
tbsz
);
}
// check result or not
tfileWriteFstOffset
(
tw
,
fstOffset
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
...
...
@@ -237,6 +257,7 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
// write reversed data in buf to tindex
tw
->
ctx
->
write
(
tw
->
ctx
,
buf
,
offset
);
}
tfree
(
buf
);
// write fst
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
...
...
@@ -244,11 +265,8 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
TFileValue
*
v
=
taosArrayGetP
((
SArray
*
)
data
,
i
);
if
(
tfileWriteData
(
tw
,
v
)
==
0
)
{
//
//
}
}
tfree
(
buf
);
return
0
;
}
void
tfileWriterDestroy
(
TFileWriter
*
tw
)
{
...
...
@@ -270,17 +288,19 @@ void IndexTFileDestroy(IndexTFile* tfile) {
}
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
if
(
tfile
==
NULL
)
{
return
-
1
;
}
int
ret
=
-
1
;
if
(
tfile
==
NULL
)
{
return
ret
;
}
IndexTFile
*
pTfile
=
(
IndexTFile
*
)
tfile
;
SIndexTerm
*
term
=
query
->
term
;
TFileCacheKey
key
=
{.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
version
=
0
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
TFileCacheKey
key
=
{.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
TFileReader
*
reader
=
tfileCacheGet
(
pTfile
->
cache
,
&
key
);
return
tfileReaderSearch
(
reader
,
query
,
result
);
}
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
TFileWriterOpt
wOpt
=
{.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
,
.
version
=
1
};
// TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName, .version =
// 1};
return
0
;
}
...
...
@@ -310,7 +330,6 @@ static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset) {
}
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
));
...
...
@@ -339,7 +358,6 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) {
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
));
...
...
@@ -368,20 +386,32 @@ static int tfileReadLoadFst(TFileReader* reader) {
static
int
tfileReadLoadTableIds
(
TFileReader
*
reader
,
int32_t
offset
,
SArray
*
result
)
{
int32_t
nid
;
WriterCtx
*
ctx
=
reader
->
ctx
;
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
(
char
*
)
&
nid
,
sizeof
(
nid
),
offset
);
assert
(
sizeof
(
nid
)
==
nread
);
char
*
buf
=
calloc
(
1
,
sizeof
(
uint64_t
)
*
nid
);
int32_t
total
=
sizeof
(
uint64_t
)
*
nid
;
char
*
buf
=
calloc
(
1
,
total
);
if
(
buf
==
NULL
)
{
return
-
1
;
}
nread
=
ctx
->
read
(
ctx
,
buf
,
sizeof
(
uint64_t
)
*
nid
);
uint64_t
*
ids
=
(
uint64_t
*
)
buf
;
nread
=
ctx
->
read
(
ctx
,
buf
,
total
);
assert
(
total
==
nread
);
for
(
int32_t
i
=
0
;
i
<
nid
;
i
++
)
{
taosArrayPush
(
result
,
ids
+
i
);
taosArrayPush
(
result
,
(
uint64_t
*
)
buf
+
i
);
}
free
(
buf
);
return
0
;
}
static
void
tfileReadRef
(
TFileReader
*
reader
)
{
int
ref
=
T_REF_INC
(
reader
);
UNUSED
(
ref
);
}
static
void
tfileReadUnRef
(
TFileReader
*
reader
)
{
int
ref
=
T_REF_DEC
(
reader
);
if
(
ref
==
0
)
{
tfileReaderDestroy
(
reader
);
}
}
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
DIR
*
dir
=
opendir
(
path
);
...
...
@@ -397,6 +427,10 @@ static int tfileGetFileList(const char* path, SArray* result) {
closedir
(
dir
);
return
0
;
}
static
int
tfileRmExpireFile
(
SArray
*
result
)
{
// TODO(yihao): remove expire tindex after restart
return
0
;
}
static
void
tfileDestroyFileName
(
void
*
elem
)
{
char
*
p
=
*
(
char
**
)
elem
;
free
(
p
);
...
...
@@ -423,7 +457,5 @@ static void tfileSerialCacheKey(TFileCacheKey* key, char* buf) {
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录