Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9920b43b
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看板
提交
9920b43b
编写于
12月 31, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix fst bug
上级
2eb0053e
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
127 addition
and
20 deletion
+127
-20
source/libs/index/src/index.c
source/libs/index/src/index.c
+2
-0
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+4
-1
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+2
-2
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+4
-2
source/libs/index/test/fstTest.cc
source/libs/index/test/fstTest.cc
+111
-4
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+4
-11
未找到文件。
source/libs/index/src/index.c
浏览文件 @
9920b43b
...
@@ -360,6 +360,7 @@ static void indexMergeSameKey(SArray* result, TFileValue* tv) {
...
@@ -360,6 +360,7 @@ static void indexMergeSameKey(SArray* result, TFileValue* tv) {
if
(
sz
>
0
)
{
if
(
sz
>
0
)
{
// TODO(yihao): remove duplicate tableid
// TODO(yihao): remove duplicate tableid
TFileValue
*
lv
=
taosArrayGetP
(
result
,
sz
-
1
);
TFileValue
*
lv
=
taosArrayGetP
(
result
,
sz
-
1
);
// indexError("merge colVal: %s", lv->colVal);
if
(
strcmp
(
lv
->
colVal
,
tv
->
colVal
)
==
0
)
{
if
(
strcmp
(
lv
->
colVal
,
tv
->
colVal
)
==
0
)
{
taosArrayAddAll
(
lv
->
tableId
,
tv
->
tableId
);
taosArrayAddAll
(
lv
->
tableId
,
tv
->
tableId
);
tfileValueDestroy
(
tv
);
tfileValueDestroy
(
tv
);
...
@@ -368,6 +369,7 @@ static void indexMergeSameKey(SArray* result, TFileValue* tv) {
...
@@ -368,6 +369,7 @@ static void indexMergeSameKey(SArray* result, TFileValue* tv) {
}
}
}
else
{
}
else
{
taosArrayPush
(
result
,
&
tv
);
taosArrayPush
(
result
,
&
tv
);
// indexError("merge colVal: %s", tv->colVal);
}
}
}
}
static
void
indexDestroyTempResult
(
SArray
*
result
)
{
static
void
indexDestroyTempResult
(
SArray
*
result
)
{
...
...
source/libs/index/src/index_cache.c
浏览文件 @
9920b43b
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MEM_TERM_LIMIT 10
000 * 1
0
#define MEM_TERM_LIMIT 10
* 1000
0
// ref index_cache.h:22
// ref index_cache.h:22
//#define CACHE_KEY_LEN(p) \
//#define CACHE_KEY_LEN(p) \
// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) +
// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) +
...
@@ -353,6 +353,9 @@ static bool indexCacheIteratorNext(Iterate* itera) {
...
@@ -353,6 +353,9 @@ static bool indexCacheIteratorNext(Iterate* itera) {
SSkipListIterator
*
iter
=
itera
->
iter
;
SSkipListIterator
*
iter
=
itera
->
iter
;
if
(
iter
==
NULL
)
{
return
false
;
}
if
(
iter
==
NULL
)
{
return
false
;
}
IterateValue
*
iv
=
&
itera
->
val
;
IterateValue
*
iv
=
&
itera
->
val
;
if
(
iv
->
colVal
!=
NULL
&&
iv
->
val
!=
NULL
)
{
// indexError("value in cache: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val));
}
iterateValueDestroy
(
iv
,
false
);
iterateValueDestroy
(
iv
,
false
);
bool
next
=
tSkipListIterNext
(
iter
);
bool
next
=
tSkipListIterNext
(
iter
);
...
...
source/libs/index/src/index_fst.c
浏览文件 @
9920b43b
...
@@ -319,7 +319,7 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) {
...
@@ -319,7 +319,7 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) {
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
uint8_t
val
;
uint8_t
val
;
COMMON_INDEX
(
inp
,
0
x
111111
,
val
);
COMMON_INDEX
(
inp
,
0
b
111111
,
val
);
s
->
val
=
(
s
->
val
&
fstStateDict
[
s
->
state
].
val
)
|
val
;
s
->
val
=
(
s
->
val
&
fstStateDict
[
s
->
state
].
val
)
|
val
;
}
}
...
@@ -369,7 +369,7 @@ uint8_t fstStateInput(FstState* s, FstNode* node) {
...
@@ -369,7 +369,7 @@ uint8_t fstStateInput(FstState* s, FstNode* node) {
bool
null
=
false
;
bool
null
=
false
;
uint8_t
inp
=
fstStateCommInput
(
s
,
&
null
);
uint8_t
inp
=
fstStateCommInput
(
s
,
&
null
);
uint8_t
*
data
=
fstSliceData
(
slice
,
NULL
);
uint8_t
*
data
=
fstSliceData
(
slice
,
NULL
);
return
null
==
false
?
inp
:
data
[
-
1
];
return
null
==
false
?
inp
:
data
[
node
->
start
-
1
];
}
}
uint8_t
fstStateInputForAnyTrans
(
FstState
*
s
,
FstNode
*
node
,
uint64_t
i
)
{
uint8_t
fstStateInputForAnyTrans
(
FstState
*
s
,
FstNode
*
node
,
uint64_t
i
)
{
assert
(
s
->
state
==
AnyTrans
);
assert
(
s
->
state
==
AnyTrans
);
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
9920b43b
...
@@ -385,8 +385,10 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
...
@@ -385,8 +385,10 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
}
}
static
bool
tfileIteratorNext
(
Iterate
*
iiter
)
{
static
bool
tfileIteratorNext
(
Iterate
*
iiter
)
{
IterateValue
*
iv
=
&
iiter
->
val
;
IterateValue
*
iv
=
&
iiter
->
val
;
if
(
iv
->
colVal
!=
NULL
&&
iv
->
val
!=
NULL
)
{
// indexError("value in fst: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val));
}
iterateValueDestroy
(
iv
,
false
);
iterateValueDestroy
(
iv
,
false
);
// SArray* tblIds = iv->val;
char
*
colVal
=
NULL
;
char
*
colVal
=
NULL
;
uint64_t
offset
=
0
;
uint64_t
offset
=
0
;
...
@@ -406,7 +408,7 @@ static bool tfileIteratorNext(Iterate* iiter) {
...
@@ -406,7 +408,7 @@ static bool tfileIteratorNext(Iterate* iiter) {
if
(
tfileReaderLoadTableIds
(
tIter
->
rdr
,
offset
,
iv
->
val
)
!=
0
)
{
return
false
;
}
if
(
tfileReaderLoadTableIds
(
tIter
->
rdr
,
offset
,
iv
->
val
)
!=
0
)
{
return
false
;
}
iv
->
colVal
=
colVal
;
iv
->
colVal
=
colVal
;
return
true
;
// std::string key(ch, sz);
// std::string key(ch, sz);
}
}
...
...
source/libs/index/test/fstTest.cc
浏览文件 @
9920b43b
...
@@ -24,8 +24,13 @@ class FstWriter {
...
@@ -24,8 +24,13 @@ class FstWriter {
_b
=
fstBuilderCreate
(
_wc
,
0
);
_b
=
fstBuilderCreate
(
_wc
,
0
);
}
}
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
// char buf[128] = {0};
// int len = 0;
// taosMbsToUcs4(key.c_str(), key.size(), buf, 128, &len);
// FstSlice skey = fstSliceCreate((uint8_t*)buf, len);
FstSlice
skey
=
fstSliceCreate
((
uint8_t
*
)
key
.
c_str
(),
key
.
size
());
FstSlice
skey
=
fstSliceCreate
((
uint8_t
*
)
key
.
c_str
(),
key
.
size
());
bool
ok
=
fstBuilderInsert
(
_b
,
skey
,
val
);
bool
ok
=
fstBuilderInsert
(
_b
,
skey
,
val
);
fstSliceDestroy
(
&
skey
);
fstSliceDestroy
(
&
skey
);
return
ok
;
return
ok
;
}
}
...
@@ -61,6 +66,11 @@ class FstReadMemory {
...
@@ -61,6 +66,11 @@ class FstReadMemory {
return
_fst
!=
NULL
;
return
_fst
!=
NULL
;
}
}
bool
Get
(
const
std
::
string
&
key
,
uint64_t
*
val
)
{
bool
Get
(
const
std
::
string
&
key
,
uint64_t
*
val
)
{
// char buf[128] = {0};
// int len = 0;
// taosMbsToUcs4(key.c_str(), key.size(), buf, 128, &len);
// FstSlice skey = fstSliceCreate((uint8_t*)buf, len);
FstSlice
skey
=
fstSliceCreate
((
uint8_t
*
)
key
.
c_str
(),
key
.
size
());
FstSlice
skey
=
fstSliceCreate
((
uint8_t
*
)
key
.
c_str
(),
key
.
size
());
bool
ok
=
fstGet
(
_fst
,
&
skey
,
val
);
bool
ok
=
fstGet
(
_fst
,
&
skey
,
val
);
fstSliceDestroy
(
&
skey
);
fstSliceDestroy
(
&
skey
);
...
@@ -135,15 +145,109 @@ int Performance_fstWriteRecords(FstWriter* b) {
...
@@ -135,15 +145,109 @@ int Performance_fstWriteRecords(FstWriter* b) {
}
}
return
L
*
M
*
N
;
return
L
*
M
*
N
;
}
}
void
Performance_fstReadRecords
(
FstReadMemory
*
m
)
{
std
::
string
str
(
"aa"
);
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
str
[
0
]
=
'a'
+
i
;
str
.
resize
(
2
);
for
(
int
j
=
0
;
j
<
N
;
j
++
)
{
str
[
1
]
=
'a'
+
j
;
str
.
resize
(
2
);
for
(
int
k
=
0
;
k
<
L
;
k
++
)
{
str
.
push_back
(
'a'
);
uint64_t
val
,
cost
;
if
(
m
->
GetWithTimeCostUs
(
str
,
&
val
,
&
cost
))
{
printf
(
"succes to get kv(%s, %"
PRId64
"), cost: %"
PRId64
"
\n
"
,
str
.
c_str
(),
val
,
cost
);
}
else
{
printf
(
"failed to get key: %s
\n
"
,
str
.
c_str
());
}
}
}
}
}
void
checkMillonWriteAndReadOfFst
()
{
tfInit
();
FstWriter
*
fw
=
new
FstWriter
;
Performance_fstWriteRecords
(
fw
);
delete
fw
;
FstReadMemory
*
fr
=
new
FstReadMemory
(
1024
*
64
*
1024
);
if
(
fr
->
init
())
{
printf
(
"success to init fst read"
);
}
Performance_fstReadRecords
(
fr
);
tfCleanup
();
delete
fr
;
}
void
checkFstLongTerm
()
{
tfInit
();
FstWriter
*
fw
=
new
FstWriter
;
// Performance_fstWriteRecords(fw);
fw
->
Put
(
"A B"
,
1
);
fw
->
Put
(
"C"
,
2
);
fw
->
Put
(
"a"
,
3
);
delete
fw
;
FstReadMemory
*
m
=
new
FstReadMemory
(
1024
*
64
);
if
(
m
->
init
()
==
false
)
{
std
::
cout
<<
"init readMemory failed"
<<
std
::
endl
;
delete
m
;
return
;
}
{
uint64_t
val
=
0
;
if
(
m
->
Get
(
"A B"
,
&
val
))
{
std
::
cout
<<
"success to Get: "
<<
val
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"failed to Get:"
<<
val
<<
std
::
endl
;
}
}
{
uint64_t
val
=
0
;
if
(
m
->
Get
(
"C"
,
&
val
))
{
std
::
cout
<<
"success to Get: "
<<
val
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"failed to Get:"
<<
val
<<
std
::
endl
;
}
}
{
uint64_t
val
=
0
;
if
(
m
->
Get
(
"a"
,
&
val
))
{
std
::
cout
<<
"success to Get: "
<<
val
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"failed to Get:"
<<
val
<<
std
::
endl
;
}
}
// prefix search
// std::vector<uint64_t> result;
// AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
// m->Search(ctx, result);
// std::cout << "size: " << result.size() << std::endl;
// assert(result.size() == count);
// for (int i = 0; i < result.size(); i++) {
// assert(result[i] == i); // check result
//}
tfCleanup
();
// free(ctx);
// delete m;
}
void
checkFstCheckIterator
()
{
void
checkFstCheckIterator
()
{
tfInit
();
tfInit
();
FstWriter
*
fw
=
new
FstWriter
;
FstWriter
*
fw
=
new
FstWriter
;
int64_t
s
=
taosGetTimestampUs
();
int64_t
s
=
taosGetTimestampUs
();
int
count
=
2
;
int
count
=
2
;
Performance_fstWriteRecords
(
fw
);
//
Performance_fstWriteRecords(fw);
int64_t
e
=
taosGetTimestampUs
();
int64_t
e
=
taosGetTimestampUs
();
std
::
cout
<<
"insert data count : "
<<
count
<<
"elapas time: "
<<
e
-
s
<<
std
::
endl
;
std
::
cout
<<
"insert data count : "
<<
count
<<
"elapas time: "
<<
e
-
s
<<
std
::
endl
;
fw
->
Put
(
"Hello world"
,
1
);
fw
->
Put
(
"hello world"
,
2
);
fw
->
Put
(
"hello worle"
,
3
);
fw
->
Put
(
"hello worlf"
,
4
);
delete
fw
;
delete
fw
;
FstReadMemory
*
m
=
new
FstReadMemory
(
1024
*
64
);
FstReadMemory
*
m
=
new
FstReadMemory
(
1024
*
64
);
...
@@ -171,7 +275,7 @@ void checkFstCheckIterator() {
...
@@ -171,7 +275,7 @@ void checkFstCheckIterator() {
void
fst_get
(
Fst
*
fst
)
{
void
fst_get
(
Fst
*
fst
)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
std
::
string
term
=
"Hello"
;
std
::
string
term
=
"Hello
World
"
;
FstSlice
key
=
fstSliceCreate
((
uint8_t
*
)
term
.
c_str
(),
term
.
size
());
FstSlice
key
=
fstSliceCreate
((
uint8_t
*
)
term
.
c_str
(),
term
.
size
());
uint64_t
offset
=
0
;
uint64_t
offset
=
0
;
bool
ret
=
fstGet
(
fst
,
&
key
,
&
offset
);
bool
ret
=
fstGet
(
fst
,
&
key
,
&
offset
);
...
@@ -189,7 +293,7 @@ void validateTFile(char* arg) {
...
@@ -189,7 +293,7 @@ void validateTFile(char* arg) {
std
::
thread
threads
[
NUM_OF_THREAD
];
std
::
thread
threads
[
NUM_OF_THREAD
];
// std::vector<std::thread> threads;
// std::vector<std::thread> threads;
TFileReader
*
reader
=
tfileReaderOpen
(
arg
,
0
,
295868
,
"tag1"
);
TFileReader
*
reader
=
tfileReaderOpen
(
arg
,
0
,
999992
,
"tag1"
);
for
(
int
i
=
0
;
i
<
NUM_OF_THREAD
;
i
++
)
{
for
(
int
i
=
0
;
i
<
NUM_OF_THREAD
;
i
++
)
{
threads
[
i
]
=
std
::
thread
(
fst_get
,
reader
->
fst
);
threads
[
i
]
=
std
::
thread
(
fst_get
,
reader
->
fst
);
...
@@ -203,9 +307,12 @@ void validateTFile(char* arg) {
...
@@ -203,9 +307,12 @@ void validateTFile(char* arg) {
tfCleanup
();
tfCleanup
();
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
>
1
)
{
validateTFile
(
argv
[
1
]);
}
// tool to check all kind of fst test
// if (argc > 1) { validateTFile(argv[1]); }
// checkFstCheckIterator();
// checkFstCheckIterator();
// checkFstLongTerm();
// checkFstPrefixSearch();
// checkFstPrefixSearch();
checkMillonWriteAndReadOfFst
();
return
1
;
return
1
;
}
}
source/libs/index/test/indexTests.cc
浏览文件 @
9920b43b
...
@@ -787,14 +787,15 @@ TEST_F(IndexEnv2, testIndexOpen) {
...
@@ -787,14 +787,15 @@ TEST_F(IndexEnv2, testIndexOpen) {
}
}
TEST_F
(
IndexEnv2
,
testIndex_TrigeFlush
)
{
TEST_F
(
IndexEnv2
,
testIndex_TrigeFlush
)
{
std
::
string
path
=
"/tmp/test"
;
std
::
string
path
=
"/tmp/test
1
"
;
if
(
index
->
Init
(
path
)
!=
0
)
{
if
(
index
->
Init
(
path
)
!=
0
)
{
// r
// r
std
::
cout
<<
"failed to init"
<<
std
::
endl
;
std
::
cout
<<
"failed to init"
<<
std
::
endl
;
}
}
int
numOfTable
=
100
*
10000
;
int
numOfTable
=
100
*
10000
;
index
->
WriteMillonData
(
"tag1"
,
"Hello"
,
numOfTable
);
index
->
WriteMillonData
(
"tag1"
,
"Hello Wolrd"
,
numOfTable
);
int
target
=
index
->
SearchOne
(
"tag1"
,
"Hello"
);
int
target
=
index
->
SearchOne
(
"tag1"
,
"Hello Wolrd"
);
std
::
cout
<<
"Get Index: "
<<
target
<<
std
::
endl
;
assert
(
numOfTable
==
target
);
assert
(
numOfTable
==
target
);
}
}
...
@@ -821,14 +822,6 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
...
@@ -821,14 +822,6 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
threads
[
i
].
join
();
threads
[
i
].
join
();
}
}
}
}
TEST_F
(
IndexEnv2
,
testIndex_multi_thread_write
)
{
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
TEST_F
(
IndexEnv2
,
testIndex_multi_thread_read
)
{
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
TEST_F
(
IndexEnv2
,
testIndex_restart
)
{
TEST_F
(
IndexEnv2
,
testIndex_restart
)
{
std
::
string
path
=
"/tmp"
;
std
::
string
path
=
"/tmp"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录