Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f074a4b3
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f074a4b3
编写于
12月 18, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update cache put
上级
c5178062
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
116 addition
and
40 deletion
+116
-40
cmake/cmake.options
cmake/cmake.options
+1
-1
include/libs/index/index.h
include/libs/index/index.h
+1
-1
source/libs/index/CMakeLists.txt
source/libs/index/CMakeLists.txt
+5
-1
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+2
-2
source/libs/index/src/index.c
source/libs/index/src/index.c
+28
-26
source/libs/index/test/CMakeLists.txt
source/libs/index/test/CMakeLists.txt
+1
-1
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+78
-8
未找到文件。
cmake/cmake.options
浏览文件 @
f074a4b3
...
...
@@ -57,7 +57,7 @@ option(
)
option(
USE
_INVERTEDINDEX
BUILD_WITH
_INVERTEDINDEX
"If use invertedIndex"
ON
)
include/libs/index/index.h
浏览文件 @
f074a4b3
...
...
@@ -51,7 +51,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, SIndexTerm
* @param:
* @param:
*/
SIndex
*
indexOpen
(
SIndexOpts
*
opt
,
const
char
*
path
);
int
indexOpen
(
SIndexOpts
*
opt
,
const
char
*
path
,
SIndex
**
index
);
void
indexClose
(
SIndex
*
index
);
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
terms
,
int
uid
);
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
);
...
...
source/libs/index/CMakeLists.txt
浏览文件 @
f074a4b3
...
...
@@ -22,9 +22,13 @@ if (${BUILD_WITH_LUCENE})
index
PUBLIC lucene++
)
endif
(
${
BUILD_WITH_LUCENE
}
)
if
(
${
BUILD_WITH_INVERTEDINDEX
}
)
add_definitions
(
-DUSE_INVERTED_INDEX
)
endif
(
${
BUILD_WITH_INVERTEDINDEX
}
)
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
endif
(
${
BUILD_TEST
}
)
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
f074a4b3
...
...
@@ -37,10 +37,10 @@ struct SIndex {
#endif
void
*
cache
;
void
*
tindex
;
SHashObj
*
field
Obj
;
// < field name, field id>
SHashObj
*
col
Obj
;
// < field name, field id>
int64_t
suid
;
// current super table id, -1 is normal table
int
field
Id
;
// field id allocated to cache
int
col
Id
;
// field id allocated to cache
int32_t
cVersion
;
// current version allocated to cache
pthread_mutex_t
mtx
;
};
...
...
source/libs/index/src/index.c
浏览文件 @
f074a4b3
...
...
@@ -22,11 +22,10 @@
#endif
typedef
struct
SIdx
Field
Info
{
int
field
Id
;
// generated by index internal
typedef
struct
SIdx
Col
Info
{
int
col
Id
;
// generated by index internal
int
cVersion
;
int
type
;
// field type
}
SIdxFieldInfo
;
}
SIdxColInfo
;
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
static
void
indexInit
();
...
...
@@ -38,9 +37,10 @@ static int indexMergeCacheIntoTindex(struct SIndex *sIdx) {
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
return
0
;
}
SIndex
*
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
)
{
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
pthread_once
(
&
isInit
,
indexInit
);
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
#ifdef USE_LUCENE
index_t
*
index
=
index_open
(
path
);
...
...
@@ -49,11 +49,13 @@ SIndex *indexOpen(SIndexOpts *opts, const char *path) {
sIdx
->
cache
=
(
void
*
)
indexCacheCreate
();
sIdx
->
tindex
=
NULL
;
sIdx
->
field
Obj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
field
Id
=
1
;
sIdx
->
col
Obj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
col
Id
=
1
;
sIdx
->
cVersion
=
1
;
pthread_mutex_init
(
&
sIdx
->
mtx
,
NULL
);
return
sIdx
;
*
index
=
sIdx
;
return
0
;
}
void
indexClose
(
SIndex
*
sIdx
)
{
...
...
@@ -62,16 +64,16 @@ void indexClose(SIndex *sIdx) {
sIdx
->
index
=
NULL
;
#endif
#ifdef USE_INVERTEDINDEX
#ifdef USE_INVERTED
_
INDEX
indexCacheDestroy
(
sIdx
->
cache
);
taosHashCleanup
(
sIdx
->
field
Obj
);
taosHashCleanup
(
sIdx
->
col
Obj
);
pthread_mutex_destroy
(
&
sIdx
->
mtx
);
#endif
free
(
sIdx
);
return
;
}
int
indexPut
(
SIndex
*
index
,
S
Array
*
fVals
,
int
uid
)
{
int
indexPut
(
SIndex
*
index
,
S
IndexMultiTerm
*
fVals
,
int
uid
)
{
#ifdef USE_LUCENE
index_document_t
*
doc
=
index_document_create
();
...
...
@@ -89,38 +91,38 @@ int indexPut(SIndex *index, SArray* fVals, int uid) {
index_document_destroy
(
doc
);
#endif
#ifdef USE_INVERTEDINDEX
#ifdef USE_INVERTED_INDEX
//TODO(yihao): reduce the lock range
pthread_mutex_lock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIdx
FieldInfo
*
fi
=
taosHashGet
(
index
->
fieldObj
,
p
->
key
,
p
->
nKey
);
SIdx
ColInfo
*
fi
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
if
(
fi
==
NULL
)
{
SIdx
FieldInfo
tfi
=
{.
fieldId
=
index
->
fieldId
,
.
type
=
p
->
type
};
SIdx
ColInfo
tfi
=
{.
colId
=
index
->
colId
};
index
->
cVersion
++
;
index
->
field
Id
++
;
taosHashPut
(
index
->
fieldObj
,
p
->
key
,
p
->
nKey
,
&
tfi
,
sizeof
(
tfi
));
index
->
col
Id
++
;
taosHashPut
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
,
&
tfi
,
sizeof
(
tfi
));
}
else
{
//TODO, del
}
}
pthread_mutex_unlock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIdx
FieldInfo
*
fi
=
taosHashGet
(
index
->
fieldObj
,
p
->
key
,
p
->
nKey
);
SIdx
ColInfo
*
fi
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
assert
(
fi
!=
NULL
);
int32_t
fieldId
=
fi
->
fieldId
;
int32_t
fieldType
=
fi
->
type
;
int32_t
colId
=
fi
->
colId
;
int32_t
version
=
index
->
cVersion
;
int
re
s
=
indexCachePut
(
index
->
cache
,
fieldId
,
fieldType
,
p
->
val
,
p
->
n
Val
,
version
,
uid
,
p
->
operType
);
int
re
t
=
indexCachePut
(
index
->
cache
,
colId
,
p
->
colType
,
p
->
colVal
,
p
->
nCol
Val
,
version
,
uid
,
p
->
operType
);
if
(
ret
!=
0
)
{
return
return
ret
;
}
}
pthread_mutex_unlock
(
&
index
->
mtx
);
#endif
return
1
;
return
0
;
}
int
indexSearch
(
SIndex
*
index
,
SIndexMultiTermQuery
*
multiQuerys
,
SArray
*
result
)
{
#ifdef USE_LUCENE
...
...
@@ -159,7 +161,7 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
free
(
types
);
#endif
#ifdef USE_INVERTEDINDEX
#ifdef USE_INVERTED
_
INDEX
#endif
return
1
;
...
...
@@ -167,13 +169,13 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
)
{
#ifdef USE_INVERTEDINDEX
#ifdef USE_INVERTED
_
INDEX
#endif
return
1
;
}
int
indexRebuild
(
SIndex
*
index
,
SIndexOpts
*
opts
)
{
#ifdef USE_INVERTEDINDEX
#ifdef USE_INVERTED
_
INDEX
#endif
}
...
...
source/libs/index/test/CMakeLists.txt
浏览文件 @
f074a4b3
add_executable
(
indexTest
""
)
target_sources
(
indexTest
PRIVATE
"indexTests.c
pp
"
"indexTests.c
c
"
)
target_include_directories
(
indexTest
PUBLIC
...
...
source/libs/index/test/indexTests.c
pp
→
source/libs/index/test/indexTests.c
c
浏览文件 @
f074a4b3
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <string>
#include <iostream>
...
...
@@ -61,7 +75,7 @@ class FstReadMemory {
// add later
bool
Search
(
AutomationCtx
*
ctx
,
std
::
vector
<
uint64_t
>
&
result
)
{
FstStreamBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
StreamWithState
*
st
=
streamBuilderIntoStream
(
sb
);
StreamWithState
*
st
=
streamBuilderIntoStream
(
sb
);
StreamWithStateResult
*
rt
=
NULL
;
while
((
rt
=
streamWithStateNextWith
(
st
,
NULL
))
!=
NULL
)
{
...
...
@@ -279,15 +293,71 @@ void validateFst() {
delete
m
;
}
class
IndexEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
taosRemoveDir
(
path
);
opts
=
indexOptsCreate
();
int
ret
=
indexOpen
(
opts
,
path
,
&
index
);
assert
(
ret
==
0
);
}
virtual
void
TearDown
()
{
indexClose
(
index
);
indexOptsDestroy
(
opts
);
}
const
char
*
path
=
"/tmp/tindex"
;
SIndexOpts
*
opts
;
SIndex
*
index
;
};
TEST_F
(
IndexEnv
,
testPut
)
{
// single index column
{
std
::
string
colName
(
"tag1"
),
colVal
(
"Hello world"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
indexMultiTermAdd
(
terms
,
term
);
for
(
size_t
i
=
0
;
i
<
100
;
i
++
)
{
int
tableId
=
i
;
int
ret
=
indexPut
(
index
,
terms
,
tableId
);
assert
(
ret
==
0
);
}
indexMultiTermDestroy
(
terms
);
}
// multi index column
{
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
{
std
::
string
colName
(
"tag1"
),
colVal
(
"Hello world"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
indexMultiTermAdd
(
terms
,
term
);
}
{
std
::
string
colName
(
"tag2"
),
colVal
(
"Hello world"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
indexMultiTermAdd
(
terms
,
term
);
}
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
int
tableId
=
i
;
int
ret
=
indexPut
(
index
,
terms
,
tableId
);
assert
(
ret
==
0
);
}
indexMultiTermDestroy
(
terms
);
}
//
}
int
main
(
int
argc
,
char
**
argv
)
{
checkFstPerf
();
//checkFstPrefixSearch();
return
1
;
TEST_F
(
IndexEnv
,
testDel
)
{
}
//TEST(IndexFstBuilder, IndexFstInput) {
//
//}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录